From 225017adeeeaa26d1348397124d2a4469124506f Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 30 Jul 2015 16:40:30 -0400 Subject: [PATCH] Lots of refactoring -- accessors/mutators instead of direct access, reduce query builder test database connections, and simplify some logic --- autoload.php | 7 +- phpunit.xml | 1 + src/Query/Abstract_Driver.php | 48 +++++- src/Query/Abstract_Query_Builder.php | 8 +- src/Query/Connection_Manager.php | 32 ++-- src/Query/Driver_Interface.php | 1 - src/Query/Drivers/Firebird/Driver.php | 2 +- src/Query/Drivers/Firebird/Result.php | 12 +- src/Query/Drivers/Firebird/Util.php | 3 +- src/Query/Drivers/Mysql/Driver.php | 1 + src/Query/Drivers/Pdo_firebird/Util.php | 1 - src/Query/Drivers/Pgsql/Driver.php | 1 + src/Query/Drivers/Pgsql/SQL.php | 1 - src/Query/Query_Builder_Interface.php | 2 +- src/common.php | 3 - tests/bootstrap.php | 7 +- ...b_test.php => base_query_builder_test.php} | 155 +++++++++--------- tests/core/connection_manager_test.php | 81 +++++++++ tests/core/core.php | 13 -- tests/core/db_test.php | 3 +- .../{db_qp_test.php => query_parser_test.php} | 0 tests/databases/firebird/FirebirdQBTest.php | 39 +++-- tests/databases/firebird/FirebirdTest.php | 6 +- tests/databases/mysql/MySQLQBTest.php | 14 +- tests/databases/mysql/MySQLTest.php | 8 +- .../pdofirebird/PDOFirebirdQBTest.php | 16 +- .../databases/pdofirebird/PDOFirebirdTest.php | 11 +- tests/databases/pgsql/PgSQLQBTest.php | 27 +-- tests/databases/pgsql/PgSQLTest.php | 6 +- tests/databases/sqlite/SQLiteQBTest.php | 15 +- tests/databases/sqlite/SQLiteTest.php | 8 +- tests/index.php | 28 +++- 32 files changed, 350 insertions(+), 210 deletions(-) rename tests/core/{db_qb_test.php => base_query_builder_test.php} (84%) create mode 100644 tests/core/connection_manager_test.php rename tests/core/{db_qp_test.php => query_parser_test.php} (100%) diff --git a/autoload.php b/autoload.php index 2fad55f..52e0f05 100644 --- a/autoload.php +++ b/autoload.php @@ -43,12 +43,7 @@ spl_autoload_register(function ($class) $path = str_replace('\\', DIRECTORY_SEPARATOR, $class); $file = QBASE_PATH . "{$path}.php"; - // @codeCoverageIgnoreStart - if (file_exists($file)) - { - require_once($file); - } - // @codeCoverageIgnoreEnd + if (file_exists($file)) require_once($file); }); // End of autoload.php \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index dee5698..dd86caf 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -13,6 +13,7 @@ tests/core/core.php tests/core/db_qp_test.php + tests/core/connection_manager_test.php tests/databases/mysql/MySQLTest.php diff --git a/src/Query/Abstract_Driver.php b/src/Query/Abstract_Driver.php index 6cfd3a0..8025a0d 100644 --- a/src/Query/Abstract_Driver.php +++ b/src/Query/Abstract_Driver.php @@ -49,19 +49,19 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { * Reference to util class * @var Abstract_Util */ - public $util; + protected $util; /** * Last query executed * @var string */ - public $last_query; + protected $last_query; /** * Prefix to apply to table names * @var string */ - public $table_prefix = ''; + protected $table_prefix = ''; /** * Whether the driver supports 'TRUNCATE' @@ -130,7 +130,32 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { } // -------------------------------------------------------------------------- - // ! Concrete functions that can be overridden in child classes + // ! Accessors / Mutators + // -------------------------------------------------------------------------- + + /** + * Get the last sql query exexcuted + * + * @return string + */ + public function get_last_query() + { + return $this->last_query; + } + + // -------------------------------------------------------------------------- + + /** + * Set the last query sql + * + * @param string $query_string + * @return void + */ + public function set_last_query($query_string) + { + $this->last_query = $query_string; + } + // -------------------------------------------------------------------------- /** @@ -157,6 +182,21 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { // -------------------------------------------------------------------------- + /** + * Set the common table name prefix + * + * @param string + * @return void + */ + public function set_table_prefix($prefix) + { + $this->table_prefix = $prefix; + } + + // -------------------------------------------------------------------------- + // ! Concrete functions that can be overridden in child classes + // -------------------------------------------------------------------------- + /** * Simplifies prepared statements for database queries * diff --git a/src/Query/Abstract_Query_Builder.php b/src/Query/Abstract_Query_Builder.php index 63bfea4..4da157c 100644 --- a/src/Query/Abstract_Query_Builder.php +++ b/src/Query/Abstract_Query_Builder.php @@ -229,10 +229,10 @@ abstract class Abstract_Query_Builder { // Escape the identifiers $field = $this->db->quote_ident($field); - $as = ($as !== FALSE) - ? $this->db->quote_ident($as) - : $field; + if ( ! is_string($as)) return $field; + + $as = $this->db->quote_ident($as); return "({$field}) AS {$as} "; } @@ -519,7 +519,7 @@ abstract class Abstract_Query_Builder { $this->queries['total_time'] += $total_time; // Set the last query to get rowcounts properly - $this->db->last_query = $sql; + $this->db->set_last_query($sql); } // -------------------------------------------------------------------------- diff --git a/src/Query/Connection_Manager.php b/src/Query/Connection_Manager.php index b1fde05..2b62423 100644 --- a/src/Query/Connection_Manager.php +++ b/src/Query/Connection_Manager.php @@ -48,18 +48,31 @@ final class Connection_Manager { /** * Private clone method to prevent cloning - * @codeCoverageIgnore + * @throws \DomainException */ - private function __clone() {} + public function __clone() + { + throw new \DomainException("Can't clone singleton"); + } + + // -------------------------------------------------------------------------- + + /** + * Prevent serialization of this object + * @throws \DomainException + */ + public function __sleep() + { + throw new \DomainException("No serializing of singleton"); + } // -------------------------------------------------------------------------- /** * Make sure serialize/deserialize doesn't work - * @codeCoverageIgnore * @throws \DomainException */ - private function __wakeup() + public function __wakeup() { throw new \DomainException("Can't unserialize singleton"); } @@ -74,12 +87,7 @@ final class Connection_Manager { */ public static function get_instance() { - // @codeCoverageIgnoreStart - if (self::$instance === null) - { - self::$instance = new self(); - } - // @codeCoverageIgnoreEnd + if (self::$instance === null) self::$instance = new self(); return self::$instance; } @@ -132,7 +140,7 @@ final class Connection_Manager { // Set the table prefix, if it exists if (isset($params->prefix)) { - $db->table_prefix = $params->prefix; + $db->set_table_prefix($params->prefix); } // Create Query Builder object @@ -161,7 +169,7 @@ final class Connection_Manager { * @return array * @throws BadDBDriverException */ - private function parse_params(\stdClass $params) + public function parse_params(\stdClass $params) { $params->type = strtolower($params->type); $dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql'; diff --git a/src/Query/Driver_Interface.php b/src/Query/Driver_Interface.php index 06b9d17..29548fe 100644 --- a/src/Query/Driver_Interface.php +++ b/src/Query/Driver_Interface.php @@ -30,7 +30,6 @@ interface Driver_Interface { * @param string $username * @param string $password * @param array $driver_options - * @return void */ public function __construct($dsn, $username=NULL, $password=NULL, array $driver_options = array()); diff --git a/src/Query/Drivers/Firebird/Driver.php b/src/Query/Drivers/Firebird/Driver.php index 73cd7cf..3c1f197 100644 --- a/src/Query/Drivers/Firebird/Driver.php +++ b/src/Query/Drivers/Firebird/Driver.php @@ -190,7 +190,7 @@ class Driver extends \Query\Abstract_Driver { : \fbird_query($this->conn, $sql); // Throw the error as a exception - $err_string = \fbird_errmsg() . "Last query:" . $this->last_query; + $err_string = \fbird_errmsg() . "Last query:" . $this->get_last_query(); if ($this->statement_link === FALSE) throw new \PDOException($err_string, \fbird_errcode(), NULL); $this->statement = new Result($this->statement_link, $this); diff --git a/src/Query/Drivers/Firebird/Result.php b/src/Query/Drivers/Firebird/Result.php index 48f260c..1bc4d36 100644 --- a/src/Query/Drivers/Firebird/Result.php +++ b/src/Query/Drivers/Firebird/Result.php @@ -258,17 +258,7 @@ class Result extends \PDOStatement { */ public function rowCount() { - $rows = \fbird_affected_rows(); - - // Get the number of rows for the select query if you can - if ($rows === 0 && \is_resource($this->statement) && \get_resource_type($this->statement) === "interbase result") - { - // @codeCoverageIgnoreStart - $rows = \count($this->result); - } - // @codeCoverageIgnoreEnd - - return $rows; + return \fbird_affected_rows(); } // -------------------------------------------------------------------------- diff --git a/src/Query/Drivers/Firebird/Util.php b/src/Query/Drivers/Firebird/Util.php index ef55fe8..c30628a 100644 --- a/src/Query/Drivers/Firebird/Util.php +++ b/src/Query/Drivers/Firebird/Util.php @@ -53,7 +53,7 @@ class Util extends \Query\Abstract_Util { /** * Create an SQL backup file for the current database's structure - * @codeCoverageIgnore + * * @param string $db_path * @param string $new_file * @return string @@ -69,7 +69,6 @@ class Util extends \Query\Abstract_Util { /** * Create an SQL backup file for the current database's data * - * @codeCoverageIgnore * @param array $exclude * @param bool $system_tables * @return string diff --git a/src/Query/Drivers/Mysql/Driver.php b/src/Query/Drivers/Mysql/Driver.php index af8fb13..c9cd111 100644 --- a/src/Query/Drivers/Mysql/Driver.php +++ b/src/Query/Drivers/Mysql/Driver.php @@ -33,6 +33,7 @@ class Driver extends \Query\Abstract_Driver { /** * Connect to MySQL Database * + * @codeCoverageIgnore * @param string $dsn * @param string $username * @param string $password diff --git a/src/Query/Drivers/Pdo_firebird/Util.php b/src/Query/Drivers/Pdo_firebird/Util.php index 5770f26..8014419 100644 --- a/src/Query/Drivers/Pdo_firebird/Util.php +++ b/src/Query/Drivers/Pdo_firebird/Util.php @@ -25,7 +25,6 @@ class Util extends \Query\Drivers\Firebird\Util { /** * Create an SQL backup file for the current database's structure - * @codeCoverageIgnore * @param string $db_path * @param string $new_file * @return string diff --git a/src/Query/Drivers/Pgsql/Driver.php b/src/Query/Drivers/Pgsql/Driver.php index 070c89a..adc39af 100644 --- a/src/Query/Drivers/Pgsql/Driver.php +++ b/src/Query/Drivers/Pgsql/Driver.php @@ -26,6 +26,7 @@ class Driver extends \Query\Abstract_Driver { /** * Connect to a PosgreSQL database * + * @codeCoverageIgnore * @param string $dsn * @param string $username * @param string $password diff --git a/src/Query/Drivers/Pgsql/SQL.php b/src/Query/Drivers/Pgsql/SQL.php index cc4352d..f002583 100644 --- a/src/Query/Drivers/Pgsql/SQL.php +++ b/src/Query/Drivers/Pgsql/SQL.php @@ -25,7 +25,6 @@ class SQL extends \Query\Abstract_SQL { /** * Get the query plan for the sql query * - * @codeCoverageIgnore * @param string $sql * @return string */ diff --git a/src/Query/Query_Builder_Interface.php b/src/Query/Query_Builder_Interface.php index c411468..7cb2fac 100644 --- a/src/Query/Query_Builder_Interface.php +++ b/src/Query/Query_Builder_Interface.php @@ -305,7 +305,7 @@ interface Query_Builder_Interface { * * @param int $limit * @param int|bool $offset - * @return string + * @return Query_Builder */ public function limit($limit, $offset=FALSE); diff --git a/src/common.php b/src/common.php index 7f5145e..24e40c7 100644 --- a/src/common.php +++ b/src/common.php @@ -26,7 +26,6 @@ if ( ! function_exists('do_include')) * Bulk directory loading workaround for use * with array_map and glob * - * @codeCoverageIgnore * @param string $path * @return void */ @@ -221,8 +220,6 @@ if ( ! function_exists('Query')) // Otherwise, return a new connection return $cmanager->connect($params_object); } - // @codeCoverageIgnoreStart } - // @codeCoverageIgnoreEnd } // End of common.php \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 772e34a..da920ea 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -93,13 +93,16 @@ define('QTEST_DIR', realpath(dirname(__FILE__))); define('QBASE_DIR', realpath(QTEST_DIR.'/../') . '/'); define('QDS', DIRECTORY_SEPARATOR); +$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'; +@unlink($path); + // Include db classes require_once(QBASE_DIR . 'autoload.php'); // Require base testing classes require_once(QTEST_DIR . '/core/core.php'); require_once(QTEST_DIR . '/core/db_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/query_parser_test.php'); +require_once(QTEST_DIR . '/core/base_query_builder_test.php'); // End of bootstrap.php \ No newline at end of file diff --git a/tests/core/db_qb_test.php b/tests/core/base_query_builder_test.php similarity index 84% rename from tests/core/db_qb_test.php rename to tests/core/base_query_builder_test.php index 048b9a8..ba4aea0 100644 --- a/tests/core/db_qb_test.php +++ b/tests/core/base_query_builder_test.php @@ -18,14 +18,23 @@ */ abstract class QBTest extends Query_TestCase { + protected static $db; + public function __destruct() { if (isset($_GET['show_queries'])) { - echo '
' . print_r($this->db->queries, TRUE) . '
'; + echo '
' . print_r(self::$db->queries, TRUE) . '
'; } } + // -------------------------------------------------------------------------- + + public static function tearDownAfterClass() + { + self::$db = NULL; + } + // -------------------------------------------------------------------------- // ! Driver-specific results // -------------------------------------------------------------------------- @@ -50,18 +59,9 @@ abstract class QBTest extends Query_TestCase { // -------------------------------------------------------------------------- - public function testQueryFunctionAlias() - { - $db = Query(); - - $this->assertTrue($this->db === $db); - } - - // -------------------------------------------------------------------------- - public function testFunctionGet() { - $query = $this->db->select('id, COUNT(id) as count') + $query = self::$db->select('id, COUNT(id) as count') ->from('test') ->group_by('id') ->get(); @@ -73,7 +73,7 @@ abstract class QBTest extends Query_TestCase { public function testGet() { - $query = $this->db->get('test'); + $query = self::$db->get('test'); $this->assertIsA($query, 'PDOStatement'); } @@ -82,27 +82,27 @@ abstract class QBTest extends Query_TestCase { public function testPrefixGet() { - $query = $this->db->from('test')->get(); + $query = self::$db->from('test')->get(); $this->assertIsA($query, 'PDOStatement'); - $this->assertTrue($this->db->num_rows() > 0); + $this->assertTrue(self::$db->num_rows() > 0); } // -------------------------------------------------------------------------- public function testGetWNumRows() { - $query = $this->db->get('test'); + $query = self::$db->get('test'); $numrows = count($query->fetchAll(PDO::FETCH_NUM)); - $this->assertEqual($this->db->num_rows(), $numrows); + $this->assertEqual(self::$db->num_rows(), $numrows); } // -------------------------------------------------------------------------- public function testGetLimit() { - $query = $this->db->get('test', 2); + $query = self::$db->get('test', 2); $this->assertIsA($query, 'PDOStatement'); } @@ -111,7 +111,7 @@ abstract class QBTest extends Query_TestCase { public function testGetLimitSkip() { - $query = $this->db->get('test', 2, 1); + $query = self::$db->get('test', 2, 1); $this->assertIsA($query, 'PDOStatement'); } @@ -120,7 +120,7 @@ abstract class QBTest extends Query_TestCase { public function testGetWhere() { - $query = $this->db->get_where('test', array('id !=' => 1), 2, 1); + $query = self::$db->get_where('test', array('id !=' => 1), 2, 1); $this->assertIsA($query, 'PDOStatement'); } @@ -129,7 +129,7 @@ abstract class QBTest extends Query_TestCase { public function testHaving() { - $query = $this->db->select('id') + $query = self::$db->select('id') ->from('test') ->group_by('id') ->having(array('id >' => 1)) @@ -143,7 +143,7 @@ abstract class QBTest extends Query_TestCase { public function testOrHaving() { - $query = $this->db->select('id') + $query = self::$db->select('id') ->from('test') ->group_by('id') ->having(array('id >' => 1)) @@ -159,7 +159,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectWhereGet() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->where('id >', 1) ->where('id <', 900) ->get('test', 2, 1); @@ -171,7 +171,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectAvg() { - $query = $this->db->select_avg('id', 'di') + $query = self::$db->select_avg('id', 'di') ->get('test'); $this->assertIsA($query, 'PDOStatement'); @@ -181,7 +181,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectSum() { - $query = $this->db->select_sum('id', 'di') + $query = self::$db->select_sum('id', 'di') ->get('test'); $this->assertIsA($query, 'PDOStatement'); @@ -191,7 +191,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectDistinct() { - $query = $this->db->select_sum('id', 'di') + $query = self::$db->select_sum('id', 'di') ->distinct() ->get('test'); @@ -202,7 +202,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectGet() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->get('test', 2, 1); $this->assertIsA($query, 'PDOStatement'); @@ -212,7 +212,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectFromGet() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test ct') ->where('id >', 1) ->get(); @@ -224,7 +224,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectFromLimitGet() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test ct') ->where('id >', 1) ->limit(3) @@ -238,7 +238,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectWhereGet2() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->where('id !=', 1) ->get('test', 2, 1); @@ -249,7 +249,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectMax() { - $query = $this->db->select_max('id', 'di') + $query = self::$db->select_max('id', 'di') ->get('test'); $this->assertIsA($query, 'PDOStatement'); @@ -259,7 +259,7 @@ abstract class QBTest extends Query_TestCase { public function testSelectMin() { - $query = $this->db->select_min('id', 'di') + $query = self::$db->select_min('id', 'di') ->get('test'); $this->assertIsA($query, 'PDOStatement'); @@ -269,7 +269,7 @@ abstract class QBTest extends Query_TestCase { public function testMultiOrderBy() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->order_by('id, key') ->get(); @@ -282,7 +282,7 @@ abstract class QBTest extends Query_TestCase { public function testGroup() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->group_start() ->where('id >', 1) @@ -298,7 +298,7 @@ abstract class QBTest extends Query_TestCase { public function testOrGroup() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->group_start() ->where('id >', 1) @@ -317,7 +317,7 @@ abstract class QBTest extends Query_TestCase { public function testOrNotGroup() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->group_start() ->where('id >', 1) @@ -336,7 +336,7 @@ abstract class QBTest extends Query_TestCase { public function testGroupCamelCase() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->groupStart() ->where('id >', 1) @@ -357,7 +357,7 @@ abstract class QBTest extends Query_TestCase { public function testWhereIn() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->where_in('id', array(0, 6, 56, 563, 341)) ->get(); @@ -368,7 +368,7 @@ abstract class QBTest extends Query_TestCase { public function testOrWhereIn() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->where('key', 'false') ->or_where_in('id', array(0, 6, 56, 563, 341)) ->get(); @@ -380,7 +380,7 @@ abstract class QBTest extends Query_TestCase { public function testWhereNotIn() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->where('key', 'false') ->where_not_in('id', array(0, 6, 56, 563, 341)) ->get(); @@ -392,7 +392,7 @@ abstract class QBTest extends Query_TestCase { public function testOrWhereNotIn() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->where('key', 'false') ->or_where_not_in('id', array(0, 6, 56, 563, 341)) ->get(); @@ -406,7 +406,7 @@ abstract class QBTest extends Query_TestCase { public function testOrderBy() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->where('id >', 0) ->where('id <', 9000) @@ -422,7 +422,7 @@ abstract class QBTest extends Query_TestCase { public function testOrderByRandom() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->where('id >', 0) ->where('id <', 9000) @@ -437,7 +437,7 @@ abstract class QBTest extends Query_TestCase { public function testGroupBy() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->where('id >', 0) ->where('id <', 9000) @@ -459,7 +459,7 @@ abstract class QBTest extends Query_TestCase { public function testOrWhere() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->where(' id ', 1) ->or_where('key >', 0) @@ -473,7 +473,7 @@ abstract class QBTest extends Query_TestCase { public function testLike() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->like('key', 'og') ->get(); @@ -484,7 +484,7 @@ abstract class QBTest extends Query_TestCase { public function testOrLike() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->like('key', 'og') ->or_like('key', 'val') ->get(); @@ -496,7 +496,7 @@ abstract class QBTest extends Query_TestCase { public function testOrNotLike() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->like('key', 'og', 'before') ->or_not_like('key', 'val') ->get(); @@ -508,7 +508,7 @@ abstract class QBTest extends Query_TestCase { public function testNotLike() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->like('key', 'og', 'before') ->not_like('key', 'val') ->get(); @@ -520,7 +520,7 @@ abstract class QBTest extends Query_TestCase { public function testLikeBefore() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->like('key', 'og', 'before') ->get(); @@ -531,7 +531,7 @@ abstract class QBTest extends Query_TestCase { public function testLikeAfter() { - $query = $this->db->from('test') + $query = self::$db->from('test') ->like('key', 'og', 'after') ->get(); @@ -542,7 +542,7 @@ abstract class QBTest extends Query_TestCase { public function testJoin() { - $query = $this->db->from('test ct') + $query = self::$db->from('test ct') ->join('join cj', 'cj.id = ct.id') ->get(); @@ -553,7 +553,7 @@ abstract class QBTest extends Query_TestCase { public function testLeftJoin() { - $query = $this->db->from('test ct') + $query = self::$db->from('test ct') ->join('join cj', 'cj.id = ct.id', 'left') ->get(); @@ -564,7 +564,7 @@ abstract class QBTest extends Query_TestCase { public function testInnerJoin() { - $query = $this->db->from('test ct') + $query = self::$db->from('test ct') ->join('join cj', 'cj.id = ct.id', 'inner') ->get(); @@ -575,7 +575,7 @@ abstract class QBTest extends Query_TestCase { public function testJoinWithMultipleWhereValues() { - $query = $this->db->from('test ct') + $query = self::$db->from('test ct') ->join('join cj', 'cj.id=ct.id', 'inner') ->where(array( 'ct.id < ' => 3, @@ -592,7 +592,7 @@ abstract class QBTest extends Query_TestCase { public function testInsert() { - $query = $this->db->set('id', 98) + $query = self::$db->set('id', 98) ->set('key', 84) ->set('val', 120) ->insert('test'); @@ -604,7 +604,7 @@ abstract class QBTest extends Query_TestCase { public function testInsertArray() { - $query = $this->db->insert('test', array( + $query = self::$db->insert('test', array( 'id' => 587, 'key' => 1, 'val' => 2, @@ -635,7 +635,7 @@ abstract class QBTest extends Query_TestCase { ), ); - $query = $this->db->insert_batch('test', $data); + $query = self::$db->insert_batch('test', $data); $this->assertIsA($query, 'PDOStatement'); } @@ -644,7 +644,7 @@ abstract class QBTest extends Query_TestCase { public function testUpdate() { - $query = $this->db->where('id', 7) + $query = self::$db->where('id', 7) ->update('test', array( 'id' => 7, 'key' => 'gogle', @@ -664,7 +664,7 @@ abstract class QBTest extends Query_TestCase { 'val' => 'non-word' ); - $query = $this->db->set($array) + $query = self::$db->set($array) ->where('id', 22) ->update('test'); @@ -675,7 +675,7 @@ abstract class QBTest extends Query_TestCase { public function testWhereSetUpdate() { - $query = $this->db->where('id', 36) + $query = self::$db->where('id', 36) ->set('id', 36) ->set('key', 'gogle') ->set('val', 'non-word') @@ -688,8 +688,7 @@ abstract class QBTest extends Query_TestCase { public function testDelete() { -//$this->markTestSkipped(); - $query = $this->db->delete('test', array('id' => 5)); + $query = self::$db->delete('test', array('id' => 5)); $this->assertIsA($query, 'PDOStatement'); } @@ -698,7 +697,7 @@ abstract class QBTest extends Query_TestCase { public function testDeleteWithMultipleWhereValues() { - $query = $this->db->delete('test', array( + $query = self::$db->delete('test', array( 'id' => 5, 'key' => 'gogle' )); @@ -712,7 +711,7 @@ abstract class QBTest extends Query_TestCase { public function testCountAll() { - $query = $this->db->count_all('test'); + $query = self::$db->count_all('test'); $this->assertTrue(is_numeric($query)); } @@ -721,7 +720,7 @@ abstract class QBTest extends Query_TestCase { public function testCountAllResults() { - $query = $this->db->count_all_results('test'); + $query = self::$db->count_all_results('test'); $this->assertTrue(is_numeric($query)); } @@ -730,7 +729,7 @@ abstract class QBTest extends Query_TestCase { public function testCountAllResults2() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->from('test') ->where(' id ', 1) ->or_where('key >', 0) @@ -744,9 +743,9 @@ abstract class QBTest extends Query_TestCase { public function testNumRows() { - $query = $this->db->get('test'); + $query = self::$db->get('test'); - $this->assertTrue(is_numeric($this->db->num_rows())); + $this->assertTrue(is_numeric(self::$db->num_rows())); } // -------------------------------------------------------------------------- @@ -755,9 +754,9 @@ abstract class QBTest extends Query_TestCase { public function testGetCompiledSelect() { - $sql = $this->db->get_compiled_select('test'); - $qb_res = $this->db->get('test'); - $sql_res = $this->db->query($sql); + $sql = self::$db->get_compiled_select('test'); + $qb_res = self::$db->get('test'); + $sql_res = self::$db->query($sql); $this->assertIsA($qb_res,'PDOStatement', "Query Builder Result is a PDO Statement"); $this->assertIsA($sql_res, 'PDOStatement', "SQL Result is a PDO Statement"); @@ -766,7 +765,7 @@ abstract class QBTest extends Query_TestCase { public function testGetCompiledUpdate() { - $sql = $this->db->set(array( + $sql = self::$db->set(array( 'id' => 4, 'key' => 'foo', 'val' => 'baz' @@ -777,7 +776,7 @@ abstract class QBTest extends Query_TestCase { public function testGetCompiledInsert() { - $sql = $this->db->set(array( + $sql = self::$db->set(array( 'id' => 4, 'key' => 'foo', 'val' => 'baz' @@ -788,7 +787,7 @@ abstract class QBTest extends Query_TestCase { public function testGetCompiledDelete() { - $sql = $this->db->where('id', 4) + $sql = self::$db->where('id', 4) ->get_compiled_delete('test'); $this->assertTrue(is_string($sql)); @@ -814,7 +813,7 @@ abstract class QBTest extends Query_TestCase { try { - $this->db = Query($params); + self::$db = Query($params); } catch(\Query\BadDBDriverException $e) { @@ -828,7 +827,7 @@ abstract class QBTest extends Query_TestCase { { try { - $this->db->foo(); + self::$db->foo(); } catch(BadMethodCallException $e) { @@ -840,13 +839,13 @@ abstract class QBTest extends Query_TestCase { public function testBadNumRows() { - $this->db->set(array( + self::$db->set(array( 'id' => 999, 'key' => 'ring', 'val' => 'sale' ))->insert('test'); - $res = $this->db->num_rows(); + $res = self::$db->num_rows(); $this->assertEqual(NULL, $res); } } diff --git a/tests/core/connection_manager_test.php b/tests/core/connection_manager_test.php new file mode 100644 index 0000000..2216595 --- /dev/null +++ b/tests/core/connection_manager_test.php @@ -0,0 +1,81 @@ +setExpectedException('DomainException', "Can't clone singleton"); + $clone = clone self::$instance; + } + + // -------------------------------------------------------------------------- + + public function testNoSerialize() + { + $this->setExpectedException('DomainException', "No serializing of singleton"); + $string = serialize(self::$instance); + + $this->setExpectedException('DomainException', "No serializing of singleton"); + $string = self::$instance->__sleep(); + } + + // -------------------------------------------------------------------------- + + public function testNoUnserialize() + { + $this->setExpectedException('DomainException', "Can't unserialize singleton"); + $obj = self::$instance->__wakeup(); + } + + // -------------------------------------------------------------------------- + + public function testParseParams() + { + $params = (object) array( + 'type' => 'sqlite', + 'file' => ':memory:', + 'options' => array( + 'foo' => 'bar' + ) + ); + + $expected = array( + ':memory:', + 'Sqlite', + $params, + array('foo' => 'bar') + ); + + $this->assertEqual($expected, self::$instance->parse_params($params)); + } + + // -------------------------------------------------------------------------- + + public function testConnect() + { + $params = (object) array( + 'type' => 'sqlite', + 'file' => ':memory:', + 'options' => array( + 'foo' => 'bar' + ) + ); + + $conn = self::$instance->connect($params); + $this->assertInstanceOf('Query\\Query_Builder', $conn); + + + // Check that the connection just made is returned from the get_connection method + $this->assertEqual($conn, self::$instance->get_connection()); + } +} +// End of connection_manager_test.php \ No newline at end of file diff --git a/tests/core/core.php b/tests/core/core.php index ef41945..b71576a 100644 --- a/tests/core/core.php +++ b/tests/core/core.php @@ -19,19 +19,6 @@ */ class CoreTest extends Query_TestCase { - /** - * __construct function. - * - * @access public - * @return void - */ - public function __construct() - { - parent::__construct(); - } - - // -------------------------------------------------------------------------- - /** * TestPHPVersion function. * diff --git a/tests/core/db_test.php b/tests/core/db_test.php index f41b3ae..5b17024 100644 --- a/tests/core/db_test.php +++ b/tests/core/db_test.php @@ -51,7 +51,8 @@ abstract class DBTest extends Query_TestCase { public function testBackupData() { - $this->assertTrue(is_string(self::$db->util->backup_data(array('create_delete', TRUE)))); + $this->assertTrue(is_string(self::$db->get_util()->backup_data(array('create_delete', FALSE)))); + $this->assertTrue(is_string(self::$db->get_util()->backup_data(array('create_delete', TRUE)))); } // -------------------------------------------------------------------------- diff --git a/tests/core/db_qp_test.php b/tests/core/query_parser_test.php similarity index 100% rename from tests/core/db_qp_test.php rename to tests/core/query_parser_test.php diff --git a/tests/databases/firebird/FirebirdQBTest.php b/tests/databases/firebird/FirebirdQBTest.php index 28f6122..25cea6f 100644 --- a/tests/databases/firebird/FirebirdQBTest.php +++ b/tests/databases/firebird/FirebirdQBTest.php @@ -19,13 +19,8 @@ */ class FirebirdQBTest extends QBTest { - public function setUp() + public static function setUpBeforeClass() { - if ( ! function_exists('\\fbird_connect')) - { - $this->markTestSkipped('Firebird extension does not exist'); - } - $dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB'; // test the query builder @@ -37,9 +32,19 @@ class FirebirdQBTest extends QBTest { $params->user = 'SYSDBA'; $params->pass = 'masterkey'; $params->prefix = 'create_'; - $this->db = Query($params); + self::$db = Query($params); } + public function setUp() + { + if ( ! function_exists('\\fbird_connect')) + { + $this->markTestSkipped('Firebird extension does not exist'); + } + } + + // -------------------------------------------------------------------------- + public function testGetNamedConnectionException() { try @@ -52,13 +57,17 @@ class FirebirdQBTest extends QBTest { } } + // -------------------------------------------------------------------------- + public function testQueryFunctionAlias() { $db = Query(); - $this->assertTrue($this->db === $db); + $this->assertTrue(self::$db === $db); } + // -------------------------------------------------------------------------- + public function testGetNamedConnection() { $dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB'; @@ -82,8 +91,8 @@ class FirebirdQBTest extends QBTest { public function testTypeList() { - $sql = $this->db->sql->type_list(); - $query = $this->db->query($sql); + $sql = self::$db->sql->type_list(); + $query = self::$db->query($sql); $this->assertIsA($query, 'PDOStatement'); @@ -96,14 +105,14 @@ class FirebirdQBTest extends QBTest { public function testQueryExplain() { - $res = $this->db->select('id, key as k, val') + $res = self::$db->select('id, key as k, val') ->explain() ->where('id >', 1) ->where('id <', 900) ->limit(2, 1) ->get_compiled_select(); - $res2 = $this->db->select('id, key as k, val') + $res2 = self::$db->select('id, key as k, val') ->where('id >', 1) ->where('id <', 900) ->limit(2, 1) @@ -117,7 +126,7 @@ class FirebirdQBTest extends QBTest { public function testResultErrors() { - $obj = $this->db->query('SELECT * FROM "create_test"'); + $obj = self::$db->query('SELECT * FROM "create_test"'); // Test row count $this->assertEqual(0, $obj->rowCount()); @@ -136,11 +145,13 @@ class FirebirdQBTest extends QBTest { $this->assertEqual($expected, $error); } + // -------------------------------------------------------------------------- + public function testBackupStructure() { $existing = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB'; $backup = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_BKP.FDB'; - $this->assertTrue($this->db->util->backup_structure($existing, $backup)); + $this->assertTrue(self::$db->get_util()->backup_structure($existing, $backup)); } } \ No newline at end of file diff --git a/tests/databases/firebird/FirebirdTest.php b/tests/databases/firebird/FirebirdTest.php index 915e8c7..f8bbdbf 100644 --- a/tests/databases/firebird/FirebirdTest.php +++ b/tests/databases/firebird/FirebirdTest.php @@ -29,7 +29,7 @@ class FirebirdTest extends DBtest { // test the db driver directly self::$db = new \Query\Drivers\Firebird\Driver('localhost:'.$dbpath); - self::$db->table_prefix = 'create_'; + self::$db->set_table_prefix('create_'); } public function setUp() @@ -108,7 +108,7 @@ class FirebirdTest extends DBtest { public function testCreateTable() { //Attempt to create the table - $sql = self::$db->util->create_table('create_delete', array( + $sql = self::$db->get_util()->create_table('create_delete', array( 'id' => 'SMALLINT', 'key' => 'VARCHAR(64)', 'val' => 'BLOB SUB_TYPE TEXT' @@ -124,7 +124,7 @@ class FirebirdTest extends DBtest { public function testDeleteTable() { //Attempt to delete the table - $sql = self::$db->util->delete_table('create_delete'); + $sql = self::$db->get_util()->delete_table('create_delete'); self::$db->query($sql); //Check diff --git a/tests/databases/mysql/MySQLQBTest.php b/tests/databases/mysql/MySQLQBTest.php index 511d3e0..50770ea 100644 --- a/tests/databases/mysql/MySQLQBTest.php +++ b/tests/databases/mysql/MySQLQBTest.php @@ -18,9 +18,9 @@ */ class MySQLQBTest extends QBTest { - public function setUp() - { - // Attempt to connect, if there is a test config file + public static function setUpBeforeClass() + { + // Attempt to connect, if there is a test config file if (is_file(QTEST_DIR . "/settings.json")) { $params = json_decode(file_get_contents(QTEST_DIR . "/settings.json")); @@ -42,10 +42,8 @@ class MySQLQBTest extends QBTest { ); } - $this->db = Query($params); - - //echo "Mysql Queries
"; - } + self::$db = Query($params); + } // -------------------------------------------------------------------------- @@ -58,7 +56,7 @@ class MySQLQBTest extends QBTest { public function testQueryExplain() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->explain() ->where('id >', 1) ->where('id <', 900) diff --git a/tests/databases/mysql/MySQLTest.php b/tests/databases/mysql/MySQLTest.php index ec119e2..c7d232f 100644 --- a/tests/databases/mysql/MySQLTest.php +++ b/tests/databases/mysql/MySQLTest.php @@ -38,7 +38,7 @@ class MySQLTest extends DBTest { self::$db = new \Query\Drivers\Mysql\Driver('host=127.0.0.1;port=3306;dbname=test', 'root'); } - self::$db->table_prefix = 'create_'; + self::$db->set_table_prefix('create_'); } // -------------------------------------------------------------------------- @@ -62,7 +62,7 @@ class MySQLTest extends DBTest { self::$db->exec(file_get_contents(QTEST_DIR.'/db_files/mysql.sql')); //Attempt to create the table - $sql = self::$db->util->create_table('test', + $sql = self::$db->get_util()->create_table('test', array( 'id' => 'int(10)', 'key' => 'TEXT', @@ -76,7 +76,7 @@ class MySQLTest extends DBTest { self::$db->query($sql); //Attempt to create the table - $sql = self::$db->util->create_table('join', + $sql = self::$db->get_util()->create_table('join', array( 'id' => 'int(10)', 'key' => 'TEXT', @@ -198,7 +198,7 @@ SQL; public function testBackup() { - $this->assertTrue(is_string(self::$db->util->backup_structure())); + $this->assertTrue(is_string(self::$db->get_util()->backup_structure())); } diff --git a/tests/databases/pdofirebird/PDOFirebirdQBTest.php b/tests/databases/pdofirebird/PDOFirebirdQBTest.php index c0fa588..cb523b8 100644 --- a/tests/databases/pdofirebird/PDOFirebirdQBTest.php +++ b/tests/databases/pdofirebird/PDOFirebirdQBTest.php @@ -38,15 +38,15 @@ class PDOFirebirdQBTest extends QBTest { $params->pass = 'masterkey'; $params->prefix = 'create_'; - $this->db = Query($params); + self::$db = Query($params); } public function testQueryFunctionAlias() { -$this->markTestSkipped(); +$this->markTestSkipped("Segfault"); $db = Query(); - $this->assertTrue($this->db === $db); + $this->assertTrue(self::$db === $db); } public function testGetNamedConnectionException() @@ -84,10 +84,10 @@ $this->markTestSkipped(); public function testTypeList() { -$this->markTestSkipped(); +$this->markTestSkipped("Segfault"); $this->doSetUp(); - $sql = $this->db->get_sql()->type_list(); - $query = $this->db->query($sql); + $sql = self::$db->get_sql()->type_list(); + $query = self::$db->query($sql); $this->assertIsA('PDOStatement', $query); @@ -100,14 +100,14 @@ $this->markTestSkipped(); public function testQueryExplain() { - $res = $this->db->select('id, key as k, val') + $res = self::$db->select('id, key as k, val') ->explain() ->where('id >', 1) ->where('id <', 900) ->limit(2, 1) ->get_compiled_select(); - $res2 = $this->db->select('id, key as k, val') + $res2 = self::$db->select('id, key as k, val') ->where('id >', 1) ->where('id <', 900) ->limit(2, 1) diff --git a/tests/databases/pdofirebird/PDOFirebirdTest.php b/tests/databases/pdofirebird/PDOFirebirdTest.php index d45ec95..b0b2867 100644 --- a/tests/databases/pdofirebird/PDOFirebirdTest.php +++ b/tests/databases/pdofirebird/PDOFirebirdTest.php @@ -29,7 +29,7 @@ class PDOFirebirdTest extends DBtest { // test the db driver directly self::$db = new \Query\Drivers\Pdo_firebird\Driver('firebird:host=localhost;dbname='.$dbpath); - self::$db->table_prefix = 'create_'; + self::$db->set_table_prefix('create_'); } public function setUp() @@ -83,6 +83,11 @@ class PDOFirebirdTest extends DBtest { $this->assertTrue($only_system); } + public function testBackupStructure() + { + $this->assertNull(self::$db->get_util()->backup_structure()); + } + // -------------------------------------------------------------------------- // ! Create / Delete Tables // -------------------------------------------------------------------------- @@ -91,7 +96,7 @@ class PDOFirebirdTest extends DBtest { { $this->markTestSkipped(); //Attempt to create the table - $sql = self::$db->util->create_table('create_delete', array( + $sql = self::$db->get_util()->create_table('create_delete', array( 'id' => 'SMALLINT', 'key' => 'VARCHAR(64)', 'val' => 'BLOB SUB_TYPE TEXT' @@ -108,7 +113,7 @@ $this->markTestSkipped(); { $this->markTestSkipped(); //Attempt to delete the table - $sql = self::$db->util->delete_table('create_delete'); + $sql = self::$db->get_util()->delete_table('create_delete'); self::$db->query($sql); //Check diff --git a/tests/databases/pgsql/PgSQLQBTest.php b/tests/databases/pgsql/PgSQLQBTest.php index 286f904..57b9775 100644 --- a/tests/databases/pgsql/PgSQLQBTest.php +++ b/tests/databases/pgsql/PgSQLQBTest.php @@ -17,15 +17,9 @@ */ class PgSQLQBTest extends QBTest { - public function setUp() - { - // If the database isn't installed, skip the tests - if ( ! in_array('pgsql', PDO::getAvailableDrivers())) - { - $this->markTestSkipped("Postgres extension for PDO not loaded"); - } - - // Attempt to connect, if there is a test config file + public static function setUpBeforeClass() + { + // Attempt to connect, if there is a test config file if (is_file(QTEST_DIR . "/settings.json")) { $params = json_decode(file_get_contents(QTEST_DIR . "/settings.json")); @@ -49,7 +43,16 @@ class PgSQLQBTest extends QBTest { ); } - $this->db = Query($params); + self::$db = Query($params); + } + + public function setUp() + { + // If the database isn't installed, skip the tests + if ( ! in_array('pgsql', PDO::getAvailableDrivers())) + { + $this->markTestSkipped("Postgres extension for PDO not loaded"); + } } // -------------------------------------------------------------------------- @@ -68,7 +71,7 @@ class PgSQLQBTest extends QBTest { $this->markTestSkipped("Skip this test on CI, because the check is Postgres version dependent"); } - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->explain() ->where('id >', 1) ->where('id <', 900) @@ -105,6 +108,6 @@ class PgSQLQBTest extends QBTest { public function testBackupStructure() { - $this->assertEquals('', $this->db->util->backup_structure()); + $this->assertEquals('', self::$db->util->backup_structure()); } } \ No newline at end of file diff --git a/tests/databases/pgsql/PgSQLTest.php b/tests/databases/pgsql/PgSQLTest.php index f788759..d3b3752 100644 --- a/tests/databases/pgsql/PgSQLTest.php +++ b/tests/databases/pgsql/PgSQLTest.php @@ -49,7 +49,7 @@ class PgTest extends DBTest { self::$db = new $class('host=127.0.0.1;port=5432;dbname=test', 'postgres'); } - self::$db->table_prefix = 'create_'; + self::$db->set_table_prefix('create_'); } // -------------------------------------------------------------------------- @@ -83,7 +83,7 @@ class PgTest extends DBTest { //Attempt to create the table - $sql = self::$db->util->create_table('create_test', + $sql = self::$db->get_util()->create_table('create_test', array( 'id' => 'integer', 'key' => 'TEXT', @@ -97,7 +97,7 @@ class PgTest extends DBTest { self::$db->query($sql); //Attempt to create the table - $sql = self::$db->util->create_table('create_join', + $sql = self::$db->get_util()->create_table('create_join', array( 'id' => 'integer', 'key' => 'TEXT', diff --git a/tests/databases/sqlite/SQLiteQBTest.php b/tests/databases/sqlite/SQLiteQBTest.php index 10dca65..7f77483 100644 --- a/tests/databases/sqlite/SQLiteQBTest.php +++ b/tests/databases/sqlite/SQLiteQBTest.php @@ -19,12 +19,11 @@ */ class SQLiteQBTest extends QBTest { - public function setUp() - { - // Set up in the bootstrap to mitigate - // connection locking issues - $this->db = Query('test_sqlite'); - } + public static function setUpBeforeClass() + { + // Defined in the SQLiteTest.php file + self::$db = Query('test_sqlite'); + } // -------------------------------------------------------------------------- @@ -32,14 +31,14 @@ { $db = Query('test_sqlite'); - $this->assertTrue($this->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() { - $query = $this->db->select('id, key as k, val') + $query = self::$db->select('id, key as k, val') ->explain() ->where('id >', 1) ->where('id <', 900) diff --git a/tests/databases/sqlite/SQLiteTest.php b/tests/databases/sqlite/SQLiteTest.php index 52f66ff..be31871 100644 --- a/tests/databases/sqlite/SQLiteTest.php +++ b/tests/databases/sqlite/SQLiteTest.php @@ -34,7 +34,7 @@ class SQLiteTest extends DBTest { ); self::$db = Query($params); - self::$db->table_prefix = 'create_'; + self::$db->set_table_prefix('create_'); } // -------------------------------------------------------------------------- @@ -61,7 +61,7 @@ class SQLiteTest extends DBTest { /*public function testBackupData() { - $sql = mb_trim(self::$db->util->backup_data(array('create_join', 'create_test'))); + $sql = mb_trim(self::$db->get_util()->backup_data(array('create_join', 'create_test'))); $sql_array = explode("\n", $sql); @@ -80,7 +80,7 @@ SQL; public function testBackupStructure() { - $sql = mb_trim(self::$db->util->backup_structure()); + $sql = mb_trim(self::$db->get_util()->backup_structure()); $expected = <<util->delete_table('create_delete'); + $sql = self::$db->get_util()->delete_table('create_delete'); self::$db->query($sql); diff --git a/tests/index.php b/tests/index.php index 408ff24..220aac6 100644 --- a/tests/index.php +++ b/tests/index.php @@ -32,7 +32,7 @@ if ( ! defined('IS_QUERCUS')) // Include simpletest // it has to be in the tests folder -require_once('/htdocs/__lib/simpletest/autorun.php'); +require_once('simpletest/autorun.php'); /** * Base class for TestCases @@ -51,6 +51,16 @@ abstract class Query_TestCase extends UnitTestCase { parent::__construct(); } + public function __destruct() + { + $class = get_class($this); + + if (method_exists($class, 'tearDownAfterClass')) + { + $class::tearDownAfterClass(); + } + } + /** * Define assertInstanceOf for simpletest * @@ -84,6 +94,18 @@ abstract class Query_TestCase extends UnitTestCase { { $this->skipUnless(FALSE, $message); } + + /** + * Alias for phpunit method + * + * @param string $name + * @param string $message + * @param int $code + */ + public function setExpectedException($name, $message='', $code=NULL) + { + $this->expectException($name); + } } // -------------------------------------------------------------------------- @@ -104,8 +126,10 @@ $test_path = QTEST_DIR.'/databases/'; // Require base testing classes require_once(QTEST_DIR . '/core/core.php'); +require_once(QTEST_DIR . '/core/connection_manager_test.php'); require_once(QTEST_DIR . '/core/db_test.php'); -require_once(QTEST_DIR . '/core/db_qb_test.php'); +//require_once(QTEST_DIR . '/core/query_parser_test.php'); +require_once(QTEST_DIR . '/core/base_query_builder_test.php'); $drivers = PDO::getAvailableDrivers();