From 11d5ce027432405ee3eea3513ff4bbd5b39a08f5 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 21 Oct 2009 23:09:14 +0000 Subject: [PATCH] BUGFIX Moved SINGLETON resetting for test runs from SiteTreeTest/ObjectTest into SapphireTest - there should be no caching between all test invocations to avoid side effects git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89893 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- dev/SapphireTest.php | 10 ++++++++++ tests/ObjectTest.php | 12 ------------ tests/SiteTreeTest.php | 8 -------- tests/model/TranslatableTest.php | 4 ---- tests/search/TranslatableSearchFormTest.php | 4 ---- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 5bafa5de3..579a1d7f5 100755 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -65,6 +65,11 @@ class SapphireTest extends PHPUnit_Framework_TestCase { DataObject::reset(); SiteTree::reset(); Controller::curr()->setSession(new Session(array())); + + // clear singletons, they're caching old extension info + // which is used in DatabaseAdmin->doBuild() + global $_SINGLETONS; + $_SINGLETONS = array(); $className = get_class($this); $fixtureFile = eval("return {$className}::\$fixture_file;"); @@ -223,6 +228,11 @@ class SapphireTest extends PHPUnit_Framework_TestCase { } function tearDown() { + // clear singletons, they're caching old extension info + // which is used in DatabaseAdmin->doBuild() + global $_SINGLETONS; + $_SINGLETONS = array(); + // Restore email configuration Email::set_mailer($this->originalMailer); $this->originalMailer = null; diff --git a/tests/ObjectTest.php b/tests/ObjectTest.php index aa4bbbb38..809835f4f 100755 --- a/tests/ObjectTest.php +++ b/tests/ObjectTest.php @@ -79,9 +79,6 @@ class ObjectTest extends SapphireTest { } function testStaticGetterMethod() { - static $_SINGLETONS; - $_SINGLETONS= null; - $obj = singleton('ObjectTest_MyObject'); $this->assertEquals( ObjectTest_MyObject::$mystaticProperty, @@ -91,9 +88,6 @@ class ObjectTest extends SapphireTest { } function testStaticInheritanceGetters() { - static $_SINGLETONS; - $_SINGLETONS = null; - $obj = singleton('ObjectTest_MyObject'); $subObj = singleton('ObjectTest_MyObject'); $this->assertEquals( @@ -104,9 +98,6 @@ class ObjectTest extends SapphireTest { } function testStaticSettingOnSingletons() { - static $_SINGLETONS; - $_SINGLETONS = null; - $singleton1 = singleton('ObjectTest_MyObject'); $singleton2 = singleton('ObjectTest_MyObject'); $singleton1->set_stat('mystaticProperty', 'changed'); @@ -118,9 +109,6 @@ class ObjectTest extends SapphireTest { } function testStaticSettingOnInstances() { - static $_SINGLETONS; - $_SINGLETONS = null; - $instance1 = new ObjectTest_MyObject(); $instance2 = new ObjectTest_MyObject(); $instance1->set_stat('mystaticProperty', 'changed'); diff --git a/tests/SiteTreeTest.php b/tests/SiteTreeTest.php index dfd937616..a1b1174af 100755 --- a/tests/SiteTreeTest.php +++ b/tests/SiteTreeTest.php @@ -26,10 +26,6 @@ class SiteTreeTest extends SapphireTest { if(self::$origTranslatableSettings['has_extension']) Object::remove_extension('SiteTree', 'Translatable'); - // clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild() - global $_SINGLETONS; - $_SINGLETONS = array(); - // recreate database with new settings $dbname = self::create_temp_db(); DB::set_alternative_database_name($dbname); @@ -44,10 +40,6 @@ class SiteTreeTest extends SapphireTest { Translatable::set_default_locale(self::$origTranslatableSettings['default_locale']); Translatable::set_current_locale(self::$origTranslatableSettings['default_locale']); - // clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild() - global $_SINGLETONS; - $_SINGLETONS = array(); - self::kill_temp_db(); self::create_temp_db(); diff --git a/tests/model/TranslatableTest.php b/tests/model/TranslatableTest.php index db9cd010d..4fd5fb1e0 100755 --- a/tests/model/TranslatableTest.php +++ b/tests/model/TranslatableTest.php @@ -29,10 +29,6 @@ class TranslatableTest extends FunctionalTest { if(!self::$origTranslatableSettings['has_extension']) Object::add_extension('SiteTree', 'Translatable'); Object::add_extension('TranslatableTest_DataObject', 'Translatable'); - // clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild() - global $_SINGLETONS; - $_SINGLETONS = array(); - // recreate database with new settings $dbname = self::create_temp_db(); DB::set_alternative_database_name($dbname); diff --git a/tests/search/TranslatableSearchFormTest.php b/tests/search/TranslatableSearchFormTest.php index 263533807..875a7aaa9 100644 --- a/tests/search/TranslatableSearchFormTest.php +++ b/tests/search/TranslatableSearchFormTest.php @@ -29,10 +29,6 @@ class TranslatableSearchFormTest extends FunctionalTest { if(!self::$origTranslatableSettings['has_extension']) Object::add_extension('SiteTree', 'Translatable'); Object::add_extension('TranslatableTest_DataObject', 'Translatable'); - // clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild() - global $_SINGLETONS; - $_SINGLETONS = array(); - // recreate database with new settings $dbname = self::create_temp_db(); DB::set_alternative_database_name($dbname);