Made db tests less redundant

This commit is contained in:
Timothy Warren 2012-03-19 13:38:49 -04:00
parent 0c82208694
commit 58719d6ab5
9 changed files with 128 additions and 297 deletions

View File

@ -511,5 +511,37 @@ class Firebird_Result {
return array(0, $code, $msg); 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 // End of firebird-fbird.php

View File

@ -119,7 +119,7 @@ class FirebirdQBTest extends QBTest {
$this->assertIsA($query, 'Firebird_Result'); $this->assertIsA($query, 'Firebird_Result');
} }
function TestOrderByRand() function TestOrderByRandom()
{ {
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->from('create_test') ->from('create_test')
@ -144,6 +144,11 @@ class FirebirdQBTest extends QBTest {
$this->assertIsA($query, 'Firebird_Result'); $this->assertIsA($query, 'Firebird_Result');
} }
function TestGroupBy()
{
}
/*function TestGroupBy() /*function TestGroupBy()
{ {
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')

View File

@ -17,18 +17,7 @@
* *
* @extends UnitTestCase * @extends UnitTestCase
*/ */
class FirebirdTest extends UnitTestCase { class FirebirdTest extends DBTest {
/**
* __construct function.
*
* @access public
* @return void
*/
function __construct()
{
parent::__construct();
}
function setUp() function setUp()
{ {

View File

@ -17,12 +17,7 @@
* *
* @extends UnitTestCase * @extends UnitTestCase
*/ */
class MySQLTest extends UnitTestCase { class MySQLTest extends DBTest {
function __construct()
{
parent::__construct();
}
function setUp() function setUp()
{ {
@ -36,11 +31,6 @@ class MySQLTest extends UnitTestCase {
} }
} }
function tearDown()
{
unset($this->db);
}
function TestExists() function TestExists()
{ {
$this->assertTrue(in_array('mysql', pdo_drivers())); $this->assertTrue(in_array('mysql', pdo_drivers()));
@ -52,32 +42,6 @@ class MySQLTest extends UnitTestCase {
$this->assertIsA($this->db, 'MySQL'); $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() function TestCreateTable()
{ {
@ -116,68 +80,5 @@ class MySQLTest extends UnitTestCase {
$this->assertTrue(in_array('create_test', $dbs)); $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 = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
$statement->execute();
}
function TestPrepareExecute()
{
if (empty($this->db)) return;
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$this->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);
}
} }

View File

@ -12,12 +12,7 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class ODBCQBTest extends UnitTestCase { class ODBCQBTest extends QBTest {
function __construct()
{
}
function TestExists() function TestExists()
{ {

View File

@ -17,7 +17,7 @@
* *
* @extends UnitTestCase * @extends UnitTestCase
*/ */
class PgTest extends UnitTestCase { class PgTest extends DBTest {
function __construct() function __construct()
{ {
@ -36,11 +36,6 @@ class PgTest extends UnitTestCase {
} }
} }
function tearDown()
{
unset($this->db);
}
function TestExists() function TestExists()
{ {
$this->assertTrue(in_array('pgsql', pdo_drivers())); $this->assertTrue(in_array('pgsql', pdo_drivers()));
@ -52,32 +47,6 @@ class PgTest extends UnitTestCase {
$this->assertIsA($this->db, 'PgSQL'); $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() /*function TestCreateTable()
{ {
@ -118,67 +87,4 @@ class PgTest extends UnitTestCase {
$this->assertTrue(in_array('create_test', $dbs)); $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 = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
$statement->execute();
}
function TestPrepareExecute()
{
if (empty($this->db)) return;
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$this->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);
}
} }

View File

@ -19,11 +19,6 @@
*/ */
class SQLiteTest extends DBTest { class SQLiteTest extends DBTest {
function __construct()
{
//parent::__construct();
}
function setUp() function setUp()
{ {
$path = TEST_DIR.DS.'test_dbs'.DS.'test_sqlite.db'; $path = TEST_DIR.DS.'test_dbs'.DS.'test_sqlite.db';
@ -40,25 +35,7 @@ class SQLiteTest extends DBTest {
$this->assertIsA($this->db, 'SQLite'); $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() function TestCreateTable()
{ {
//Attempt to create the table //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 )'); $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->db->truncate('create_test');
$this->assertIsA($this->db->affected_rows(), 'int'); $this->assertIsA($this->db->affected_rows(), 'int');
} }*/
function TestPreparedStatements()
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
$statement->execute();
}
function TestPrepareExecute()
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$this->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 // This is really time intensive ! Run only when needed
/*function TestDeleteTable() /*function TestDeleteTable()
{ {

View File

@ -9,9 +9,92 @@
* @link https://github.com/aviat4ion/Query * @link https://github.com/aviat4ion/Query
* @license http://philsturgeon.co.uk/code/dbad-license * @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 = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
$statement->execute();
}
function TestPrepareExecute()
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$this->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 { abstract class QBTest extends UnitTestCase {
function TestGet() function TestGet()
@ -220,15 +303,3 @@ abstract class QBTest extends UnitTestCase {
} }
// --------------------------------------------------------------------------
abstract class DBTest extends UnitTestCase {
abstract function TestConnection();
function tearDown()
{
unset($this->db);
}
}

Binary file not shown.