Ver Fonte

prefer strings for install handling when possible

Steve Buzonas há 10 anos atrás
pai
commit
73c1f8c0e0
2 ficheiros alterados com 18 adições e 13 exclusões
  1. 16 12
      src/Composer/Config.php
  2. 2 1
      tests/Composer/Test/ConfigTest.php

+ 16 - 12
src/Composer/Config.php

@@ -113,18 +113,22 @@ class Config
                 if (in_array($key, array('github-oauth', 'http-basic')) && isset($this->config[$key])) {
                     $this->config[$key] = array_merge($this->config[$key], $val);
                 } elseif ('preferred-install' === $key && isset($this->config[$key])) {
-                    if (is_string($val)) {
-                        $val = array('*' => $val);
-                    }
-                    if (is_string($this->config[$key])) {
-                        $this->config[$key] = array('*' => $this->config[$key]);
-                    }
-                    $this->config[$key] = array_merge($this->config[$key], $val);
-                    // the full match pattern needs to be last
-                    if (isset($this->config[$key]['*'])) {
-                        $wildcard = $this->config[$key]['*'];
-                        unset($this->config[$key]['*']);
-                        $this->config[$key]['*'] = $wildcard;
+                    if (is_array($val) || is_array($this->config[$key])) {
+                        if (is_string($val)) {
+                            $val = array('*' => $val);
+                        }
+                        if (is_string($this->config[$key])) {
+                            $this->config[$key] = array('*' => $this->config[$key]);
+                        }
+                        $this->config[$key] = array_merge($this->config[$key], $val);
+                        // the full match pattern needs to be last
+                        if (isset($this->config[$key]['*'])) {
+                            $wildcard = $this->config[$key]['*'];
+                            unset($this->config[$key]['*']);
+                            $this->config[$key]['*'] = $wildcard;
+                        }
+                    } else {
+                        $this->config[$key] = $val;
                     }
                 } else {
                     $this->config[$key] = $val;

+ 2 - 1
tests/Composer/Test/ConfigTest.php

@@ -116,8 +116,9 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
     {
         $config = new Config(false);
         $config->merge(array('config' => array('preferred-install' => 'source')));
+        $config->merge(array('config' => array('preferred-install' => 'dist')));
 
-        $this->assertEquals(array('*' => 'source'), $config->get('preferred-install'));
+        $this->assertEquals('dist', $config->get('preferred-install'));
     }
 
     public function testMergePreferredInstall()