mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
25a437e5a0
commit
252fbf0ba7
@ -154,6 +154,14 @@ class Versioned extends DataObjectDecorator {
|
|||||||
* @todo Reduce the coupling between this and SapphireTest, somehow.
|
* @todo Reduce the coupling between this and SapphireTest, somehow.
|
||||||
*/
|
*/
|
||||||
public static function on_db_reset() {
|
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();
|
self::$archive_tables = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +112,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
singleton('DataObject')->flushCache();
|
singleton('DataObject')->flushCache();
|
||||||
|
|
||||||
$dbadmin = new DatabaseAdmin();
|
self::empty_temp_db();
|
||||||
$dbadmin->clearAllData();
|
|
||||||
|
|
||||||
$fixtureFiles = (is_array($fixtureFile)) ? $fixtureFile : array($fixtureFile);
|
$fixtureFiles = (is_array($fixtureFile)) ? $fixtureFile : array($fixtureFile);
|
||||||
|
|
||||||
@ -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
|
// Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls
|
||||||
self::$is_running_test = $this->originalIsRunningTest;
|
self::$is_running_test = $this->originalIsRunningTest;
|
||||||
$this->originalIsRunningTest = null;
|
$this->originalIsRunningTest = null;
|
||||||
|
|
||||||
|
// Reset mocked datetime
|
||||||
|
SSDatetime::clear_mock_now();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Clear the log of emails sent
|
* 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
|
* @todo Make this db agnostic
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user