Pārlūkot izejas kodu

ZF-6459: use array_merge_recursive when setting options

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15379 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 gadi atpakaļ
vecāks
revīzija
afb7bdbaf8

+ 1 - 1
library/Zend/Application/Bootstrap/BootstrapAbstract.php

@@ -132,7 +132,7 @@ abstract class Zend_Application_Bootstrap_BootstrapAbstract
                 }
             }
         }
-        $this->_options = $this->_options + $options;
+        $this->_options = array_merge_recursive($this->_options, $options);
         return $this;
     }
 

+ 1 - 1
library/Zend/Application/Resource/ResourceAbstract.php

@@ -94,7 +94,7 @@ abstract class Zend_Application_Resource_ResourceAbstract implements Zend_Applic
             }
         }
         
-        $this->_options += $options;
+        $this->_options = array_merge_recursive($this->_options, $options);
 
         return $this;
     }

+ 26 - 0
tests/Zend/Application/Bootstrap/BootstrapAbstractTest.php

@@ -125,6 +125,32 @@ class Zend_Application_Bootstrap_BootstrapAbstractTest extends PHPUnit_Framework
         $this->assertEquals('foo', $bootstrap->getArbitrary());
     }
 
+    /**
+     * @group ZF-6459
+     */
+    public function testCallingSetOptionsMultipleTimesShouldMergeOptionsRecursively()
+    {
+        require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
+        $options = array(
+            'deep' => array(
+                'foo' => 'bar',
+                'bar' => 'baz',
+            ),
+        );
+        $bootstrap = new ZfAppBootstrap($this->application);
+        $bootstrap->setOptions($options);
+        $options2 = array(
+            'deep' => array(
+                'bar' => 'bat',
+                'baz' => 'foo',
+            ),
+        );
+        $bootstrap->setOptions($options2);
+        $expected = array_merge_recursive($options, $options2);
+        $test     = $bootstrap->getOptions();
+        $this->assertEquals($expected, $test);
+    }
+
     public function testPluginPathsOptionKeyShouldAddPrefixPathsToPluginLoader()
     {
         require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';