From 80a878d16e00e91886beca16a2cf96bcb23e0dd8 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 9 Mar 2012 16:17:21 -0500 Subject: [PATCH] Split query builder tests --- sys/db/query_builder.php | 2 +- tests/databases/firebird-qb.php | 114 ++++++++++++++++++++++++++++++++ tests/databases/firebird.php | 101 ---------------------------- tests/databases/odbc.php | 13 ---- tests/databases/sqlite-qb.php | 103 +++++++++++++++++++++++++++++ tests/databases/sqlite.php | 92 -------------------------- 6 files changed, 218 insertions(+), 207 deletions(-) create mode 100644 tests/databases/firebird-qb.php create mode 100644 tests/databases/sqlite-qb.php diff --git a/sys/db/query_builder.php b/sys/db/query_builder.php index 5bb4979..2d1502c 100644 --- a/sys/db/query_builder.php +++ b/sys/db/query_builder.php @@ -91,7 +91,7 @@ class Query_Builder { $sql = $this->_compile('select'); - echo $sql."
"; + //echo $sql."
"; // Do prepared statements for anything involving a "where" clause if ( ! empty($this->where_string)) diff --git a/tests/databases/firebird-qb.php b/tests/databases/firebird-qb.php new file mode 100644 index 0000000..929ad6d --- /dev/null +++ b/tests/databases/firebird-qb.php @@ -0,0 +1,114 @@ +type = 'firebird'; + $params->file = $dbpath; + $params->host = 'localhost'; + $params->user = 'sysdba'; + $params->pass = 'masterkey'; + $this->qb = new Query_Builder($params); + } + + function tearDown() + { + unset($this->qb); + } + + function TestQBGet() + { + $query = $this->qb->get('create_test'); + + $this->assertTrue(is_resource($query)); + } + + function TestQBGetLimit() + { + $query = $this->qb->get('create_test', 2); + + $this->assertTrue(is_resource($query)); + } + + function TestQBGetLimitSkip() + { + $query = $this->qb->get('create_test', 2, 1); + + $this->assertTrue(is_resource($query)); + } + + function TestQBSelectWhereGet() + { + $query = $this->qb->select('id, key as k, val') + ->where('id >', 1) + ->where('id <', 800) + ->get('create_test', 2, 1); + + $this->assertTrue(is_resource($query)); + } + + function TestQBSelectWhereGet2() + { + $query = $this->qb->select('id, key as k, val') + ->where(' id ', 1) + + ->get('create_test', 2, 1); + + $this->assertTrue(is_resource($query)); + } + + + function TestQBSelectGet() + { + $query = $this->qb->select('id, key as k, val') + ->get('create_test', 2, 1); + + $this->assertTrue(is_resource($query)); + } + + function TestSelectFromGet() + { + $query = $this->qb->select('id, key as k, val') + ->from('create_test ct') + ->where('id >', 1) + ->get(); + + $this->assertTrue(is_resource($query)); + } + + function TestSelectFromLimitGet() + { + $query = $this->qb->select('id, key as k, val') + ->from('create_test ct') + ->where('id >', 1) + ->limit(3) + ->get(); + + $this->assertTrue(is_resource($query)); + } +} \ No newline at end of file diff --git a/tests/databases/firebird.php b/tests/databases/firebird.php index e8a4b8b..82a7cf6 100644 --- a/tests/databases/firebird.php +++ b/tests/databases/firebird.php @@ -169,105 +169,4 @@ SQL; $table_exists = in_array('create_test', $this->tables); $this->assertFalse($table_exists); }*/ -} - -/** - * Firebird Query Builder Tests - */ -class FirebirdQBTest extends UnitTestCase { - - function __construct() - { - parent::__construct(); - } - - function setUp() - { - $dbpath = TEST_DIR.DS.'test_dbs'.DS.'FB_TEST_DB.FDB'; - - // Test the query builder - $params = new Stdclass(); - $params->type = 'firebird'; - $params->file = $dbpath; - $params->host = 'localhost'; - $params->user = 'sysdba'; - $params->pass = 'masterkey'; - $this->qb = new Query_Builder($params); - } - - function tearDown() - { - unset($this->qb); - } - - function TestQBGet() - { - $query = $this->qb->get('create_test'); - - $this->assertTrue(is_resource($query)); - } - - function TestQBGetLimit() - { - $query = $this->qb->get('create_test', 2); - - $this->assertTrue(is_resource($query)); - } - - function TestQBGetLimitSkip() - { - $query = $this->qb->get('create_test', 2, 1); - - $this->assertTrue(is_resource($query)); - } - - function TestQBSelectWhereGet() - { - $query = $this->qb->select('id, key as k, val') - ->where('id >', 1) - ->where('id <', 800) - ->get('create_test', 2, 1); - - $this->assertTrue(is_resource($query)); - } - - function TestQBSelectWhereGet2() - { - $query = $this->qb->select('id, key as k, val') - ->where(' id ', 1) - - ->get('create_test', 2, 1); - - $this->assertTrue(is_resource($query)); - } - - - function TestQBSelectGet() - { - $query = $this->qb->select('id, key as k, val') - ->get('create_test', 2, 1); - - $this->assertTrue(is_resource($query)); - } - - function TestSelectFromGet() - { - $query = $this->qb->select('id, key as k, val') - ->from('create_test ct') - ->where('id >', 1) - ->get(); - - $this->assertTrue(is_resource($query)); - } - - function TestSelectFromLimitGet() - { - $query = $this->qb->select('id, key as k, val') - ->from('create_test ct') - ->where('id >', 1) - ->limit(3) - ->get(); - - $this->assertTrue(is_resource($query)); - } } \ No newline at end of file diff --git a/tests/databases/odbc.php b/tests/databases/odbc.php index cb0ad08..ba73a49 100644 --- a/tests/databases/odbc.php +++ b/tests/databases/odbc.php @@ -28,18 +28,5 @@ class ODBCTest extends UnitTestCase { function __construct() { parent::__construct(); - - // Connection Test with SQLite - $path = dirname(__FILE__)."/../test_dbs/test_sqlite.db"; - - try - { - $this->db = new ODBC("Driver=/usr/lib/libsqlite3odbc.so;Database={$path}"); - } - catch(PDOException $e) - { - - } - } } \ No newline at end of file diff --git a/tests/databases/sqlite-qb.php b/tests/databases/sqlite-qb.php new file mode 100644 index 0000000..5270d33 --- /dev/null +++ b/tests/databases/sqlite-qb.php @@ -0,0 +1,103 @@ +type = 'sqlite'; + $params->file = $path; + $params->host = 'localhost'; + $this->qb = new Query_Builder($params); + } + + function tearDown() + { + unset($this->qb); + } + + function TestGet() + { + $query = $this->qb->get('create_test'); + + $this->assertIsA($query, 'PDOStatement'); + } + + function TestGetLimit() + { + $query = $this->qb->get('create_test', 2); + + $this->assertIsA($query, 'PDOStatement'); + } + + function TestGetLimitSkip() + { + $query = $this->qb->get('create_test', 2, 1); + + $this->assertIsA($query, 'PDOStatement'); + } + + function TestSelectWhereGet() + { + $query = $this->qb->select('id, key as k, val') + ->where('id >', 1) + ->where('id <', 900) + ->get('create_test', 2, 1); + + $this->assertIsA($query, 'PDOStatement'); + } + + function TestSelectWhereGet2() + { + $query = $this->qb->select('id, key as k, val') + ->where('id !=', 1) + ->get('create_test', 2, 1); + + $this->assertIsA($query, 'PDOStatement'); + } + + function TestSelectGet() + { + $query = $this->qb->select('id, key as k, val') + ->get('create_test', 2, 1); + + $this->assertIsA($query, 'PDOStatement'); + } + + function TestSelectFromGet() + { + $query = $this->qb->select('id, key as k, val') + ->from('create_test ct') + ->where('id >', 1) + ->get(); + + $this->assertIsA($query, 'PDOStatement'); + } + + function TestSelectFromLimitGet() + { + $query = $this->qb->select('id, key as k, val') + ->from('create_test ct') + ->where('id >', 1) + ->limit(3) + ->get(); + + $this->assertIsA($query, 'PDOStatement'); + } +} \ No newline at end of file diff --git a/tests/databases/sqlite.php b/tests/databases/sqlite.php index 95b20f5..314cbf4 100644 --- a/tests/databases/sqlite.php +++ b/tests/databases/sqlite.php @@ -141,96 +141,4 @@ SQL; $this->assertFalse(in_array('create_test', $dbs)); }*/ -} - -// -------------------------------------------------------------------------- - -/** - * Class for testing Query Builder with SQLite - */ - class SQLiteQBTest extends UnitTestCase { - - function setUp() - { - $path = TEST_DIR.DS.'test_dbs'.DS.'test_sqlite.db'; - $params = new Stdclass(); - $params->type = 'sqlite'; - $params->file = $path; - $params->host = 'localhost'; - $this->qb = new Query_Builder($params); - } - - function tearDown() - { - unset($this->qb); - } - - function TestGet() - { - $query = $this->qb->get('create_test'); - - $this->assertIsA($query, 'PDOStatement'); - } - - function TestGetLimit() - { - $query = $this->qb->get('create_test', 2); - - $this->assertIsA($query, 'PDOStatement'); - } - - function TestGetLimitSkip() - { - $query = $this->qb->get('create_test', 2, 1); - - $this->assertIsA($query, 'PDOStatement'); - } - - function TestSelectWhereGet() - { - $query = $this->qb->select('id, key as k, val') - ->where('id >', 1) - ->where('id <', 900) - ->get('create_test', 2, 1); - - $this->assertIsA($query, 'PDOStatement'); - } - - function TestSelectWhereGet2() - { - $query = $this->qb->select('id, key as k, val') - ->where('id !=', 1) - ->get('create_test', 2, 1); - - $this->assertIsA($query, 'PDOStatement'); - } - - function TestSelectGet() - { - $query = $this->qb->select('id, key as k, val') - ->get('create_test', 2, 1); - - $this->assertIsA($query, 'PDOStatement'); - } - - function TestSelectFromGet() - { - $query = $this->qb->select('id, key as k, val') - ->from('create_test ct') - ->where('id >', 1) - ->get(); - - $this->assertIsA($query, 'PDOStatement'); - } - - function TestSelectFromLimitGet() - { - $query = $this->qb->select('id, key as k, val') - ->from('create_test ct') - ->where('id >', 1) - ->limit(3) - ->get(); - - $this->assertIsA($query, 'PDOStatement'); - } } \ No newline at end of file