Przeglądaj źródła

Clean up and deduplicate the output of RULE_LEARNED

Jordi Boggiano 5 lat temu
rodzic
commit
6c9d9e775c

+ 6 - 6
src/Composer/DependencyResolver/Rule.php

@@ -196,18 +196,18 @@ abstract class Rule
             case self::RULE_PACKAGE_IMPLICIT_OBSOLETES:
             case self::RULE_PACKAGE_IMPLICIT_OBSOLETES:
                 return $ruleText;
                 return $ruleText;
             case self::RULE_LEARNED:
             case self::RULE_LEARNED:
-                // TODO not sure this is a good idea, most of these rules should be listed in the problem anyway
-                $learnedString = '(learned rule, ';
                 if (isset($learnedPool[$this->reasonData])) {
                 if (isset($learnedPool[$this->reasonData])) {
+                    $learnedString = ', learned rules:'."\n        - ";
+                    $reasons = array();
                     foreach ($learnedPool[$this->reasonData] as $learnedRule) {
                     foreach ($learnedPool[$this->reasonData] as $learnedRule) {
-                        $learnedString .= $learnedRule->getPrettyString($repositorySet, $request, $installedMap, $learnedPool);
+                        $reasons[] = $learnedRule->getPrettyString($repositorySet, $request, $installedMap, $learnedPool);
                     }
                     }
+                    $learnedString .= implode("\n        - ", array_unique($reasons));
                 } else {
                 } else {
-                    $learnedString .= 'reasoning unavailable';
+                    $learnedString = ' (reasoning unavailable)';
                 }
                 }
-                $learnedString .= ')';
 
 
-                return 'Conclusion: '.$ruleText.' '.$learnedString;
+                return 'Conclusion: '.$ruleText.$learnedString;
             case self::RULE_PACKAGE_ALIAS:
             case self::RULE_PACKAGE_ALIAS:
                 return $ruleText;
                 return $ruleText;
             default:
             default:

+ 54 - 0
tests/Composer/Test/Fixtures/installer/provider-conflicts3.test

@@ -0,0 +1,54 @@
+--TEST--
+Test that a replacer can not be installed together with another version of the package it replaces
+--COMPOSER--
+{
+    "repositories": [
+        {
+            "type": "package",
+            "package": [
+                {"name": "replacer/pkg", "version": "2.0.0", "replace": { "regular/pkg": "self.version" }},
+                {"name": "replacer/pkg", "version": "2.0.1", "replace": { "regular/pkg": "self.version" }},
+                {"name": "replacer/pkg", "version": "2.0.2", "replace": { "regular/pkg": "self.version" }},
+                {"name": "replacer/pkg", "version": "2.0.3", "replace": { "regular/pkg": "self.version" }},
+                {"name": "regular/pkg", "version": "1.0.0"},
+                {"name": "regular/pkg", "version": "1.0.1"},
+                {"name": "regular/pkg", "version": "1.0.2"},
+                {"name": "regular/pkg", "version": "1.0.3"},
+                {"name": "regular/pkg", "version": "2.0.0"},
+                {"name": "regular/pkg", "version": "2.0.1"}
+            ]
+        }
+    ],
+    "require": {
+        "regular/pkg": "1.*",
+        "replacer/pkg": "2.*"
+    }
+}
+
+--RUN--
+update
+
+--EXPECT-EXIT-CODE--
+2
+
+--EXPECT-OUTPUT--
+Loading composer repositories with package information
+Updating dependencies
+Your requirements could not be resolved to an installable set of packages.
+
+  Problem 1
+    - Conclusion: don't install regular/pkg 1.0.3, learned rules:
+        - Root composer.json requires replacer/pkg 2.* -> satisfiable by replacer/pkg[2.0.0, 2.0.1, 2.0.2, 2.0.3].
+        - Only one of these can be installed: regular/pkg[1.0.3, 1.0.2, 1.0.1, 1.0.0], replacer/pkg[2.0.3, 2.0.2, 2.0.1, 2.0.0]. They all provide regular/pkg and can thus not coexist.
+    - Conclusion: don't install regular/pkg 1.0.2, learned rules:
+        - Root composer.json requires replacer/pkg 2.* -> satisfiable by replacer/pkg[2.0.0, 2.0.1, 2.0.2, 2.0.3].
+        - Only one of these can be installed: regular/pkg[1.0.3, 1.0.2, 1.0.1, 1.0.0], replacer/pkg[2.0.3, 2.0.2, 2.0.1, 2.0.0]. They all provide regular/pkg and can thus not coexist.
+    - Conclusion: don't install regular/pkg 1.0.1, learned rules:
+        - Root composer.json requires replacer/pkg 2.* -> satisfiable by replacer/pkg[2.0.0, 2.0.1, 2.0.2, 2.0.3].
+        - Only one of these can be installed: regular/pkg[1.0.3, 1.0.2, 1.0.1, 1.0.0], replacer/pkg[2.0.3, 2.0.2, 2.0.1, 2.0.0]. They all provide regular/pkg and can thus not coexist.
+    - Only one of these can be installed: regular/pkg[1.0.3, 1.0.2, 1.0.1, 1.0.0], replacer/pkg[2.0.3, 2.0.2, 2.0.1, 2.0.0]. They all provide regular/pkg and can thus not coexist.
+    - Root composer.json requires regular/pkg 1.* -> satisfiable by regular/pkg[1.0.0, 1.0.1, 1.0.2, 1.0.3].
+    - Root composer.json requires replacer/pkg 2.* -> satisfiable by replacer/pkg[2.0.0, 2.0.1, 2.0.2, 2.0.3].
+
+--EXPECT--
+