BUGFIX: Don't let Versioned archive tables clutter the global state when testing.

BUGFIX: Don't let mocked datetimes clutter the global state when testing. (from r96640) (from r96648) (from r96774)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102403 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-12 03:21:30 +00:00
parent 89176afbc4
commit 9fc3256025
2 changed files with 27 additions and 3 deletions

View File

@ -154,6 +154,14 @@ class Versioned extends DataObjectDecorator {
* @todo Reduce the coupling between this and SapphireTest, somehow.
*/
public static function on_db_reset() {
// Drop all temporary tables
$db = DB::getConn();
foreach(self::$archive_tables as $tableName) {
if(method_exists($db, 'dropTable')) $db->dropTable($tableName);
else $db->query("DROP TABLE \"$tableName\"");
}
// Remove references to them
self::$archive_tables = array();
}

View File

@ -120,8 +120,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
singleton('DataObject')->flushCache();
$dbadmin = new DatabaseAdmin();
$dbadmin->clearAllData();
self::empty_temp_db();
$fixtureFiles = (is_array($fixtureFile)) ? $fixtureFile : array($fixtureFile);
@ -337,6 +336,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
// Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls
self::$is_running_test = $this->originalIsRunningTest;
$this->originalIsRunningTest = null;
// Reset mocked datetime
SSDatetime::clear_mock_now();
}
/**
* Clear the log of emails sent
@ -559,6 +561,20 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
}
}
/**
* Remove all content from the temporary database.
*/
static function empty_temp_db() {
if(self::using_temp_db()) {
$dbadmin = new DatabaseAdmin();
$dbadmin->clearAllData();
// Todo: it would be good to remove this inappropriate coupling, somehow.
// The versioned class keeps a static cache of information about temporary tables.
Versioned::on_db_reset();
}
}
/**
* @todo Make this db agnostic
*/