Skip to content

Commit

Permalink
Gravity: Add base DAO test class with assert for matching formatted S…
Browse files Browse the repository at this point in the history
…QL strings

Reviewed at https://reviews.lunr.nl/r/938/
  • Loading branch information
pprkut committed Mar 30, 2023
1 parent 5a0dd7f commit bc574a3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

use Lunr\Gravity\Database\MySQL\MySQLDMLQueryBuilder;
use Lunr\Gravity\Database\MySQL\MySQLQueryEscaper;
use Lunr\Halo\LunrBaseTest;
use Lunr\Gravity\Database\Tests\Helpers\DatabaseAccessObjectBaseTest;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionClass;

/**
* This class contains setup and tear down methods for DAOs using MySQL access.
*/
abstract class AbstractMySQLDatabaseAccessObjectTest extends LunrBaseTest
abstract class AbstractMySQLDatabaseAccessObjectTest extends DatabaseAccessObjectBaseTest
{

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

use Lunr\Gravity\Database\MySQL\MySQLDMLQueryBuilder;
use Lunr\Gravity\Database\MySQL\MySQLQueryEscaper;
use Lunr\Halo\LunrBaseTest;
use Lunr\Gravity\Database\Tests\Helpers\DatabaseAccessObjectBaseTest;
use ReflectionClass;

/**
* This class contains setup and tear down methods for DAOs using MySQL access.
*/
abstract class MySQLDatabaseAccessObjectTest extends LunrBaseTest
abstract class MySQLDatabaseAccessObjectTest extends DatabaseAccessObjectBaseTest
{

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* This file contains the DatabaseAccessObjectBaseTest class.
*
* @package Lunr\Gravity
* @author Heinz Wiesinger <[email protected]>
* @copyright 2023, Move Agency B.V., Zwolle, The Netherlands
* @license http://lunr.nl/LICENSE MIT License
*/

namespace Lunr\Gravity\Database\Tests\Helpers;

use Lunr\Halo\LunrBaseTest;

/**
* This class contains setup and tear down methods for DAOs using MySQL access.
*/
abstract class DatabaseAccessObjectBaseTest extends LunrBaseTest
{

/**
* Testcase Destructor.
*/
public function tearDown(): void
{
parent::tearDown();
}

/**
* Reports an error if the value of $actualSql does not match the value in $expectedFile.
*
* @param string $expectedFile File containing the (optionally pretty-printed) expected SQL query
* @param string $actualSql The actual SQL query string
*
* @return void
*/
public function assertSqlStringEqualsSqlFile($expectedFile, $actualSql): void
{
$formatted = file_get_contents($expectedFile);
$formatted = trim(preg_replace('/\s+/', ' ', $formatted));
$formatted = str_replace('( ', '(', $formatted);
$formatted = str_replace(' )', ')', $formatted);

$this->assertEquals($formatted, $actualSql);
}

}

?>

0 comments on commit bc574a3

Please sign in to comment.