1
0
Fork 0

Add better error reporting for cases where a package conflicts with a replace and not directly a package, fixes #9834

pull/9928/head
Jordi Boggiano 2021-06-02 10:02:34 +02:00
parent b751156e1c
commit 1f37d1c1d5
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
5 changed files with 206 additions and 1 deletions

View File

@ -211,7 +211,40 @@ abstract class Rule
$package1 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[0])); $package1 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[0]));
$package2 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[1])); $package2 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[1]));
return $package2->getPrettyString().' conflicts with '.$package1->getPrettyString().'.'; $conflictTarget = $package1->getPrettyString();
if ($reasonData = $this->getReasonData()) {
// swap literals if they are not in the right order with package2 being the conflicter
if ($reasonData->getSource() === $package1->getName()) {
list($package2, $package1) = array($package1, $package2);
}
// if the conflict is not directly against the package but something it provides/replaces,
// we try to find that link to display a better message
if ($reasonData->getTarget() !== $package1->getName()) {
$provideType = null;
$provided = null;
foreach ($package1->getProvides() as $provide) {
if ($provide->getTarget() === $reasonData->getTarget()) {
$provideType = 'provides';
$provided = $provide->getPrettyConstraint();
break;
}
}
foreach ($package1->getReplaces() as $replace) {
if ($replace->getTarget() === $reasonData->getTarget()) {
$provideType = 'replaces';
$provided = $replace->getPrettyConstraint();
break;
}
}
if (null !== $provideType) {
$conflictTarget = $reasonData->getTarget().' '.$reasonData->getPrettyConstraint().' ('.$package1->getPrettyString().' '.$provideType.' '.$reasonData->getTarget().' '.$provided.')';
}
}
}
return $package2->getPrettyString().' conflicts with '.$conflictTarget.'.';
case self::RULE_PACKAGE_REQUIRES: case self::RULE_PACKAGE_REQUIRES:
$sourceLiteral = array_shift($literals); $sourceLiteral = array_shift($literals);

View File

@ -0,0 +1,39 @@
--TEST--
Test that a conflict against a name that is provided by a dependency does not error
--COMPOSER--
{
"version": "1.2.3",
"repositories": [
{
"type": "package",
"package": [
{
"name": "conflicting/pkg",
"version": "1.0.0",
"conflict": {
"provided/pkg2": "2.*"
}
},
{
"name": "provider/pkg",
"version": "1.0.0",
"provide": { "provided/pkg2": "2.*" }
}
]
}
],
"require": {
"conflicting/pkg": "*",
"provider/pkg": "*"
}
}
--RUN--
update
--EXPECT-EXIT-CODE--
0
--EXPECT--
Installing conflicting/pkg (1.0.0)
Installing provider/pkg (1.0.0)

View File

@ -0,0 +1,40 @@
--TEST--
Test that a conflict against a name that provided by the root does not error
--COMPOSER--
{
"version": "1.2.3",
"repositories": [
{
"type": "package",
"package": [
{
"name": "conflicting/pkg",
"version": "1.0.0",
"conflict": {
"provided/pkg": "2.*"
}
},
{
"name": "provider/pkg",
"version": "1.0.0",
"provide": { "provided/pkg2": "2.0.5" }
}
]
}
],
"require": {
"conflicting/pkg": "*"
},
"provide": {
"provided/pkg": "2.*"
}
}
--RUN--
update
--EXPECT-EXIT-CODE--
0
--EXPECT--
Installing conflicting/pkg (1.0.0)

View File

@ -0,0 +1,48 @@
--TEST--
Test that a conflict against a name that is only replaced by a dependency correctly highlights the issue
--COMPOSER--
{
"version": "1.2.3",
"repositories": [
{
"type": "package",
"package": [
{
"name": "conflicting/pkg",
"version": "1.0.0",
"conflict": {
"replaced/pkg2": ">=2.1"
}
},
{
"name": "provider/pkg",
"version": "1.0.0",
"replace": { "replaced/pkg2": "2.5" }
}
]
}
],
"require": {
"conflicting/pkg": "*",
"provider/pkg": "*"
}
}
--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
- Root composer.json requires conflicting/pkg * -> satisfiable by conflicting/pkg[1.0.0].
- conflicting/pkg 1.0.0 conflicts with replaced/pkg2 >=2.1 (provider/pkg 1.0.0 replaces replaced/pkg2 2.5).
- Root composer.json requires provider/pkg * -> satisfiable by provider/pkg[1.0.0].
--EXPECT--

View File

@ -0,0 +1,45 @@
--TEST--
Test that a conflict against a name that is only replaced by root correctly highlights the issue
--COMPOSER--
{
"version": "1.2.3",
"repositories": [
{
"type": "package",
"package": [
{
"name": "conflicting/pkg",
"version": "1.0.0",
"conflict": {
"replaced/pkg": "2.*"
}
}
]
}
],
"require": {
"conflicting/pkg": "*"
},
"replace": {
"replaced/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
- __root__ is present at version 1.2.3 and cannot be modified by Composer
- conflicting/pkg 1.0.0 conflicts with replaced/pkg 2.* (__root__ 1.2.3 replaces replaced/pkg 2.*).
- Root composer.json requires conflicting/pkg * -> satisfiable by conflicting/pkg[1.0.0].
--EXPECT--