diff --git a/src/Illuminate/Config/FileLoader.php b/src/Illuminate/Config/FileLoader.php index c740976ac8de..d121a91df774 100644 --- a/src/Illuminate/Config/FileLoader.php +++ b/src/Illuminate/Config/FileLoader.php @@ -84,7 +84,7 @@ public function load($environment, $group, $namespace = null) if ($this->files->exists($file)) { - $items = array_merge($items, $this->files->getRequire($file)); + $items = array_replace_recursive($items, $this->files->getRequire($file)); } return $items; @@ -147,7 +147,7 @@ public function cascadePackage($environment, $package, $group, $items) if ($this->files->exists($path = $this->defaultPath.'/'.$file)) { - $items = array_merge($items, $this->getRequire($path)); + $items = array_replace_recursive($items, $this->getRequire($path)); } // Once we have merged the regular package configuration we need to look for @@ -157,7 +157,7 @@ public function cascadePackage($environment, $package, $group, $items) if ($this->files->exists($path)) { - $items = array_merge($items, $this->getRequire($path)); + $items = array_replace_recursive($items, $this->getRequire($path)); } return $items; diff --git a/tests/Config/ConfigFileLoaderTest.php b/tests/Config/ConfigFileLoaderTest.php index 20f6ad5d84d0..4c9e0d8f8b81 100644 --- a/tests/Config/ConfigFileLoaderTest.php +++ b/tests/Config/ConfigFileLoaderTest.php @@ -31,14 +31,47 @@ public function testBasicArrayIsReturned() public function testEnvironmentArrayIsMerged() { + $app_config = array( + 'foo' => 'bar', + 'database' => array( + 'mysql' => array( + 'user' => 'root', + 'password' => '', + 'db' => 'test', + ), + ), + ); + + $local_app_config = array( + 'foo' => 'blah', + 'baz' => 'boom', + 'database' => array( + 'mysql' => array( + 'password' => 'toor', + ), + ), + ); + + $expected = array( + 'foo' => 'blah', + 'baz' => 'boom', + 'database' => array( + 'mysql' => array( + 'user' => 'root', + 'password' => 'toor', + 'db' => 'test', + ), + ), + ); + $loader = $this->getLoader(); $loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/app.php')->andReturn(true); $loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/local/app.php')->andReturn(true); - $loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/app.php')->andReturn(array('foo' => 'bar')); - $loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/local/app.php')->andReturn(array('foo' => 'blah', 'baz' => 'boom')); + $loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/app.php')->andReturn($app_config); + $loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/local/app.php')->andReturn($local_app_config); $array = $loader->load('local', 'app', null); - $this->assertEquals(array('foo' => 'blah', 'baz' => 'boom'), $array); + $this->assertEquals($expected, $array); } @@ -77,14 +110,47 @@ public function testGroupExistsReturnsFalseWhenNamespaceGroupDoesntExists() public function testCascadingPackagesProperlyLoadsFiles() { + $package_config = array( + 'foo' => 'bar', + 'database' => array( + 'mysql' => array( + 'user' => 'root', + 'password' => '', + 'db' => 'test', + ), + ), + ); + + $local_package_config = array( + 'foo' => 'blah', + 'baz' => 'boom', + 'database' => array( + 'mysql' => array( + 'password' => 'toor', + ), + ), + ); + + $expected = array( + 'foo' => 'blah', + 'baz' => 'boom', + 'database' => array( + 'mysql' => array( + 'user' => 'root', + 'password' => 'toor', + 'db' => 'test', + ), + ), + ); + $loader = $this->getLoader(); $loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/packages/dayle/rees/group.php')->andReturn(true); - $loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/packages/dayle/rees/group.php')->andReturn(array('bar' => 'baz')); + $loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/packages/dayle/rees/group.php')->andReturn($package_config); $loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/local/packages/dayle/rees/group.php')->andReturn(true); - $loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/local/packages/dayle/rees/group.php')->andReturn(array('foo' => 'boom')); + $loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/local/packages/dayle/rees/group.php')->andReturn($local_package_config); $items = $loader->cascadePackage('local', 'dayle/rees', 'group', array('foo' => 'bar')); - $this->assertEquals(array('foo' => 'boom', 'bar' => 'baz'), $items); + $this->assertEquals($expected, $items); } @@ -93,4 +159,4 @@ protected function getLoader() return new Illuminate\Config\FileLoader(m::mock('Illuminate\Filesystem\Filesystem'), __DIR__); } -} \ No newline at end of file +}