From 252fbf0ba7e39054bb78b17ca4aacdbaa76a172a Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 12 Jan 2010 23:44:37 +0000 Subject: [PATCH] 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 --- core/model/Versioned.php | 8 ++++++++ dev/SapphireTest.php | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/model/Versioned.php b/core/model/Versioned.php index 2b0ea87fe..328bbd21e 100755 --- a/core/model/Versioned.php +++ b/core/model/Versioned.php @@ -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(); } diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 10bf825a6..2c49b5bcf 100755 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -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 */