Преглед на файлове

Merge remote-tracking branch 'adrianosferreira/package-install-method-cli'

Fixed formatting, and handling of config command to be preferred-install.foo value

Refs #8517
Jordi Boggiano преди 5 години
родител
ревизия
ee3fd0f745
променени са 2 файла, в които са добавени 72 реда и са изтрити 0 реда
  1. 27 0
      src/Composer/Command/ConfigCommand.php
  2. 45 0
      tests/Composer/Test/Json/JsonManipulatorTest.php

+ 27 - 0
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(

+ 45 - 0
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('{