Fix tests, by fixing some issues with auto-prefixing table names

This commit is contained in:
Timothy Warren 2014-04-09 10:30:01 -04:00
parent 74d4a00eef
commit 3ce35d78d2
5 changed files with 14 additions and 8 deletions

View File

@ -62,6 +62,7 @@ class MySQL extends Abstract_Driver {
*/
public function truncate($table)
{
$table = $this->prefix_table($table);
$this->query("TRUNCATE `{$table}`");
}
}

View File

@ -41,6 +41,7 @@ class MySQLQBTest extends QBTest {
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'prefix' => 'create_',
'user' => 'root',
'pass' => NULL,
'type' => 'mysql'
@ -73,7 +74,7 @@ class MySQLQBTest extends QBTest {
array (
'id' => '1',
'select_type' => 'SIMPLE',
'table' => 'test',
'table' => 'create_test',
'type' => 'range',
'possible_keys' => 'PRIMARY',
'key' => 'PRIMARY',

View File

@ -43,6 +43,8 @@ class MySQLTest extends DBTest {
{
$this->db = new \Query\Driver\MySQL('host=127.0.0.1;port=3306;dbname=test', 'root');
}
$this->db->table_prefix = 'create_';
}
// --------------------------------------------------------------------------
@ -95,7 +97,7 @@ class MySQLTest extends DBTest {
//Check
$dbs = $this->db->get_tables();
$this->assertTrue(in_array('test', $dbs));
$this->assertTrue(in_array('create_test', $dbs));
}
@ -112,7 +114,7 @@ class MySQLTest extends DBTest {
public function testPreparedStatements()
{
$sql = <<<SQL
INSERT INTO `test` (`id`, `key`, `val`)
INSERT INTO `create_test` (`id`, `key`, `val`)
VALUES (?,?,?)
SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
@ -128,7 +130,7 @@ SQL;
public function testBadPreparedStatement()
{
$sql = <<<SQL
INSERT INTO `test` (`id`, `key`, `val`)
INSERT INTO `create_test` (`id`, `key`, `val`)
VALUES (?,?,?)
SQL;
try
@ -147,7 +149,7 @@ SQL;
public function testPrepareExecute()
{
$sql = <<<SQL
INSERT INTO `test` (`id`, `key`, `val`)
INSERT INTO `create_test` (`id`, `key`, `val`)
VALUES (?,?,?)
SQL;
$res = $this->db->prepare_execute($sql, array(
@ -164,7 +166,7 @@ SQL;
{
$res = $this->db->beginTransaction();
$sql = 'INSERT INTO `test` (`id`, `key`, `val`) VALUES (10, 12, 14)';
$sql = 'INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (10, 12, 14)';
$this->db->query($sql);
$res = $this->db->commit();
@ -177,7 +179,7 @@ SQL;
{
$res = $this->db->beginTransaction();
$sql = 'INSERT INTO `test` (`id`, `key`, `val`) VALUES (182, 96, 43)';
$sql = 'INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (182, 96, 43)';
$this->db->query($sql);
$res = $this->db->rollback();

View File

@ -37,12 +37,13 @@ class PgTest extends DBTest {
$params = $params->pgsql;
$this->db = new $class("pgsql:dbname={$params->database}", $params->user, $params->pass);
$this->db->table_prefix = $params->prefix;
}
elseif (($var = getenv('CI')))
{
$this->db = new $class('host=127.0.0.1;port=5432;dbname=test', 'postgres');
}
$this->db->table_prefix = 'create_';
}
// --------------------------------------------------------------------------

View File

@ -25,6 +25,7 @@ class SQLiteTest extends DBTest {
// Set up in the bootstrap to mitigate
// connection locking issues
$this->db = Query('test_sqlite');
$this->db->table_prefix = 'create_';
}
// --------------------------------------------------------------------------