From f262feebec342733785e304333498715de524a59 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Sat, 22 Aug 2020 20:07:13 +0300 Subject: [PATCH 1/4] fixing error message for higher repository priority, when higher repo has only a dev-branch --- src/Composer/DependencyResolver/Problem.php | 6 +-- src/Composer/Repository/RepositorySet.php | 2 +- .../installer/repositories-priorities4.test | 50 +++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/repositories-priorities4.test diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index 6d94b068b..c455a36ea 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -279,11 +279,11 @@ class Problem return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose).' but '.(self::hasMultipleNames($packages) ? 'these do' : 'it does').' not match your minimum-stability.'); } - // check if the package is found when bypassing the constraint check - if ($packages = $repositorySet->findPackages($packageName, null)) { + // check if the package is found when bypassing the constraint check and stability checks + if ($packages = $repositorySet->findPackages($packageName, null, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES)) { // we must first verify if a valid package would be found in a lower priority repository if ($allReposPackages = $repositorySet->findPackages($packageName, $constraint, RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) { - $higherRepoPackages = $repositorySet->findPackages($packageName, null); + $higherRepoPackages = $repositorySet->findPackages($packageName, null, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES); $nextRepoPackages = array(); $nextRepo = null; diff --git a/src/Composer/Repository/RepositorySet.php b/src/Composer/Repository/RepositorySet.php index 9417dec97..04db0becd 100644 --- a/src/Composer/Repository/RepositorySet.php +++ b/src/Composer/Repository/RepositorySet.php @@ -193,7 +193,7 @@ class RepositorySet } } - return $candidates; + return $result; } public function getProviders($packageName) diff --git a/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test b/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test new file mode 100644 index 000000000..7e251002f --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test @@ -0,0 +1,50 @@ +--TEST-- +Packages found in a higher priority repository won't be considered as found if version does not match +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { + "name": "ruflin/elastica", + "version": "dev-outdated-branch" + } + ] + }, + { + "type": "package", + "package": [ + { + "name": "friendsofsymfony/elastica-bundle", + "version": "dev-foobar-master", + "require": { + "ruflin/elastica": "2.*" + } + } + ] + }, + { + "type": "composer", + "url": "https://repo.packagist.org" + } + ], + "require": { + "friendsofsymfony/elastica-bundle": "dev-foobar-master" + } +} + +--RUN-- +update +--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 friendsofsymfony/elastica-bundle dev-foobar-master -> satisfiable by friendsofsymfony/elastica-bundle[dev-foobar-master]. + - friendsofsymfony/elastica-bundle dev-foobar-master requires ruflin/elastica 2.* -> satisfiable by ruflin/elastica[2.0.0, ..., 2.3.3] from composer repo (https://repo.packagist.org) but ruflin/elastica[dev-outdated-branch] from package repo (defining 1 package) has higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance. + +--EXPECT-- +--EXPECT-EXIT-CODE-- +2 From e745e5965619b01850c11d6dc73e3a34599d7021 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Sat, 22 Aug 2020 20:11:15 +0300 Subject: [PATCH 2/4] updated repositories-priorities4.test --- .../Test/Fixtures/installer/repositories-priorities4.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test b/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test index 7e251002f..f124c76e1 100644 --- a/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test +++ b/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test @@ -1,5 +1,5 @@ --TEST-- -Packages found in a higher priority repository won't be considered as found if version does not match +Packages found in a higher priority repository take precedence even if they are not found in the requested version case #2 --COMPOSER-- { "repositories": [ From 4d837836411ded944d63b03124af19048e133817 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 23 Aug 2020 16:03:00 +0200 Subject: [PATCH 3/4] Fix test to avoid network usage --- .../installer/repositories-priorities4.test | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test b/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test index f124c76e1..9ef597daa 100644 --- a/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test +++ b/tests/Composer/Test/Fixtures/installer/repositories-priorities4.test @@ -25,8 +25,17 @@ Packages found in a higher priority repository take precedence even if they are ] }, { - "type": "composer", - "url": "https://repo.packagist.org" + "type": "package", + "package": [ + { + "name": "ruflin/elastica", + "version": "2.0.0" + }, + { + "name": "ruflin/elastica", + "version": "2.0.1" + } + ] } ], "require": { @@ -43,7 +52,7 @@ Your requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires friendsofsymfony/elastica-bundle dev-foobar-master -> satisfiable by friendsofsymfony/elastica-bundle[dev-foobar-master]. - - friendsofsymfony/elastica-bundle dev-foobar-master requires ruflin/elastica 2.* -> satisfiable by ruflin/elastica[2.0.0, ..., 2.3.3] from composer repo (https://repo.packagist.org) but ruflin/elastica[dev-outdated-branch] from package repo (defining 1 package) has higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance. + - friendsofsymfony/elastica-bundle dev-foobar-master requires ruflin/elastica 2.* -> satisfiable by ruflin/elastica[2.0.0, 2.0.1] from package repo (defining 2 packages) but ruflin/elastica[dev-outdated-branch] from package repo (defining 1 package) has higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance. --EXPECT-- --EXPECT-EXIT-CODE-- From 448daea69687a557a9fc9a05b80646ba02295e91 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 23 Aug 2020 16:48:07 +0200 Subject: [PATCH 4/4] Add support for detecting packages not matching only due to minimum stability --- src/Composer/DependencyResolver/Problem.php | 40 ++++++++++++------- .../installer/repositories-priorities5.test | 35 ++++++++++++++++ 2 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/repositories-priorities5.test diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index c455a36ea..9d4405330 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -276,27 +276,19 @@ class Problem // check if the package is found when bypassing stability checks if ($packages = $repositorySet->findPackages($packageName, $constraint, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES)) { + // we must first verify if a valid package would be found in a lower priority repository + if ($allReposPackages = $repositorySet->findPackages($packageName, $constraint, RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) { + return self::computeCheckForLowerPrioRepo($isVerbose, $packageName, $constraint, $packages, $allReposPackages, 'minimum-stability'); + } + return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose).' but '.(self::hasMultipleNames($packages) ? 'these do' : 'it does').' not match your minimum-stability.'); } - // check if the package is found when bypassing the constraint check and stability checks + // check if the package is found when bypassing the constraint and stability checks if ($packages = $repositorySet->findPackages($packageName, null, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES)) { // we must first verify if a valid package would be found in a lower priority repository if ($allReposPackages = $repositorySet->findPackages($packageName, $constraint, RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) { - $higherRepoPackages = $repositorySet->findPackages($packageName, null, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES); - $nextRepoPackages = array(); - $nextRepo = null; - - foreach ($allReposPackages as $package) { - if ($nextRepo === null || $nextRepo === $package->getRepository()) { - $nextRepoPackages[] = $package; - $nextRepo = $package->getRepository(); - } else { - break; - } - } - - return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', it is ', 'satisfiable by '.self::getPackageList($nextRepoPackages, $isVerbose).' from '.$nextRepo->getRepoName().' but '.self::getPackageList($higherRepoPackages, $isVerbose).' from '.reset($higherRepoPackages)->getRepository()->getRepoName().' has higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance.'); + return self::computeCheckForLowerPrioRepo($isVerbose, $packageName, $constraint, $packages, $allReposPackages, 'constraint'); } return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose).' but '.(self::hasMultipleNames($packages) ? 'these do' : 'it does').' not match the constraint.'); @@ -396,6 +388,24 @@ class Problem return false; } + private static function computeCheckForLowerPrioRepo($isVerbose, $packageName, $constraint, array $higherRepoPackages, array $allReposPackages, $reason) + { + $nextRepoPackages = array(); + $nextRepo = null; + + foreach ($allReposPackages as $package) { + if ($nextRepo === null || $nextRepo === $package->getRepository()) { + $nextRepoPackages[] = $package; + $nextRepo = $package->getRepository(); + } else { + break; + } + } + + return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', it is ', 'satisfiable by '.self::getPackageList($nextRepoPackages, $isVerbose).' from '.$nextRepo->getRepoName().' but '.self::getPackageList($higherRepoPackages, $isVerbose).' from '.reset($higherRepoPackages)->getRepository()->getRepoName().' has higher repository priority. The packages with higher priority do not match your '.$reason.' and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance.'); + + } + /** * Turns a constraint into text usable in a sentence describing a request * diff --git a/tests/Composer/Test/Fixtures/installer/repositories-priorities5.test b/tests/Composer/Test/Fixtures/installer/repositories-priorities5.test new file mode 100644 index 000000000..7a196988e --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/repositories-priorities5.test @@ -0,0 +1,35 @@ +--TEST-- +Packages found in a higher priority repository take precedence even if they are not found in the requested version case #3 +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "foo/a", "version": "2.0.0-dev" } + ] + }, + { + "type": "package", + "package": [ + { "name": "foo/a", "version": "2.0.0" } + ] + } + ], + "require": { + "foo/a": "2.*" + } +} +--RUN-- +update +--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 foo/a 2.*, it is satisfiable by foo/a[2.0.0] from package repo (defining 1 package) but foo/a[2.0.0-dev] from package repo (defining 1 package) has higher repository priority. The packages with higher priority do not match your minimum-stability and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance. + +--EXPECT-- +--EXPECT-EXIT-CODE-- +2