Update test layout to better match source layout
This commit is contained in:
parent
369ca6eb04
commit
4df07b6c72
@ -31,7 +31,7 @@
|
||||
"phploc/phploc": "^4.0",
|
||||
"phpmd/phpmd": "^2.4",
|
||||
"phpstan/phpstan": "^0.9.1",
|
||||
"phpunit/phpunit": "^5.5",
|
||||
"phpunit/phpunit": "^6.5",
|
||||
"sebastian/phpcpd": "^2.0",
|
||||
"simpletest/simpletest": "^1.1",
|
||||
"squizlabs/php_codesniffer": "^3.0.0"
|
||||
@ -50,7 +50,7 @@
|
||||
"scripts": {
|
||||
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
|
||||
"phpstan": "phpstan analyse -l 3 -c phpstan.neon src tests",
|
||||
"test": "phpunit -c build"
|
||||
"test": "phpunit -c build --no-coverage"
|
||||
},
|
||||
"scripts-descriptions": {
|
||||
"coverage": "Generate test coverage report",
|
||||
|
@ -1,6 +1,12 @@
|
||||
parameters:
|
||||
autoload_files:
|
||||
- %rootDir%/../../../tests/bootstrap.php
|
||||
- %rootDir%/../../../tests/databases/mysql/MySQLTest.php
|
||||
- %rootDir%/../../../tests/databases/mysql/MySQLQBTest.php
|
||||
- %rootDir%/../../../tests/databases/pgsql/PgSQLTest.php
|
||||
- %rootDir%/../../../tests/databases/pgsql/PgSQLQBTest.php
|
||||
- %rootDir%/../../../tests/databases/sqlite/SQLiteTest.php
|
||||
- %rootDir%/../../../tests/databases/sqlite/SQLiteQBTest.php
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Aviat\\\Ion\\\Friend::\$[a-zA-Z0-9_]+#'
|
||||
- '#Call to an undefined method Aviat\\\Ion\\\Friend::[a-zA-Z0-9_]+\(\)#'
|
||||
|
@ -105,7 +105,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
|
||||
{
|
||||
if (method_exists($object, $methodName))
|
||||
{
|
||||
return call_user_func_array([$object, $methodName], $params);
|
||||
return \call_user_func_array([$object, $methodName], $params);
|
||||
}
|
||||
}
|
||||
|
||||
@ -645,12 +645,12 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
|
||||
}
|
||||
|
||||
// Set the limit, if it exists
|
||||
if (is_int($limit))
|
||||
if (\is_int($limit))
|
||||
{
|
||||
$this->limit($limit, $offset);
|
||||
}
|
||||
|
||||
return $this->_run("get", $table);
|
||||
return $this->_run('get', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,10 @@
|
||||
*/
|
||||
|
||||
|
||||
use Query\ConnectionManager;
|
||||
use Query\{
|
||||
ConnectionManager,
|
||||
QueryBuilderInterface
|
||||
};
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
@ -34,7 +37,7 @@ if ( ! function_exists('mb_trim'))
|
||||
*/
|
||||
function mb_trim(string $string): string
|
||||
{
|
||||
return preg_replace("/(^\s+)|(\s+$)/us", "", $string);
|
||||
return preg_replace('/(^\s+)|(\s+$)/u', '', $string);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,9 +76,10 @@ if ( ! function_exists('to_camel_case'))
|
||||
function to_camel_case(string $snakeCase): string
|
||||
{
|
||||
$pieces = explode('_', $snakeCase);
|
||||
$numPieces = count($pieces);
|
||||
|
||||
$pieces[0] = mb_strtolower($pieces[0]);
|
||||
for($i = 1; $i < count($pieces); $i++)
|
||||
for($i = 1; $i < $numPieces; $i++)
|
||||
{
|
||||
$pieces[$i] = ucfirst(mb_strtolower($pieces[$i]));
|
||||
}
|
||||
@ -161,26 +165,27 @@ if ( ! function_exists('Query'))
|
||||
* connection created.
|
||||
*
|
||||
* @param string|object|array $params
|
||||
* @return Query\QueryBuilder|null
|
||||
* @return QueryBuilderInterface|null
|
||||
*/
|
||||
function Query($params = '')
|
||||
function Query($params = ''): ?QueryBuilderInterface
|
||||
{
|
||||
$manager = ConnectionManager::getInstance();
|
||||
|
||||
if ($params === NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// If you are getting a previously created connection
|
||||
if (is_scalar($params))
|
||||
{
|
||||
return $manager->getConnection($params);
|
||||
}
|
||||
elseif ( ! is_scalar($params) && ! is_null($params))
|
||||
{
|
||||
|
||||
$paramsObject = (object) $params;
|
||||
|
||||
// Otherwise, return a new connection
|
||||
return $manager->connect($paramsObject);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
// End of common.php
|
@ -13,15 +13,19 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parent Database Test Class
|
||||
*/
|
||||
abstract class DBTest extends Query_TestCase {
|
||||
abstract class BaseDriverTest extends TestCase {
|
||||
|
||||
protected static $db = NULL;
|
||||
/**
|
||||
* @var \Query\QueryBuilder
|
||||
*/
|
||||
protected static $db;
|
||||
|
||||
abstract public function testConnection();
|
||||
|
@ -13,10 +13,14 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests;
|
||||
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* Query builder parent test class
|
||||
*/
|
||||
abstract class QBTest extends Query_TestCase {
|
||||
abstract class BaseQueryBuilderTest extends TestCase {
|
||||
|
||||
protected static $db;
|
||||
|
||||
@ -41,7 +45,7 @@ abstract class QBTest extends Query_TestCase {
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
|
||||
$db = Query('foo');
|
||||
Query('foo');
|
||||
}
|
||||
|
||||
public function testFunctionGet()
|
||||
@ -662,7 +666,7 @@ abstract class QBTest extends Query_TestCase {
|
||||
'val' => 'baz'
|
||||
))->getCompiledUpdate('test');
|
||||
|
||||
$this->assertTrue(is_string($sql));
|
||||
$this->assertTrue(\is_string($sql));
|
||||
}
|
||||
|
||||
public function testGetCompiledInsert()
|
||||
@ -673,7 +677,7 @@ abstract class QBTest extends Query_TestCase {
|
||||
'val' => 'baz'
|
||||
))->getCompiledInsert('test');
|
||||
|
||||
$this->assertTrue(is_string($sql));
|
||||
$this->assertTrue(\is_string($sql));
|
||||
}
|
||||
|
||||
public function testGetCompiledDelete()
|
||||
@ -681,7 +685,7 @@ abstract class QBTest extends Query_TestCase {
|
||||
$sql = self::$db->where('id', 4)
|
||||
->getCompiledDelete('test');
|
||||
|
||||
$this->assertTrue(is_string($sql));
|
||||
$this->assertTrue(\is_string($sql));
|
||||
}
|
||||
// ! Error tests
|
||||
/**
|
@ -13,14 +13,18 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests;
|
||||
|
||||
class Connection_Manager_Test extends Query_TestCase {
|
||||
use DomainException;
|
||||
use Query\{ConnectionManager, QueryBuilderInterface};
|
||||
|
||||
protected static $instance = NULL;
|
||||
class ConnectionManagerTest extends TestCase {
|
||||
|
||||
protected static $instance;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$instance = Query\ConnectionManager::getInstance();
|
||||
self::$instance = ConnectionManager::getInstance();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -30,25 +34,29 @@ class Connection_Manager_Test extends Query_TestCase {
|
||||
$this->expectException('DomainException');
|
||||
$this->expectExceptionMessage("Can't clone singleton");
|
||||
$clone = clone self::$instance;
|
||||
$this->assertNull($clone);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
public function testNoSerialize()
|
||||
{
|
||||
$this->setExpectedException('DomainException', "No serializing of singleton");
|
||||
$string = serialize(self::$instance);
|
||||
$this->expectException(DomainException::class);
|
||||
$this->expectExceptionMessage('No serializing of singleton');
|
||||
serialize(self::$instance);
|
||||
|
||||
$this->setExpectedException('DomainException', "No serializing of singleton");
|
||||
$string = self::$instance->__sleep();
|
||||
$this->expectException(DomainException::class);
|
||||
$this->expectExceptionMessage('No serializing of singleton');
|
||||
self::$instance->__sleep();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
public function testNoUnserialize()
|
||||
{
|
||||
$this->setExpectedException('DomainException', "Can't unserialize singleton");
|
||||
$obj = self::$instance->__wakeup();
|
||||
$this->expectException(DomainException::class);
|
||||
$this->expectExceptionMessage("Can't unserialize singleton");
|
||||
self::$instance->__wakeup();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -87,7 +95,7 @@ class Connection_Manager_Test extends Query_TestCase {
|
||||
);
|
||||
|
||||
$conn = self::$instance->connect($params);
|
||||
$this->assertInstanceOf('Query\\QueryBuilder', $conn);
|
||||
$this->assertInstanceOf(QueryBuilderInterface::class, $conn);
|
||||
|
||||
|
||||
// Check that the connection just made is returned from the get_connection method
|
||||
@ -109,7 +117,7 @@ class Connection_Manager_Test extends Query_TestCase {
|
||||
);
|
||||
|
||||
$conn = self::$instance->connect($params);
|
||||
$this->assertInstanceOf('Query\\QueryBuilder', $conn);
|
||||
$this->assertInstanceOf(QueryBuilderInterface::class, $conn);
|
||||
|
||||
$this->assertEqual($conn, self::$instance->getConnection('conn_manager'));
|
||||
}
|
@ -13,6 +13,8 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests;
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@ -21,7 +23,7 @@
|
||||
*
|
||||
* @extends UnitTestCase
|
||||
*/
|
||||
class CoreTest extends Query_TestCase {
|
||||
class CoreTest extends TestCase {
|
||||
|
||||
/**
|
||||
* TestPHPVersion function.
|
||||
@ -31,7 +33,8 @@ class CoreTest extends Query_TestCase {
|
||||
*/
|
||||
public function testPHPVersion()
|
||||
{
|
||||
$this->assertTrue(version_compare(PHP_VERSION, "5.3", "ge"));
|
||||
//$this->assertTrue(version_compare(PHP_VERSION, '7.1', 'ge'));
|
||||
$this->assertTrue(PHP_VERSION_ID >= 70000);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -49,15 +52,15 @@ class CoreTest extends Query_TestCase {
|
||||
|
||||
|
||||
// Make sure at least one of the supported drivers is enabled
|
||||
$supported = array(
|
||||
$supported = [
|
||||
'firebird',
|
||||
'mysql',
|
||||
'pgsql',
|
||||
'odbc',
|
||||
'sqlite',
|
||||
);
|
||||
];
|
||||
|
||||
$drivers = PDO::getAvailableDrivers();
|
||||
$drivers = \PDO::getAvailableDrivers();
|
||||
|
||||
$numSupported = count(array_intersect($drivers, $supported));
|
||||
|
@ -13,7 +13,12 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests\Drivers\MySQL;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PDO;
|
||||
use Query\Drivers\Mysql\Driver;
|
||||
use Query\Tests\BaseDriverTest;
|
||||
|
||||
/**
|
||||
* MySQLTest class.
|
||||
@ -21,12 +26,12 @@ use Query\Drivers\Mysql\Driver;
|
||||
* @extends DBTest
|
||||
* @requires extension pdo_mysql
|
||||
*/
|
||||
class MySQLTest extends DBTest {
|
||||
class MySQLDriverTest extends BaseDriverTest {
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$params = get_json_config();
|
||||
if (($var = getenv('TRAVIS')))
|
||||
if ($var = getenv('TRAVIS'))
|
||||
{
|
||||
self::$db = new Driver('host=127.0.0.1;port=3306;dbname=test', 'root');
|
||||
}
|
||||
@ -54,7 +59,7 @@ class MySQLTest extends DBTest {
|
||||
|
||||
public function testConnection()
|
||||
{
|
||||
$this->assertIsA(self::$db, '\\Query\\Drivers\\Mysql\\Driver');
|
||||
$this->assertIsA(self::$db, Driver::class);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -102,7 +107,10 @@ class MySQLTest extends DBTest {
|
||||
public function testTruncate()
|
||||
{
|
||||
self::$db->truncate('test');
|
||||
$this->assertEquals(0, self::$db->countAll('test'));
|
||||
|
||||
self::$db->truncate('join');
|
||||
$this->assertEquals(0, self::$db->countAll('join'));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -125,18 +133,14 @@ SQL;
|
||||
|
||||
public function testBadPreparedStatement()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$sql = <<<SQL
|
||||
INSERT INTO `create_test` (`id`, `key`, `val`)
|
||||
VALUES (?,?,?)
|
||||
SQL;
|
||||
try
|
||||
{
|
||||
$statement = self::$db->prepareQuery($sql, 'foo');
|
||||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
$this->assertTrue(TRUE);
|
||||
}
|
||||
|
||||
self::$db->prepareQuery($sql, 'foo');
|
||||
|
||||
}
|
||||
|
@ -13,13 +13,17 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests\Drivers\MySQL;
|
||||
|
||||
use PDO;
|
||||
use Query\Tests\BaseQueryBuilderTest;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @requires extension pdo_mysql
|
||||
*/
|
||||
class MySQLQBTest extends QBTest {
|
||||
class MySQLQueryBuilderTest extends BaseQueryBuilderTest {
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
@ -52,7 +56,7 @@ class MySQLQBTest extends QBTest {
|
||||
|
||||
public function testExists()
|
||||
{
|
||||
$this->assertTrue(in_array('mysql', PDO::getAvailableDrivers()));
|
||||
$this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
@ -13,42 +13,44 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests\Drivers\PgSQL;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Query\Drivers\Pgsql\Driver;
|
||||
use Query\Tests\BaseDriverTest;
|
||||
|
||||
/**
|
||||
* PgTest class.
|
||||
*
|
||||
* @extends DBTest
|
||||
* @requires extension pdo_pgsql
|
||||
*/
|
||||
class PgTest extends DBTest {
|
||||
class PgSQLDriverTest extends BaseDriverTest {
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$class = "Query\\Drivers\\Pgsql\\Driver";
|
||||
|
||||
// If the database isn't installed, skip the tests
|
||||
if (( ! class_exists($class)) && ! IS_QUERCUS)
|
||||
if ( ! class_exists(Driver::class))
|
||||
{
|
||||
$this->markTestSkipped("Postgres extension for PDO not loaded");
|
||||
$this->markTestSkipped('Postgres extension for PDO not loaded');
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$class = "Query\\Drivers\\Pgsql\\Driver";
|
||||
|
||||
$params = get_json_config();
|
||||
if (($var = getenv('TRAVIS')))
|
||||
if ($var = getenv('TRAVIS'))
|
||||
{
|
||||
self::$db = new $class('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
|
||||
else if ($params !== FALSE)
|
||||
{
|
||||
$params = $params->pgsql;
|
||||
self::$db = new $class("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);
|
||||
}
|
||||
|
||||
self::$db->setTablePrefix('create_');
|
||||
@ -59,7 +61,7 @@ class PgTest extends DBTest {
|
||||
public function testExists()
|
||||
{
|
||||
$drivers = \PDO::getAvailableDrivers();
|
||||
$this->assertTrue(in_array('pgsql', $drivers));
|
||||
$this->assertTrue(in_array('pgsql', $drivers, TRUE));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -68,7 +70,7 @@ class PgTest extends DBTest {
|
||||
{
|
||||
if (empty(self::$db)) return;
|
||||
|
||||
$this->assertIsA(self::$db, '\\Query\\Drivers\\Pgsql\\Driver');
|
||||
$this->assertIsA(self::$db, Driver::class);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -119,7 +121,7 @@ class PgTest extends DBTest {
|
||||
|
||||
//Check
|
||||
$dbs = self::$db->getTables();
|
||||
$this->assertTrue(in_array('create_test', $dbs));
|
||||
$this->assertTrue(in_array('create_test', $dbs, TRUE));
|
||||
|
||||
}
|
||||
|
||||
@ -127,11 +129,11 @@ class PgTest extends DBTest {
|
||||
|
||||
public function testTruncate()
|
||||
{
|
||||
self::$db->truncate('create_test');
|
||||
self::$db->truncate('create_join');
|
||||
self::$db->truncate('test');
|
||||
$this->assertEquals(0, self::$db->countAll('test'));
|
||||
|
||||
$ctQuery = self::$db->query('SELECT * FROM create_test');
|
||||
$cjQuery = self::$db->query('SELECT * FROM create_join');
|
||||
self::$db->truncate('join');
|
||||
$this->assertEquals(0, self::$db->countAll('join'));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -142,7 +144,7 @@ class PgTest extends DBTest {
|
||||
INSERT INTO "create_test" ("id", "key", "val")
|
||||
VALUES (?,?,?)
|
||||
SQL;
|
||||
$statement = self::$db->prepareQuery($sql, array(1,"boogers", "Gross"));
|
||||
$statement = self::$db->prepareQuery($sql, array(1,'boogers', 'Gross'));
|
||||
|
||||
$statement->execute();
|
||||
|
||||
@ -152,19 +154,14 @@ SQL;
|
||||
|
||||
public function testBadPreparedStatement()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$sql = <<<SQL
|
||||
INSERT INTO "create_test" ("id", "key", "val")
|
||||
VALUES (?,?,?)
|
||||
SQL;
|
||||
try
|
||||
{
|
||||
$statement = self::$db->prepareQuery($sql, 'foo');
|
||||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
$this->assertTrue(TRUE);
|
||||
}
|
||||
|
||||
self::$db->prepareQuery($sql, 'foo');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -189,7 +186,7 @@ SQL;
|
||||
{
|
||||
if (empty(self::$db)) return;
|
||||
|
||||
$res = self::$db->beginTransaction();
|
||||
self::$db->beginTransaction();
|
||||
|
||||
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
|
||||
self::$db->query($sql);
|
||||
@ -204,7 +201,7 @@ SQL;
|
||||
{
|
||||
if (empty(self::$db)) return;
|
||||
|
||||
$res = self::$db->beginTransaction();
|
||||
self::$db->beginTransaction();
|
||||
|
||||
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
|
||||
self::$db->query($sql);
|
@ -13,13 +13,17 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests\Drivers\PgSQL;
|
||||
|
||||
use PDO;
|
||||
use Query\Tests\BaseQueryBuilderTest;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @requires extension pdo_pgsql
|
||||
*/
|
||||
class PgSQLQBTest extends QBTest {
|
||||
class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
@ -13,6 +13,11 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests\Drivers\SQLite;
|
||||
|
||||
use PDO;
|
||||
use Query\Drivers\Sqlite\Driver;
|
||||
use Query\Tests\BaseDriverTest;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@ -22,7 +27,7 @@
|
||||
* @extends DBTest
|
||||
* @requires extension pdo_sqlite
|
||||
*/
|
||||
class SQLiteTest extends DBTest {
|
||||
class SQLiteDriverTest extends BaseDriverTest {
|
||||
|
||||
public static function setupBeforeClass()
|
||||
{
|
||||
@ -175,7 +180,7 @@ SQL;
|
||||
|
||||
public function testConnection()
|
||||
{
|
||||
$class = '\\Query\\Drivers\\Sqlite\\Driver';
|
||||
$class = Driver::class;
|
||||
|
||||
$db = new $class(QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db');
|
||||
|
||||
@ -190,6 +195,7 @@ SQL;
|
||||
public function testTruncate()
|
||||
{
|
||||
self::$db->truncate('create_test');
|
||||
$this->assertEquals(0, self::$db->countAll('create_test'));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -281,7 +287,7 @@ SQL;
|
||||
public function testGetSystemTables()
|
||||
{
|
||||
$sql = self::$db->getSystemTables();
|
||||
$this->assertTrue(is_array($sql));
|
||||
$this->assertTrue(\is_array($sql));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
@ -13,6 +13,10 @@
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests\Drivers\SQLite;
|
||||
|
||||
use PDO;
|
||||
use Query\Tests\BaseQueryBuilderTest;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@ -21,7 +25,7 @@
|
||||
*
|
||||
* @requires extension pdo_sqlite
|
||||
*/
|
||||
class SQLiteQBTest extends QBTest {
|
||||
class SQLiteQueryBuilderTest extends BaseQueryBuilderTest {
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
@ -4,27 +4,28 @@
|
||||
*
|
||||
* SQL Query Builder / Database Abstraction Layer
|
||||
*
|
||||
* PHP version 7
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @package Query
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
* @copyright 2012 - 2016 Timothy J. Warren
|
||||
* @copyright 2012 - 2018 Timothy J. Warren
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
namespace Query\Tests;
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
use Query\QueryParser;
|
||||
use Query\Drivers\Sqlite\Driver;
|
||||
|
||||
/**
|
||||
* Tests for the Query Parser
|
||||
*/
|
||||
class Query_Parser_Test extends Query_TestCase {
|
||||
class QueryParserTest extends TestCase {
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$db = new Query\Drivers\Sqlite\Driver("sqlite::memory:");
|
||||
$this->parser = new Query\QueryParser($db);
|
||||
$db = new Driver('sqlite::memory:');
|
||||
$this->parser = new QueryParser($db);
|
||||
}
|
||||
|
||||
public function testGeneric()
|
72
tests/TestCase.php
Normal file
72
tests/TestCase.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Query
|
||||
*
|
||||
* SQL Query Builder / Database Abstraction Layer
|
||||
*
|
||||
* PHP version 7
|
||||
*
|
||||
* @package Query
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
* @copyright 2012 - 2016 Timothy J. Warren
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link https://git.timshomepage.net/aviat4ion/Query
|
||||
*/
|
||||
|
||||
namespace Query\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase as PHPUnit_TestCase;
|
||||
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
class TestCase extends PHPUnit_TestCase {
|
||||
|
||||
/**
|
||||
* Wrapper for Simpletest's assertEqual
|
||||
*
|
||||
* @param mixed $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertEqual($expected, $actual, $message='')
|
||||
{
|
||||
$this->assertEquals($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for SimpleTest's assertIsA
|
||||
*
|
||||
* @param mixed $object
|
||||
* @param string $type
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertIsA($object, $type, $message='')
|
||||
{
|
||||
$this->assertTrue(is_a($object, $type), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of SimpleTest's assertReference
|
||||
*
|
||||
* @param mixed $first
|
||||
* @param mixed $second
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertReference($first, $second, $message='')
|
||||
{
|
||||
if (\is_object($first))
|
||||
{
|
||||
$res = ($first === $second);
|
||||
}
|
||||
else
|
||||
{
|
||||
$temp = $first;
|
||||
$first = uniqid('test', TRUE);
|
||||
$isRef = ($first === $second);
|
||||
$first = $temp;
|
||||
$res = $isRef;
|
||||
}
|
||||
$this->assertTrue($res, $message);
|
||||
}
|
||||
}
|
@ -11,8 +11,6 @@
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit test bootstrap - Using phpunit
|
||||
*/
|
||||
@ -20,9 +18,6 @@ define('QTEST_DIR', realpath(__DIR__));
|
||||
define('QBASE_DIR', realpath(QTEST_DIR.'/../') . '/');
|
||||
define('QDS', DIRECTORY_SEPARATOR);
|
||||
|
||||
// Set up autoloader
|
||||
require_once QBASE_DIR . 'vendor/autoload.php';
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
function get_json_config()
|
||||
@ -43,67 +38,8 @@ function get_json_config()
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
class Query_TestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* Wrapper for Simpletest's assertEqual
|
||||
*
|
||||
* @param mixed $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertEqual($expected, $actual, $message='')
|
||||
{
|
||||
$this->assertEquals($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for SimpleTest's assertIsA
|
||||
*
|
||||
* @param object $object
|
||||
* @param string $type
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertIsA($object, $type, $message='')
|
||||
{
|
||||
$this->assertTrue(is_a($object, $type), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of SimpleTest's assertReference
|
||||
*
|
||||
* @param mixed $first
|
||||
* @param mixed $second
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertReference($first, $second, $message='')
|
||||
{
|
||||
if (is_object($first))
|
||||
{
|
||||
$res = ($first === $second);
|
||||
}
|
||||
else
|
||||
{
|
||||
$temp = $first;
|
||||
$first = uniqid("test");
|
||||
$isRef = ($first === $second);
|
||||
$first = $temp;
|
||||
$res = $isRef;
|
||||
}
|
||||
$this->assertTrue($res, $message);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db';
|
||||
@unlink($path);
|
||||
|
||||
// Require base testing classes
|
||||
require_once(QTEST_DIR . '/core/base_db_test.php');
|
||||
require_once(QTEST_DIR . '/core/base_query_builder_test.php');
|
||||
|
||||
|
||||
// End of bootstrap.php
|
||||
|
133
tests/index.php
133
tests/index.php
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Query
|
||||
*
|
||||
@ -11,41 +11,33 @@
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
function get_json_config()
|
||||
{
|
||||
$files = array(
|
||||
__DIR__ . '/settings.json',
|
||||
__DIR__ . '/settings.json.dist'
|
||||
);
|
||||
namespace {
|
||||
/**
|
||||
* Unit test bootstrap - Using php simpletest
|
||||
*/
|
||||
\define('QTEST_DIR', __DIR__);
|
||||
\define('QBASE_DIR', realpath(__DIR__ . '/../') . '/');
|
||||
\define('QDS', DIRECTORY_SEPARATOR);
|
||||
|
||||
foreach($files as $file)
|
||||
{
|
||||
if (is_file($file))
|
||||
{
|
||||
return json_decode(file_get_contents($file));
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
require_once QBASE_DIR . 'vendor/simpletest/simpletest/autorun.php';
|
||||
require_once QBASE_DIR . 'vendor/autoload.php';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
namespace Query\Tests {
|
||||
|
||||
// Set up autoloaders
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../vendor/simpletest/simpletest/autorun.php';
|
||||
|
||||
/**
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
abstract class Query_TestCase extends UnitTestCase {
|
||||
abstract class TestCase extends \UnitTestCase
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$class = get_class($this);
|
||||
$class = \get_class($this);
|
||||
|
||||
if (method_exists($class, 'setupBeforeClass'))
|
||||
{
|
||||
echo 'Ran test suite: ' . $class . '<br />';
|
||||
|
||||
if (method_exists($class, 'setupBeforeClass')) {
|
||||
$class::setupBeforeClass();
|
||||
}
|
||||
|
||||
@ -54,10 +46,9 @@ abstract class Query_TestCase extends UnitTestCase {
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$class = get_class($this);
|
||||
$class = \get_class($this);
|
||||
|
||||
if (method_exists($class, 'tearDownAfterClass'))
|
||||
{
|
||||
if (method_exists($class, 'tearDownAfterClass')) {
|
||||
$class::tearDownAfterClass();
|
||||
}
|
||||
}
|
||||
@ -105,64 +96,66 @@ abstract class Query_TestCase extends UnitTestCase {
|
||||
{
|
||||
// noop
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for phpunit method
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
*/
|
||||
public function setExpectedException($name, $message='', $code=NULL)
|
||||
{
|
||||
$this->expectException($name, $message);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit test bootstrap - Using php simpletest
|
||||
* Load the test suites
|
||||
*/
|
||||
define('QTEST_DIR', __DIR__);
|
||||
define('QBASE_DIR', realpath(__DIR__ . '/../') . '/');
|
||||
define('QDS', DIRECTORY_SEPARATOR);
|
||||
namespace {
|
||||
function get_json_config()
|
||||
{
|
||||
$files = array(
|
||||
__DIR__ . '/settings.json',
|
||||
__DIR__ . '/settings.json.dist'
|
||||
);
|
||||
|
||||
// Include db tests
|
||||
// Load db classes based on capability
|
||||
$testPath = QTEST_DIR.'/databases/';
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
return json_decode(file_get_contents($file));
|
||||
}
|
||||
}
|
||||
|
||||
// Require base testing classes
|
||||
require_once QTEST_DIR . '/core/core_test.php';
|
||||
require_once QTEST_DIR . '/core/connection_manager_test.php';
|
||||
require_once QTEST_DIR . '/core/base_db_test.php';
|
||||
require_once QTEST_DIR . '/core/query_parser_test.php';
|
||||
require_once QTEST_DIR . '/core/base_query_builder_test.php';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$drivers = PDO::getAvailableDrivers();
|
||||
// Include db tests
|
||||
// Load db classes based on capability
|
||||
$testPath = QTEST_DIR.'/Drivers/';
|
||||
|
||||
if (function_exists('fbird_connect'))
|
||||
{
|
||||
// Require base testing classes
|
||||
require_once QTEST_DIR . '/CoreTest.php';
|
||||
require_once QTEST_DIR . '/ConnectionManagerTest.php';
|
||||
require_once QTEST_DIR . '/QueryParserTest.php';
|
||||
|
||||
$drivers = PDO::getAvailableDrivers();
|
||||
|
||||
/* if (function_exists('fbird_connect'))
|
||||
{
|
||||
$drivers[] = 'interbase';
|
||||
}
|
||||
} */
|
||||
|
||||
$driverTestMap = [
|
||||
'MySQL' => in_array('mysql', $drivers, TRUE),
|
||||
'SQLite' => in_array('sqlite', $drivers, TRUE),
|
||||
'PgSQL' => in_array('pgsql', $drivers, TRUE),
|
||||
$driverTestMap = [
|
||||
'MySQL' => \in_array('mysql', $drivers, TRUE),
|
||||
'SQLite' => \in_array('sqlite', $drivers, TRUE),
|
||||
'PgSQL' => \in_array('pgsql', $drivers, TRUE),
|
||||
// 'Firebird' => in_array('interbase', $drivers),
|
||||
//'PDOFirebird' => in_array('firebird', $drivers)
|
||||
];
|
||||
];
|
||||
|
||||
// Determine which testcases to load
|
||||
foreach($driverTestMap as $name => $doLoad)
|
||||
{
|
||||
$path = $testPath . strtolower($name) . '/';
|
||||
// Determine which testcases to load
|
||||
foreach($driverTestMap as $name => $doLoad)
|
||||
{
|
||||
$path = $testPath . $name;
|
||||
|
||||
if ($doLoad)
|
||||
{
|
||||
require_once "{$path}{$name}Test.php";
|
||||
require_once "{$path}{$name}QBTest.php";
|
||||
require_once "{$path}/{$name}DriverTest.php";
|
||||
require_once "{$path}/{$name}QueryBuilderTest.php";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// End of index.php
|
||||
|
Loading…
Reference in New Issue
Block a user