ENHANCEMENT: Added db-abstraction for test database creation and removal.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@76345 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-05-07 03:49:15 +00:00
parent e4efbcb78c
commit 392608b0fa
2 changed files with 4 additions and 3 deletions

View File

@ -225,9 +225,10 @@ class DatabaseAdmin extends Controller {
* @todo Move this code into Database class, for DB abstraction * @todo Move this code into Database class, for DB abstraction
*/ */
function clearAllData() { function clearAllData() {
$tables = DB::query("SHOW TABLES")->column(); $tables = DB::getConn()->tableList();
foreach($tables as $table) { foreach($tables as $table) {
DB::query("TRUNCATE \"$table\""); if(DB::getConn()->hasMethod('clearTable')) DB::getConn()->clearTable($table);
else DB::query("TRUNCATE \"$table\"");
} }
} }

View File

@ -229,7 +229,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
if(self::using_temp_db()) { if(self::using_temp_db()) {
$dbConn = DB::getConn(); $dbConn = DB::getConn();
$dbName = $dbConn->currentDatabase(); $dbName = $dbConn->currentDatabase();
if($dbName && DB::query("SHOW DATABASES LIKE '$dbName'")->value()) { if($dbName && DB::getConn()->databaseExists($dbName)) {
// echo "Deleted temp database " . $dbConn->currentDatabase() . "\n"; // echo "Deleted temp database " . $dbConn->currentDatabase() . "\n";
$dbConn->dropDatabase(); $dbConn->dropDatabase();
} }