From 73c1f8c0e009a4be089bc771f37eea69423a9009 Mon Sep 17 00:00:00 2001 From: Steve Buzonas Date: Sat, 18 Apr 2015 18:31:16 -0400 Subject: [PATCH] prefer strings for install handling when possible --- src/Composer/Config.php | 28 ++++++++++++++++------------ tests/Composer/Test/ConfigTest.php | 3 ++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 2d823cea3..a95d5a33d 100644 --- a/src/Composer/Config.php +++ b/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; diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index fb7a5ef22..441344c29 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/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()