Browse Source

Fix regression caused by PR #6942.

ADmad 10 years ago
parent
commit
badc37b114
2 changed files with 14 additions and 7 deletions
  1. 4 6
      src/Core/ObjectRegistry.php
  2. 10 1
      tests/TestCase/ORM/BehaviorRegistryTest.php

+ 4 - 6
src/Core/ObjectRegistry.php

@@ -69,10 +69,11 @@ abstract class ObjectRegistry
      */
     public function load($objectName, $config = [])
     {
-        if (empty($config) && !isset($this->_loaded[$objectName])) {
-            list(, $name) = pluginSplit($objectName);
-        } else {
+        if (is_array($config) && isset($config['className'])) {
             $name = $objectName;
+            $objectName = $config['className'];
+        } else {
+            list(, $name) = pluginSplit($objectName);
         }
 
         $loaded = isset($this->_loaded[$name]);
@@ -83,9 +84,6 @@ abstract class ObjectRegistry
             return $this->_loaded[$name];
         }
 
-        if (is_array($config) && isset($config['className'])) {
-            $objectName = $config['className'];
-        }
         $className = $this->_resolveClassName($objectName);
         if (!$className || (is_string($className) && !class_exists($className))) {
             list($plugin, $objectName) = pluginSplit($objectName);

+ 10 - 1
tests/TestCase/ORM/BehaviorRegistryTest.php

@@ -110,7 +110,16 @@ class BehaviorRegistryTest extends TestCase
     {
         Plugin::load('TestPlugin');
         $result = $this->Behaviors->load('TestPlugin.PersisterOne');
-        $this->assertInstanceOf('TestPlugin\Model\Behavior\PersisterOneBehavior', $result);
+
+        $expected = 'TestPlugin\Model\Behavior\PersisterOneBehavior';
+        $this->assertInstanceOf($expected, $result);
+        $this->assertInstanceOf($expected, $this->Behaviors->PersisterOne);
+
+        $this->Behaviors->unload('PersisterOne');
+
+        $result = $this->Behaviors->load('TestPlugin.PersisterOne', ['foo' => 'bar']);
+        $this->assertInstanceOf($expected, $result);
+        $this->assertInstanceOf($expected, $this->Behaviors->PersisterOne);
     }
 
     /**