diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 13a67b550..3ddd7cb9d 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -466,6 +466,16 @@ EOT }, ), ); + $uniqueOrDotNestedArray = array( + 'preferred-install' => array( + function ($val) { + return in_array($val, array('auto', 'source', 'dist'), true); + }, + function ($val) { + return $val; + }, + ), + ); if ($input->getOption('unset') && (isset($uniqueConfigValues[$settingKey]) || isset($multiConfigValues[$settingKey]))) { if ($settingKey === 'disable-tls' && $this->config->get('disable-tls')) { @@ -486,6 +496,23 @@ EOT return 0; } + // handle preferred-install per-package config + if (preg_match('/^preferred-install\.(.+)/', $settingKey, $matches)) { + if ($input->getOption('unset')) { + $this->configSource->removeConfigSetting($settingKey); + + return 0; + } + + list($validator) = $uniqueConfigValues['preferred-install']; + if (!$validator($values[0])) { + throw new \RuntimeException('Invalid value for '.$settingKey.'. Should be one of: auto, source, or dist'); + } + + $this->configSource->addConfigSetting($settingKey, $values[0]); + + return 0; + } // handle properties $uniqueProps = array( diff --git a/tests/Composer/Test/Json/JsonManipulatorTest.php b/tests/Composer/Test/Json/JsonManipulatorTest.php index 914de1882..063fcbc5e 100644 --- a/tests/Composer/Test/Json/JsonManipulatorTest.php +++ b/tests/Composer/Test/Json/JsonManipulatorTest.php @@ -1814,6 +1814,51 @@ class JsonManipulatorTest extends TestCase ', $manipulator->getContents()); } + public function testAddConfigWithPackage() { + $manipulator = new JsonManipulator('{ + "repositories": [ + { + "type": "package", + "package": { + "authors": [], + "extra": { + "package-xml": "package.xml" + } + } + } + ], + "config": { + "platform": { + "php": "5.3.9" + } + } +}'); + + $this->assertTrue($manipulator->addConfigSetting('preferred-install.my-organization/stable-package', 'dist')); + $this->assertEquals('{ + "repositories": [ + { + "type": "package", + "package": { + "authors": [], + "extra": { + "package-xml": "package.xml" + } + } + } + ], + "config": { + "platform": { + "php": "5.3.9" + }, + "preferred-install": { + "my-organization/stable-package": "dist" + } + } +} +', $manipulator->getContents()); + } + public function testAddSuggestWithPackage() { $manipulator = new JsonManipulator('{