From 23d45f67c1206734fdd91801b07d637f1b2cfd73 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 8 Dec 2012 21:45:21 +0100 Subject: [PATCH] Fix config merging for arrays --- src/Composer/Config.php | 8 +++++++- tests/Composer/Test/ConfigTest.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 0784b7b39..53f93faff 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -69,7 +69,13 @@ class Config { // override defaults with given config if (!empty($config['config']) && is_array($config['config'])) { - $this->config = array_replace_recursive($this->config, $config['config']); + foreach ($config['config'] as $key => $val) { + if (in_array($key, array('github-oauth')) && isset($this->config[$key])) { + $this->config[$key] = array_merge($this->config[$key], $val); + } else { + $this->config[$key] = $val; + } + } } if (!empty($config['repositories']) && is_array($config['repositories'])) { diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index 76acb288a..3410d92a1 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/tests/Composer/Test/ConfigTest.php @@ -99,4 +99,22 @@ class ConfigTest extends \PHPUnit_Framework_TestCase return $data; } + + public function testMergeGithubOauth() + { + $config = new Config(); + $config->merge(array('config' => array('github-oauth' => array('foo' => 'bar')))); + $config->merge(array('config' => array('github-oauth' => array('bar' => 'baz')))); + + $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $config->get('github-oauth')); + } + + public function testOverrideGithubProtocols() + { + $config = new Config(); + $config->merge(array('config' => array('github-protocols' => array('https', 'http')))); + $config->merge(array('config' => array('github-protocols' => array('http')))); + + $this->assertEquals(array('http'), $config->get('github-oauth')); + } }