Browse Source

Fix config merging for arrays

Jordi Boggiano 12 years ago
parent
commit
23d45f67c1
2 changed files with 25 additions and 1 deletions
  1. 7 1
      src/Composer/Config.php
  2. 18 0
      tests/Composer/Test/ConfigTest.php

+ 7 - 1
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'])) {

+ 18 - 0
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'));
+    }
 }