From 2d80d8ea157c6fad6d7f42cdf127698d8e770ecd Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 17 Mar 2023 16:00:56 -0400 Subject: [PATCH] Cleanup a bunch of Simpletest weirdness from the tests --- build/phpunit.xml | 2 +- composer.json | 4 +- tests/BaseDriverTest.php | 6 +- tests/BaseQueryBuilderTest.php | 10 +- tests/{TestCase.php => BaseTestCase.php} | 56 ++++---- tests/ConnectionManagerTest.php | 8 +- tests/CoreTest.php | 4 +- tests/Drivers/SQLite/SQLiteDriverTest.php | 6 +- tests/QueryParserTest.php | 10 +- tests/bootstrap.php | 2 +- tests/index.php | 164 ---------------------- 11 files changed, 51 insertions(+), 221 deletions(-) rename tests/{TestCase.php => BaseTestCase.php} (54%) delete mode 100644 tests/index.php diff --git a/build/phpunit.xml b/build/phpunit.xml index 1b1e6b2..46c4334 100644 --- a/build/phpunit.xml +++ b/build/phpunit.xml @@ -1,5 +1,5 @@ - + ./../src/ diff --git a/composer.json b/composer.json index 3604016..aa6b063 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "ext-pdo": "*" }, "require-dev": { - "phpunit/phpunit": "^9.4" + "phpunit/phpunit": "^10.0.16" }, "autoload": { "psr-4": { @@ -51,7 +51,7 @@ "build": "tools/vendor/bin/robo build", "clean": "tools/vendor/bin/robo clean", "docs": "php tools/phpDocumentor run --sourcecode", - "coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build", + "coverage": "php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude=\"~vendor~\" ./vendor/bin/phpunit -c build", "pcov": "vendor/bin/phpunit -c build", "phpstan": "tools/vendor/bin/phpstan analyse -l 3 -c phpstan.neon src tests", "test": "phpunit -c build --no-coverage" diff --git a/tests/BaseDriverTest.php b/tests/BaseDriverTest.php index ba4e72e..4997c24 100644 --- a/tests/BaseDriverTest.php +++ b/tests/BaseDriverTest.php @@ -21,7 +21,7 @@ use Query\QueryBuilderInterface; /** * Parent Database Test Class */ -abstract class BaseDriverTest extends TestCase +abstract class BaseDriverTest extends BaseTestCase { /** * @var QueryBuilderInterface|null @@ -80,7 +80,7 @@ abstract class BaseDriverTest extends TestCase ]]; $keys = self::$db->getFks('testconstraints2'); - $this->assertEqual($expected, $keys); + $this->assertEquals($expected, $keys); } public function testGetIndexes(): void @@ -119,7 +119,7 @@ abstract class BaseDriverTest extends TestCase $expected = ['newtable_seq']; $this->assertIsArray($seqs); - $this->assertEqual($expected, $seqs); + $this->assertEquals($expected, $seqs); } public function testGetProcedures(): void diff --git a/tests/BaseQueryBuilderTest.php b/tests/BaseQueryBuilderTest.php index c03f59d..e67fa25 100644 --- a/tests/BaseQueryBuilderTest.php +++ b/tests/BaseQueryBuilderTest.php @@ -24,7 +24,7 @@ use Query\QueryBuilderInterface; /** * Query builder parent test class */ -abstract class BaseQueryBuilderTest extends TestCase +abstract class BaseQueryBuilderTest extends BaseTestCase { /** * @var QueryBuilderInterface|null @@ -91,7 +91,7 @@ abstract class BaseQueryBuilderTest extends TestCase $query = self::$db->get('test'); $numrows = count($query->fetchAll(PDO::FETCH_NUM)); - $this->assertEqual(self::$db->numRows(), $numrows); + $this->assertEquals(self::$db->numRows(), $numrows); } public function testGetLimit(): void @@ -583,7 +583,7 @@ abstract class BaseQueryBuilderTest extends TestCase $row = $query->fetch(PDO::FETCH_ASSOC); $this->assertIsA($query, 'PDOStatement'); - $this->assertEqual([ + $this->assertEquals([ 'id' => 99, 'key' => 84, 'val' => 120, @@ -647,7 +647,7 @@ abstract class BaseQueryBuilderTest extends TestCase $this->assertIsA($query, 'PDOStatement'); $row = $query->fetch(PDO::FETCH_ASSOC); - $this->assertEqual([ + $this->assertEquals([ 'key' => 'gogle', ], $row, json_encode($query->errorInfo())); @@ -840,6 +840,6 @@ abstract class BaseQueryBuilderTest extends TestCase ])->insert('test'); $res = self::$db->numRows(); - $this->assertEqual(NULL, $res); + $this->assertNull($res); } } diff --git a/tests/TestCase.php b/tests/BaseTestCase.php similarity index 54% rename from tests/TestCase.php rename to tests/BaseTestCase.php index 4de4100..172ecbf 100644 --- a/tests/TestCase.php +++ b/tests/BaseTestCase.php @@ -13,35 +13,31 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests; -use PHPUnit\Framework\TestCase as PHPUnit_TestCase; +use PHPUnit\Framework\TestCase; /** * Base class for TestCases */ -class TestCase extends PHPUnit_TestCase { - +abstract class BaseTestCase extends TestCase +{ /** * Wrapper for Simpletest's assertEqual * * @param mixed $expected * @param mixed $actual - * @param string $message */ - public function assertEqual($expected, $actual, $message='') - { - $this->assertEquals($expected, $actual, $message); - } +// public function assertEqual($expected, $actual, $message='') +// { +// $this->assertEquals($expected, $actual, $message); +// } /** * Wrapper for SimpleTest's assertIsA - * - * @param mixed $object - * @param string $type - * @param string $message */ - public function assertIsA($object, $type, $message='') + public function assertIsA(mixed $object, string $type, string $message='') { $this->assertTrue(is_a($object, $type), $message); } @@ -53,20 +49,20 @@ class TestCase extends PHPUnit_TestCase { * @param mixed $second * @param string $message */ - public function assertReference($first, $second, $message='') - { - if (\is_object($first)) - { - $res = ($first === $second); - } - else - { - $temp = $first; - $first = uniqid('test', TRUE); - $isRef = ($first === $second); - $first = $temp; - $res = $isRef; - } - $this->assertTrue($res, $message); - } -} \ No newline at end of file +// public function assertReference($first, $second, $message='') +// { +// if (\is_object($first)) +// { +// $res = ($first === $second); +// } +// else +// { +// $temp = $first; +// $first = uniqid('test', TRUE); +// $isRef = ($first === $second); +// $first = $temp; +// $res = $isRef; +// } +// $this->assertTrue($res, $message); +// } +} diff --git a/tests/ConnectionManagerTest.php b/tests/ConnectionManagerTest.php index 02a903e..33c6141 100644 --- a/tests/ConnectionManagerTest.php +++ b/tests/ConnectionManagerTest.php @@ -19,7 +19,7 @@ namespace Query\Tests; use DomainException; use Query\{ConnectionManager, QueryBuilderInterface}; -class ConnectionManagerTest extends TestCase +class ConnectionManagerTest extends BaseTestCase { protected static $instance; @@ -77,7 +77,7 @@ class ConnectionManagerTest extends TestCase ['foo' => 'bar'], ]; - $this->assertEqual($expected, self::$instance->parseParams($params)); + $this->assertEquals($expected, self::$instance->parseParams($params)); } public function testConnect(): void @@ -94,7 +94,7 @@ class ConnectionManagerTest extends TestCase $conn = self::$instance->connect($params); // Check that the connection just made is returned from the get_connection method - $this->assertEqual($conn, self::$instance->getConnection()); + $this->assertEquals($conn, self::$instance->getConnection()); } public function testGetConnection(): void @@ -111,7 +111,7 @@ class ConnectionManagerTest extends TestCase $conn = self::$instance->connect($params); - $this->assertEqual($conn, self::$instance->getConnection('conn_manager')); + $this->assertEquals($conn, self::$instance->getConnection('conn_manager')); } } // End of connection_manager_test.php diff --git a/tests/CoreTest.php b/tests/CoreTest.php index be5f9fe..57b7e35 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -22,10 +22,8 @@ use function regexInArray; /** * CoreTest class - Compatibility and core functionality tests - * - * @extends UnitTestCase */ -class CoreTest extends TestCase +class CoreTest extends BaseTestCase { /** * TestHasPDO function. diff --git a/tests/Drivers/SQLite/SQLiteDriverTest.php b/tests/Drivers/SQLite/SQLiteDriverTest.php index c3ba987..3bf1357 100644 --- a/tests/Drivers/SQLite/SQLiteDriverTest.php +++ b/tests/Drivers/SQLite/SQLiteDriverTest.php @@ -79,7 +79,7 @@ INSERT INTO "create_test" ("id","key","val") VALUES (587,1,2); INSERT INTO "create_test" ("id","key","val") VALUES (999,'''ring''','''sale'''); SQL; $expectedArray = explode("\n", $expected); - $this->assertEqual($expectedArray, $sqlArray); + $this->assertEquals($expectedArray, $sqlArray); }*/ public function testBackupStructure(): void @@ -154,7 +154,7 @@ SQL; $expectedArray = explode("\n", $expected); $resultArray = explode("\n", $sql); - $this->assertEqual($expectedArray, $resultArray); + $this->assertEquals($expectedArray, $resultArray); } public function testDeleteTable(): void @@ -254,7 +254,7 @@ SQL; public function testGetDBs(): void { $driverSQL = self::$db->getSql()->dbList(); - $this->assertEqual('', $driverSQL); + $this->assertEquals('', $driverSQL); $this->assertNull(self::$db->getDbs()); } diff --git a/tests/QueryParserTest.php b/tests/QueryParserTest.php index 489e73d..2e40bce 100644 --- a/tests/QueryParserTest.php +++ b/tests/QueryParserTest.php @@ -22,7 +22,7 @@ use Query\QueryParser; /** * Tests for the Query Parser */ -class QueryParserTest extends TestCase +class QueryParserTest extends BaseTestCase { /** * @var QueryParser @@ -38,7 +38,7 @@ class QueryParserTest extends TestCase public function testGeneric(): void { $matches = $this->parser->parseJoin('table1.field1=table2.field2'); - $this->assertEqual($matches['combined'], [ + $this->assertEquals($matches['combined'], [ 'table1.field1', '=', 'table2.field2', ]); } @@ -46,7 +46,7 @@ class QueryParserTest extends TestCase public function testGeneric2(): void { $matches = $this->parser->parseJoin('db1.table1.field1!=db2.table2.field2'); - $this->assertEqual($matches['combined'], [ + $this->assertEquals($matches['combined'], [ 'db1.table1.field1', '!=', 'db2.table2.field2', ]); } @@ -54,7 +54,7 @@ class QueryParserTest extends TestCase public function testWUnderscore(): void { $matches = $this->parser->parseJoin('table_1.field1 = tab_le2.field_2'); - $this->assertEqual($matches['combined'], [ + $this->assertEquals($matches['combined'], [ 'table_1.field1', '=', 'tab_le2.field_2', ]); } @@ -62,7 +62,7 @@ class QueryParserTest extends TestCase public function testFunction(): void { $matches = $this->parser->parseJoin('table1.field1 > SUM(3+5)'); - $this->assertEqual($matches['combined'], [ + $this->assertEquals($matches['combined'], [ 'table1.field1', '>', 'SUM(3+5)', ]); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f9b31de..df3ca38 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -39,6 +39,6 @@ function get_json_config() $path = QTEST_DIR . QDS . 'db_files' . QDS . 'test_sqlite.db'; @unlink($path); -require_once __DIR__ . '/TestCase.php'; +require_once __DIR__ . '/BaseTestCase.php'; // End of bootstrap.php diff --git a/tests/index.php b/tests/index.php deleted file mode 100644 index 5ba76de..0000000 --- a/tests/index.php +++ /dev/null @@ -1,164 +0,0 @@ - - * @copyright 2012 - 2023 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @link https://git.timshomepage.net/aviat/Query - * @version 4.0.0 - */ - -namespace { - /** - * Unit test bootstrap - Using php simpletest - */ - define('QTEST_DIR', __DIR__); - define('QBASE_DIR', realpath(__DIR__ . '/../') . '/'); - define('QDS', DIRECTORY_SEPARATOR); - - require_once QBASE_DIR . 'vendor/simpletest/simpletest/autorun.php'; - require_once QBASE_DIR . 'vendor/autoload.php'; -} - -namespace Query\Tests { - /** - * Base class for TestCases - */ - abstract class TestCase extends \UnitTestCase - { - public function __construct() - { - $class = static::class; - - if (PHP_SAPI !== 'cli') - { - echo 'Running test suite: ' . $class . '
'; - flush(); - } - - if (method_exists($class, 'setupBeforeClass')) - { - $class::setupBeforeClass(); - } - - parent::__construct(); - } - - public function __destruct() - { - $class = static::class; - - if (method_exists($class, 'tearDownAfterClass')) - { - $class::tearDownAfterClass(); - } - } - - /** - * Define assertInstanceOf for simpletest - * - * @param string $message - */ - public function assertInstanceOf($expected, $actual, $message = '') - { - $this->assertIsA($actual, $expected, $message); - } - - /** - * Alias to assertEqual - * - * @param mixed $expected - * @param mixed $actual - * @param string $message - */ - public function assertEquals($expected, $actual, $message = '') - { - $this->assertEqual($expected, $actual, $message); - } - - /** - * Alias to skipIf in SimpleTest - * - * @param string $message - */ - public function markTestSkipped($message = '') - { - $this->skipUnless(FALSE, $message); - } - - public function expectException($exception = FALSE, $message = '%s') - { - return parent::expectException(FALSE); - } - - /** - * Alias to the method in PHPUnit - * - * @param string $message - */ - public function expectExceptionMessage($message) - { - // noop - } - } -} - -/** - * Load the test suites - */ - -namespace { - function get_json_config() - { - $files = [ - __DIR__ . '/settings.json', - __DIR__ . '/settings.json.dist', - ]; - - foreach ($files as $file) - { - if (is_file($file)) - { - return json_decode(file_get_contents($file)); - } - } - - return FALSE; - } - - // Include db tests - // Load db classes based on capability - $testPath = QTEST_DIR . '/Drivers/'; - - // Require base testing classes - require_once QTEST_DIR . '/CoreTest.php'; - require_once QTEST_DIR . '/ConnectionManagerTest.php'; - require_once QTEST_DIR . '/QueryParserTest.php'; - - $drivers = PDO::getAvailableDrivers(); - $driverTestMap = [ - 'MySQL' => \in_array('mysql', $drivers, TRUE), - 'SQLite' => \in_array('sqlite', $drivers, TRUE), - 'PgSQL' => \in_array('pgsql', $drivers, TRUE), - ]; - - // Determine which testcases to load - foreach ($driverTestMap as $name => $doLoad) - { - $path = $testPath . $name; - - if ($doLoad) - { - require_once "{$path}/{$name}DriverTest.php"; - require_once "{$path}/{$name}QueryBuilderTest.php"; - } - } -} - -// End of index.php