Fix Firebird tests and speed up tests by using one database connection for each query builder datbase test
This commit is contained in:
parent
6b20982f61
commit
28f5cb2934
@ -1,3 +1,5 @@
|
|||||||
|
sudo: false
|
||||||
|
|
||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
@ -15,7 +17,7 @@ before_script:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- mkdir -p build/logs
|
- mkdir -p build/logs
|
||||||
- cd tests && phpunit --coverage-clover build/logs/clover.xml
|
- phpunit --coverage-clover build/logs/clover.xml
|
||||||
|
|
||||||
after_script:
|
after_script:
|
||||||
- wget https://scrutinizer-ci.com/ocular.phar
|
- wget https://scrutinizer-ci.com/ocular.phar
|
||||||
|
@ -41,13 +41,13 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to sql class
|
* Reference to sql class
|
||||||
* @var SQL\SQL_Interface
|
* @var SQL_Interface
|
||||||
*/
|
*/
|
||||||
public $sql;
|
protected $sql;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to util class
|
* Reference to util class
|
||||||
* @var Util\Abstract_Util
|
* @var Abstract_Util
|
||||||
*/
|
*/
|
||||||
public $util;
|
public $util;
|
||||||
|
|
||||||
|
@ -123,7 +123,6 @@ final class Connection_Manager {
|
|||||||
|
|
||||||
$dbtype = ucfirst($dbtype);
|
$dbtype = ucfirst($dbtype);
|
||||||
$driver = "\\Query\\Drivers\\{$dbtype}\\Driver";
|
$driver = "\\Query\\Drivers\\{$dbtype}\\Driver";
|
||||||
//echo $driver . "\n";
|
|
||||||
|
|
||||||
// Create the database connection
|
// Create the database connection
|
||||||
$db = ( ! empty($params->user))
|
$db = ( ! empty($params->user))
|
||||||
@ -158,7 +157,7 @@ final class Connection_Manager {
|
|||||||
/**
|
/**
|
||||||
* Parses params into a dsn and option array
|
* Parses params into a dsn and option array
|
||||||
*
|
*
|
||||||
* @param \stdClass $params
|
* @param \stdClass $set_params
|
||||||
* @return array
|
* @return array
|
||||||
* @throws BadDBDriverException
|
* @throws BadDBDriverException
|
||||||
*/
|
*/
|
||||||
@ -183,7 +182,15 @@ final class Connection_Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the dsn for the database to connect to
|
// Create the dsn for the database to connect to
|
||||||
|
if (strtolower($dbtype) === 'firebird')
|
||||||
|
{
|
||||||
|
$dsn = "{$params->host}:{$params->file}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$dsn = $this->create_dsn($dbtype, $params);
|
$dsn = $this->create_dsn($dbtype, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return array($dsn, $dbtype, $params, $options);
|
return array($dsn, $dbtype, $params, $options);
|
||||||
}
|
}
|
||||||
@ -199,10 +206,14 @@ final class Connection_Manager {
|
|||||||
*/
|
*/
|
||||||
private function create_dsn($dbtype, \stdClass $params)
|
private function create_dsn($dbtype, \stdClass $params)
|
||||||
{
|
{
|
||||||
if ($dbtype === 'firebird') $dsn = "{$params->host}:{$params->file}";
|
if ($dbtype === 'sqlite')
|
||||||
elseif ($dbtype === 'sqlite') $dsn = $params->file;
|
{
|
||||||
|
$dsn = $params->file;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (strtolower($dbtype) === 'pdo_firebird') $dbtype = 'firebird';
|
||||||
|
|
||||||
$dsn = strtolower($dbtype) . ':';
|
$dsn = strtolower($dbtype) . ':';
|
||||||
|
|
||||||
if ( ! empty($params->database))
|
if ( ! empty($params->database))
|
||||||
@ -224,7 +235,7 @@ final class Connection_Manager {
|
|||||||
|
|
||||||
foreach($params as $key => $val)
|
foreach($params as $key => $val)
|
||||||
{
|
{
|
||||||
if ( ! isset($skip[$key]))
|
if (( ! array_key_exists($key, $skip)) && ! empty($val))
|
||||||
{
|
{
|
||||||
$dsn .= ";{$key}={$val}";
|
$dsn .= ";{$key}={$val}";
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,6 @@ class Driver extends \Query\Abstract_Driver {
|
|||||||
*/
|
*/
|
||||||
public function __construct($dbpath, $user='SYSDBA', $pass='masterkey', array $options = array())
|
public function __construct($dbpath, $user='SYSDBA', $pass='masterkey', array $options = array())
|
||||||
{
|
{
|
||||||
|
|
||||||
$connect_function = (isset($options[\PDO::ATTR_PERSISTENT]) && $options[\PDO::ATTR_PERSISTENT] == TRUE)
|
$connect_function = (isset($options[\PDO::ATTR_PERSISTENT]) && $options[\PDO::ATTR_PERSISTENT] == TRUE)
|
||||||
? '\\fbird_pconnect'
|
? '\\fbird_pconnect'
|
||||||
: '\\fbird_connect';
|
: '\\fbird_connect';
|
||||||
@ -195,7 +194,7 @@ class Driver extends \Query\Abstract_Driver {
|
|||||||
$err_string = \fbird_errmsg() . "Last query:" . $this->last_query;
|
$err_string = \fbird_errmsg() . "Last query:" . $this->last_query;
|
||||||
if ($this->statement_link === FALSE) throw new \PDOException($err_string, \fbird_errcode(), NULL);
|
if ($this->statement_link === FALSE) throw new \PDOException($err_string, \fbird_errcode(), NULL);
|
||||||
|
|
||||||
$this->statement = new FireBird_Result($this->statement_link, $this);
|
$this->statement = new Result($this->statement_link, $this);
|
||||||
|
|
||||||
return $this->statement;
|
return $this->statement;
|
||||||
}
|
}
|
||||||
@ -217,7 +216,7 @@ class Driver extends \Query\Abstract_Driver {
|
|||||||
// Throw the error as an exception
|
// Throw the error as an exception
|
||||||
if ($this->statement_link === FALSE) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL);
|
if ($this->statement_link === FALSE) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL);
|
||||||
|
|
||||||
$this->statement = new FireBird_Result($this->statement_link, $this);
|
$this->statement = new Result($this->statement_link, $this);
|
||||||
|
|
||||||
return $this->statement;
|
return $this->statement;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class Result extends \PDOStatement {
|
|||||||
* @param \Query\Driver\Firebird|null $db
|
* @param \Query\Driver\Firebird|null $db
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($link, Firebird $db = NULL)
|
public function __construct($link, Driver $db = NULL)
|
||||||
{
|
{
|
||||||
if ( ! is_null($db)) $this->db = $db;
|
if ( ! is_null($db)) $this->db = $db;
|
||||||
$this->statement = $link;
|
$this->statement = $link;
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace Query\Drivers\Util;
|
namespace Query\Drivers\Firebird;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firebird-specific backup, import and creation methods
|
* Firebird-specific backup, import and creation methods
|
||||||
@ -21,7 +21,7 @@ namespace Query\Drivers\Util;
|
|||||||
* @package Query
|
* @package Query
|
||||||
* @subpackage Drivers
|
* @subpackage Drivers
|
||||||
*/
|
*/
|
||||||
class Firebird extends \Query\Abstract_Util {
|
class Util extends \Query\Abstract_Util {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience public function to generate sql for creating a db table
|
* Convenience public function to generate sql for creating a db table
|
||||||
|
40
phpunit.xml
Normal file
40
phpunit.xml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<phpunit
|
||||||
|
colors="true"
|
||||||
|
stopOnFailure="false"
|
||||||
|
bootstrap="tests/bootstrap.php">
|
||||||
|
<filter>
|
||||||
|
<blacklist>
|
||||||
|
<directory suffix=".php">coverage</directory>
|
||||||
|
<directory suffix=".php">docs</directory>
|
||||||
|
<directory suffix=".php">tests</directory>
|
||||||
|
</blacklist>
|
||||||
|
</filter>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="CoreTests">
|
||||||
|
<file>tests/core/core.php</file>
|
||||||
|
<file>tests/core/db_qp_test.php</file>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="MySQLTests">
|
||||||
|
<file>tests/databases/mysql/MySQLTest.php</file>
|
||||||
|
<file>tests/databases/mysql/MySQLQBTest.php</file>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="PgSQLTests">
|
||||||
|
<file>tests/databases/pgsql/PgSQLTest.php</file>
|
||||||
|
<file>tests/databases/pgsql/PgSQLQBTest.php</file>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="SQLiteTests">
|
||||||
|
<file>tests/databases/sqlite/SQLiteTest.php</file>
|
||||||
|
<file>tests/databases/sqlite/SQLiteQBTest.php</file>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="FirebirdTests">
|
||||||
|
<file>tests/databases/firebird/FirebirdTest.php</file>
|
||||||
|
<file>tests/databases/firebird/FirebirdQBTest.php</file>
|
||||||
|
</testsuite>
|
||||||
|
<!-- <testsuite name="PDOFirebirdTests">
|
||||||
|
<file>tests/databases/pdo_firebird/PDOFirebirdTest.php</file>
|
||||||
|
<file>tests/databases/pdo_firebird/PDOFirebirdQBTest.php</file>
|
||||||
|
</testsuite> -->
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
@ -102,23 +102,4 @@ require_once(QTEST_DIR . '/core/db_test.php');
|
|||||||
require_once(QTEST_DIR . '/core/db_qp_test.php');
|
require_once(QTEST_DIR . '/core/db_qp_test.php');
|
||||||
require_once(QTEST_DIR . '/core/db_qb_test.php');
|
require_once(QTEST_DIR . '/core/db_qb_test.php');
|
||||||
|
|
||||||
// Preset SQLite connection, so there aren't locking issues
|
|
||||||
if (extension_loaded('pdo_sqlite'))
|
|
||||||
{
|
|
||||||
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db';
|
|
||||||
@unlink($path);
|
|
||||||
$params = array(
|
|
||||||
'type' => 'sqlite',
|
|
||||||
'file' => ':memory:',
|
|
||||||
'host' => 'localhost',
|
|
||||||
'prefix' => 'create_',
|
|
||||||
'alias' => 'test_sqlite',
|
|
||||||
'options' => array(
|
|
||||||
PDO::ATTR_PERSISTENT => TRUE
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
Query($params);
|
|
||||||
}
|
|
||||||
|
|
||||||
// End of bootstrap.php
|
// End of bootstrap.php
|
@ -18,20 +18,22 @@
|
|||||||
*/
|
*/
|
||||||
abstract class DBTest extends Query_TestCase {
|
abstract class DBTest extends Query_TestCase {
|
||||||
|
|
||||||
|
protected static $db = NULL;
|
||||||
|
|
||||||
abstract public function testConnection();
|
abstract public function testConnection();
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function tearDown()
|
public static function tearDownAfterClass()
|
||||||
{
|
{
|
||||||
$this->db = NULL;
|
self::$db = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetTables()
|
public function testGetTables()
|
||||||
{
|
{
|
||||||
$tables = $this->db->get_tables();
|
$tables = self::$db->get_tables();
|
||||||
$this->assertTrue(is_array($tables));
|
$this->assertTrue(is_array($tables));
|
||||||
$this->assertTrue( ! empty($tables));
|
$this->assertTrue( ! empty($tables));
|
||||||
}
|
}
|
||||||
@ -40,7 +42,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testGetSystemTables()
|
public function testGetSystemTables()
|
||||||
{
|
{
|
||||||
$tables = $this->db->get_system_tables();
|
$tables = self::$db->get_system_tables();
|
||||||
$this->assertTrue(is_array($tables));
|
$this->assertTrue(is_array($tables));
|
||||||
$this->assertTrue( ! empty($tables));
|
$this->assertTrue( ! empty($tables));
|
||||||
}
|
}
|
||||||
@ -49,14 +51,14 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testBackupData()
|
public function testBackupData()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_string($this->db->util->backup_data(array('create_delete', TRUE))));
|
$this->assertTrue(is_string(self::$db->util->backup_data(array('create_delete', TRUE))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetColumns()
|
public function testGetColumns()
|
||||||
{
|
{
|
||||||
$cols = $this->db->get_columns('test');
|
$cols = self::$db->get_columns('test');
|
||||||
$this->assertTrue(is_array($cols));
|
$this->assertTrue(is_array($cols));
|
||||||
$this->assertTrue( ! empty($cols));
|
$this->assertTrue( ! empty($cols));
|
||||||
}
|
}
|
||||||
@ -65,7 +67,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testGetTypes()
|
public function testGetTypes()
|
||||||
{
|
{
|
||||||
$types = $this->db->get_types();
|
$types = self::$db->get_types();
|
||||||
$this->assertTrue(is_array($types));
|
$this->assertTrue(is_array($types));
|
||||||
$this->assertTrue( ! empty($types));
|
$this->assertTrue( ! empty($types));
|
||||||
}
|
}
|
||||||
@ -82,7 +84,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
'delete' => 'CASCADE'
|
'delete' => 'CASCADE'
|
||||||
));
|
));
|
||||||
|
|
||||||
$keys = $this->db->get_fks('testconstraints2');
|
$keys = self::$db->get_fks('testconstraints2');
|
||||||
$this->assertEqual($expected, $keys);
|
$this->assertEqual($expected, $keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +92,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testGetIndexes()
|
public function testGetIndexes()
|
||||||
{
|
{
|
||||||
$keys = $this->db->get_indexes('test');
|
$keys = self::$db->get_indexes('test');
|
||||||
$this->assertTrue(is_array($keys));
|
$this->assertTrue(is_array($keys));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testGetViews()
|
public function testGetViews()
|
||||||
{
|
{
|
||||||
$views = $this->db->get_views();
|
$views = self::$db->get_views();
|
||||||
$expected = array('numbersview', 'testview');
|
$expected = array('numbersview', 'testview');
|
||||||
$this->assertEqual($expected, array_values($views));
|
$this->assertEqual($expected, array_values($views));
|
||||||
$this->assertTrue(is_array($views));
|
$this->assertTrue(is_array($views));
|
||||||
@ -110,7 +112,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
{
|
{
|
||||||
// @TODO standardize trigger output for different databases
|
// @TODO standardize trigger output for different databases
|
||||||
|
|
||||||
$triggers = $this->db->get_triggers();
|
$triggers = self::$db->get_triggers();
|
||||||
$this->assertTrue(is_array($triggers));
|
$this->assertTrue(is_array($triggers));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testGetSequences()
|
public function testGetSequences()
|
||||||
{
|
{
|
||||||
$seqs = $this->db->get_sequences();
|
$seqs = self::$db->get_sequences();
|
||||||
|
|
||||||
// Normalize sequence names
|
// Normalize sequence names
|
||||||
$seqs = array_map('strtolower', $seqs);
|
$seqs = array_map('strtolower', $seqs);
|
||||||
@ -133,7 +135,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testGetProcedures()
|
public function testGetProcedures()
|
||||||
{
|
{
|
||||||
$procedures = $this->db->get_procedures();
|
$procedures = self::$db->get_procedures();
|
||||||
$this->assertTrue(is_array($procedures));
|
$this->assertTrue(is_array($procedures));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +143,7 @@ abstract class DBTest extends Query_TestCase {
|
|||||||
|
|
||||||
public function testGetFunctions()
|
public function testGetFunctions()
|
||||||
{
|
{
|
||||||
$funcs = $this->db->get_functions();
|
$funcs = self::$db->get_functions();
|
||||||
$this->assertTrue(is_array($funcs));
|
$this->assertTrue(is_array($funcs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,13 @@ class FirebirdQBTest extends QBTest {
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
|
||||||
|
|
||||||
if ( ! function_exists('\\fbird_connect'))
|
if ( ! function_exists('\\fbird_connect'))
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('Firebird extension does not exist');
|
$this->markTestSkipped('Firebird extension does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
||||||
|
|
||||||
// test the query builder
|
// test the query builder
|
||||||
$params = new Stdclass();
|
$params = new Stdclass();
|
||||||
$params->alias = 'fire';
|
$params->alias = 'fire';
|
||||||
@ -44,7 +44,7 @@ class FirebirdQBTest extends QBTest {
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$db = Query('fire');
|
$db = Query('water');
|
||||||
}
|
}
|
||||||
catch(InvalidArgumentException $e)
|
catch(InvalidArgumentException $e)
|
||||||
{
|
{
|
||||||
@ -52,13 +52,20 @@ class FirebirdQBTest extends QBTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testQueryFunctionAlias()
|
||||||
|
{
|
||||||
|
$db = Query();
|
||||||
|
|
||||||
|
$this->assertTrue($this->db === $db);
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetNamedConnection()
|
public function testGetNamedConnection()
|
||||||
{
|
{
|
||||||
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
||||||
|
|
||||||
// test the query builder
|
// test the query builder
|
||||||
$params = new Stdclass();
|
$params = new Stdclass();
|
||||||
$params->alias = 'fire';
|
$params->alias = 'wood';
|
||||||
$params->type = 'firebird';
|
$params->type = 'firebird';
|
||||||
$params->file = $dbpath;
|
$params->file = $dbpath;
|
||||||
$params->host = 'localhost';
|
$params->host = 'localhost';
|
||||||
@ -66,7 +73,7 @@ class FirebirdQBTest extends QBTest {
|
|||||||
$params->pass = 'masterkey';
|
$params->pass = 'masterkey';
|
||||||
$params->prefix = '';
|
$params->prefix = '';
|
||||||
$f_conn = Query($params);
|
$f_conn = Query($params);
|
||||||
$q_conn = Query('fire');
|
$q_conn = Query('wood');
|
||||||
|
|
||||||
$this->assertReference($f_conn, $q_conn);
|
$this->assertReference($f_conn, $q_conn);
|
||||||
}
|
}
|
||||||
@ -131,7 +138,6 @@ class FirebirdQBTest extends QBTest {
|
|||||||
|
|
||||||
public function testBackupStructure()
|
public function testBackupStructure()
|
||||||
{
|
{
|
||||||
|
|
||||||
$existing = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
$existing = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
||||||
$backup = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_BKP.FDB';
|
$backup = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_BKP.FDB';
|
||||||
|
|
||||||
|
@ -23,26 +23,29 @@
|
|||||||
*/
|
*/
|
||||||
class FirebirdTest extends DBtest {
|
class FirebirdTest extends DBtest {
|
||||||
|
|
||||||
public function setUp()
|
public static function setupBeforeClass()
|
||||||
{
|
{
|
||||||
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
|
||||||
|
|
||||||
|
// test the db driver directly
|
||||||
|
self::$db = new \Query\Drivers\Firebird\Driver('localhost:'.$dbpath);
|
||||||
|
self::$db->table_prefix = 'create_';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
if ( ! function_exists('\\fbird_connect'))
|
if ( ! function_exists('\\fbird_connect'))
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('Firebird extension does not exist');
|
$this->markTestSkipped('Firebird extension does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
// test the db driver directly
|
$this->tables = self::$db->get_tables();
|
||||||
$this->db = new \Query\Drivers\Firebird\Driver('localhost:'.$dbpath);
|
|
||||||
$this->db->table_prefix = 'create_';
|
|
||||||
$this->tables = $this->db->get_tables();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
unset($this->db);
|
|
||||||
unset($this->tables);
|
unset($this->tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +56,7 @@ class FirebirdTest extends DBtest {
|
|||||||
*/
|
*/
|
||||||
public function testNullResultMethods()
|
public function testNullResultMethods()
|
||||||
{
|
{
|
||||||
$obj = $this->db->query('SELECT "id" FROM "create_test"');
|
$obj = self::$db->query('SELECT "id" FROM "create_test"');
|
||||||
|
|
||||||
$val = "bar";
|
$val = "bar";
|
||||||
|
|
||||||
@ -75,7 +78,7 @@ class FirebirdTest extends DBtest {
|
|||||||
|
|
||||||
public function testConnection()
|
public function testConnection()
|
||||||
{
|
{
|
||||||
$this->assertIsA($this->db, '\\Query\\Drivers\\Firebird\\Driver');
|
$this->assertIsA(self::$db, '\\Query\\Drivers\\Firebird\\Driver');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -84,7 +87,7 @@ class FirebirdTest extends DBtest {
|
|||||||
{
|
{
|
||||||
$only_system = TRUE;
|
$only_system = TRUE;
|
||||||
|
|
||||||
$tables = $this->db->get_system_tables();
|
$tables = self::$db->get_system_tables();
|
||||||
|
|
||||||
foreach($tables as $t)
|
foreach($tables as $t)
|
||||||
{
|
{
|
||||||
@ -105,15 +108,15 @@ class FirebirdTest extends DBtest {
|
|||||||
public function testCreateTable()
|
public function testCreateTable()
|
||||||
{
|
{
|
||||||
//Attempt to create the table
|
//Attempt to create the table
|
||||||
$sql = $this->db->util->create_table('create_delete', array(
|
$sql = self::$db->util->create_table('create_delete', array(
|
||||||
'id' => 'SMALLINT',
|
'id' => 'SMALLINT',
|
||||||
'key' => 'VARCHAR(64)',
|
'key' => 'VARCHAR(64)',
|
||||||
'val' => 'BLOB SUB_TYPE TEXT'
|
'val' => 'BLOB SUB_TYPE TEXT'
|
||||||
));
|
));
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
//Check
|
//Check
|
||||||
$this->assertTrue(in_array('create_delete', $this->db->get_tables()));
|
$this->assertTrue(in_array('create_delete', self::$db->get_tables()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -121,11 +124,11 @@ class FirebirdTest extends DBtest {
|
|||||||
public function testDeleteTable()
|
public function testDeleteTable()
|
||||||
{
|
{
|
||||||
//Attempt to delete the table
|
//Attempt to delete the table
|
||||||
$sql = $this->db->util->delete_table('create_delete');
|
$sql = self::$db->util->delete_table('create_delete');
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
//Check
|
//Check
|
||||||
$table_exists = in_array('create_delete', $this->db->get_tables());
|
$table_exists = in_array('create_delete', self::$db->get_tables());
|
||||||
$this->assertFalse($table_exists);
|
$this->assertFalse($table_exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,21 +136,21 @@ class FirebirdTest extends DBtest {
|
|||||||
|
|
||||||
public function testTruncate()
|
public function testTruncate()
|
||||||
{
|
{
|
||||||
$this->db->truncate('create_test');
|
self::$db->truncate('create_test');
|
||||||
|
|
||||||
$this->assertTrue($this->db->affected_rows() > 0);
|
$this->assertTrue(self::$db->affected_rows() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testCommitTransaction()
|
public function testCommitTransaction()
|
||||||
{
|
{
|
||||||
$res = $this->db->beginTransaction();
|
$res = self::$db->beginTransaction();
|
||||||
|
|
||||||
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
|
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
$res = $this->db->commit();
|
$res = self::$db->commit();
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,12 +158,12 @@ class FirebirdTest extends DBtest {
|
|||||||
|
|
||||||
public function testRollbackTransaction()
|
public function testRollbackTransaction()
|
||||||
{
|
{
|
||||||
$res = $this->db->beginTransaction();
|
$res = self::$db->beginTransaction();
|
||||||
|
|
||||||
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
|
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
$res = $this->db->rollback();
|
$res = self::$db->rollback();
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +175,7 @@ class FirebirdTest extends DBtest {
|
|||||||
INSERT INTO "create_test" ("id", "key", "val")
|
INSERT INTO "create_test" ("id", "key", "val")
|
||||||
VALUES (?,?,?)
|
VALUES (?,?,?)
|
||||||
SQL;
|
SQL;
|
||||||
$query = $this->db->prepare($sql);
|
$query = self::$db->prepare($sql);
|
||||||
$query->execute(array(1,"booger's", "Gross"));
|
$query->execute(array(1,"booger's", "Gross"));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -185,7 +188,7 @@ SQL;
|
|||||||
INSERT INTO "create_test" ("id", "key", "val")
|
INSERT INTO "create_test" ("id", "key", "val")
|
||||||
VALUES (?,?,?)
|
VALUES (?,?,?)
|
||||||
SQL;
|
SQL;
|
||||||
$this->db->prepare_execute($sql, array(
|
self::$db->prepare_execute($sql, array(
|
||||||
2, "works", 'also?'
|
2, "works", 'also?'
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -195,7 +198,7 @@ SQL;
|
|||||||
|
|
||||||
public function testFetch()
|
public function testFetch()
|
||||||
{
|
{
|
||||||
$res = $this->db->query('SELECT "key","val" FROM "create_test"');
|
$res = self::$db->query('SELECT "key","val" FROM "create_test"');
|
||||||
|
|
||||||
// Object
|
// Object
|
||||||
$fetchObj = $res->fetchObject();
|
$fetchObj = $res->fetchObject();
|
||||||
@ -206,7 +209,7 @@ SQL;
|
|||||||
$this->assertTrue(array_key_exists('key', $fetchAssoc));
|
$this->assertTrue(array_key_exists('key', $fetchAssoc));
|
||||||
|
|
||||||
// Numeric array
|
// Numeric array
|
||||||
$res2 = $this->db->query('SELECT "id","key","val" FROM "create_test"');
|
$res2 = self::$db->query('SELECT "id","key","val" FROM "create_test"');
|
||||||
$fetch = $res2->fetch(PDO::FETCH_NUM);
|
$fetch = $res2->fetch(PDO::FETCH_NUM);
|
||||||
$this->assertTrue(is_array($fetch));
|
$this->assertTrue(is_array($fetch));
|
||||||
}
|
}
|
||||||
@ -215,14 +218,14 @@ SQL;
|
|||||||
|
|
||||||
public function testPrepareQuery()
|
public function testPrepareQuery()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->db->prepare_query('', array()));
|
$this->assertNull(self::$db->prepare_query('', array()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testErrorInfo()
|
public function testErrorInfo()
|
||||||
{
|
{
|
||||||
$result = $this->db->errorInfo();
|
$result = self::$db->errorInfo();
|
||||||
|
|
||||||
$expected = array (
|
$expected = array (
|
||||||
0 => 0,
|
0 => 0,
|
||||||
@ -237,7 +240,7 @@ SQL;
|
|||||||
|
|
||||||
public function testErrorCode()
|
public function testErrorCode()
|
||||||
{
|
{
|
||||||
$result = $this->db->errorCode();
|
$result = self::$db->errorCode();
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +248,7 @@ SQL;
|
|||||||
|
|
||||||
public function testDBList()
|
public function testDBList()
|
||||||
{
|
{
|
||||||
$res = $this->db->sql->db_list();
|
$res = self::$db->get_sql()->db_list();
|
||||||
$this->assertNULL($res);
|
$this->assertNULL($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +256,7 @@ SQL;
|
|||||||
|
|
||||||
public function testExec()
|
public function testExec()
|
||||||
{
|
{
|
||||||
$res = $this->db->exec('SELECT * FROM "create_test"');
|
$res = self::$db->exec('SELECT * FROM "create_test"');
|
||||||
$this->assertEquals(NULL, $res);
|
$this->assertEquals(NULL, $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,17 +264,17 @@ SQL;
|
|||||||
|
|
||||||
public function testInTransaction()
|
public function testInTransaction()
|
||||||
{
|
{
|
||||||
$this->db->beginTransaction();
|
self::$db->beginTransaction();
|
||||||
$this->assertTrue($this->db->inTransaction());
|
$this->assertTrue(self::$db->inTransaction());
|
||||||
$this->db->rollBack();
|
self::$db->rollBack();
|
||||||
$this->assertFalse($this->db->inTransaction());
|
$this->assertFalse(self::$db->inTransaction());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetAttribute()
|
public function testGetAttribute()
|
||||||
{
|
{
|
||||||
$res = $this->db->getAttribute("foo");
|
$res = self::$db->getAttribute("foo");
|
||||||
$this->assertEquals(NULL, $res);
|
$this->assertEquals(NULL, $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,11 +282,11 @@ SQL;
|
|||||||
|
|
||||||
public function testSetAttribute()
|
public function testSetAttribute()
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->db->setAttribute(47, 'foo'));
|
$this->assertFalse(self::$db->setAttribute(47, 'foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLastInsertId()
|
public function testLastInsertId()
|
||||||
{
|
{
|
||||||
$this->assertEqual(0, $this->db->lastInsertId('NEWTABLE_SEQ'));
|
$this->assertEqual(0, self::$db->lastInsertId('NEWTABLE_SEQ'));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
class MySQLTest extends DBTest {
|
class MySQLTest extends DBTest {
|
||||||
|
|
||||||
public function setUp()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
// Attempt to connect, if there is a test config file
|
// Attempt to connect, if there is a test config file
|
||||||
if (is_file(QTEST_DIR . "/settings.json"))
|
if (is_file(QTEST_DIR . "/settings.json"))
|
||||||
@ -29,16 +29,16 @@ class MySQLTest extends DBTest {
|
|||||||
$params = json_decode(file_get_contents(QTEST_DIR . "/settings.json"));
|
$params = json_decode(file_get_contents(QTEST_DIR . "/settings.json"));
|
||||||
$params = $params->mysql;
|
$params = $params->mysql;
|
||||||
|
|
||||||
$this->db = new \Query\Drivers\Mysql\Driver("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, array(
|
self::$db = new \Query\Drivers\Mysql\Driver("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, array(
|
||||||
PDO::ATTR_PERSISTENT => TRUE
|
PDO::ATTR_PERSISTENT => TRUE
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
elseif (($var = getenv('CI')))
|
elseif (($var = getenv('CI')))
|
||||||
{
|
{
|
||||||
$this->db = new \Query\Drivers\Mysql\Driver('host=127.0.0.1;port=3306;dbname=test', 'root');
|
self::$db = new \Query\Drivers\Mysql\Driver('host=127.0.0.1;port=3306;dbname=test', 'root');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->table_prefix = 'create_';
|
self::$db->table_prefix = 'create_';
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -52,17 +52,17 @@ class MySQLTest extends DBTest {
|
|||||||
|
|
||||||
public function testConnection()
|
public function testConnection()
|
||||||
{
|
{
|
||||||
$this->assertIsA($this->db, '\\Query\\Drivers\\Mysql\\Driver');
|
$this->assertIsA(self::$db, '\\Query\\Drivers\\Mysql\\Driver');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testCreateTable()
|
public function testCreateTable()
|
||||||
{
|
{
|
||||||
$this->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 = $this->db->util->create_table('test',
|
$sql = self::$db->util->create_table('test',
|
||||||
array(
|
array(
|
||||||
'id' => 'int(10)',
|
'id' => 'int(10)',
|
||||||
'key' => 'TEXT',
|
'key' => 'TEXT',
|
||||||
@ -73,10 +73,10 @@ class MySQLTest extends DBTest {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
//Attempt to create the table
|
//Attempt to create the table
|
||||||
$sql = $this->db->util->create_table('join',
|
$sql = self::$db->util->create_table('join',
|
||||||
array(
|
array(
|
||||||
'id' => 'int(10)',
|
'id' => 'int(10)',
|
||||||
'key' => 'TEXT',
|
'key' => 'TEXT',
|
||||||
@ -86,10 +86,10 @@ class MySQLTest extends DBTest {
|
|||||||
'id' => 'PRIMARY KEY'
|
'id' => 'PRIMARY KEY'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
//Check
|
//Check
|
||||||
$dbs = $this->db->get_tables();
|
$dbs = self::$db->get_tables();
|
||||||
|
|
||||||
$this->assertTrue(in_array('create_test', $dbs));
|
$this->assertTrue(in_array('create_test', $dbs));
|
||||||
|
|
||||||
@ -99,8 +99,8 @@ class MySQLTest extends DBTest {
|
|||||||
|
|
||||||
public function testTruncate()
|
public function testTruncate()
|
||||||
{
|
{
|
||||||
$this->db->truncate('test');
|
self::$db->truncate('test');
|
||||||
$this->db->truncate('join');
|
self::$db->truncate('join');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -111,7 +111,7 @@ class MySQLTest extends DBTest {
|
|||||||
INSERT INTO `create_test` (`id`, `key`, `val`)
|
INSERT INTO `create_test` (`id`, `key`, `val`)
|
||||||
VALUES (?,?,?)
|
VALUES (?,?,?)
|
||||||
SQL;
|
SQL;
|
||||||
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
|
$statement = self::$db->prepare_query($sql, array(1,"boogers", "Gross"));
|
||||||
|
|
||||||
$res = $statement->execute();
|
$res = $statement->execute();
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ SQL;
|
|||||||
SQL;
|
SQL;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = $this->db->prepare_query($sql, 'foo');
|
$statement = self::$db->prepare_query($sql, 'foo');
|
||||||
}
|
}
|
||||||
catch(InvalidArgumentException $e)
|
catch(InvalidArgumentException $e)
|
||||||
{
|
{
|
||||||
@ -146,7 +146,7 @@ SQL;
|
|||||||
INSERT INTO `create_test` (`id`, `key`, `val`)
|
INSERT INTO `create_test` (`id`, `key`, `val`)
|
||||||
VALUES (?,?,?)
|
VALUES (?,?,?)
|
||||||
SQL;
|
SQL;
|
||||||
$res = $this->db->prepare_execute($sql, array(
|
$res = self::$db->prepare_execute($sql, array(
|
||||||
2, "works", 'also?'
|
2, "works", 'also?'
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -158,12 +158,12 @@ SQL;
|
|||||||
|
|
||||||
public function testCommitTransaction()
|
public function testCommitTransaction()
|
||||||
{
|
{
|
||||||
$res = $this->db->beginTransaction();
|
$res = self::$db->beginTransaction();
|
||||||
|
|
||||||
$sql = 'INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (10, 12, 14)';
|
$sql = 'INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (10, 12, 14)';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
$res = $this->db->commit();
|
$res = self::$db->commit();
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,12 +171,12 @@ SQL;
|
|||||||
|
|
||||||
public function testRollbackTransaction()
|
public function testRollbackTransaction()
|
||||||
{
|
{
|
||||||
$res = $this->db->beginTransaction();
|
$res = self::$db->beginTransaction();
|
||||||
|
|
||||||
$sql = 'INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (182, 96, 43)';
|
$sql = 'INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (182, 96, 43)';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
$res = $this->db->rollback();
|
$res = self::$db->rollback();
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,21 +184,21 @@ SQL;
|
|||||||
|
|
||||||
public function testGetSchemas()
|
public function testGetSchemas()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->db->get_schemas());
|
$this->assertNull(self::$db->get_schemas());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetSequences()
|
public function testGetSequences()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->db->get_sequences());
|
$this->assertNull(self::$db->get_sequences());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testBackup()
|
public function testBackup()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_string($this->db->util->backup_structure()));
|
$this->assertTrue(is_string(self::$db->util->backup_structure()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class PgSQLQBTest extends QBTest {
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
// If the database isn't installed, skip the tests
|
// If the database isn't installed, skip the tests
|
||||||
if ( ! class_exists("Query\\Drivers\\Pgsql\\Driver") && ! IS_QUERCUS)
|
if ( ! in_array('pgsql', PDO::getAvailableDrivers()))
|
||||||
{
|
{
|
||||||
$this->markTestSkipped("Postgres extension for PDO not loaded");
|
$this->markTestSkipped("Postgres extension for PDO not loaded");
|
||||||
}
|
}
|
||||||
@ -65,7 +65,6 @@ class PgSQLQBTest extends QBTest {
|
|||||||
{
|
{
|
||||||
$this->markTestSkipped();
|
$this->markTestSkipped();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$query = $this->db->select('id, key as k, val')
|
$query = $this->db->select('id, key as k, val')
|
||||||
->explain()
|
->explain()
|
||||||
->where('id >', 1)
|
->where('id >', 1)
|
||||||
|
@ -30,20 +30,26 @@ class PgTest extends DBTest {
|
|||||||
$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";
|
||||||
|
|
||||||
// Attempt to connect, if there is a test config file
|
// Attempt to connect, if there is a test config file
|
||||||
if (is_file(QTEST_DIR . "/settings.json"))
|
if (is_file(QTEST_DIR . "/settings.json"))
|
||||||
{
|
{
|
||||||
$params = json_decode(file_get_contents(QTEST_DIR . "/settings.json"));
|
$params = json_decode(file_get_contents(QTEST_DIR . "/settings.json"));
|
||||||
$params = $params->pgsql;
|
$params = $params->pgsql;
|
||||||
|
|
||||||
$this->db = new $class("pgsql:dbname={$params->database};port=5432", $params->user, $params->pass);
|
self::$db = new $class("pgsql:dbname={$params->database};port=5432", $params->user, $params->pass);
|
||||||
}
|
}
|
||||||
elseif (($var = getenv('CI')))
|
elseif (($var = getenv('CI')))
|
||||||
{
|
{
|
||||||
$this->db = new $class('host=127.0.0.1;port=5432;dbname=test', 'postgres');
|
self::$db = new $class('host=127.0.0.1;port=5432;dbname=test', 'postgres');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->table_prefix = 'create_';
|
self::$db->table_prefix = 'create_';
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -51,7 +57,6 @@ class PgTest extends DBTest {
|
|||||||
public function testExists()
|
public function testExists()
|
||||||
{
|
{
|
||||||
$drivers = \PDO::getAvailableDrivers();
|
$drivers = \PDO::getAvailableDrivers();
|
||||||
print_r($drivers);
|
|
||||||
$this->assertTrue(in_array('pgsql', $drivers));
|
$this->assertTrue(in_array('pgsql', $drivers));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,26 +64,26 @@ print_r($drivers);
|
|||||||
|
|
||||||
public function testConnection()
|
public function testConnection()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty(self::$db)) return;
|
||||||
|
|
||||||
$this->assertIsA($this->db, '\\Query\\Drivers\\Pgsql\\Driver');
|
$this->assertIsA(self::$db, '\\Query\\Drivers\\Pgsql\\Driver');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testCreateTable()
|
public function testCreateTable()
|
||||||
{
|
{
|
||||||
$this->db->exec(file_get_contents(QTEST_DIR.'/db_files/pgsql.sql'));
|
self::$db->exec(file_get_contents(QTEST_DIR.'/db_files/pgsql.sql'));
|
||||||
|
|
||||||
// Drop the table(s) if they exist
|
// Drop the table(s) if they exist
|
||||||
$sql = 'DROP TABLE IF EXISTS "create_test"';
|
$sql = 'DROP TABLE IF EXISTS "create_test"';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
$sql = 'DROP TABLE IF EXISTS "create_join"';
|
$sql = 'DROP TABLE IF EXISTS "create_join"';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
|
|
||||||
//Attempt to create the table
|
//Attempt to create the table
|
||||||
$sql = $this->db->util->create_table('create_test',
|
$sql = self::$db->util->create_table('create_test',
|
||||||
array(
|
array(
|
||||||
'id' => 'integer',
|
'id' => 'integer',
|
||||||
'key' => 'TEXT',
|
'key' => 'TEXT',
|
||||||
@ -89,10 +94,10 @@ print_r($drivers);
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
//Attempt to create the table
|
//Attempt to create the table
|
||||||
$sql = $this->db->util->create_table('create_join',
|
$sql = self::$db->util->create_table('create_join',
|
||||||
array(
|
array(
|
||||||
'id' => 'integer',
|
'id' => 'integer',
|
||||||
'key' => 'TEXT',
|
'key' => 'TEXT',
|
||||||
@ -102,16 +107,16 @@ print_r($drivers);
|
|||||||
'id' => 'PRIMARY KEY'
|
'id' => 'PRIMARY KEY'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
//echo $sql.'<br />';
|
//echo $sql.'<br />';
|
||||||
|
|
||||||
//Reset
|
//Reset
|
||||||
unset($this->db);
|
//unset(self::$db);
|
||||||
$this->setUp();
|
//$this->setUp();
|
||||||
|
|
||||||
//Check
|
//Check
|
||||||
$dbs = $this->db->get_tables();
|
$dbs = self::$db->get_tables();
|
||||||
$this->assertTrue(in_array('create_test', $dbs));
|
$this->assertTrue(in_array('create_test', $dbs));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -120,11 +125,11 @@ print_r($drivers);
|
|||||||
|
|
||||||
public function testTruncate()
|
public function testTruncate()
|
||||||
{
|
{
|
||||||
$this->db->truncate('create_test');
|
self::$db->truncate('create_test');
|
||||||
$this->db->truncate('create_join');
|
self::$db->truncate('create_join');
|
||||||
|
|
||||||
$ct_query = $this->db->query('SELECT * FROM create_test');
|
$ct_query = self::$db->query('SELECT * FROM create_test');
|
||||||
$cj_query = $this->db->query('SELECT * FROM create_join');
|
$cj_query = self::$db->query('SELECT * FROM create_join');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -135,7 +140,7 @@ print_r($drivers);
|
|||||||
INSERT INTO "create_test" ("id", "key", "val")
|
INSERT INTO "create_test" ("id", "key", "val")
|
||||||
VALUES (?,?,?)
|
VALUES (?,?,?)
|
||||||
SQL;
|
SQL;
|
||||||
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
|
$statement = self::$db->prepare_query($sql, array(1,"boogers", "Gross"));
|
||||||
|
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
@ -151,7 +156,7 @@ SQL;
|
|||||||
SQL;
|
SQL;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = $this->db->prepare_query($sql, 'foo');
|
$statement = self::$db->prepare_query($sql, 'foo');
|
||||||
}
|
}
|
||||||
catch(InvalidArgumentException $e)
|
catch(InvalidArgumentException $e)
|
||||||
{
|
{
|
||||||
@ -164,13 +169,13 @@ SQL;
|
|||||||
|
|
||||||
public function testPrepareExecute()
|
public function testPrepareExecute()
|
||||||
{
|
{
|
||||||
if (empty($this->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;
|
||||||
$this->db->prepare_execute($sql, array(
|
self::$db->prepare_execute($sql, array(
|
||||||
2, "works", 'also?'
|
2, "works", 'also?'
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -180,14 +185,14 @@ SQL;
|
|||||||
|
|
||||||
public function testCommitTransaction()
|
public function testCommitTransaction()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty(self::$db)) return;
|
||||||
|
|
||||||
$res = $this->db->beginTransaction();
|
$res = self::$db->beginTransaction();
|
||||||
|
|
||||||
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
|
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
$res = $this->db->commit();
|
$res = self::$db->commit();
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,14 +200,14 @@ SQL;
|
|||||||
|
|
||||||
public function testRollbackTransaction()
|
public function testRollbackTransaction()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty(self::$db)) return;
|
||||||
|
|
||||||
$res = $this->db->beginTransaction();
|
$res = self::$db->beginTransaction();
|
||||||
|
|
||||||
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
|
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
$res = $this->db->rollback();
|
$res = self::$db->rollback();
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,20 +215,20 @@ SQL;
|
|||||||
|
|
||||||
public function testGetSchemas()
|
public function testGetSchemas()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_array($this->db->get_schemas()));
|
$this->assertTrue(is_array(self::$db->get_schemas()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetDBs()
|
public function testGetDBs()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_array($this->db->get_dbs()));
|
$this->assertTrue(is_array(self::$db->get_dbs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetFunctions()
|
public function testGetFunctions()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->db->get_functions());
|
$this->assertNull(self::$db->get_functions());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,12 +20,23 @@
|
|||||||
*/
|
*/
|
||||||
class SQLiteTest extends DBTest {
|
class SQLiteTest extends DBTest {
|
||||||
|
|
||||||
public function setUp()
|
public static function setupBeforeClass()
|
||||||
{
|
{
|
||||||
// Set up in the bootstrap to mitigate
|
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db';
|
||||||
// connection locking issues
|
$params = array(
|
||||||
$this->db = Query('test_sqlite');
|
'type' => 'sqlite',
|
||||||
$this->db->table_prefix = 'create_';
|
'file' => ':memory:',
|
||||||
|
'prefix' => 'create_',
|
||||||
|
'alias' => 'test_sqlite',
|
||||||
|
'options' => array(
|
||||||
|
PDO::ATTR_PERSISTENT => TRUE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Query($params);
|
||||||
|
|
||||||
|
self::$db = Query('test_sqlite');
|
||||||
|
self::$db->table_prefix = 'create_';
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -34,10 +45,10 @@ class SQLiteTest extends DBTest {
|
|||||||
|
|
||||||
public function testCreateTable()
|
public function testCreateTable()
|
||||||
{
|
{
|
||||||
$this->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 = $this->db->get_tables();
|
$dbs = self::$db->get_tables();
|
||||||
|
|
||||||
$this->assertTrue(in_array('TEST1', $dbs));
|
$this->assertTrue(in_array('TEST1', $dbs));
|
||||||
$this->assertTrue(in_array('TEST2', $dbs));
|
$this->assertTrue(in_array('TEST2', $dbs));
|
||||||
@ -52,7 +63,7 @@ class SQLiteTest extends DBTest {
|
|||||||
|
|
||||||
/*public function testBackupData()
|
/*public function testBackupData()
|
||||||
{
|
{
|
||||||
$sql = mb_trim($this->db->util->backup_data(array('create_join', 'create_test')));
|
$sql = mb_trim(self::$db->util->backup_data(array('create_join', 'create_test')));
|
||||||
|
|
||||||
$sql_array = explode("\n", $sql);
|
$sql_array = explode("\n", $sql);
|
||||||
|
|
||||||
@ -71,7 +82,7 @@ SQL;
|
|||||||
|
|
||||||
public function testBackupStructure()
|
public function testBackupStructure()
|
||||||
{
|
{
|
||||||
$sql = mb_trim($this->db->util->backup_structure());
|
$sql = mb_trim(self::$db->util->backup_structure());
|
||||||
$expected = <<<SQL
|
$expected = <<<SQL
|
||||||
CREATE TABLE "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
CREATE TABLE "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
||||||
CREATE TABLE "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
CREATE TABLE "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
||||||
@ -147,12 +158,12 @@ SQL;
|
|||||||
|
|
||||||
public function testDeleteTable()
|
public function testDeleteTable()
|
||||||
{
|
{
|
||||||
$sql = $this->db->util->delete_table('create_delete');
|
$sql = self::$db->util->delete_table('create_delete');
|
||||||
|
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
//Check
|
//Check
|
||||||
$dbs = $this->db->get_tables();
|
$dbs = self::$db->get_tables();
|
||||||
$this->assertFalse(in_array('create_delete', $dbs));
|
$this->assertFalse(in_array('create_delete', $dbs));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +178,7 @@ SQL;
|
|||||||
$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);
|
||||||
$this->assertIsA($this->db->db, $class);
|
$this->assertIsA(self::$db->db, $class);
|
||||||
|
|
||||||
unset($db);
|
unset($db);
|
||||||
}
|
}
|
||||||
@ -176,7 +187,7 @@ SQL;
|
|||||||
|
|
||||||
public function testTruncate()
|
public function testTruncate()
|
||||||
{
|
{
|
||||||
$this->db->truncate('create_test');
|
self::$db->truncate('create_test');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -187,7 +198,7 @@ SQL;
|
|||||||
INSERT INTO "create_test" ("id", "key", "val")
|
INSERT INTO "create_test" ("id", "key", "val")
|
||||||
VALUES (?,?,?)
|
VALUES (?,?,?)
|
||||||
SQL;
|
SQL;
|
||||||
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
|
$statement = self::$db->prepare_query($sql, array(1,"boogers", "Gross"));
|
||||||
|
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
@ -201,7 +212,7 @@ SQL;
|
|||||||
INSERT INTO "create_test" ("id", "key", "val")
|
INSERT INTO "create_test" ("id", "key", "val")
|
||||||
VALUES (?,?,?)
|
VALUES (?,?,?)
|
||||||
SQL;
|
SQL;
|
||||||
$this->db->prepare_execute($sql, array(
|
self::$db->prepare_execute($sql, array(
|
||||||
2, "works", 'also?'
|
2, "works", 'also?'
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -216,12 +227,12 @@ SQL;
|
|||||||
$this->markTestSkipped("JDBC Driver doesn't support transactions");
|
$this->markTestSkipped("JDBC Driver doesn't support transactions");
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $this->db->beginTransaction();
|
$res = self::$db->beginTransaction();
|
||||||
|
|
||||||
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
|
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
$res = $this->db->commit();
|
$res = self::$db->commit();
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,12 +245,12 @@ SQL;
|
|||||||
$this->markTestSkipped("JDBC Driver doesn't support transactions");
|
$this->markTestSkipped("JDBC Driver doesn't support transactions");
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $this->db->beginTransaction();
|
$res = self::$db->beginTransaction();
|
||||||
|
|
||||||
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
|
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
|
||||||
$this->db->query($sql);
|
self::$db->query($sql);
|
||||||
|
|
||||||
$res = $this->db->rollback();
|
$res = self::$db->rollback();
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,14 +258,14 @@ SQL;
|
|||||||
|
|
||||||
public function testGetDBs()
|
public function testGetDBs()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_array($this->db->get_dbs()));
|
$this->assertTrue(is_array(self::$db->get_dbs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetSchemas()
|
public function testGetSchemas()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->db->get_schemas());
|
$this->assertNull(self::$db->get_schemas());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -263,13 +274,13 @@ SQL;
|
|||||||
|
|
||||||
public function testNullMethods()
|
public function testNullMethods()
|
||||||
{
|
{
|
||||||
$sql = $this->db->sql->function_list();
|
$sql = self::$db->sql->function_list();
|
||||||
$this->assertEqual(NULL, $sql);
|
$this->assertEqual(NULL, $sql);
|
||||||
|
|
||||||
$sql = $this->db->sql->procedure_list();
|
$sql = self::$db->sql->procedure_list();
|
||||||
$this->assertEqual(NULL, $sql);
|
$this->assertEqual(NULL, $sql);
|
||||||
|
|
||||||
$sql = $this->db->sql->sequence_list();
|
$sql = self::$db->sql->sequence_list();
|
||||||
$this->assertEqual(NULL, $sql);
|
$this->assertEqual(NULL, $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +288,7 @@ SQL;
|
|||||||
|
|
||||||
public function testGetSystemTables()
|
public function testGetSystemTables()
|
||||||
{
|
{
|
||||||
$sql = $this->db->get_system_tables();
|
$sql = self::$db->get_system_tables();
|
||||||
$this->assertTrue(is_array($sql));
|
$this->assertTrue(is_array($sql));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,20 +296,20 @@ SQL;
|
|||||||
|
|
||||||
public function testGetSequences()
|
public function testGetSequences()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->db->get_sequences());
|
$this->assertNull(self::$db->get_sequences());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetFunctions()
|
public function testGetFunctions()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->db->get_functions());
|
$this->assertNull(self::$db->get_functions());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function testGetProcedures()
|
public function testGetProcedures()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->db->get_procedures());
|
$this->assertNull(self::$db->get_procedures());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,36 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<phpunit
|
|
||||||
colors="true"
|
|
||||||
stopOnFailure="false"
|
|
||||||
bootstrap="bootstrap.php">
|
|
||||||
<filter>
|
|
||||||
<blacklist>
|
|
||||||
<directory suffix=".php">../coverage</directory>
|
|
||||||
<directory suffix=".php">../docs</directory>
|
|
||||||
<directory suffix=".php">.</directory>
|
|
||||||
</blacklist>
|
|
||||||
</filter>
|
|
||||||
<testsuites>
|
|
||||||
<testsuite name="CoreTests">
|
|
||||||
<file>core/core.php</file>
|
|
||||||
<file>core/db_qp_test.php</file>
|
|
||||||
</testsuite>
|
|
||||||
<testsuite name="FirebirdTests">
|
|
||||||
<file>databases/firebird/FirebirdTest.php</file>
|
|
||||||
<file>databases/firebird/FirebirdQBTest.php</file>
|
|
||||||
</testsuite>
|
|
||||||
<testsuite name="MySQLTests">
|
|
||||||
<file>databases/mysql/MySQLTest.php</file>
|
|
||||||
<file>databases/mysql/MySQLQBTest.php</file>
|
|
||||||
</testsuite>
|
|
||||||
<testsuite name="PgSQLTests">
|
|
||||||
<file>databases/pgsql/PgSQLTest.php</file>
|
|
||||||
<file>databases/pgsql/PgSQLQBTest.php</file>
|
|
||||||
</testsuite>
|
|
||||||
<testsuite name="SQLiteTests">
|
|
||||||
<file>databases/sqlite/SQLiteTest.php</file>
|
|
||||||
<file>databases/sqlite/SQLiteQBTest.php</file>
|
|
||||||
</testsuite>
|
|
||||||
</testsuites>
|
|
||||||
</phpunit>
|
|
Loading…
Reference in New Issue
Block a user