diff --git a/control/injector/Injector.php b/control/injector/Injector.php index 96c69854b..3ab429a29 100644 --- a/control/injector/Injector.php +++ b/control/injector/Injector.php @@ -866,7 +866,7 @@ class Injector { return $this->instantiate($spec, $name); } - return $this->instantiate($spec); + return $this->instantiate($spec, null, 'prototype'); } /** diff --git a/core/Object.php b/core/Object.php index 0a28bae0a..21a741511 100644 --- a/core/Object.php +++ b/core/Object.php @@ -908,6 +908,10 @@ abstract class SS_Object { $methods = $this->findMethodsFromExtension($extension); if ($methods) { foreach ($methods as $method) { + if (!isset(self::$extra_methods[$this->class][$method])) { + continue; + } + $methodInfo = self::$extra_methods[$this->class][$method]; if ($methodInfo['property'] === $property && $methodInfo['index'] === $index) { diff --git a/model/Versioned.php b/model/Versioned.php index 399b2b50d..f525d5db1 100644 --- a/model/Versioned.php +++ b/model/Versioned.php @@ -446,7 +446,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider { // Build a list of suffixes whose tables need versioning $allSuffixes = array(); - $versionableExtensions = $this->owner->config()->versionableExtensions; + $versionableExtensions = (array)$this->owner->config()->versionableExtensions; if(count($versionableExtensions)){ foreach ($versionableExtensions as $versionableExtension => $suffixes) { @@ -936,7 +936,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider { * @return string */ public function extendWithSuffix($table) { - $versionableExtensions = $this->owner->config()->versionableExtensions; + $versionableExtensions = (array)$this->owner->config()->versionableExtensions; if(count($versionableExtensions)){ foreach ($versionableExtensions as $versionableExtension => $suffixes) { diff --git a/tests/model/DataObjectTest.php b/tests/model/DataObjectTest.php index e4fdb953e..ca51d30dc 100644 --- a/tests/model/DataObjectTest.php +++ b/tests/model/DataObjectTest.php @@ -39,6 +39,13 @@ class DataObjectTest extends SapphireTest { */ public function testSingleton($inst, $defaultValue, $altDefaultValue) { + // Calls to scaffold the test database may have cached service specs for DataObjects + // with the incorrect 'type' set (singleton instead of prototype) + Injector::nest(); + $reflectionProp = new ReflectionProperty('Injector', 'specs'); + $reflectionProp->setAccessible(true); + $reflectionProp->setValue(Injector::inst(), array()); + $inst = $inst(); // Test that populateDefaults() isn't called on singletons // which can lead to SQL errors during build, and endless loops @@ -53,6 +60,8 @@ class DataObjectTest extends SapphireTest { } else { $this->assertEmpty($inst->MyFieldWithAltDefault); } + + Injector::unnest(); } public function provideSingletons()