From 58719d6ab52f8d06d594822e79e5b14f5f3b02f6 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 19 Mar 2012 13:38:49 -0400 Subject: [PATCH] Made db tests less redundant --- drivers/firebird.php | 32 ++++++++++ tests/databases/firebird-qb.php | 7 ++- tests/databases/firebird.php | 13 +--- tests/databases/mysql.php | 101 +------------------------------- tests/databases/odbc-qb.php | 7 +-- tests/databases/pgsql.php | 96 +----------------------------- tests/databases/sqlite.php | 74 +---------------------- tests/parent.php | 95 ++++++++++++++++++++++++++---- tests/test_dbs/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 9 files changed, 128 insertions(+), 297 deletions(-) diff --git a/drivers/firebird.php b/drivers/firebird.php index 295442e..e50f8fe 100644 --- a/drivers/firebird.php +++ b/drivers/firebird.php @@ -511,5 +511,37 @@ class Firebird_Result { return array(0, $code, $msg); } + + // -------------------------------------------------------------------------- + + /** + * Method to emulate PDOStatement->errorCode() + * + * @return int + */ + public function errorCode() + { + return fbird_errcode(); + } + + // -------------------------------------------------------------------------- + + /** + * Method to emulate PDOStatement->debugDumpParams + * + * @return string + */ + public function debugDumpParams() + { + $params = array(); + $num_params = fbird_num_params($this->statement); + + for($i=0; $i < $num_params; $i++) + { + $params[] = fbird_param_info($this->statement, $i); + } + + return print_r($params, TRUE); + } } // End of firebird-fbird.php \ No newline at end of file diff --git a/tests/databases/firebird-qb.php b/tests/databases/firebird-qb.php index c13e9c8..02c3ad6 100644 --- a/tests/databases/firebird-qb.php +++ b/tests/databases/firebird-qb.php @@ -119,7 +119,7 @@ class FirebirdQBTest extends QBTest { $this->assertIsA($query, 'Firebird_Result'); } - function TestOrderByRand() + function TestOrderByRandom() { $query = $this->db->select('id, key as k, val') ->from('create_test') @@ -144,6 +144,11 @@ class FirebirdQBTest extends QBTest { $this->assertIsA($query, 'Firebird_Result'); } + function TestGroupBy() + { + + } + /*function TestGroupBy() { $query = $this->db->select('id, key as k, val') diff --git a/tests/databases/firebird.php b/tests/databases/firebird.php index 8b55882..b836662 100644 --- a/tests/databases/firebird.php +++ b/tests/databases/firebird.php @@ -17,18 +17,7 @@ * * @extends UnitTestCase */ -class FirebirdTest extends UnitTestCase { - - /** - * __construct function. - * - * @access public - * @return void - */ - function __construct() - { - parent::__construct(); - } +class FirebirdTest extends DBTest { function setUp() { diff --git a/tests/databases/mysql.php b/tests/databases/mysql.php index 01d7643..be81848 100644 --- a/tests/databases/mysql.php +++ b/tests/databases/mysql.php @@ -17,12 +17,7 @@ * * @extends UnitTestCase */ -class MySQLTest extends UnitTestCase { - - function __construct() - { - parent::__construct(); - } +class MySQLTest extends DBTest { function setUp() { @@ -36,11 +31,6 @@ class MySQLTest extends UnitTestCase { } } - function tearDown() - { - unset($this->db); - } - function TestExists() { $this->assertTrue(in_array('mysql', pdo_drivers())); @@ -52,32 +42,6 @@ class MySQLTest extends UnitTestCase { $this->assertIsA($this->db, 'MySQL'); } - - function TestGetTables() - { - if (empty($this->db)) return; - - $tables = $this->db->get_tables(); - - $this->assertTrue(is_array($tables)); - } - - function TestGetSystemTables() - { - if (empty($this->db)) return; - - $tables = $this->db->get_system_tables(); - - $this->assertTrue(is_array($tables)); - } - - function TestCreateTransaction() - { - if (empty($this->db)) return; - - $res = $this->db->beginTransaction(); - $this->assertTrue($res); - } function TestCreateTable() { @@ -116,68 +80,5 @@ class MySQLTest extends UnitTestCase { $this->assertTrue(in_array('create_test', $dbs)); } - - /*function TestTruncate() - { - if (empty($this->db)) return; - - $this->db->truncate('create_test'); - $this->assertIsA($this->db->affected_rows(), 'int'); - }*/ - - function TestPreparedStatements() - { - if (empty($this->db)) return; - - $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross")); - - $statement->execute(); - - } - - function TestPrepareExecute() - { - if (empty($this->db)) return; - - $sql = <<db->prepare_execute($sql, array( - 2, "works", 'also?' - )); - - } - - function TestCommitTransaction() - { - if (empty($this->db)) return; - - $res = $this->db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; - $this->db->query($sql); - - $res = $this->db->commit(); - $this->assertTrue($res); - } - - function TestRollbackTransaction() - { - if (empty($this->db)) return; - - $res = $this->db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; - $this->db->query($sql); - - $res = $this->db->rollback(); - $this->assertTrue($res); - } - } diff --git a/tests/databases/odbc-qb.php b/tests/databases/odbc-qb.php index a794797..c82b677 100644 --- a/tests/databases/odbc-qb.php +++ b/tests/databases/odbc-qb.php @@ -12,12 +12,7 @@ // -------------------------------------------------------------------------- -class ODBCQBTest extends UnitTestCase { - - function __construct() - { - - } +class ODBCQBTest extends QBTest { function TestExists() { diff --git a/tests/databases/pgsql.php b/tests/databases/pgsql.php index 37e2839..66eccd0 100644 --- a/tests/databases/pgsql.php +++ b/tests/databases/pgsql.php @@ -17,7 +17,7 @@ * * @extends UnitTestCase */ -class PgTest extends UnitTestCase { +class PgTest extends DBTest { function __construct() { @@ -36,11 +36,6 @@ class PgTest extends UnitTestCase { } } - function tearDown() - { - unset($this->db); - } - function TestExists() { $this->assertTrue(in_array('pgsql', pdo_drivers())); @@ -52,32 +47,6 @@ class PgTest extends UnitTestCase { $this->assertIsA($this->db, 'PgSQL'); } - - function TestGetTables() - { - if (empty($this->db)) return; - - $tables = $this->db->get_tables(); - - $this->assertTrue(is_array($tables)); - } - - function TestGetSystemTables() - { - if (empty($this->db)) return; - - $tables = $this->db->get_system_tables(); - - $this->assertTrue(is_array($tables)); - } - - function TestCreateTransaction() - { - if (empty($this->db)) return; - - $res = $this->db->beginTransaction(); - $this->assertTrue($res); - } /*function TestCreateTable() { @@ -118,67 +87,4 @@ class PgTest extends UnitTestCase { $this->assertTrue(in_array('create_test', $dbs)); }*/ - - /*function TestTruncate() - { - if (empty($this->db)) return; - - $this->db->truncate('create_test'); - $this->assertIsA($this->db->affected_rows(), 'int'); - }*/ - - function TestPreparedStatements() - { - if (empty($this->db)) return; - - $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross")); - - $statement->execute(); - - } - - function TestPrepareExecute() - { - if (empty($this->db)) return; - - $sql = <<db->prepare_execute($sql, array( - 2, "works", 'also?' - )); - - } - - function TestCommitTransaction() - { - if (empty($this->db)) return; - - $res = $this->db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; - $this->db->query($sql); - - $res = $this->db->commit(); - $this->assertTrue($res); - } - - function TestRollbackTransaction() - { - if (empty($this->db)) return; - - $res = $this->db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; - $this->db->query($sql); - - $res = $this->db->rollback(); - $this->assertTrue($res); - } - } \ No newline at end of file diff --git a/tests/databases/sqlite.php b/tests/databases/sqlite.php index 8cf21bc..b361b62 100644 --- a/tests/databases/sqlite.php +++ b/tests/databases/sqlite.php @@ -19,11 +19,6 @@ */ class SQLiteTest extends DBTest { - function __construct() - { - //parent::__construct(); - } - function setUp() { $path = TEST_DIR.DS.'test_dbs'.DS.'test_sqlite.db'; @@ -40,25 +35,7 @@ class SQLiteTest extends DBTest { $this->assertIsA($this->db, 'SQLite'); } - function TestGetTables() - { - $tables = $this->db->get_tables(); - $this->assertTrue(is_array($tables)); - } - function TestGetSystemTables() - { - $tables = $this->db->get_system_tables(); - - $this->assertTrue(is_array($tables)); - } - - function TestCreateTransaction() - { - $res = $this->db->beginTransaction(); - $this->assertTrue($res); - } - function TestCreateTable() { //Attempt to create the table @@ -92,58 +69,13 @@ class SQLiteTest extends DBTest { $this->assertEqual($dbs['create_test'], 'CREATE TABLE "create_test" (id INTEGER PRIMARY KEY, key TEXT , val TEXT )'); } - function TestTruncate() + /*function TestTruncate() { $this->db->truncate('create_test'); $this->assertIsA($this->db->affected_rows(), 'int'); - } + }*/ - function TestPreparedStatements() - { - $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross")); - - $statement->execute(); - - } - - function TestPrepareExecute() - { - $sql = <<db->prepare_execute($sql, array( - 2, "works", 'also?' - )); - - } - - function TestCommitTransaction() - { - $res = $this->db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; - $this->db->query($sql); - - $res = $this->db->commit(); - $this->assertTrue($res); - } - - function TestRollbackTransaction() - { - $res = $this->db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; - $this->db->query($sql); - - $res = $this->db->rollback(); - $this->assertTrue($res); - } - + // This is really time intensive ! Run only when needed /*function TestDeleteTable() { diff --git a/tests/parent.php b/tests/parent.php index b6cac60..bdbbf75 100644 --- a/tests/parent.php +++ b/tests/parent.php @@ -9,9 +9,92 @@ * @link https://github.com/aviat4ion/Query * @license http://philsturgeon.co.uk/code/dbad-license */ + +// -------------------------------------------------------------------------- + +/** + * Parent Database Test Class + */ +abstract class DBTest extends UnitTestCase { + + abstract function TestConnection(); + + function tearDown() + { + unset($this->db); + } + + function TestGetTables() + { + $tables = $this->db->get_tables(); + $this->assertTrue(is_array($tables)); + } + + function TestGetSystemTables() + { + $tables = $this->db->get_system_tables(); + + $this->assertTrue(is_array($tables)); + } + + function TestCreateTransaction() + { + $res = $this->db->beginTransaction(); + $this->assertTrue($res); + } + + function TestPreparedStatements() + { + $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross")); + + $statement->execute(); + + } + + function TestPrepareExecute() + { + $sql = <<db->prepare_execute($sql, array( + 2, "works", 'also?' + )); + + } + + function TestCommitTransaction() + { + $res = $this->db->beginTransaction(); + + $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; + $this->db->query($sql); + + $res = $this->db->commit(); + $this->assertTrue($res); + } + + function TestRollbackTransaction() + { + $res = $this->db->beginTransaction(); + + $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; + $this->db->query($sql); + + $res = $this->db->rollback(); + $this->assertTrue($res); + } +} // -------------------------------------------------------------------------- +/** + * Query builder parent test class + */ abstract class QBTest extends UnitTestCase { function TestGet() @@ -220,15 +303,3 @@ abstract class QBTest extends UnitTestCase { } -// -------------------------------------------------------------------------- - -abstract class DBTest extends UnitTestCase { - - abstract function TestConnection(); - - function tearDown() - { - unset($this->db); - } - -} \ No newline at end of file diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB index 719164c685cac762c02b8ac823e67017ca82baa7..55a51ded46a322c760b4b3a81131d8ea0b04b18e 100755 GIT binary patch delta 1696 zcmai!OGs2v9LE3W%tM{STu*A?EwdSQ#*osvqEtds^dPb)h)|2L5^^CLO3zJGi@S)5 zpv76VXy>9;R@f$@$D$C_o%C9a4}@Z7h!C31K>z#rkGG33cjnHy-#K@_-}x>xUpj51 z)5b{#dsA<=!1^IYI^Zg6oX`Po;0eIllWze1yXRY1>zo@TaC{Bgg5l?c{xUxJqWZ2h zB{L;AWx$j{Q-(|#Hf4n=D@|E7Eh9n6Z|bkZu}E+D@qXFP0#j!mRGF#BbV>xDpSVPH zhXDhu8it|?TlGhya6g)KSDfLM7K2AxQ)zBQYlcJG4v67cPzN%iR;^`4Js;MUmJ?kJ z)TzAK%rEQeSwn=Z|ymTbKOANQj8Ufq^)n@IyAA~ePNE4*a8>iMAN0y1B`ADRRM4CupZ=8@Dhp)#;7~pdxO^&3=v7qiO zi@0jfi8l6Ey`0RxX|kL1>~7YxyBTM9pM7?u$&NJHy({f5 zS!1=ORU6J4$M#gWvLY4=6al1qniUPzPzj@Bqr0w;jSm%yxIU8=+Y^YSgMq|L1Ix-X zp|cyV>FRt28|L03Hq2GK!J6%-dV3t9bXeU4;Rtq_(fI*F1L#muwBGK)ZFgxqyM1Tf z+jYhJgTZUkcIZ&Bq@7?;FVwiNa)_My{KwP;|)^Omm4 L;yUv?rngOW1JNNUJ;)d+8#wXbLF%Oqvac&T(V9AlH1_Np(W!%93uk)W0fIEOmmOg0yrRF(l$X2bg(a9JG)sgm z5w=9c5>ZQZSt4eMcwHpILi?n@i5iLFC_Az=@h)x^6ZIkwFCLEJ&90wLGfvl&Iftf` zDf*l;sFuo7CAFI-Q+uhJ%scl=ij#7p!M8ms$F!O*Z#DQH*}uW_+JY{>H2A1i)n#9k zXBf%Fb#9o?)hDg0XEkEP(nMfIYBx(@a(IxQO7@fI93^`qN7j}8Z<80;V|nKX&%*jJ zUO_-#2yG}!O()C&3j^Vp4hA})(BX^u!3RLeX(gbwzng; zC!hsG3x+n~iH&c?rhDwQ$No{BadUG6Yr33jaU;^@{2mWld}ntlMl-WB`>)MjzQEL4 zCF?D|D@21N8^5@reRNiXl3Z=_KJA0M8u0hZ+TP^t?|jI7>&;cqf}LFUXA|7cWy^N% m7+cyZEwESi92_%W`b^XXh6xN)%{QM5?tE5*^ZDX8AO8nc`Y?_F