Reformat test files

This commit is contained in:
Timothy Warren 2023-03-17 15:30:36 -04:00
parent cf2255ce87
commit 282935d9f8
15 changed files with 216 additions and 184 deletions

View File

@ -13,6 +13,7 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests; namespace Query\Tests;
use Query\QueryBuilderInterface; use Query\QueryBuilderInterface;
@ -20,8 +21,8 @@ use Query\QueryBuilderInterface;
/** /**
* Parent Database Test Class * Parent Database Test Class
*/ */
abstract class BaseDriverTest extends TestCase { abstract class BaseDriverTest extends TestCase
{
/** /**
* @var QueryBuilderInterface|null * @var QueryBuilderInterface|null
*/ */
@ -37,34 +38,34 @@ abstract class BaseDriverTest extends TestCase {
public function testGetTables(): void public function testGetTables(): void
{ {
$tables = self::$db->getTables(); $tables = self::$db->getTables();
$this->assertTrue(\is_array($tables)); $this->assertIsArray($tables);
$this->assertTrue( ! empty($tables)); $this->assertTrue( ! empty($tables));
} }
public function testGetSystemTables(): void public function testGetSystemTables(): void
{ {
$tables = self::$db->getSystemTables(); $tables = self::$db->getSystemTables();
$this->assertTrue(\is_array($tables)); $this->assertIsArray($tables);
$this->assertTrue( ! empty($tables)); $this->assertTrue( ! empty($tables));
} }
public function testBackupData(): void public function testBackupData(): void
{ {
$this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', FALSE]))); $this->assertIsString(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', TRUE]));
} }
public function testGetColumns(): void public function testGetColumns(): void
{ {
$cols = self::$db->getColumns('test'); $cols = self::$db->getColumns('test');
$this->assertTrue(\is_array($cols)); $this->assertIsArray($cols);
$this->assertTrue( ! empty($cols)); $this->assertTrue( ! empty($cols));
} }
public function testGetTypes(): void public function testGetTypes(): void
{ {
$types = self::$db->getTypes(); $types = self::$db->getTypes();
$this->assertTrue(\is_array($types)); $this->assertIsArray($types);
$this->assertTrue( ! empty($types)); $this->assertTrue( ! empty($types));
} }
@ -75,7 +76,7 @@ abstract class BaseDriverTest extends TestCase {
'parent_table' => 'testconstraints', 'parent_table' => 'testconstraints',
'parent_column' => 'someid', 'parent_column' => 'someid',
'update' => 'CASCADE', 'update' => 'CASCADE',
'delete' => 'CASCADE' 'delete' => 'CASCADE',
]]; ]];
$keys = self::$db->getFks('testconstraints2'); $keys = self::$db->getFks('testconstraints2');
@ -85,14 +86,15 @@ abstract class BaseDriverTest extends TestCase {
public function testGetIndexes(): void public function testGetIndexes(): void
{ {
$keys = self::$db->getIndexes('test'); $keys = self::$db->getIndexes('test');
$this->assertTrue(\is_array($keys)); $this->assertIsArray($keys);
} }
public function testGetViews(): void public function testGetViews(): void
{ {
$views = self::$db->getViews(); $views = self::$db->getViews();
$this->assertTrue(\is_array($views)); $this->assertIsArray($views);
foreach (['numbersview', 'testview'] as $searchView) foreach (['numbersview', 'testview'] as $searchView)
{ {
$this->assertTrue(in_array($searchView, $views, TRUE)); $this->assertTrue(in_array($searchView, $views, TRUE));
@ -104,7 +106,7 @@ abstract class BaseDriverTest extends TestCase {
$this->markTestSkipped('Deprecated'); $this->markTestSkipped('Deprecated');
$triggers = self::$db->getTriggers(); $triggers = self::$db->getTriggers();
$this->assertTrue(\is_array($triggers)); $this->assertIsArray($triggers);
} }
public function testGetSequences(): void public function testGetSequences(): void
@ -116,7 +118,7 @@ abstract class BaseDriverTest extends TestCase {
$expected = ['newtable_seq']; $expected = ['newtable_seq'];
$this->assertTrue(\is_array($seqs)); $this->assertIsArray($seqs);
$this->assertEqual($expected, $seqs); $this->assertEqual($expected, $seqs);
} }
@ -125,7 +127,7 @@ abstract class BaseDriverTest extends TestCase {
$this->markTestSkipped('Deprecated'); $this->markTestSkipped('Deprecated');
$procedures = self::$db->getProcedures(); $procedures = self::$db->getProcedures();
$this->assertTrue(\is_array($procedures)); $this->assertIsArray($procedures);
} }
public function testGetFunctions(): void public function testGetFunctions(): void
@ -133,14 +135,14 @@ abstract class BaseDriverTest extends TestCase {
$this->markTestSkipped('Deprecated'); $this->markTestSkipped('Deprecated');
$funcs = self::$db->getFunctions(); $funcs = self::$db->getFunctions();
$this->assertTrue(\is_array($funcs)); $this->assertIsArray($funcs);
} }
public function testGetVersion(): void public function testGetVersion(): void
{ {
$version = self::$db->getVersion(); $version = self::$db->getVersion();
$this->assertTrue(is_string($version)); $this->assertIsString($version);
$this->assertTrue(strlen($version) > 0); $this->assertTrue($version !== '');
} }
} }
// End of db_test.php // End of db_test.php

View File

@ -13,6 +13,7 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests; namespace Query\Tests;
use BadMethodCallException; use BadMethodCallException;
@ -23,8 +24,8 @@ use Query\QueryBuilderInterface;
/** /**
* Query builder parent test class * Query builder parent test class
*/ */
abstract class BaseQueryBuilderTest extends TestCase { abstract class BaseQueryBuilderTest extends TestCase
{
/** /**
* @var QueryBuilderInterface|null * @var QueryBuilderInterface|null
*/ */
@ -75,7 +76,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
$lastQuery = self::$db->getLastQuery(); $lastQuery = self::$db->getLastQuery();
$this->assertTrue(\is_string($lastQuery)); $this->assertIsString($lastQuery);
} }
public function testPrefixGet(): void public function testPrefixGet(): void
@ -137,6 +138,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
// ! Select tests // ! Select tests
public function testSelectWhereGet(): void public function testSelectWhereGet(): void
{ {
@ -255,6 +257,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
// ! Grouping tests // ! Grouping tests
public function testGroup(): void public function testGroup(): void
{ {
@ -350,6 +353,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
// ! Where In tests // ! Where In tests
public function testWhereIn(): void public function testWhereIn(): void
{ {
@ -389,6 +393,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
// ! Query modifier tests // ! Query modifier tests
public function testOrderBy(): void public function testOrderBy(): void
{ {
@ -398,7 +403,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
->where('id <', 9000) ->where('id <', 9000)
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->orderBy('k', 'ASC') ->orderBy('k', 'ASC')
->limit(5,2) ->limit(5, 2)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
@ -411,7 +416,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
->where('id >', 0) ->where('id >', 0)
->where('id <', 9000) ->where('id <', 9000)
->orderBy('id', 'rand') ->orderBy('id', 'rand')
->limit(5,2) ->limit(5, 2)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
@ -424,10 +429,10 @@ abstract class BaseQueryBuilderTest extends TestCase {
->where('id >', 0) ->where('id >', 0)
->where('id <', 9000) ->where('id <', 9000)
->groupBy('k') ->groupBy('k')
->groupBy(['id','val']) ->groupBy(['id', 'val'])
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->orderBy('k', 'ASC') ->orderBy('k', 'ASC')
->limit(5,2) ->limit(5, 2)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
@ -537,7 +542,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
->join('join cj', 'cj.id=ct.id', 'inner') ->join('join cj', 'cj.id=ct.id', 'inner')
->where([ ->where([
'ct.id < ' => 3, 'ct.id < ' => 3,
'ct.key' => 'foo' 'ct.key' => 'foo',
]) ])
->get(); ->get();
@ -616,7 +621,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
->update('test', [ ->update('test', [
'id' => 7, 'id' => 7,
'key' => 'gogle', 'key' => 'gogle',
'val' => 'non-word' 'val' => 'non-word',
]); ]);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
@ -635,7 +640,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
->set([ ->set([
'id' => 7, 'id' => 7,
'key' => 'gogle', 'key' => 'gogle',
'val' => 'non-word' 'val' => 'non-word',
]) ])
->returning('key') ->returning('key')
->update('test'); ->update('test');
@ -661,13 +666,13 @@ abstract class BaseQueryBuilderTest extends TestCase {
[ [
'id' => 480, 'id' => 480,
'key' => 49, 'key' => 49,
'val' => '7x7' 'val' => '7x7',
], ],
[ [
'id' => 890, 'id' => 890,
'key' => 100, 'key' => 100,
'val' => '10x10' 'val' => '10x10',
] ],
]; ];
$affectedRows = self::$db->updateBatch('test', $data, 'id'); $affectedRows = self::$db->updateBatch('test', $data, 'id');
@ -679,7 +684,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$array = [ $array = [
'id' => 22, 'id' => 22,
'key' => 'gogle', 'key' => 'gogle',
'val' => 'non-word' 'val' => 'non-word',
]; ];
$query = self::$db->set($array) $query = self::$db->set($array)
@ -707,7 +712,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testDeleteReturning():void public function testDeleteReturning(): void
{ {
$query = self::$db->returning()->delete('test', ['id' => 99]); $query = self::$db->returning()->delete('test', ['id' => 99]);
@ -718,7 +723,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
{ {
$query = self::$db->delete('test', [ $query = self::$db->delete('test', [
'id' => 5, 'id' => 5,
'key' => 'gogle' 'key' => 'gogle',
]); ]);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
@ -729,14 +734,14 @@ abstract class BaseQueryBuilderTest extends TestCase {
{ {
$query = self::$db->countAll('test'); $query = self::$db->countAll('test');
$this->assertTrue(is_numeric($query)); $this->assertIsNumeric($query);
} }
public function testCountAllResults(): void public function testCountAllResults(): void
{ {
$query = self::$db->countAllResults('test'); $query = self::$db->countAllResults('test');
$this->assertTrue(is_numeric($query)); $this->assertIsNumeric($query);
} }
public function testCountAllResults2(): void public function testCountAllResults2(): void
@ -748,13 +753,13 @@ abstract class BaseQueryBuilderTest extends TestCase {
->limit(2, 1) ->limit(2, 1)
->countAllResults(); ->countAllResults();
$this->assertTrue(is_numeric($query)); $this->assertIsNumeric($query);
} }
public function testNumRows(): void public function testNumRows(): void
{ {
self::$db->get('test'); self::$db->get('test');
$this->assertTrue(is_numeric(self::$db->numRows())); $this->assertIsNumeric(self::$db->numRows());
} }
// ! Compiled Query tests // ! Compiled Query tests
@ -764,7 +769,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$qbRes = self::$db->get('test'); $qbRes = self::$db->get('test');
$sqlRes = self::$db->query($sql); $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->assertIsA($sqlRes, 'PDOStatement', 'SQL Result is a PDO Statement');
//$this->assertEquals($qbRes, $sqlRes); //$this->assertEquals($qbRes, $sqlRes);
} }
@ -774,10 +779,10 @@ abstract class BaseQueryBuilderTest extends TestCase {
$sql = self::$db->set([ $sql = self::$db->set([
'id' => 4, 'id' => 4,
'key' => 'foo', 'key' => 'foo',
'val' => 'baz' 'val' => 'baz',
])->getCompiledUpdate('test'); ])->getCompiledUpdate('test');
$this->assertTrue(\is_string($sql)); $this->assertIsString($sql);
} }
public function testGetCompiledInsert(): void public function testGetCompiledInsert(): void
@ -785,10 +790,10 @@ abstract class BaseQueryBuilderTest extends TestCase {
$sql = self::$db->set([ $sql = self::$db->set([
'id' => 4, 'id' => 4,
'key' => 'foo', 'key' => 'foo',
'val' => 'baz' 'val' => 'baz',
])->getCompiledInsert('test'); ])->getCompiledInsert('test');
$this->assertTrue(\is_string($sql)); $this->assertIsString($sql);
} }
public function testGetCompiledDelete(): void public function testGetCompiledDelete(): void
@ -796,8 +801,9 @@ abstract class BaseQueryBuilderTest extends TestCase {
$sql = self::$db->where('id', 4) $sql = self::$db->where('id', 4)
->getCompiledDelete('test'); ->getCompiledDelete('test');
$this->assertTrue(\is_string($sql)); $this->assertIsString($sql);
} }
// ! Error tests // ! Error tests
/** /**
* Handles invalid drivers * Handles invalid drivers
@ -810,7 +816,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
'database' => 'test', 'database' => 'test',
'user' => 'root', 'user' => 'root',
'pass' => NULL, 'pass' => NULL,
'type' => 'QGYFHGEG' 'type' => 'QGYFHGEG',
]; ];
$this->expectException(BadDBDriverException::class); $this->expectException(BadDBDriverException::class);
@ -830,7 +836,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
self::$db->set([ self::$db->set([
'id' => 999, 'id' => 999,
'key' => 'ring', 'key' => 'ring',
'val' => 'sale' 'val' => 'sale',
])->insert('test'); ])->insert('test');
$res = self::$db->numRows(); $res = self::$db->numRows();

View File

@ -13,13 +13,14 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests; namespace Query\Tests;
use DomainException; use DomainException;
use Query\{ConnectionManager, QueryBuilderInterface}; use Query\{ConnectionManager, QueryBuilderInterface};
class ConnectionManagerTest extends TestCase { class ConnectionManagerTest extends TestCase
{
protected static $instance; protected static $instance;
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
@ -65,7 +66,7 @@ class ConnectionManagerTest extends TestCase {
public $type = 'sqlite'; public $type = 'sqlite';
public $file = ':memory:'; public $file = ':memory:';
public $options = [ public $options = [
'foo' => 'bar' 'foo' => 'bar',
]; ];
}; };
@ -73,7 +74,7 @@ class ConnectionManagerTest extends TestCase {
':memory:', ':memory:',
'Sqlite', 'Sqlite',
$params, $params,
['foo' => 'bar'] ['foo' => 'bar'],
]; ];
$this->assertEqual($expected, self::$instance->parseParams($params)); $this->assertEqual($expected, self::$instance->parseParams($params));
@ -86,7 +87,7 @@ class ConnectionManagerTest extends TestCase {
public $file = ':memory:'; public $file = ':memory:';
public $prefix = 'create_'; public $prefix = 'create_';
public $options = [ public $options = [
'foo' => 'bar' 'foo' => 'bar',
]; ];
}; };
@ -104,8 +105,8 @@ class ConnectionManagerTest extends TestCase {
'prefix' => 'create_', 'prefix' => 'create_',
'alias' => 'conn_manager', 'alias' => 'conn_manager',
'options' => [ 'options' => [
'foo' => 'bar' 'foo' => 'bar',
] ],
]; ];
$conn = self::$instance->connect($params); $conn = self::$instance->connect($params);

View File

@ -13,30 +13,28 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests; namespace Query\Tests;
use PDO;
use function Query; use function Query;
use function regexInArray; use function regexInArray;
use PDO;
/** /**
* CoreTest class - Compatibility and core functionality tests * CoreTest class - Compatibility and core functionality tests
* *
* @extends UnitTestCase * @extends UnitTestCase
*/ */
class CoreTest extends TestCase { class CoreTest extends TestCase
{
/** /**
* TestHasPDO function. * TestHasPDO function.
*
* @access public
* @return void
*/ */
public function testHasPDO(): void public function testHasPDO(): void
{ {
// PDO class exists // PDO class exists
$this->assertTrue(class_exists('PDO')); $this->assertTrue(class_exists('PDO'));
// Make sure at least one of the supported drivers is enabled // Make sure at least one of the supported drivers is enabled
$supported = [ $supported = [
'mysql', 'mysql',

View File

@ -13,20 +13,22 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests\Drivers\MySQL; namespace Query\Tests\Drivers\MySQL;
use PDO; use PDO;
use Query\Drivers\Mysql\Driver; use Query\Drivers\Mysql\Driver;
use Query\Tests\BaseDriverTest; use Query\Tests\BaseDriverTest;
use TypeError; use TypeError;
use UnitTestCase;
/** /**
* MySQLTest class. * MySQLTest class.
* *
* @requires extension pdo_mysql * @requires extension pdo_mysql
*/ */
class MySQLDriverTest extends BaseDriverTest { class MySQLDriverTest extends BaseDriverTest
{
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
{ {
$params = get_json_config(); $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'); self::$db = new Driver('host=127.0.0.1;port=3306;dbname=test', 'root');
} }
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
else if ($params !== FALSE) elseif ($params !== FALSE)
{ {
$params = $params->mysql; $params = $params->mysql;
self::$db = new Driver("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, [ 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 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 //Attempt to create the table
$sql = self::$db->getUtil()->createTable('test', $sql = self::$db->getUtil()->createTable(
'test',
[ [
'id' => 'int(10)', 'id' => 'int(10)',
'key' => 'TEXT', 'key' => 'TEXT',
'val' => 'TEXT', 'val' => 'TEXT',
], ],
[ [
'id' => 'PRIMARY KEY' 'id' => 'PRIMARY KEY',
], ],
); );
self::$db->query($sql); self::$db->query($sql);
//Attempt to create the table //Attempt to create the table
$sql = self::$db->getUtil()->createTable('join', $sql = self::$db->getUtil()->createTable(
'join',
[ [
'id' => 'int(10)', 'id' => 'int(10)',
'key' => 'TEXT', 'key' => 'TEXT',
'val' => 'TEXT', 'val' => 'TEXT',
], ],
[ [
'id' => 'PRIMARY KEY' 'id' => 'PRIMARY KEY',
] ]
); );
self::$db->query($sql); self::$db->query($sql);
@ -92,10 +96,8 @@ class MySQLDriverTest extends BaseDriverTest {
$dbs = self::$db->getTables(); $dbs = self::$db->getTables();
$this->assertTrue(\in_array('create_test', $dbs, TRUE)); $this->assertTrue(\in_array('create_test', $dbs, TRUE));
} }
public function testTruncate(): void public function testTruncate(): void
{ {
self::$db->truncate('test'); self::$db->truncate('test');
@ -107,7 +109,7 @@ class MySQLDriverTest extends BaseDriverTest {
public function testPreparedStatements(): void public function testPreparedStatements(): void
{ {
$sql = <<<SQL $sql = <<<'SQL'
INSERT INTO `create_test` (`id`, `key`, `val`) INSERT INTO `create_test` (`id`, `key`, `val`)
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
@ -116,40 +118,38 @@ SQL;
$res = $statement->execute(); $res = $statement->execute();
$this->assertTrue($res); $this->assertTrue($res);
} }
public function testBadPreparedStatement(): void public function testBadPreparedStatement(): void
{ {
if (is_a($this, \UnitTestCase::class)) if (is_a($this, UnitTestCase::class))
{ {
$this->markTestSkipped(); $this->markTestSkipped();
return; return;
} }
$this->expectException(TypeError::class); $this->expectException(TypeError::class);
$sql = <<<SQL $sql = <<<'SQL'
INSERT INTO `create_test` (`id`, `key`, `val`) INSERT INTO `create_test` (`id`, `key`, `val`)
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
self::$db->prepareQuery($sql, 'foo'); self::$db->prepareQuery($sql, 'foo');
} }
public function testPrepareExecute(): void public function testPrepareExecute(): void
{ {
$sql = <<<SQL $sql = <<<'SQL'
INSERT INTO `create_test` (`id`, `key`, `val`) INSERT INTO `create_test` (`id`, `key`, `val`)
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
$res = self::$db->prepareExecute($sql, [ $res = self::$db->prepareExecute($sql, [
2, 'works', 'also?' 2, 'works', 'also?',
]); ]);
$this->assertInstanceOf('PDOStatement', $res); $this->assertInstanceOf('PDOStatement', $res);
} }
public function testCommitTransaction(): void public function testCommitTransaction(): void
@ -190,7 +190,7 @@ SQL;
public function testGetSchemas(): void 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 public function testGetSequences(): void
@ -200,6 +200,6 @@ SQL;
public function testBackup(): void public function testBackup(): void
{ {
$this->assertTrue(\is_string(self::$db->getUtil()->backupStructure())); $this->assertIsString(self::$db->getUtil()->backupStructure());
} }
} }

View File

@ -13,16 +13,18 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests\Drivers\MySQL; namespace Query\Tests\Drivers\MySQL;
use PDO; use PDO;
use Query\Tests\BaseQueryBuilderTest; use Query\Tests\BaseQueryBuilderTest;
use function in_array;
/** /**
* @requires extension pdo_mysql * @requires extension pdo_mysql
*/ */
class MySQLQueryBuilderTest extends BaseQueryBuilderTest { class MySQLQueryBuilderTest extends BaseQueryBuilderTest
{
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
{ {
$params = get_json_config(); $params = get_json_config();
@ -35,11 +37,11 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest {
'prefix' => 'create_', 'prefix' => 'create_',
'user' => 'root', 'user' => 'root',
'pass' => NULL, 'pass' => NULL,
'type' => 'mysql' 'type' => 'mysql',
]; ];
} }
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
else if ($params !== FALSE) elseif ($params !== FALSE)
{ {
$params = $params->mysql; $params = $params->mysql;
$params->type = 'MySQL'; $params->type = 'MySQL';
@ -52,7 +54,7 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest {
public function testExists(): void public function testExists(): void
{ {
$this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE)); $this->assertTrue(in_array('mysql', PDO::getAvailableDrivers(), TRUE));
} }
public function testQueryExplain(): void public function testQueryExplain(): void
@ -68,9 +70,9 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest {
// The exact results are version dependent // The exact results are version dependent
// The important thing is that there is an array // The important thing is that there is an array
// of results returned // of results returned
$this->assertTrue(\is_array($res)); $this->assertIsArray($res);
$this->assertTrue(count(array_keys($res[0])) > 1); $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 public function testInsertReturning(): void

View File

@ -13,12 +13,14 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests\Drivers\PgSQL; namespace Query\Tests\Drivers\PgSQL;
use PDO; use PDO;
use Query\Drivers\Pgsql\Driver; use Query\Drivers\Pgsql\Driver;
use Query\Tests\BaseDriverTest; use Query\Tests\BaseDriverTest;
use TypeError; use TypeError;
use UnitTestCase;
/** /**
* PgTest class. * PgTest class.
@ -26,10 +28,10 @@ use TypeError;
* @extends DBTest * @extends DBTest
* @requires extension pdo_pgsql * @requires extension pdo_pgsql
*/ */
class PgSQLDriverTest extends BaseDriverTest { class PgSQLDriverTest extends BaseDriverTest
{
public function setUp(): void protected function setUp(): void
{ {
// If the database isn't installed, skip the tests // If the database isn't installed, skip the tests
if ( ! class_exists(Driver::class)) if ( ! class_exists(Driver::class))
{ {
@ -39,14 +41,13 @@ class PgSQLDriverTest extends BaseDriverTest {
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
{ {
$params = get_json_config(); $params = get_json_config();
if ($var = getenv('TRAVIS')) if ($var = getenv('TRAVIS'))
{ {
self::$db = new Driver('host=127.0.0.1;port=5432;dbname=test', 'postgres'); self::$db = new Driver('host=127.0.0.1;port=5432;dbname=test', 'postgres');
} }
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
else if ($params !== FALSE) elseif ($params !== FALSE)
{ {
$params = $params->pgsql; $params = $params->pgsql;
self::$db = new Driver("pgsql:host={$params->host};dbname={$params->database};port=5432", $params->user, $params->pass); 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 public function testConnection(): void
{ {
if (empty(self::$db)) return; if (empty(self::$db))
{
return;
}
$this->assertIsA(self::$db, Driver::class); $this->assertIsA(self::$db, Driver::class);
} }
@ -78,30 +82,31 @@ class PgSQLDriverTest extends BaseDriverTest {
$sql = 'DROP TABLE IF EXISTS "create_join"'; $sql = 'DROP TABLE IF EXISTS "create_join"';
self::$db->query($sql); self::$db->query($sql);
//Attempt to create the table //Attempt to create the table
$sql = self::$db->getUtil()->createTable('create_test', $sql = self::$db->getUtil()->createTable(
'create_test',
[ [
'id' => 'integer', 'id' => 'integer',
'key' => 'TEXT', 'key' => 'TEXT',
'val' => 'TEXT', 'val' => 'TEXT',
], ],
[ [
'id' => 'PRIMARY KEY' 'id' => 'PRIMARY KEY',
] ]
); );
self::$db->query($sql); self::$db->query($sql);
//Attempt to create the table //Attempt to create the table
$sql = self::$db->getUtil()->createTable('create_join', $sql = self::$db->getUtil()->createTable(
'create_join',
[ [
'id' => 'integer', 'id' => 'integer',
'key' => 'TEXT', 'key' => 'TEXT',
'val' => 'TEXT', 'val' => 'TEXT',
], ],
[ [
'id' => 'PRIMARY KEY' 'id' => 'PRIMARY KEY',
] ]
); );
self::$db->query($sql); self::$db->query($sql);
@ -115,7 +120,6 @@ class PgSQLDriverTest extends BaseDriverTest {
//Check //Check
$dbs = self::$db->getTables(); $dbs = self::$db->getTables();
$this->assertTrue(in_array('create_test', $dbs, TRUE)); $this->assertTrue(in_array('create_test', $dbs, TRUE));
} }
public function testTruncate(): void public function testTruncate(): void
@ -129,11 +133,11 @@ class PgSQLDriverTest extends BaseDriverTest {
public function testPreparedStatements(): void public function testPreparedStatements(): void
{ {
$sql = <<<SQL $sql = <<<'SQL'
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
$statement = self::$db->prepareQuery($sql, [1,'boogers', 'Gross']); $statement = self::$db->prepareQuery($sql, [1, 'boogers', 'Gross']);
$statement->execute(); $statement->execute();
@ -143,21 +147,22 @@ SQL;
$this->assertEquals([ $this->assertEquals([
'id' => 1, 'id' => 1,
'key' => 'boogers', 'key' => 'boogers',
'val' => 'Gross' 'val' => 'Gross',
], $res); ], $res);
} }
public function testBadPreparedStatement(): void public function testBadPreparedStatement(): void
{ {
if (is_a($this, \UnitTestCase::class)) if (is_a($this, UnitTestCase::class))
{ {
$this->markTestSkipped(); $this->markTestSkipped();
return; return;
} }
$this->expectException(TypeError::class); $this->expectException(TypeError::class);
$sql = <<<SQL $sql = <<<'SQL'
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
@ -167,14 +172,17 @@ SQL;
public function testPrepareExecute(): void public function testPrepareExecute(): void
{ {
if (empty(self::$db)) return; if (empty(self::$db))
{
return;
}
$sql = <<<SQL $sql = <<<'SQL'
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
self::$db->prepareExecute($sql, [ self::$db->prepareExecute($sql, [
2, 'works', 'also?' 2, 'works', 'also?',
]); ]);
$res = self::$db->query('SELECT * FROM "create_test" WHERE "id"=2') $res = self::$db->query('SELECT * FROM "create_test" WHERE "id"=2')
@ -183,13 +191,16 @@ SQL;
$this->assertEquals([ $this->assertEquals([
'id' => 2, 'id' => 2,
'key' => 'works', 'key' => 'works',
'val' => 'also?' 'val' => 'also?',
], $res); ], $res);
} }
public function testCommitTransaction(): void public function testCommitTransaction(): void
{ {
if (empty(self::$db)) return; if (empty(self::$db))
{
return;
}
self::$db->beginTransaction(); self::$db->beginTransaction();
@ -202,7 +213,10 @@ SQL;
public function testRollbackTransaction(): void public function testRollbackTransaction(): void
{ {
if (empty(self::$db)) return; if (empty(self::$db))
{
return;
}
self::$db->beginTransaction(); self::$db->beginTransaction();
@ -215,12 +229,12 @@ SQL;
public function testGetSchemas(): void public function testGetSchemas(): void
{ {
$this->assertTrue(\is_array(self::$db->getSchemas())); $this->assertIsArray(self::$db->getSchemas());
} }
public function testGetDBs(): void public function testGetDBs(): void
{ {
$this->assertTrue(\is_array(self::$db->getDbs())); $this->assertIsArray(self::$db->getDbs());
} }
public function testGetFunctions(): void public function testGetFunctions(): void

View File

@ -13,16 +13,18 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests\Drivers\PgSQL; namespace Query\Tests\Drivers\PgSQL;
use PDO; use PDO;
use Query\Tests\BaseQueryBuilderTest; use Query\Tests\BaseQueryBuilderTest;
use function in_array;
/** /**
* @requires extension pdo_pgsql * @requires extension pdo_pgsql
*/ */
class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { class PgSQLQueryBuilderTest extends BaseQueryBuilderTest
{
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
{ {
$params = get_json_config(); $params = get_json_config();
@ -35,11 +37,11 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
'user' => 'postgres', 'user' => 'postgres',
'pass' => '', 'pass' => '',
'type' => 'pgsql', 'type' => 'pgsql',
'prefix' => 'create_' 'prefix' => 'create_',
]; ];
} }
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
else if ($params !== FALSE) elseif ($params !== FALSE)
{ {
$params = $params->pgsql; $params = $params->pgsql;
$params->type = 'pgsql'; $params->type = 'pgsql';
@ -52,18 +54,18 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
self::$db = Query($params); self::$db = Query($params);
} }
public function setUp(): void protected function setUp(): void
{ {
// If the database isn't installed, skip the tests // If the database isn't installed, skip the tests
if ( ! \in_array('pgsql', PDO::getAvailableDrivers(), TRUE)) if ( ! in_array('pgsql', PDO::getAvailableDrivers(), TRUE))
{ {
$this->markTestSkipped('Postgres extension for PDO not loaded'); $this->markTestSkipped('Postgres extension for PDO not loaded');
} }
} }
public function testExists(): void public function testExists(): void
{ {
$this->assertTrue(\in_array('pgsql', PDO::getAvailableDrivers(), TRUE)); $this->assertTrue(in_array('pgsql', PDO::getAvailableDrivers(), TRUE));
} }
public function testQueryExplain(): void public function testQueryExplain(): void
@ -79,31 +81,31 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
// The exact results are version dependent // The exact results are version dependent
// The important thing is that there is an array // The important thing is that there is an array
// of results returned // of results returned
$this->assertTrue(\is_array($res)); $this->assertIsArray($res);
$this->assertTrue(count($res) > 1); $this->assertTrue(count($res) > 1);
$this->assertTrue(array_key_exists('QUERY PLAN', $res[0])); $this->assertArrayHasKey('QUERY PLAN', $res[0]);
/*$expected = array ( /*$expected = array (
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 ( array (
'QUERY PLAN' => ' Output: id, key, val', 'QUERY PLAN' => ' Output: id, key, val',
), ),
array ( 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 ( array (
'QUERY PLAN' => ' Output: id, key, val', 'QUERY PLAN' => ' Output: id, key, val',
), ),
array ( 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 ( 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 ( 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))',
), ),
); );

View File

@ -13,6 +13,7 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests\Drivers\SQLite; namespace Query\Tests\Drivers\SQLite;
use PDO; use PDO;
@ -26,8 +27,8 @@ use Query\Tests\BaseDriverTest;
* @extends DBTest * @extends DBTest
* @requires extension pdo_sqlite * @requires extension pdo_sqlite
*/ */
class SQLiteDriverTest extends BaseDriverTest { class SQLiteDriverTest extends BaseDriverTest
{
public static function setupBeforeClass(): void public static function setupBeforeClass(): void
{ {
$params = [ $params = [
@ -36,8 +37,8 @@ class SQLiteDriverTest extends BaseDriverTest {
'prefix' => 'create_', 'prefix' => 'create_',
'alias' => 'test_sqlite', 'alias' => 'test_sqlite',
'options' => [ 'options' => [
PDO::ATTR_PERSISTENT => TRUE PDO::ATTR_PERSISTENT => TRUE,
] ],
]; ];
self::$db = Query($params); self::$db = Query($params);
@ -50,7 +51,7 @@ class SQLiteDriverTest extends BaseDriverTest {
public function testCreateTable(): void 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 //Check
$dbs = self::$db->getTables(); $dbs = self::$db->getTables();
@ -84,7 +85,7 @@ SQL;
public function testBackupStructure(): void public function testBackupStructure(): void
{ {
$sql = mb_trim(self::$db->getUtil()->backupStructure()); $sql = mb_trim(self::$db->getUtil()->backupStructure());
$expected = <<<SQL $expected = <<<'SQL'
CREATE TABLE "create_test" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "key" TEXT, "val" TEXT); CREATE TABLE "create_test" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "key" TEXT, "val" TEXT);
CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT); CREATE TABLE "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
@ -164,7 +165,7 @@ SQL;
//Check //Check
$dbs = self::$db->getTables(); $dbs = self::$db->getTables();
$this->assertFalse(in_array('create_delete', $dbs)); $this->assertFalse(in_array('create_delete', $dbs, TRUE));
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -175,7 +176,7 @@ SQL;
{ {
$class = Driver::class; $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); $this->assertIsA($db, $class);
@ -190,7 +191,7 @@ SQL;
public function testPreparedStatements(): void public function testPreparedStatements(): void
{ {
$sql = <<<SQL $sql = <<<'SQL'
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
@ -204,18 +205,18 @@ SQL;
$this->assertEquals([ $this->assertEquals([
'id' => 1, 'id' => 1,
'key' => 'boogers', 'key' => 'boogers',
'val' => 'Gross' 'val' => 'Gross',
], $res); ], $res);
} }
public function testPrepareExecute(): void public function testPrepareExecute(): void
{ {
$sql = <<<SQL $sql = <<<'SQL'
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
self::$db->prepareExecute($sql, [ self::$db->prepareExecute($sql, [
2, 'works', 'also?' 2, 'works', 'also?',
]); ]);
$res = self::$db->query('SELECT * FROM "create_test" WHERE "id"=2') $res = self::$db->query('SELECT * FROM "create_test" WHERE "id"=2')
@ -224,7 +225,7 @@ SQL;
$this->assertEquals([ $this->assertEquals([
'id' => 2, 'id' => 2,
'key' => 'works', 'key' => 'works',
'val' => 'also?' 'val' => 'also?',
], $res); ], $res);
} }
@ -270,7 +271,7 @@ SQL;
public function testGetSystemTables(): void public function testGetSystemTables(): void
{ {
$sql = self::$db->getSystemTables(); $sql = self::$db->getSystemTables();
$this->assertTrue(\is_array($sql)); $this->assertIsArray($sql);
} }
public function testGetSequences(): void public function testGetSequences(): void

View File

@ -13,6 +13,7 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests\Drivers\SQLite; namespace Query\Tests\Drivers\SQLite;
use PDO; use PDO;
@ -23,8 +24,8 @@ use Query\Tests\BaseQueryBuilderTest;
* *
* @requires extension pdo_sqlite * @requires extension pdo_sqlite
*/ */
class SQLiteQueryBuilderTest extends BaseQueryBuilderTest { class SQLiteQueryBuilderTest extends BaseQueryBuilderTest
{
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
{ {
// Defined in the SQLiteTest.php file // Defined in the SQLiteTest.php file
@ -48,7 +49,7 @@ use Query\Tests\BaseQueryBuilderTest;
$res = $query->fetchAll(PDO::FETCH_ASSOC); $res = $query->fetchAll(PDO::FETCH_ASSOC);
$actualDetail = $res[0]['detail']; $actualDetail = $res[0]['detail'];
$this->assertTrue(is_string($actualDetail)); $this->assertIsString($actualDetail);
/* $expectedPossibilities = [ /* $expectedPossibilities = [
'TABLE create_test USING PRIMARY KEY', 'TABLE create_test USING PRIMARY KEY',
@ -77,11 +78,11 @@ use Query\Tests\BaseQueryBuilderTest;
public function testInsertReturning(): void public function testInsertReturning(): void
{ {
$this->markTestSkipped('Not implemented'); $this->markTestSkipped('Not implemented');
} }
public function testUpdateReturning(): void public function testUpdateReturning(): void
{ {
$this->markTestSkipped('Not implemented'); $this->markTestSkipped('Not implemented');
} }
} }

View File

@ -13,21 +13,23 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace Query\Tests; namespace Query\Tests;
use Query\QueryParser;
use Query\Drivers\Sqlite\Driver; use Query\Drivers\Sqlite\Driver;
use Query\QueryParser;
/** /**
* Tests for the Query Parser * Tests for the Query Parser
*/ */
class QueryParserTest extends TestCase { class QueryParserTest extends TestCase
{
/** /**
* @var QueryParser * @var QueryParser
*/ */
protected $parser; protected $parser;
public function setUp(): void protected function setUp(): void
{ {
$db = new Driver('sqlite::memory:'); $db = new Driver('sqlite::memory:');
$this->parser = new QueryParser($db); $this->parser = new QueryParser($db);
@ -37,7 +39,7 @@ class QueryParserTest extends TestCase {
{ {
$matches = $this->parser->parseJoin('table1.field1=table2.field2'); $matches = $this->parser->parseJoin('table1.field1=table2.field2');
$this->assertEqual($matches['combined'], [ $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'); $matches = $this->parser->parseJoin('db1.table1.field1!=db2.table2.field2');
$this->assertEqual($matches['combined'], [ $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'); $matches = $this->parser->parseJoin('table_1.field1 = tab_le2.field_2');
$this->assertEqual($matches['combined'], [ $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)'); $matches = $this->parser->parseJoin('table1.field1 > SUM(3+5)');
$this->assertEqual($matches['combined'], [ $this->assertEqual($matches['combined'], [
'table1.field1', '>', 'SUM(3+5)' 'table1.field1', '>', 'SUM(3+5)',
]); ]);
} }
} }

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types=1);
/** /**
* Query * Query
* *
@ -15,17 +15,17 @@
* Unit test bootstrap - Using phpunit * Unit test bootstrap - Using phpunit
*/ */
define('QTEST_DIR', realpath(__DIR__)); define('QTEST_DIR', realpath(__DIR__));
define('QBASE_DIR', realpath(QTEST_DIR.'/../') . '/'); define('QBASE_DIR', realpath(QTEST_DIR . '/../') . '/');
define('QDS', DIRECTORY_SEPARATOR); define('QDS', DIRECTORY_SEPARATOR);
function get_json_config() function get_json_config()
{ {
$files = [ $files = [
__DIR__ . '/settings.json', __DIR__ . '/settings.json',
__DIR__ . '/settings.json.dist' __DIR__ . '/settings.json.dist',
]; ];
foreach($files as $file) foreach ($files as $file)
{ {
if (is_file($file)) if (is_file($file))
{ {
@ -36,7 +36,7 @@ function get_json_config()
return FALSE; return FALSE;
} }
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'; $path = QTEST_DIR . QDS . 'db_files' . QDS . 'test_sqlite.db';
@unlink($path); @unlink($path);
require_once __DIR__ . '/TestCase.php'; require_once __DIR__ . '/TestCase.php';

View File

@ -13,6 +13,7 @@
* @link https://git.timshomepage.net/aviat/Query * @link https://git.timshomepage.net/aviat/Query
* @version 4.0.0 * @version 4.0.0
*/ */
namespace { namespace {
/** /**
* Unit test bootstrap - Using php simpletest * Unit test bootstrap - Using php simpletest
@ -26,14 +27,14 @@ namespace {
} }
namespace Query\Tests { namespace Query\Tests {
/** /**
* Base class for TestCases * Base class for TestCases
*/ */
abstract class TestCase extends \UnitTestCase { abstract class TestCase extends \UnitTestCase
{
public function __construct() public function __construct()
{ {
$class = \get_class($this); $class = static::class;
if (PHP_SAPI !== 'cli') if (PHP_SAPI !== 'cli')
{ {
@ -41,7 +42,8 @@ namespace Query\Tests {
flush(); flush();
} }
if (method_exists($class, 'setupBeforeClass')) { if (method_exists($class, 'setupBeforeClass'))
{
$class::setupBeforeClass(); $class::setupBeforeClass();
} }
@ -50,9 +52,10 @@ namespace Query\Tests {
public function __destruct() public function __destruct()
{ {
$class = \get_class($this); $class = static::class;
if (method_exists($class, 'tearDownAfterClass')) { if (method_exists($class, 'tearDownAfterClass'))
{
$class::tearDownAfterClass(); $class::tearDownAfterClass();
} }
} }
@ -60,8 +63,6 @@ namespace Query\Tests {
/** /**
* Define assertInstanceOf for simpletest * Define assertInstanceOf for simpletest
* *
* @param $expected
* @param $actual
* @param string $message * @param string $message
*/ */
public function assertInstanceOf($expected, $actual, $message = '') public function assertInstanceOf($expected, $actual, $message = '')
@ -111,16 +112,19 @@ namespace Query\Tests {
/** /**
* Load the test suites * Load the test suites
*/ */
namespace { namespace {
function get_json_config() function get_json_config()
{ {
$files = [ $files = [
__DIR__ . '/settings.json', __DIR__ . '/settings.json',
__DIR__ . '/settings.json.dist' __DIR__ . '/settings.json.dist',
]; ];
foreach ($files as $file) { foreach ($files as $file)
if (is_file($file)) { {
if (is_file($file))
{
return json_decode(file_get_contents($file)); return json_decode(file_get_contents($file));
} }
} }
@ -130,7 +134,7 @@ namespace {
// Include db tests // Include db tests
// Load db classes based on capability // Load db classes based on capability
$testPath = QTEST_DIR.'/Drivers/'; $testPath = QTEST_DIR . '/Drivers/';
// Require base testing classes // Require base testing classes
require_once QTEST_DIR . '/CoreTest.php'; require_once QTEST_DIR . '/CoreTest.php';
@ -145,7 +149,7 @@ namespace {
]; ];
// Determine which testcases to load // Determine which testcases to load
foreach($driverTestMap as $name => $doLoad) foreach ($driverTestMap as $name => $doLoad)
{ {
$path = $testPath . $name; $path = $testPath . $name;
@ -157,5 +161,4 @@ namespace {
} }
} }
// End of index.php // End of index.php