From 6c9d9e775ccf1d99b5b874bdf8e786d364963382 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 30 Jan 2020 11:37:19 +0100 Subject: [PATCH] Clean up and deduplicate the output of RULE_LEARNED --- src/Composer/DependencyResolver/Rule.php | 12 ++--- .../installer/provider-conflicts3.test | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/provider-conflicts3.test diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 462f3e4df..f92a38da3 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -196,18 +196,18 @@ abstract class Rule case self::RULE_PACKAGE_IMPLICIT_OBSOLETES: return $ruleText; 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])) { + $learnedString = ', learned rules:'."\n - "; + $reasons = array(); 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 { - $learnedString .= 'reasoning unavailable'; + $learnedString = ' (reasoning unavailable)'; } - $learnedString .= ')'; - return 'Conclusion: '.$ruleText.' '.$learnedString; + return 'Conclusion: '.$ruleText.$learnedString; case self::RULE_PACKAGE_ALIAS: return $ruleText; default: diff --git a/tests/Composer/Test/Fixtures/installer/provider-conflicts3.test b/tests/Composer/Test/Fixtures/installer/provider-conflicts3.test new file mode 100644 index 000000000..7cc4f27b0 --- /dev/null +++ b/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-- +