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)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96774 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-01-12 23:44:37 +00:00
parent 25a437e5a0
commit 252fbf0ba7
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

@ -111,10 +111,9 @@ 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);
$i = 0;
@ -329,6 +328,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
@ -551,6 +553,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
*/