Version 3 #1

Manually merged
timw4mail merged 47 commits from develop into master 2020-04-23 18:39:27 -04:00
18 changed files with 200 additions and 215 deletions
Showing only changes of commit 6a36a85ac0 - Show all commits

View File

@ -1,27 +0,0 @@
before_script:
# Install dependencies
- sh build/docker_install.sh > /dev/null
- curl -sS https://getcomposer.org/installer | php
- php composer.phar install --ignore-platform-reqs
services:
- mysql:latest
- postgres:alpine
variables:
MYSQL_ROOT_PASSWORD: foo-bar-baz
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
POSTGRES_DB: test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
test:7.1:
image: php:7.1-alpine
script:
- vendor/bin/phpunit -c build --no-coverage
test:7.2:
image: php:7.2-alpine
script:
- vendor/bin/phpunit -c build --no-coverage

View File

@ -190,7 +190,7 @@ class RoboFile extends \Robo\Tasks {
{ {
$this->lint(); $this->lint();
$this->taskPhpUnit() $this->taskPhpUnit()
->configFile('phpunit.xml') ->configFile('build/phpunit.xml')
->run(); ->run();
$this->_run(["php tests/index.php"]); $this->_run(["php tests/index.php"]);
} }

View File

@ -3,11 +3,12 @@
* *
* SQL Query Builder / Database Abstraction Layer * SQL Query Builder / Database Abstraction Layer
* *
* PHP version 7.1 * PHP version 7.2
* *
* @package Query * @package Query
* @author Timothy J. Warren <tim@timshomepage.net> * @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2012 - 2018 Timothy J. Warren * @copyright 2012 - 2018 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License * @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query * @link https://git.timshomepage.net/aviat4ion/Query
* @version 3.0.0
*/ */

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit <phpunit
addUncoveredFilesFromWhitelist="true"
colors="true" colors="true"
stopOnFailure="false" stopOnFailure="false"
bootstrap="./../tests/bootstrap.php"> bootstrap="./../tests/bootstrap.php">
@ -29,6 +28,6 @@
<log type="coverage-html" target="./../coverage"/> <log type="coverage-html" target="./../coverage"/>
<log type="coverage-clover" target="logs/clover.xml"/> <log type="coverage-clover" target="logs/clover.xml"/>
<log type="coverage-xml" target="logs/coverage" /> <log type="coverage-xml" target="logs/coverage" />
<log type="xml" target="logs/junit.xml" logIncompleteSkipped="true"/> <log type="junit" target="logs/junit.xml" />
</logging> </logging>
</phpunit> </phpunit>

View File

@ -1,7 +0,0 @@
sonar.projectKey=query
sonar.projectName=Query Builder
sonar.projectVersion=2.5.1
sonar.sources=src
sonar.language=php
sonar.php.coverage.reportPath=build/logs/clover.xml
sonar.php.tests.reportPath=build/logs/junit.xml

View File

@ -14,6 +14,8 @@
*/ */
namespace Query\Drivers; namespace Query\Drivers;
use function dbFilter;
use InvalidArgumentException; use InvalidArgumentException;
use PDO; use PDO;
use PDOStatement; use PDOStatement;
@ -297,7 +299,7 @@ abstract class AbstractDriver
*/ */
public function quoteIdent($identifier) public function quoteIdent($identifier)
{ {
if (\is_array($identifier)) if (is_array($identifier))
{ {
return array_map([$this, __METHOD__], $identifier); return array_map([$this, __METHOD__], $identifier);
} }
@ -480,14 +482,14 @@ abstract class AbstractDriver
public function driverQuery($query, $filteredIndex=TRUE): ?array public function driverQuery($query, $filteredIndex=TRUE): ?array
{ {
// Call the appropriate method, if it exists // Call the appropriate method, if it exists
if (\is_string($query) && method_exists($this->sql, $query)) if (is_string($query) && method_exists($this->sql, $query))
{ {
$query = $this->getSql()->$query(); $query = $this->getSql()->$query();
} }
// Return if the values are returned instead of a query, // Return if the values are returned instead of a query,
// or if the query doesn't apply to the driver // or if the query doesn't apply to the driver
if ( ! \is_string($query)) if ( ! is_string($query))
{ {
return $query; return $query;
} }
@ -498,7 +500,7 @@ abstract class AbstractDriver
$flag = $filteredIndex ? PDO::FETCH_NUM : PDO::FETCH_ASSOC; $flag = $filteredIndex ? PDO::FETCH_NUM : PDO::FETCH_ASSOC;
$all = $res->fetchAll($flag); $all = $res->fetchAll($flag);
return $filteredIndex ? \dbFilter($all, 0) : $all; return $filteredIndex ? dbFilter($all, 0) : $all;
} }
/** /**
@ -526,7 +528,7 @@ abstract class AbstractDriver
* *
* @param string $table * @param string $table
* @param mixed $data * @param mixed $data
* @return null|array<string|array|null> * @return array<string|array|null>
*/ */
public function insertBatch(string $table, array $data=[]): array public function insertBatch(string $table, array $data=[]): array
{ {
@ -539,6 +541,7 @@ abstract class AbstractDriver
{ {
$vals = array_merge($vals, array_values($group)); $vals = array_merge($vals, array_values($group));
} }
$table = $this->quoteTable($table); $table = $this->quoteTable($table);
$fields = array_keys($firstRow); $fields = array_keys($firstRow);
@ -577,7 +580,7 @@ abstract class AbstractDriver
// Get the keys of the current set of data, except the one used to // Get the keys of the current set of data, except the one used to
// set the update condition // set the update condition
$fields = array_unique( $fields = array_unique(
array_reduce($data, function ($previous, $current) use (&$affectedRows, $where) { array_reduce($data, static function ($previous, $current) use (&$affectedRows, $where) {
$affectedRows++; $affectedRows++;
$keys = array_diff(array_keys($current), [$where]); $keys = array_diff(array_keys($current), [$where]);

View File

@ -14,6 +14,7 @@
*/ */
namespace Query\Drivers; namespace Query\Drivers;
use InvalidArgumentException;
use PDOStatement; use PDOStatement;
/** /**
@ -36,8 +37,8 @@ interface DriverInterface {
* *
* @param string $sql * @param string $sql
* @param array $data * @param array $data
* @return \PDOStatement|null * @return PDOStatement|null
* @throws \InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function prepareQuery(string $sql, array $data): PDOStatement; public function prepareQuery(string $sql, array $data): PDOStatement;
@ -129,15 +130,6 @@ interface DriverInterface {
*/ */
public function getTriggers(): ?array; public function getTriggers(): ?array;
/**
* Quotes a string for use in a query (from native PDO)
*
* @param string $string
* @param int $parameter_type
* @return string
*/
public function quote($string, $parameter_type = NULL);
/** /**
* Surrounds the string with the databases identifier escape characters * Surrounds the string with the databases identifier escape characters
* *

View File

@ -14,6 +14,8 @@
*/ */
namespace Query; namespace Query;
use function regexInArray;
use BadMethodCallException; use BadMethodCallException;
use PDOStatement; use PDOStatement;
use Query\Drivers\DriverInterface; use Query\Drivers\DriverInterface;
@ -1059,7 +1061,7 @@ class QueryBuilder implements QueryBuilderInterface {
// Determine the correct conjunction // Determine the correct conjunction
$conjunctionList = array_column($queryMap, 'conjunction'); $conjunctionList = array_column($queryMap, 'conjunction');
if (empty($queryMap) || ( ! \regexInArray($conjunctionList, "/^ ?\n?WHERE/i"))) if (empty($queryMap) || ( ! regexInArray($conjunctionList, "/^ ?\n?WHERE/i")))
{ {
$conj = "\nWHERE "; $conj = "\nWHERE ";
} }
@ -1152,10 +1154,10 @@ class QueryBuilder implements QueryBuilderInterface {
* @param int $totalTime * @param int $totalTime
* @return void * @return void
*/ */
protected function _appendQuery(array $values = NULL, string $sql, int $totalTime): void protected function _appendQuery(array $values, string $sql, int $totalTime): void
{ {
$evals = \is_array($values) ? $values : []; $evals = \is_array($values) ? $values : [];
$esql = str_replace('?', "%s", $sql); $esql = str_replace('?', '%s', $sql);
// Quote string values // Quote string values
foreach($evals as &$v) foreach($evals as &$v)

View File

@ -14,58 +14,60 @@
*/ */
namespace Query\Tests; namespace Query\Tests;
use Query\QueryBuilderInterface;
/** /**
* Parent Database Test Class * Parent Database Test Class
*/ */
abstract class BaseDriverTest extends TestCase { abstract class BaseDriverTest extends TestCase {
/** /**
* @var \Query\QueryBuilderInterface|null * @var QueryBuilderInterface|null
*/ */
protected static $db; protected static $db;
abstract public function testConnection(); abstract public function testConnection();
public static function tearDownAfterClass() public static function tearDownAfterClass(): void
{ {
self::$db = NULL; self::$db = NULL;
} }
public function testGetTables() public function testGetTables(): void
{ {
$tables = self::$db->getTables(); $tables = self::$db->getTables();
$this->assertTrue(\is_array($tables)); $this->assertTrue(\is_array($tables));
$this->assertTrue( ! empty($tables)); $this->assertTrue( ! empty($tables));
} }
public function testGetSystemTables() public function testGetSystemTables(): void
{ {
$tables = self::$db->getSystemTables(); $tables = self::$db->getSystemTables();
$this->assertTrue(\is_array($tables)); $this->assertTrue(\is_array($tables));
$this->assertTrue( ! empty($tables)); $this->assertTrue( ! empty($tables));
} }
public function testBackupData() 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', FALSE])));
$this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', TRUE]))); $this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', TRUE])));
} }
public function testGetColumns() public function testGetColumns(): void
{ {
$cols = self::$db->getColumns('test'); $cols = self::$db->getColumns('test');
$this->assertTrue(\is_array($cols)); $this->assertTrue(\is_array($cols));
$this->assertTrue( ! empty($cols)); $this->assertTrue( ! empty($cols));
} }
public function testGetTypes() public function testGetTypes(): void
{ {
$types = self::$db->getTypes(); $types = self::$db->getTypes();
$this->assertTrue(\is_array($types)); $this->assertTrue(\is_array($types));
$this->assertTrue( ! empty($types)); $this->assertTrue( ! empty($types));
} }
public function testGetFKs() public function testGetFKs(): void
{ {
$expected = [[ $expected = [[
'child_column' => 'ext_id', 'child_column' => 'ext_id',
@ -79,13 +81,13 @@ abstract class BaseDriverTest extends TestCase {
$this->assertEqual($expected, $keys); $this->assertEqual($expected, $keys);
} }
public function testGetIndexes() public function testGetIndexes(): void
{ {
$keys = self::$db->getIndexes('test'); $keys = self::$db->getIndexes('test');
$this->assertTrue(\is_array($keys)); $this->assertTrue(\is_array($keys));
} }
public function testGetViews() public function testGetViews(): void
{ {
$views = self::$db->getViews(); $views = self::$db->getViews();
$expected = ['numbersview', 'testview']; $expected = ['numbersview', 'testview'];
@ -93,7 +95,7 @@ abstract class BaseDriverTest extends TestCase {
$this->assertTrue(\is_array($views)); $this->assertTrue(\is_array($views));
} }
public function testGetTriggers() public function testGetTriggers(): void
{ {
// @TODO standardize trigger output for different databases // @TODO standardize trigger output for different databases
@ -101,7 +103,7 @@ abstract class BaseDriverTest extends TestCase {
$this->assertTrue(\is_array($triggers)); $this->assertTrue(\is_array($triggers));
} }
public function testGetSequences() public function testGetSequences(): void
{ {
$seqs = self::$db->getSequences(); $seqs = self::$db->getSequences();
@ -114,13 +116,13 @@ abstract class BaseDriverTest extends TestCase {
$this->assertEqual($expected, $seqs); $this->assertEqual($expected, $seqs);
} }
public function testGetProcedures() public function testGetProcedures(): void
{ {
$procedures = self::$db->getProcedures(); $procedures = self::$db->getProcedures();
$this->assertTrue(\is_array($procedures)); $this->assertTrue(\is_array($procedures));
} }
public function testGetFunctions() public function testGetFunctions(): void
{ {
$funcs = self::$db->getFunctions(); $funcs = self::$db->getFunctions();
$this->assertTrue(\is_array($funcs)); $this->assertTrue(\is_array($funcs));

View File

@ -17,6 +17,7 @@ namespace Query\Tests;
use BadMethodCallException; use BadMethodCallException;
use PDO; use PDO;
use Query\Exception\BadDBDriverException; use Query\Exception\BadDBDriverException;
use Query\QueryBuilderInterface;
/** /**
* Query builder parent test class * Query builder parent test class
@ -24,7 +25,7 @@ use Query\Exception\BadDBDriverException;
abstract class BaseQueryBuilderTest extends TestCase { abstract class BaseQueryBuilderTest extends TestCase {
/** /**
* @var \Query\QueryBuilderInterface|null * @var QueryBuilderInterface|null
*/ */
protected static $db; protected static $db;
@ -36,7 +37,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
} }
} }
public static function tearDownAfterClass() public static function tearDownAfterClass(): void
{ {
if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg') if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg')
{ {
@ -47,17 +48,17 @@ abstract class BaseQueryBuilderTest extends TestCase {
} }
// ! Driver-specific results // ! Driver-specific results
abstract public function testQueryExplain(); abstract public function testQueryExplain(): void;
// ! Get tests // ! Get tests
public function testInvalidConnectionName() public function testInvalidConnectionName(): void
{ {
$this->expectException('InvalidArgumentException'); $this->expectException('InvalidArgumentException');
Query('foo'); Query('foo');
} }
public function testFunctionGet() public function testFunctionGet(): void
{ {
$query = self::$db->select('id, COUNT(id) as count') $query = self::$db->select('id, COUNT(id) as count')
->from('test') ->from('test')
@ -67,7 +68,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testGet() public function testGet(): void
{ {
$query = self::$db->get('test'); $query = self::$db->get('test');
@ -76,14 +77,14 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertTrue(\is_string($lastQuery)); $this->assertTrue(\is_string($lastQuery));
} }
public function testPrefixGet() public function testPrefixGet(): void
{ {
$query = self::$db->from('test')->get(); $query = self::$db->from('test')->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testGetWNumRows() public function testGetWNumRows(): void
{ {
$query = self::$db->get('test'); $query = self::$db->get('test');
$numrows = count($query->fetchAll(PDO::FETCH_NUM)); $numrows = count($query->fetchAll(PDO::FETCH_NUM));
@ -91,28 +92,28 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertEqual(self::$db->numRows(), $numrows); $this->assertEqual(self::$db->numRows(), $numrows);
} }
public function testGetLimit() public function testGetLimit(): void
{ {
$query = self::$db->get('test', 2); $query = self::$db->get('test', 2);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testGetLimitSkip() public function testGetLimitSkip(): void
{ {
$query = self::$db->get('test', 2, 1); $query = self::$db->get('test', 2, 1);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testGetWhere() public function testGetWhere(): void
{ {
$query = self::$db->getWhere('test', ['id !=' => 1], 2, 1); $query = self::$db->getWhere('test', ['id !=' => 1], 2, 1);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testHaving() public function testHaving(): void
{ {
$query = self::$db->select('id') $query = self::$db->select('id')
->from('test') ->from('test')
@ -124,7 +125,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testOrHaving() public function testOrHaving(): void
{ {
$query = self::$db->select('id') $query = self::$db->select('id')
->from('test') ->from('test')
@ -136,7 +137,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
// ! Select tests // ! Select tests
public function testSelectWhereGet() public function testSelectWhereGet(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->where('id >', 1) ->where('id >', 1)
@ -146,7 +147,17 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectAvg() public function testSelectWhereGetNoAs(): void
{
$query = self::$db->select('id, key, val')
->where('id >', 1)
->where('id <', 900)
->get('test', 2, 1);
$this->assertIsA($query, 'PDOStatement');
}
public function testSelectAvg(): void
{ {
$query = self::$db->selectAvg('id', 'di') $query = self::$db->selectAvg('id', 'di')
->get('test'); ->get('test');
@ -154,7 +165,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectSum() public function testSelectSum(): void
{ {
$query = self::$db->selectSum('id', 'di') $query = self::$db->selectSum('id', 'di')
->get('test'); ->get('test');
@ -162,7 +173,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectDistinct() public function testSelectDistinct(): void
{ {
$query = self::$db->selectSum('id', 'di') $query = self::$db->selectSum('id', 'di')
->distinct() ->distinct()
@ -171,7 +182,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectGet() public function testSelectGet(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->get('test', 2, 1); ->get('test', 2, 1);
@ -179,7 +190,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectFromGet() public function testSelectFromGet(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test ct') ->from('test ct')
@ -189,7 +200,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectFromLimitGet() public function testSelectFromLimitGet(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test ct') ->from('test ct')
@ -200,7 +211,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectWhereGet2() public function testSelectWhereGet2(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->where('id !=', 1) ->where('id !=', 1)
@ -209,7 +220,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectMax() public function testSelectMax(): void
{ {
$query = self::$db->selectMax('id', 'di') $query = self::$db->selectMax('id', 'di')
->get('test'); ->get('test');
@ -217,7 +228,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectMin() public function testSelectMin(): void
{ {
$query = self::$db->selectMin('id', 'di') $query = self::$db->selectMin('id', 'di')
->get('test'); ->get('test');
@ -225,7 +236,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testMultiOrderBy() public function testMultiOrderBy(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->orderBy('id, key') ->orderBy('id, key')
@ -234,7 +245,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
// ! Grouping tests // ! Grouping tests
public function testGroup() public function testGroup(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -248,7 +259,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testOrGroup() public function testOrGroup(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -265,7 +276,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testOrNotGroup() public function testOrNotGroup(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -282,7 +293,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testAndNotGroupStart() public function testAndNotGroupStart(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -299,7 +310,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testNotGroupStart() public function testNotGroupStart(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -312,7 +323,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testGroupCamelCase() public function testGroupCamelCase(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -329,7 +340,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
// ! Where In tests // ! Where In tests
public function testWhereIn() public function testWhereIn(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->whereIn('id', [0, 6, 56, 563, 341]) ->whereIn('id', [0, 6, 56, 563, 341])
@ -338,7 +349,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testOrWhereIn() public function testOrWhereIn(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->where('key', 'false') ->where('key', 'false')
@ -348,7 +359,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testWhereNotIn() public function testWhereNotIn(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->where('key', 'false') ->where('key', 'false')
@ -358,7 +369,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testOrWhereNotIn() public function testOrWhereNotIn(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->where('key', 'false') ->where('key', 'false')
@ -368,7 +379,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
// ! Query modifier tests // ! Query modifier tests
public function testOrderBy() public function testOrderBy(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -382,7 +393,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testOrderByRandom() public function testOrderByRandom(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -395,7 +406,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testGroupBy() public function testGroupBy(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -413,7 +424,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
//public function testOr //public function testOr
public function testOrWhere() public function testOrWhere(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -425,7 +436,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testLike() public function testLike(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->like('key', 'og') ->like('key', 'og')
@ -434,7 +445,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testOrLike() public function testOrLike(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->like('key', 'og') ->like('key', 'og')
@ -444,7 +455,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testOrNotLike() public function testOrNotLike(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->like('key', 'og', 'before') ->like('key', 'og', 'before')
@ -454,7 +465,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testNotLike() public function testNotLike(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->like('key', 'og', 'before') ->like('key', 'og', 'before')
@ -464,7 +475,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testLikeBefore() public function testLikeBefore(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->like('key', 'og', 'before') ->like('key', 'og', 'before')
@ -473,7 +484,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testLikeAfter() public function testLikeAfter(): void
{ {
$query = self::$db->from('test') $query = self::$db->from('test')
->like('key', 'og', 'after') ->like('key', 'og', 'after')
@ -482,7 +493,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testJoin() public function testJoin(): void
{ {
$query = self::$db->from('test ct') $query = self::$db->from('test ct')
->join('join cj', 'cj.id = ct.id') ->join('join cj', 'cj.id = ct.id')
@ -491,7 +502,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testLeftJoin() public function testLeftJoin(): void
{ {
$query = self::$db->from('test ct') $query = self::$db->from('test ct')
->join('join cj', 'cj.id = ct.id', 'left') ->join('join cj', 'cj.id = ct.id', 'left')
@ -500,7 +511,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testInnerJoin() public function testInnerJoin(): void
{ {
$query = self::$db->from('test ct') $query = self::$db->from('test ct')
->join('join cj', 'cj.id = ct.id', 'inner') ->join('join cj', 'cj.id = ct.id', 'inner')
@ -509,7 +520,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testJoinWithMultipleWhereValues() public function testJoinWithMultipleWhereValues(): void
{ {
$query = self::$db->from('test ct') $query = self::$db->from('test ct')
->join('join cj', 'cj.id=ct.id', 'inner') ->join('join cj', 'cj.id=ct.id', 'inner')
@ -523,7 +534,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
} }
// ! DB update tests // ! DB update tests
public function testInsert() public function testInsert(): void
{ {
$query = self::$db->set('id', 98) $query = self::$db->set('id', 98)
->set('key', 84) ->set('key', 84)
@ -534,7 +545,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertTrue(self::$db->affectedRows() > 0); $this->assertTrue(self::$db->affectedRows() > 0);
} }
public function testInsertArray() public function testInsertArray(): void
{ {
$query = self::$db->insert('test', [ $query = self::$db->insert('test', [
'id' => 587, 'id' => 587,
@ -545,7 +556,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testInsertBatch() public function testInsertBatch(): void
{ {
$data = [ $data = [
[ [
@ -570,7 +581,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testUpdate() public function testUpdate(): void
{ {
$query = self::$db->where('id', 7) $query = self::$db->where('id', 7)
->update('test', [ ->update('test', [
@ -582,13 +593,13 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testUpdateBatchNull() public function testUpdateBatchNull(): void
{ {
$query = self::$db->updateBatch('test', [], ''); $query = self::$db->updateBatch('test', [], '');
$this->assertNull($query); $this->assertNull($query);
} }
public function testDriverUpdateBatch() public function testDriverUpdateBatch(): void
{ {
$data = [ $data = [
[ [
@ -607,7 +618,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertEquals(2, $affectedRows); $this->assertEquals(2, $affectedRows);
} }
public function testSetArrayUpdate() public function testSetArrayUpdate(): void
{ {
$array = [ $array = [
'id' => 22, 'id' => 22,
@ -622,7 +633,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testWhereSetUpdate() public function testWhereSetUpdate(): void
{ {
$query = self::$db->where('id', 36) $query = self::$db->where('id', 36)
->set('id', 36) ->set('id', 36)
@ -633,14 +644,14 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testDelete() public function testDelete(): void
{ {
$query = self::$db->delete('test', ['id' => 5]); $query = self::$db->delete('test', ['id' => 5]);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testDeleteWithMultipleWhereValues() public function testDeleteWithMultipleWhereValues(): void
{ {
$query = self::$db->delete('test', [ $query = self::$db->delete('test', [
'id' => 5, 'id' => 5,
@ -651,21 +662,21 @@ abstract class BaseQueryBuilderTest extends TestCase {
} }
// ! Non-data read queries // ! Non-data read queries
public function testCountAll() public function testCountAll(): void
{ {
$query = self::$db->countAll('test'); $query = self::$db->countAll('test');
$this->assertTrue(is_numeric($query)); $this->assertTrue(is_numeric($query));
} }
public function testCountAllResults() public function testCountAllResults(): void
{ {
$query = self::$db->countAllResults('test'); $query = self::$db->countAllResults('test');
$this->assertTrue(is_numeric($query)); $this->assertTrue(is_numeric($query));
} }
public function testCountAllResults2() public function testCountAllResults2(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->from('test') ->from('test')
@ -677,25 +688,25 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertTrue(is_numeric($query)); $this->assertTrue(is_numeric($query));
} }
public function testNumRows() public function testNumRows(): void
{ {
self::$db->get('test'); self::$db->get('test');
$this->assertTrue(is_numeric(self::$db->numRows())); $this->assertTrue(is_numeric(self::$db->numRows()));
} }
// ! Compiled Query tests // ! Compiled Query tests
public function testGetCompiledSelect() public function testGetCompiledSelect(): void
{ {
$sql = self::$db->getCompiledSelect('test'); $sql = self::$db->getCompiledSelect('test');
$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);
} }
public function testGetCompiledUpdate() public function testGetCompiledUpdate(): void
{ {
$sql = self::$db->set([ $sql = self::$db->set([
'id' => 4, 'id' => 4,
@ -706,7 +717,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertTrue(\is_string($sql)); $this->assertTrue(\is_string($sql));
} }
public function testGetCompiledInsert() public function testGetCompiledInsert(): void
{ {
$sql = self::$db->set([ $sql = self::$db->set([
'id' => 4, 'id' => 4,
@ -717,7 +728,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertTrue(\is_string($sql)); $this->assertTrue(\is_string($sql));
} }
public function testGetCompiledDelete() public function testGetCompiledDelete(): void
{ {
$sql = self::$db->where('id', 4) $sql = self::$db->where('id', 4)
->getCompiledDelete('test'); ->getCompiledDelete('test');
@ -728,7 +739,7 @@ abstract class BaseQueryBuilderTest extends TestCase {
/** /**
* Handles invalid drivers * Handles invalid drivers
*/ */
public function testBadDriver() public function testBadDriver(): void
{ {
$params = [ $params = [
'host' => '127.0.0.1', 'host' => '127.0.0.1',
@ -744,14 +755,14 @@ abstract class BaseQueryBuilderTest extends TestCase {
self::$db = Query($params); self::$db = Query($params);
} }
public function testBadMethod() public function testBadMethod(): void
{ {
$this->expectException(BadMethodCallException::class); $this->expectException(BadMethodCallException::class);
self::$db->foo(); self::$db->foo();
} }
public function testBadNumRows() public function testBadNumRows(): void
{ {
self::$db->set([ self::$db->set([
'id' => 999, 'id' => 999,

View File

@ -21,17 +21,17 @@ class ConnectionManagerTest extends TestCase {
protected static $instance; protected static $instance;
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
self::$instance = ConnectionManager::getInstance(); self::$instance = ConnectionManager::getInstance();
} }
public static function tearDownAfterClass() public static function tearDownAfterClass(): void
{ {
self::$instance = NULL; self::$instance = NULL;
} }
public function testNoClone() public function testNoClone(): void
{ {
$this->expectException('DomainException'); $this->expectException('DomainException');
$this->expectExceptionMessage("Can't clone singleton"); $this->expectExceptionMessage("Can't clone singleton");
@ -39,7 +39,7 @@ class ConnectionManagerTest extends TestCase {
$this->assertNull($clone); $this->assertNull($clone);
} }
public function testNoSerialize() public function testNoSerialize(): void
{ {
$this->expectException(DomainException::class); $this->expectException(DomainException::class);
$this->expectExceptionMessage('No serializing of singleton'); $this->expectExceptionMessage('No serializing of singleton');
@ -50,14 +50,14 @@ class ConnectionManagerTest extends TestCase {
self::$instance->__sleep(); self::$instance->__sleep();
} }
public function testNoUnserialize() public function testNoUnserialize(): void
{ {
$this->expectException(DomainException::class); $this->expectException(DomainException::class);
$this->expectExceptionMessage("Can't unserialize singleton"); $this->expectExceptionMessage("Can't unserialize singleton");
self::$instance->__wakeup(); self::$instance->__wakeup();
} }
public function testParseParams() public function testParseParams(): void
{ {
$params = new class { $params = new class {
public $type = 'sqlite'; public $type = 'sqlite';
@ -77,7 +77,7 @@ class ConnectionManagerTest extends TestCase {
$this->assertEqual($expected, self::$instance->parseParams($params)); $this->assertEqual($expected, self::$instance->parseParams($params));
} }
public function testConnect() public function testConnect(): void
{ {
$params = new class { $params = new class {
public $type = 'sqlite'; public $type = 'sqlite';
@ -96,7 +96,7 @@ class ConnectionManagerTest extends TestCase {
$this->assertEqual($conn, self::$instance->getConnection()); $this->assertEqual($conn, self::$instance->getConnection());
} }
public function testGetConnection() public function testGetConnection(): void
{ {
$params = (object) [ $params = (object) [
'type' => 'sqlite', 'type' => 'sqlite',

View File

@ -26,7 +26,7 @@ use TypeError;
*/ */
class MySQLDriverTest extends BaseDriverTest { class MySQLDriverTest extends BaseDriverTest {
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
$params = get_json_config(); $params = get_json_config();
if ($var = getenv('TRAVIS')) if ($var = getenv('TRAVIS'))
@ -46,17 +46,17 @@ class MySQLDriverTest extends BaseDriverTest {
self::$db->setTablePrefix('create_'); self::$db->setTablePrefix('create_');
} }
public function testExists() public function testExists(): void
{ {
$this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE)); $this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE));
} }
public function testConnection() public function testConnection(): void
{ {
$this->assertIsA(self::$db, Driver::class); $this->assertIsA(self::$db, Driver::class);
} }
public function testCreateTable() 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'));
@ -95,7 +95,7 @@ class MySQLDriverTest extends BaseDriverTest {
} }
public function testTruncate() public function testTruncate(): void
{ {
self::$db->truncate('test'); self::$db->truncate('test');
$this->assertEquals(0, self::$db->countAll('test')); $this->assertEquals(0, self::$db->countAll('test'));
@ -104,13 +104,13 @@ class MySQLDriverTest extends BaseDriverTest {
$this->assertEquals(0, self::$db->countAll('join')); $this->assertEquals(0, self::$db->countAll('join'));
} }
public function testPreparedStatements() 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']);
$res = $statement->execute(); $res = $statement->execute();
@ -118,7 +118,7 @@ SQL;
} }
public function testBadPreparedStatement() public function testBadPreparedStatement(): void
{ {
if (is_a($this, \UnitTestCase::class)) if (is_a($this, \UnitTestCase::class))
{ {
@ -137,21 +137,21 @@ SQL;
} }
public function testPrepareExecute() 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() public function testCommitTransaction(): void
{ {
$res = self::$db->beginTransaction(); $res = self::$db->beginTransaction();
@ -162,7 +162,7 @@ SQL;
$this->assertTrue($res); $this->assertTrue($res);
} }
public function testRollbackTransaction() public function testRollbackTransaction(): void
{ {
$res = self::$db->beginTransaction(); $res = self::$db->beginTransaction();
@ -173,17 +173,17 @@ SQL;
$this->assertTrue($res); $this->assertTrue($res);
} }
public function testGetSchemas() public function testGetSchemas(): void
{ {
$this->assertNull(self::$db->getSchemas()); $this->assertNull(self::$db->getSchemas());
} }
public function testGetSequences() public function testGetSequences(): void
{ {
$this->assertNull(self::$db->getSequences()); $this->assertNull(self::$db->getSequences());
} }
public function testBackup() public function testBackup(): void
{ {
$this->assertTrue(\is_string(self::$db->getUtil()->backupStructure())); $this->assertTrue(\is_string(self::$db->getUtil()->backupStructure()));
} }

View File

@ -22,7 +22,7 @@ use Query\Tests\BaseQueryBuilderTest;
*/ */
class MySQLQueryBuilderTest extends BaseQueryBuilderTest { class MySQLQueryBuilderTest extends BaseQueryBuilderTest {
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
$params = get_json_config(); $params = get_json_config();
if ($var = getenv('TRAVIS')) // Travis CI Connection Info if ($var = getenv('TRAVIS')) // Travis CI Connection Info
@ -49,12 +49,12 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest {
self::$db = Query($params); self::$db = Query($params);
} }
public function testExists() public function testExists(): void
{ {
$this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE)); $this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE));
} }
public function testQueryExplain() public function testQueryExplain(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->explain() ->explain()

View File

@ -27,7 +27,7 @@ use TypeError;
*/ */
class PgSQLDriverTest extends BaseDriverTest { class PgSQLDriverTest extends BaseDriverTest {
public function setUp() public 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))
@ -36,7 +36,7 @@ class PgSQLDriverTest extends BaseDriverTest {
} }
} }
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
$params = get_json_config(); $params = get_json_config();
@ -54,20 +54,20 @@ class PgSQLDriverTest extends BaseDriverTest {
self::$db->setTablePrefix('create_'); self::$db->setTablePrefix('create_');
} }
public function testExists() public function testExists(): void
{ {
$drivers = PDO::getAvailableDrivers(); $drivers = PDO::getAvailableDrivers();
$this->assertTrue(in_array('pgsql', $drivers, TRUE)); $this->assertTrue(in_array('pgsql', $drivers, TRUE));
} }
public function testConnection() 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);
} }
public function testCreateTable() public function testCreateTable(): void
{ {
self::$db->exec(file_get_contents(QTEST_DIR.'/db_files/pgsql.sql')); self::$db->exec(file_get_contents(QTEST_DIR.'/db_files/pgsql.sql'));
@ -117,7 +117,7 @@ class PgSQLDriverTest extends BaseDriverTest {
} }
public function testTruncate() public function testTruncate(): void
{ {
self::$db->truncate('test'); self::$db->truncate('test');
$this->assertEquals(0, self::$db->countAll('test')); $this->assertEquals(0, self::$db->countAll('test'));
@ -126,7 +126,7 @@ class PgSQLDriverTest extends BaseDriverTest {
$this->assertEquals(0, self::$db->countAll('join')); $this->assertEquals(0, self::$db->countAll('join'));
} }
public function testPreparedStatements() public function testPreparedStatements(): void
{ {
$sql = <<<SQL $sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
@ -146,7 +146,7 @@ SQL;
], $res); ], $res);
} }
public function testBadPreparedStatement() public function testBadPreparedStatement(): void
{ {
if (is_a($this, \UnitTestCase::class)) if (is_a($this, \UnitTestCase::class))
{ {
@ -164,7 +164,7 @@ SQL;
self::$db->prepareQuery($sql, 'foo'); self::$db->prepareQuery($sql, 'foo');
} }
public function testPrepareExecute() public function testPrepareExecute(): void
{ {
if (empty(self::$db)) return; if (empty(self::$db)) return;
@ -186,7 +186,7 @@ SQL;
], $res); ], $res);
} }
public function testCommitTransaction() public function testCommitTransaction(): void
{ {
if (empty(self::$db)) return; if (empty(self::$db)) return;
@ -199,7 +199,7 @@ SQL;
$this->assertTrue($res); $this->assertTrue($res);
} }
public function testRollbackTransaction() public function testRollbackTransaction(): void
{ {
if (empty(self::$db)) return; if (empty(self::$db)) return;
@ -212,17 +212,17 @@ SQL;
$this->assertTrue($res); $this->assertTrue($res);
} }
public function testGetSchemas() public function testGetSchemas(): void
{ {
$this->assertTrue(\is_array(self::$db->getSchemas())); $this->assertTrue(\is_array(self::$db->getSchemas()));
} }
public function testGetDBs() public function testGetDBs(): void
{ {
$this->assertTrue(\is_array(self::$db->getDbs())); $this->assertTrue(\is_array(self::$db->getDbs()));
} }
public function testGetFunctions() public function testGetFunctions(): void
{ {
$this->assertNull(self::$db->getFunctions()); $this->assertNull(self::$db->getFunctions());
} }

View File

@ -22,7 +22,7 @@ use Query\Tests\BaseQueryBuilderTest;
*/ */
class PgSQLQueryBuilderTest extends BaseQueryBuilderTest { class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
$params = get_json_config(); $params = get_json_config();
if (getenv('TRAVIS')) // Travis CI Connection Info if (getenv('TRAVIS')) // Travis CI Connection Info
@ -51,7 +51,7 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
self::$db = Query($params); self::$db = Query($params);
} }
public function setUp() public 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))
@ -60,12 +60,12 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
} }
} }
public function testExists() public function testExists(): void
{ {
$this->assertTrue(\in_array('pgsql', PDO::getAvailableDrivers(), TRUE)); $this->assertTrue(\in_array('pgsql', PDO::getAvailableDrivers(), TRUE));
} }
public function testQueryExplain() public function testQueryExplain(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->explain() ->explain()
@ -109,7 +109,7 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
$this->assertEqual($expected, $res);*/ $this->assertEqual($expected, $res);*/
} }
public function testBackupStructure() public function testBackupStructure(): void
{ {
$this->assertEquals('', self::$db->getUtil()->backupStructure()); $this->assertEquals('', self::$db->getUtil()->backupStructure());
} }

View File

@ -27,7 +27,7 @@ use Query\Tests\BaseDriverTest;
*/ */
class SQLiteDriverTest extends BaseDriverTest { class SQLiteDriverTest extends BaseDriverTest {
public static function setupBeforeClass() public static function setupBeforeClass(): void
{ {
$params = [ $params = [
'type' => 'sqlite', 'type' => 'sqlite',
@ -47,7 +47,7 @@ class SQLiteDriverTest extends BaseDriverTest {
// ! Util Method tests // ! Util Method tests
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
public function testCreateTable() 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'));
@ -80,7 +80,7 @@ SQL;
$this->assertEqual($expectedArray, $sqlArray); $this->assertEqual($expectedArray, $sqlArray);
}*/ }*/
public function testBackupStructure() public function testBackupStructure(): void
{ {
$sql = mb_trim(self::$db->getUtil()->backupStructure()); $sql = mb_trim(self::$db->getUtil()->backupStructure());
$expected = <<<SQL $expected = <<<SQL
@ -155,7 +155,7 @@ SQL;
$this->assertEqual($expectedArray, $resultArray); $this->assertEqual($expectedArray, $resultArray);
} }
public function testDeleteTable() public function testDeleteTable(): void
{ {
$sql = self::$db->getUtil()->deleteTable('create_delete'); $sql = self::$db->getUtil()->deleteTable('create_delete');
@ -170,7 +170,7 @@ SQL;
// ! General tests // ! General tests
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
public function testConnection() public function testConnection(): void
{ {
$class = Driver::class; $class = Driver::class;
@ -182,13 +182,13 @@ SQL;
unset($db); unset($db);
} }
public function testTruncate() public function testTruncate(): void
{ {
self::$db->truncate('create_test'); self::$db->truncate('create_test');
$this->assertEquals(0, self::$db->countAll('create_test')); $this->assertEquals(0, self::$db->countAll('create_test'));
} }
public function testPreparedStatements() public function testPreparedStatements(): void
{ {
$sql = <<<SQL $sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
@ -208,7 +208,7 @@ SQL;
], $res); ], $res);
} }
public function testPrepareExecute() public function testPrepareExecute(): void
{ {
$sql = <<<SQL $sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
@ -228,7 +228,7 @@ SQL;
], $res); ], $res);
} }
public function testCommitTransaction() public function testCommitTransaction(): void
{ {
$res = self::$db->beginTransaction(); $res = self::$db->beginTransaction();
@ -239,7 +239,7 @@ SQL;
$this->assertTrue($res); $this->assertTrue($res);
} }
public function testRollbackTransaction() public function testRollbackTransaction(): void
{ {
$res = self::$db->beginTransaction(); $res = self::$db->beginTransaction();
@ -250,12 +250,12 @@ SQL;
$this->assertTrue($res); $this->assertTrue($res);
} }
public function testGetDBs() public function testGetDBs(): void
{ {
$this->assertTrue(\is_array(self::$db->getDbs())); $this->assertTrue(\is_array(self::$db->getDbs()));
} }
public function testGetSchemas() public function testGetSchemas(): void
{ {
$this->assertNull(self::$db->getSchemas()); $this->assertNull(self::$db->getSchemas());
} }
@ -264,25 +264,25 @@ SQL;
// ! SQL tests // ! SQL tests
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
public function testGetSystemTables() public function testGetSystemTables(): void
{ {
$sql = self::$db->getSystemTables(); $sql = self::$db->getSystemTables();
$this->assertTrue(\is_array($sql)); $this->assertTrue(\is_array($sql));
} }
public function testGetSequences() public function testGetSequences(): void
{ {
$sql = self::$db->getSequences(); $sql = self::$db->getSequences();
$this->assertEquals(['create_test'], $sql); $this->assertEquals(['create_test'], $sql);
} }
public function testGetFunctions() public function testGetFunctions(): void
{ {
$this->expectException(NotImplementedException::class); $this->expectException(NotImplementedException::class);
self::$db->getFunctions(); self::$db->getFunctions();
} }
public function testGetProcedures() public function testGetProcedures(): void
{ {
$this->expectException(NotImplementedException::class); $this->expectException(NotImplementedException::class);
self::$db->getProcedures(); self::$db->getProcedures();

View File

@ -24,20 +24,20 @@ use Query\Tests\BaseQueryBuilderTest;
*/ */
class SQLiteQueryBuilderTest extends BaseQueryBuilderTest { class SQLiteQueryBuilderTest extends BaseQueryBuilderTest {
public static function setUpBeforeClass() public static function setUpBeforeClass(): void
{ {
// Defined in the SQLiteTest.php file // Defined in the SQLiteTest.php file
self::$db = Query('test_sqlite'); self::$db = Query('test_sqlite');
} }
public function testQueryFunctionAlias() public function testQueryFunctionAlias(): void
{ {
$db = Query('test_sqlite'); $db = Query('test_sqlite');
$this->assertTrue(self::$db === $db, 'Alias passed into query function gives the original object back'); $this->assertTrue(self::$db === $db, 'Alias passed into query function gives the original object back');
} }
public function testQueryExplain() public function testQueryExplain(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')
->explain() ->explain()
@ -84,6 +84,15 @@ use Query\Tests\BaseQueryBuilderTest;
], ],
]; ];
$expectedPossibilities[] = [
[
'id' => '6',
'parent' => '0',
'notused' => '0',
'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid<?)',
],
];
$passed = FALSE; $passed = FALSE;
// Check for a matching possibility // Check for a matching possibility

View File

@ -26,13 +26,13 @@ class QueryParserTest extends TestCase {
*/ */
protected $parser; protected $parser;
public function setUp() public function setUp(): void
{ {
$db = new Driver('sqlite::memory:'); $db = new Driver('sqlite::memory:');
$this->parser = new QueryParser($db); $this->parser = new QueryParser($db);
} }
public function testGeneric() public function testGeneric(): void
{ {
$matches = $this->parser->parseJoin('table1.field1=table2.field2'); $matches = $this->parser->parseJoin('table1.field1=table2.field2');
$this->assertEqual($matches['combined'], [ $this->assertEqual($matches['combined'], [
@ -40,7 +40,7 @@ class QueryParserTest extends TestCase {
]); ]);
} }
public function testGeneric2() public function testGeneric2(): void
{ {
$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'], [
@ -48,7 +48,7 @@ class QueryParserTest extends TestCase {
]); ]);
} }
public function testWUnderscore() public function testWUnderscore(): void
{ {
$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'], [
@ -56,7 +56,7 @@ class QueryParserTest extends TestCase {
]); ]);
} }
public function testFunction() public function testFunction(): void
{ {
$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'], [