From 282935d9f833fc3995643e6b6ade9605505f3d03 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 17 Mar 2023 15:30:36 -0400 Subject: [PATCH] Reformat test files --- tests/BaseDriverTest.php | 38 ++++++----- tests/BaseQueryBuilderTest.php | 64 ++++++++++-------- tests/ConnectionManagerTest.php | 15 +++-- tests/CoreTest.php | 12 ++-- tests/Drivers/MySQL/MySQLDriverTest.php | 44 ++++++------- tests/Drivers/MySQL/MySQLQueryBuilderTest.php | 18 ++--- tests/Drivers/PgSQL/PgSQLDriverTest.php | 66 +++++++++++-------- tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php | 42 ++++++------ tests/Drivers/SQLite/SQLiteDriverTest.php | 29 ++++---- .../Drivers/SQLite/SQLiteQueryBuilderTest.php | 13 ++-- tests/QueryParserTest.php | 18 ++--- tests/bootstrap.php | 10 +-- tests/index.php | 31 +++++---- {build => tools}/header_comment.txt | 0 {build => tools}/update_header_comments.php | 0 15 files changed, 216 insertions(+), 184 deletions(-) rename {build => tools}/header_comment.txt (100%) rename {build => tools}/update_header_comments.php (100%) diff --git a/tests/BaseDriverTest.php b/tests/BaseDriverTest.php index a8dc55a..ba4e72e 100644 --- a/tests/BaseDriverTest.php +++ b/tests/BaseDriverTest.php @@ -13,6 +13,7 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests; use Query\QueryBuilderInterface; @@ -20,8 +21,8 @@ use Query\QueryBuilderInterface; /** * Parent Database Test Class */ -abstract class BaseDriverTest extends TestCase { - +abstract class BaseDriverTest extends TestCase +{ /** * @var QueryBuilderInterface|null */ @@ -37,34 +38,34 @@ abstract class BaseDriverTest extends TestCase { public function testGetTables(): void { $tables = self::$db->getTables(); - $this->assertTrue(\is_array($tables)); + $this->assertIsArray($tables); $this->assertTrue( ! empty($tables)); } public function testGetSystemTables(): void { $tables = self::$db->getSystemTables(); - $this->assertTrue(\is_array($tables)); + $this->assertIsArray($tables); $this->assertTrue( ! empty($tables)); } public function testBackupData(): void { - $this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', FALSE]))); - $this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', TRUE]))); + $this->assertIsString(self::$db->getUtil()->backupData(['create_delete', FALSE])); + $this->assertIsString(self::$db->getUtil()->backupData(['create_delete', TRUE])); } public function testGetColumns(): void { $cols = self::$db->getColumns('test'); - $this->assertTrue(\is_array($cols)); + $this->assertIsArray($cols); $this->assertTrue( ! empty($cols)); } public function testGetTypes(): void { $types = self::$db->getTypes(); - $this->assertTrue(\is_array($types)); + $this->assertIsArray($types); $this->assertTrue( ! empty($types)); } @@ -75,7 +76,7 @@ abstract class BaseDriverTest extends TestCase { 'parent_table' => 'testconstraints', 'parent_column' => 'someid', 'update' => 'CASCADE', - 'delete' => 'CASCADE' + 'delete' => 'CASCADE', ]]; $keys = self::$db->getFks('testconstraints2'); @@ -85,14 +86,15 @@ abstract class BaseDriverTest extends TestCase { public function testGetIndexes(): void { $keys = self::$db->getIndexes('test'); - $this->assertTrue(\is_array($keys)); + $this->assertIsArray($keys); } public function testGetViews(): void { $views = self::$db->getViews(); - $this->assertTrue(\is_array($views)); + $this->assertIsArray($views); + foreach (['numbersview', 'testview'] as $searchView) { $this->assertTrue(in_array($searchView, $views, TRUE)); @@ -104,7 +106,7 @@ abstract class BaseDriverTest extends TestCase { $this->markTestSkipped('Deprecated'); $triggers = self::$db->getTriggers(); - $this->assertTrue(\is_array($triggers)); + $this->assertIsArray($triggers); } public function testGetSequences(): void @@ -116,7 +118,7 @@ abstract class BaseDriverTest extends TestCase { $expected = ['newtable_seq']; - $this->assertTrue(\is_array($seqs)); + $this->assertIsArray($seqs); $this->assertEqual($expected, $seqs); } @@ -125,7 +127,7 @@ abstract class BaseDriverTest extends TestCase { $this->markTestSkipped('Deprecated'); $procedures = self::$db->getProcedures(); - $this->assertTrue(\is_array($procedures)); + $this->assertIsArray($procedures); } public function testGetFunctions(): void @@ -133,14 +135,14 @@ abstract class BaseDriverTest extends TestCase { $this->markTestSkipped('Deprecated'); $funcs = self::$db->getFunctions(); - $this->assertTrue(\is_array($funcs)); + $this->assertIsArray($funcs); } public function testGetVersion(): void { $version = self::$db->getVersion(); - $this->assertTrue(is_string($version)); - $this->assertTrue(strlen($version) > 0); + $this->assertIsString($version); + $this->assertTrue($version !== ''); } } -// End of db_test.php \ No newline at end of file +// End of db_test.php diff --git a/tests/BaseQueryBuilderTest.php b/tests/BaseQueryBuilderTest.php index 795e5b1..c03f59d 100644 --- a/tests/BaseQueryBuilderTest.php +++ b/tests/BaseQueryBuilderTest.php @@ -13,6 +13,7 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests; use BadMethodCallException; @@ -23,8 +24,8 @@ use Query\QueryBuilderInterface; /** * Query builder parent test class */ -abstract class BaseQueryBuilderTest extends TestCase { - +abstract class BaseQueryBuilderTest extends TestCase +{ /** * @var QueryBuilderInterface|null */ @@ -75,7 +76,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $this->assertIsA($query, 'PDOStatement'); $lastQuery = self::$db->getLastQuery(); - $this->assertTrue(\is_string($lastQuery)); + $this->assertIsString($lastQuery); } public function testPrefixGet(): void @@ -137,6 +138,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $this->assertIsA($query, 'PDOStatement'); } + // ! Select tests public function testSelectWhereGet(): void { @@ -255,6 +257,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $this->assertIsA($query, 'PDOStatement'); } + // ! Grouping tests public function testGroup(): void { @@ -350,6 +353,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $this->assertIsA($query, 'PDOStatement'); } + // ! Where In tests public function testWhereIn(): void { @@ -389,6 +393,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $this->assertIsA($query, 'PDOStatement'); } + // ! Query modifier tests public function testOrderBy(): void { @@ -398,7 +403,7 @@ abstract class BaseQueryBuilderTest extends TestCase { ->where('id <', 9000) ->orderBy('id', 'DESC') ->orderBy('k', 'ASC') - ->limit(5,2) + ->limit(5, 2) ->get(); $this->assertIsA($query, 'PDOStatement'); @@ -411,7 +416,7 @@ abstract class BaseQueryBuilderTest extends TestCase { ->where('id >', 0) ->where('id <', 9000) ->orderBy('id', 'rand') - ->limit(5,2) + ->limit(5, 2) ->get(); $this->assertIsA($query, 'PDOStatement'); @@ -424,10 +429,10 @@ abstract class BaseQueryBuilderTest extends TestCase { ->where('id >', 0) ->where('id <', 9000) ->groupBy('k') - ->groupBy(['id','val']) + ->groupBy(['id', 'val']) ->orderBy('id', 'DESC') ->orderBy('k', 'ASC') - ->limit(5,2) + ->limit(5, 2) ->get(); $this->assertIsA($query, 'PDOStatement'); @@ -537,7 +542,7 @@ abstract class BaseQueryBuilderTest extends TestCase { ->join('join cj', 'cj.id=ct.id', 'inner') ->where([ 'ct.id < ' => 3, - 'ct.key' => 'foo' + 'ct.key' => 'foo', ]) ->get(); @@ -616,7 +621,7 @@ abstract class BaseQueryBuilderTest extends TestCase { ->update('test', [ 'id' => 7, 'key' => 'gogle', - 'val' => 'non-word' + 'val' => 'non-word', ]); $this->assertIsA($query, 'PDOStatement'); @@ -635,7 +640,7 @@ abstract class BaseQueryBuilderTest extends TestCase { ->set([ 'id' => 7, 'key' => 'gogle', - 'val' => 'non-word' + 'val' => 'non-word', ]) ->returning('key') ->update('test'); @@ -661,13 +666,13 @@ abstract class BaseQueryBuilderTest extends TestCase { [ 'id' => 480, 'key' => 49, - 'val' => '7x7' + 'val' => '7x7', ], [ 'id' => 890, 'key' => 100, - 'val' => '10x10' - ] + 'val' => '10x10', + ], ]; $affectedRows = self::$db->updateBatch('test', $data, 'id'); @@ -679,7 +684,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $array = [ 'id' => 22, 'key' => 'gogle', - 'val' => 'non-word' + 'val' => 'non-word', ]; $query = self::$db->set($array) @@ -707,7 +712,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $this->assertIsA($query, 'PDOStatement'); } - public function testDeleteReturning():void + public function testDeleteReturning(): void { $query = self::$db->returning()->delete('test', ['id' => 99]); @@ -718,7 +723,7 @@ abstract class BaseQueryBuilderTest extends TestCase { { $query = self::$db->delete('test', [ 'id' => 5, - 'key' => 'gogle' + 'key' => 'gogle', ]); $this->assertIsA($query, 'PDOStatement'); @@ -729,14 +734,14 @@ abstract class BaseQueryBuilderTest extends TestCase { { $query = self::$db->countAll('test'); - $this->assertTrue(is_numeric($query)); + $this->assertIsNumeric($query); } public function testCountAllResults(): void { $query = self::$db->countAllResults('test'); - $this->assertTrue(is_numeric($query)); + $this->assertIsNumeric($query); } public function testCountAllResults2(): void @@ -748,13 +753,13 @@ abstract class BaseQueryBuilderTest extends TestCase { ->limit(2, 1) ->countAllResults(); - $this->assertTrue(is_numeric($query)); + $this->assertIsNumeric($query); } public function testNumRows(): void { self::$db->get('test'); - $this->assertTrue(is_numeric(self::$db->numRows())); + $this->assertIsNumeric(self::$db->numRows()); } // ! Compiled Query tests @@ -764,7 +769,7 @@ abstract class BaseQueryBuilderTest extends TestCase { $qbRes = self::$db->get('test'); $sqlRes = self::$db->query($sql); - $this->assertIsA($qbRes,'PDOStatement', 'Query Builder Result is a PDO Statement'); + $this->assertIsA($qbRes, 'PDOStatement', 'Query Builder Result is a PDO Statement'); $this->assertIsA($sqlRes, 'PDOStatement', 'SQL Result is a PDO Statement'); //$this->assertEquals($qbRes, $sqlRes); } @@ -774,10 +779,10 @@ abstract class BaseQueryBuilderTest extends TestCase { $sql = self::$db->set([ 'id' => 4, 'key' => 'foo', - 'val' => 'baz' + 'val' => 'baz', ])->getCompiledUpdate('test'); - $this->assertTrue(\is_string($sql)); + $this->assertIsString($sql); } public function testGetCompiledInsert(): void @@ -785,10 +790,10 @@ abstract class BaseQueryBuilderTest extends TestCase { $sql = self::$db->set([ 'id' => 4, 'key' => 'foo', - 'val' => 'baz' + 'val' => 'baz', ])->getCompiledInsert('test'); - $this->assertTrue(\is_string($sql)); + $this->assertIsString($sql); } public function testGetCompiledDelete(): void @@ -796,8 +801,9 @@ abstract class BaseQueryBuilderTest extends TestCase { $sql = self::$db->where('id', 4) ->getCompiledDelete('test'); - $this->assertTrue(\is_string($sql)); + $this->assertIsString($sql); } + // ! Error tests /** * Handles invalid drivers @@ -810,7 +816,7 @@ abstract class BaseQueryBuilderTest extends TestCase { 'database' => 'test', 'user' => 'root', 'pass' => NULL, - 'type' => 'QGYFHGEG' + 'type' => 'QGYFHGEG', ]; $this->expectException(BadDBDriverException::class); @@ -830,10 +836,10 @@ abstract class BaseQueryBuilderTest extends TestCase { self::$db->set([ 'id' => 999, 'key' => 'ring', - 'val' => 'sale' + 'val' => 'sale', ])->insert('test'); $res = self::$db->numRows(); $this->assertEqual(NULL, $res); } -} \ No newline at end of file +} diff --git a/tests/ConnectionManagerTest.php b/tests/ConnectionManagerTest.php index df68fbc..02a903e 100644 --- a/tests/ConnectionManagerTest.php +++ b/tests/ConnectionManagerTest.php @@ -13,13 +13,14 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests; use DomainException; use Query\{ConnectionManager, QueryBuilderInterface}; -class ConnectionManagerTest extends TestCase { - +class ConnectionManagerTest extends TestCase +{ protected static $instance; public static function setUpBeforeClass(): void @@ -65,7 +66,7 @@ class ConnectionManagerTest extends TestCase { public $type = 'sqlite'; public $file = ':memory:'; public $options = [ - 'foo' => 'bar' + 'foo' => 'bar', ]; }; @@ -73,7 +74,7 @@ class ConnectionManagerTest extends TestCase { ':memory:', 'Sqlite', $params, - ['foo' => 'bar'] + ['foo' => 'bar'], ]; $this->assertEqual($expected, self::$instance->parseParams($params)); @@ -86,7 +87,7 @@ class ConnectionManagerTest extends TestCase { public $file = ':memory:'; public $prefix = 'create_'; public $options = [ - 'foo' => 'bar' + 'foo' => 'bar', ]; }; @@ -104,8 +105,8 @@ class ConnectionManagerTest extends TestCase { 'prefix' => 'create_', 'alias' => 'conn_manager', 'options' => [ - 'foo' => 'bar' - ] + 'foo' => 'bar', + ], ]; $conn = self::$instance->connect($params); diff --git a/tests/CoreTest.php b/tests/CoreTest.php index 25f8e1b..be5f9fe 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -13,30 +13,28 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests; +use PDO; use function Query; use function regexInArray; -use PDO; /** * CoreTest class - Compatibility and core functionality tests * * @extends UnitTestCase */ -class CoreTest extends TestCase { +class CoreTest extends TestCase +{ /** * TestHasPDO function. - * - * @access public - * @return void */ public function testHasPDO(): void { // PDO class exists $this->assertTrue(class_exists('PDO')); - // Make sure at least one of the supported drivers is enabled $supported = [ 'mysql', @@ -60,4 +58,4 @@ class CoreTest extends TestCase { { $this->assertFalse(regexInArray([], 'foo')); } -} \ No newline at end of file +} diff --git a/tests/Drivers/MySQL/MySQLDriverTest.php b/tests/Drivers/MySQL/MySQLDriverTest.php index 5689367..0e8ee4f 100644 --- a/tests/Drivers/MySQL/MySQLDriverTest.php +++ b/tests/Drivers/MySQL/MySQLDriverTest.php @@ -13,20 +13,22 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests\Drivers\MySQL; use PDO; use Query\Drivers\Mysql\Driver; use Query\Tests\BaseDriverTest; use TypeError; +use UnitTestCase; /** * MySQLTest class. * * @requires extension pdo_mysql */ -class MySQLDriverTest extends BaseDriverTest { - +class MySQLDriverTest extends BaseDriverTest +{ public static function setUpBeforeClass(): void { $params = get_json_config(); @@ -35,12 +37,12 @@ class MySQLDriverTest extends BaseDriverTest { self::$db = new Driver('host=127.0.0.1;port=3306;dbname=test', 'root'); } // Attempt to connect, if there is a test config file - else if ($params !== FALSE) + elseif ($params !== FALSE) { $params = $params->mysql; self::$db = new Driver("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, [ - PDO::ATTR_PERSISTENT => TRUE + PDO::ATTR_PERSISTENT => TRUE, ]); } @@ -59,31 +61,33 @@ class MySQLDriverTest extends BaseDriverTest { public function testCreateTable(): void { - self::$db->exec(file_get_contents(QTEST_DIR.'/db_files/mysql.sql')); + self::$db->exec(file_get_contents(QTEST_DIR . '/db_files/mysql.sql')); //Attempt to create the table - $sql = self::$db->getUtil()->createTable('test', + $sql = self::$db->getUtil()->createTable( + 'test', [ 'id' => 'int(10)', 'key' => 'TEXT', 'val' => 'TEXT', ], [ - 'id' => 'PRIMARY KEY' + 'id' => 'PRIMARY KEY', ], ); self::$db->query($sql); //Attempt to create the table - $sql = self::$db->getUtil()->createTable('join', + $sql = self::$db->getUtil()->createTable( + 'join', [ 'id' => 'int(10)', 'key' => 'TEXT', 'val' => 'TEXT', ], [ - 'id' => 'PRIMARY KEY' + 'id' => 'PRIMARY KEY', ] ); self::$db->query($sql); @@ -92,10 +96,8 @@ class MySQLDriverTest extends BaseDriverTest { $dbs = self::$db->getTables(); $this->assertTrue(\in_array('create_test', $dbs, TRUE)); - } - public function testTruncate(): void { self::$db->truncate('test'); @@ -107,7 +109,7 @@ class MySQLDriverTest extends BaseDriverTest { public function testPreparedStatements(): void { - $sql = <<execute(); $this->assertTrue($res); - } public function testBadPreparedStatement(): void { - if (is_a($this, \UnitTestCase::class)) + if (is_a($this, UnitTestCase::class)) { $this->markTestSkipped(); + return; } $this->expectException(TypeError::class); - $sql = <<prepareQuery($sql, 'foo'); - } public function testPrepareExecute(): void { - $sql = <<prepareExecute($sql, [ - 2, 'works', 'also?' + 2, 'works', 'also?', ]); $this->assertInstanceOf('PDOStatement', $res); - } public function testCommitTransaction(): void @@ -190,7 +190,7 @@ SQL; public function testGetSchemas(): void { - $this->assertTrue(in_array('test', self::$db->getSchemas())); + $this->assertTrue(in_array('test', self::$db->getSchemas(), TRUE)); } public function testGetSequences(): void @@ -200,6 +200,6 @@ SQL; public function testBackup(): void { - $this->assertTrue(\is_string(self::$db->getUtil()->backupStructure())); + $this->assertIsString(self::$db->getUtil()->backupStructure()); } -} \ No newline at end of file +} diff --git a/tests/Drivers/MySQL/MySQLQueryBuilderTest.php b/tests/Drivers/MySQL/MySQLQueryBuilderTest.php index a4be1e1..dfe3a8e 100644 --- a/tests/Drivers/MySQL/MySQLQueryBuilderTest.php +++ b/tests/Drivers/MySQL/MySQLQueryBuilderTest.php @@ -13,16 +13,18 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests\Drivers\MySQL; use PDO; use Query\Tests\BaseQueryBuilderTest; +use function in_array; /** * @requires extension pdo_mysql */ -class MySQLQueryBuilderTest extends BaseQueryBuilderTest { - +class MySQLQueryBuilderTest extends BaseQueryBuilderTest +{ public static function setUpBeforeClass(): void { $params = get_json_config(); @@ -35,11 +37,11 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest { 'prefix' => 'create_', 'user' => 'root', 'pass' => NULL, - 'type' => 'mysql' + 'type' => 'mysql', ]; } // Attempt to connect, if there is a test config file - else if ($params !== FALSE) + elseif ($params !== FALSE) { $params = $params->mysql; $params->type = 'MySQL'; @@ -52,7 +54,7 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest { public function testExists(): void { - $this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE)); + $this->assertTrue(in_array('mysql', PDO::getAvailableDrivers(), TRUE)); } public function testQueryExplain(): void @@ -68,9 +70,9 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest { // The exact results are version dependent // The important thing is that there is an array // of results returned - $this->assertTrue(\is_array($res)); + $this->assertIsArray($res); $this->assertTrue(count(array_keys($res[0])) > 1); - $this->assertTrue(array_key_exists('table', $res[0])); + $this->assertArrayHasKey('table', $res[0]); } public function testInsertReturning(): void @@ -82,4 +84,4 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest { { $this->markTestSkipped('Not implemented'); } -} \ No newline at end of file +} diff --git a/tests/Drivers/PgSQL/PgSQLDriverTest.php b/tests/Drivers/PgSQL/PgSQLDriverTest.php index ff1e459..63ac69b 100644 --- a/tests/Drivers/PgSQL/PgSQLDriverTest.php +++ b/tests/Drivers/PgSQL/PgSQLDriverTest.php @@ -13,12 +13,14 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests\Drivers\PgSQL; use PDO; use Query\Drivers\Pgsql\Driver; use Query\Tests\BaseDriverTest; use TypeError; +use UnitTestCase; /** * PgTest class. @@ -26,10 +28,10 @@ use TypeError; * @extends DBTest * @requires extension pdo_pgsql */ -class PgSQLDriverTest extends BaseDriverTest { - - public function setUp(): void - { +class PgSQLDriverTest extends BaseDriverTest +{ + protected function setUp(): void + { // If the database isn't installed, skip the tests if ( ! class_exists(Driver::class)) { @@ -39,14 +41,13 @@ class PgSQLDriverTest extends BaseDriverTest { public static function setUpBeforeClass(): void { - $params = get_json_config(); if ($var = getenv('TRAVIS')) { self::$db = new Driver('host=127.0.0.1;port=5432;dbname=test', 'postgres'); } // Attempt to connect, if there is a test config file - else if ($params !== FALSE) + elseif ($params !== FALSE) { $params = $params->pgsql; self::$db = new Driver("pgsql:host={$params->host};dbname={$params->database};port=5432", $params->user, $params->pass); @@ -63,7 +64,10 @@ class PgSQLDriverTest extends BaseDriverTest { public function testConnection(): void { - if (empty(self::$db)) return; + if (empty(self::$db)) + { + return; + } $this->assertIsA(self::$db, Driver::class); } @@ -78,30 +82,31 @@ class PgSQLDriverTest extends BaseDriverTest { $sql = 'DROP TABLE IF EXISTS "create_join"'; self::$db->query($sql); - //Attempt to create the table - $sql = self::$db->getUtil()->createTable('create_test', + $sql = self::$db->getUtil()->createTable( + 'create_test', [ 'id' => 'integer', 'key' => 'TEXT', 'val' => 'TEXT', ], [ - 'id' => 'PRIMARY KEY' + 'id' => 'PRIMARY KEY', ] ); self::$db->query($sql); //Attempt to create the table - $sql = self::$db->getUtil()->createTable('create_join', + $sql = self::$db->getUtil()->createTable( + 'create_join', [ 'id' => 'integer', 'key' => 'TEXT', 'val' => 'TEXT', ], [ - 'id' => 'PRIMARY KEY' + 'id' => 'PRIMARY KEY', ] ); self::$db->query($sql); @@ -115,7 +120,6 @@ class PgSQLDriverTest extends BaseDriverTest { //Check $dbs = self::$db->getTables(); $this->assertTrue(in_array('create_test', $dbs, TRUE)); - } public function testTruncate(): void @@ -129,11 +133,11 @@ class PgSQLDriverTest extends BaseDriverTest { public function testPreparedStatements(): void { - $sql = <<prepareQuery($sql, [1,'boogers', 'Gross']); + $statement = self::$db->prepareQuery($sql, [1, 'boogers', 'Gross']); $statement->execute(); @@ -143,21 +147,22 @@ SQL; $this->assertEquals([ 'id' => 1, 'key' => 'boogers', - 'val' => 'Gross' + 'val' => 'Gross', ], $res); } public function testBadPreparedStatement(): void { - if (is_a($this, \UnitTestCase::class)) + if (is_a($this, UnitTestCase::class)) { $this->markTestSkipped(); + return; } $this->expectException(TypeError::class); - $sql = <<prepareExecute($sql, [ - 2, 'works', 'also?' + 2, 'works', 'also?', ]); $res = self::$db->query('SELECT * FROM "create_test" WHERE "id"=2') @@ -183,13 +191,16 @@ SQL; $this->assertEquals([ 'id' => 2, 'key' => 'works', - 'val' => 'also?' + 'val' => 'also?', ], $res); } public function testCommitTransaction(): void { - if (empty(self::$db)) return; + if (empty(self::$db)) + { + return; + } self::$db->beginTransaction(); @@ -202,7 +213,10 @@ SQL; public function testRollbackTransaction(): void { - if (empty(self::$db)) return; + if (empty(self::$db)) + { + return; + } self::$db->beginTransaction(); @@ -215,12 +229,12 @@ SQL; public function testGetSchemas(): void { - $this->assertTrue(\is_array(self::$db->getSchemas())); + $this->assertIsArray(self::$db->getSchemas()); } public function testGetDBs(): void { - $this->assertTrue(\is_array(self::$db->getDbs())); + $this->assertIsArray(self::$db->getDbs()); } public function testGetFunctions(): void diff --git a/tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php b/tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php index 99f71d8..d99b003 100644 --- a/tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php +++ b/tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php @@ -13,16 +13,18 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests\Drivers\PgSQL; use PDO; use Query\Tests\BaseQueryBuilderTest; +use function in_array; /** * @requires extension pdo_pgsql */ -class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { - +class PgSQLQueryBuilderTest extends BaseQueryBuilderTest +{ public static function setUpBeforeClass(): void { $params = get_json_config(); @@ -35,11 +37,11 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { 'user' => 'postgres', 'pass' => '', 'type' => 'pgsql', - 'prefix' => 'create_' + 'prefix' => 'create_', ]; } // Attempt to connect, if there is a test config file - else if ($params !== FALSE) + elseif ($params !== FALSE) { $params = $params->pgsql; $params->type = 'pgsql'; @@ -52,18 +54,18 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { self::$db = Query($params); } - public function setUp(): void - { - // If the database isn't installed, skip the tests - if ( ! \in_array('pgsql', PDO::getAvailableDrivers(), TRUE)) + protected function setUp(): void + { + // If the database isn't installed, skip the tests + if ( ! in_array('pgsql', PDO::getAvailableDrivers(), TRUE)) { $this->markTestSkipped('Postgres extension for PDO not loaded'); } - } + } public function testExists(): void { - $this->assertTrue(\in_array('pgsql', PDO::getAvailableDrivers(), TRUE)); + $this->assertTrue(in_array('pgsql', PDO::getAvailableDrivers(), TRUE)); } public function testQueryExplain(): void @@ -79,31 +81,31 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { // The exact results are version dependent // The important thing is that there is an array // of results returned - $this->assertTrue(\is_array($res)); + $this->assertIsArray($res); $this->assertTrue(count($res) > 1); - $this->assertTrue(array_key_exists('QUERY PLAN', $res[0])); + $this->assertArrayHasKey('QUERY PLAN', $res[0]); /*$expected = array ( array ( - 'QUERY PLAN' => 'Limit (cost=6.31..10.54 rows=2 width=68)', + 'QUERY PLAN' => 'Limit (cost=6.31..10.54 rows=2 width=68)', ), array ( - 'QUERY PLAN' => ' Output: id, key, val', + 'QUERY PLAN' => ' Output: id, key, val', ), array ( - 'QUERY PLAN' => ' -> Bitmap Heap Scan on public.create_test (cost=4.19..12.66 rows=4 width=68)', + 'QUERY PLAN' => ' -> Bitmap Heap Scan on public.create_test (cost=4.19..12.66 rows=4 width=68)', ), array ( - 'QUERY PLAN' => ' Output: id, key, val', + 'QUERY PLAN' => ' Output: id, key, val', ), array ( - 'QUERY PLAN' => ' Recheck Cond: ((create_test.id > 1) AND (create_test.id < 900))', + 'QUERY PLAN' => ' Recheck Cond: ((create_test.id > 1) AND (create_test.id < 900))', ), array ( - 'QUERY PLAN' => ' -> Bitmap Index Scan on create_test_pkey (cost=0.00..4.19 rows=4 width=0)', + 'QUERY PLAN' => ' -> Bitmap Index Scan on create_test_pkey (cost=0.00..4.19 rows=4 width=0)', ), array ( - 'QUERY PLAN' => ' Index Cond: ((create_test.id > 1) AND (create_test.id < 900))', + 'QUERY PLAN' => ' Index Cond: ((create_test.id > 1) AND (create_test.id < 900))', ), ); @@ -114,4 +116,4 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { { $this->assertEquals('', self::$db->getUtil()->backupStructure()); } -} \ No newline at end of file +} diff --git a/tests/Drivers/SQLite/SQLiteDriverTest.php b/tests/Drivers/SQLite/SQLiteDriverTest.php index c155a31..c3ba987 100644 --- a/tests/Drivers/SQLite/SQLiteDriverTest.php +++ b/tests/Drivers/SQLite/SQLiteDriverTest.php @@ -13,6 +13,7 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests\Drivers\SQLite; use PDO; @@ -26,8 +27,8 @@ use Query\Tests\BaseDriverTest; * @extends DBTest * @requires extension pdo_sqlite */ -class SQLiteDriverTest extends BaseDriverTest { - +class SQLiteDriverTest extends BaseDriverTest +{ public static function setupBeforeClass(): void { $params = [ @@ -36,8 +37,8 @@ class SQLiteDriverTest extends BaseDriverTest { 'prefix' => 'create_', 'alias' => 'test_sqlite', 'options' => [ - PDO::ATTR_PERSISTENT => TRUE - ] + PDO::ATTR_PERSISTENT => TRUE, + ], ]; self::$db = Query($params); @@ -50,7 +51,7 @@ class SQLiteDriverTest extends BaseDriverTest { public function testCreateTable(): void { - self::$db->exec(file_get_contents(QTEST_DIR.'/db_files/sqlite.sql')); + self::$db->exec(file_get_contents(QTEST_DIR . '/db_files/sqlite.sql')); //Check $dbs = self::$db->getTables(); @@ -84,7 +85,7 @@ SQL; public function testBackupStructure(): void { $sql = mb_trim(self::$db->getUtil()->backupStructure()); - $expected = <<getTables(); - $this->assertFalse(in_array('create_delete', $dbs)); + $this->assertFalse(in_array('create_delete', $dbs, TRUE)); } // -------------------------------------------------------------------------- @@ -175,7 +176,7 @@ SQL; { $class = Driver::class; - $db = new $class(QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'); + $db = new $class(QTEST_DIR . QDS . 'db_files' . QDS . 'test_sqlite.db'); $this->assertIsA($db, $class); @@ -190,7 +191,7 @@ SQL; public function testPreparedStatements(): void { - $sql = <<assertEquals([ 'id' => 1, 'key' => 'boogers', - 'val' => 'Gross' + 'val' => 'Gross', ], $res); } public function testPrepareExecute(): void { - $sql = <<prepareExecute($sql, [ - 2, 'works', 'also?' + 2, 'works', 'also?', ]); $res = self::$db->query('SELECT * FROM "create_test" WHERE "id"=2') @@ -224,7 +225,7 @@ SQL; $this->assertEquals([ 'id' => 2, 'key' => 'works', - 'val' => 'also?' + 'val' => 'also?', ], $res); } @@ -270,7 +271,7 @@ SQL; public function testGetSystemTables(): void { $sql = self::$db->getSystemTables(); - $this->assertTrue(\is_array($sql)); + $this->assertIsArray($sql); } public function testGetSequences(): void diff --git a/tests/Drivers/SQLite/SQLiteQueryBuilderTest.php b/tests/Drivers/SQLite/SQLiteQueryBuilderTest.php index 8cc1e43..71525d9 100644 --- a/tests/Drivers/SQLite/SQLiteQueryBuilderTest.php +++ b/tests/Drivers/SQLite/SQLiteQueryBuilderTest.php @@ -13,6 +13,7 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests\Drivers\SQLite; use PDO; @@ -23,8 +24,8 @@ use Query\Tests\BaseQueryBuilderTest; * * @requires extension pdo_sqlite */ - class SQLiteQueryBuilderTest extends BaseQueryBuilderTest { - +class SQLiteQueryBuilderTest extends BaseQueryBuilderTest +{ public static function setUpBeforeClass(): void { // Defined in the SQLiteTest.php file @@ -48,7 +49,7 @@ use Query\Tests\BaseQueryBuilderTest; $res = $query->fetchAll(PDO::FETCH_ASSOC); $actualDetail = $res[0]['detail']; - $this->assertTrue(is_string($actualDetail)); + $this->assertIsString($actualDetail); /* $expectedPossibilities = [ 'TABLE create_test USING PRIMARY KEY', @@ -77,11 +78,11 @@ use Query\Tests\BaseQueryBuilderTest; public function testInsertReturning(): void { - $this->markTestSkipped('Not implemented'); + $this->markTestSkipped('Not implemented'); } public function testUpdateReturning(): void { - $this->markTestSkipped('Not implemented'); + $this->markTestSkipped('Not implemented'); } -} \ No newline at end of file +} diff --git a/tests/QueryParserTest.php b/tests/QueryParserTest.php index 8997084..489e73d 100644 --- a/tests/QueryParserTest.php +++ b/tests/QueryParserTest.php @@ -13,21 +13,23 @@ * @link https://git.timshomepage.net/aviat/Query * @version 4.0.0 */ + namespace Query\Tests; -use Query\QueryParser; use Query\Drivers\Sqlite\Driver; +use Query\QueryParser; /** * Tests for the Query Parser */ -class QueryParserTest extends TestCase { +class QueryParserTest extends TestCase +{ /** * @var QueryParser */ protected $parser; - public function setUp(): void + protected function setUp(): void { $db = new Driver('sqlite::memory:'); $this->parser = new QueryParser($db); @@ -37,7 +39,7 @@ class QueryParserTest extends TestCase { { $matches = $this->parser->parseJoin('table1.field1=table2.field2'); $this->assertEqual($matches['combined'], [ - 'table1.field1', '=', 'table2.field2' + 'table1.field1', '=', 'table2.field2', ]); } @@ -45,7 +47,7 @@ class QueryParserTest extends TestCase { { $matches = $this->parser->parseJoin('db1.table1.field1!=db2.table2.field2'); $this->assertEqual($matches['combined'], [ - 'db1.table1.field1','!=','db2.table2.field2' + 'db1.table1.field1', '!=', 'db2.table2.field2', ]); } @@ -53,7 +55,7 @@ class QueryParserTest extends TestCase { { $matches = $this->parser->parseJoin('table_1.field1 = tab_le2.field_2'); $this->assertEqual($matches['combined'], [ - 'table_1.field1', '=', 'tab_le2.field_2' + 'table_1.field1', '=', 'tab_le2.field_2', ]); } @@ -61,7 +63,7 @@ class QueryParserTest extends TestCase { { $matches = $this->parser->parseJoin('table1.field1 > SUM(3+5)'); $this->assertEqual($matches['combined'], [ - 'table1.field1', '>', 'SUM(3+5)' + 'table1.field1', '>', 'SUM(3+5)', ]); } -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fcf10d9..f9b31de 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,4 @@ - $doLoad) + foreach ($driverTestMap as $name => $doLoad) { $path = $testPath . $name; @@ -157,5 +161,4 @@ namespace { } } - // End of index.php diff --git a/build/header_comment.txt b/tools/header_comment.txt similarity index 100% rename from build/header_comment.txt rename to tools/header_comment.txt diff --git a/build/update_header_comments.php b/tools/update_header_comments.php similarity index 100% rename from build/update_header_comments.php rename to tools/update_header_comments.php