From ab84916422fcfa565b5e6edb5d257c470ecc470a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 9 Mar 2021 15:01:23 +0100 Subject: [PATCH] Fix unclear error when a package can be found in lock but not in the remote repo, fixes #9750 --- src/Composer/DependencyResolver/Problem.php | 9 ++- .../installer/alias-solver-problems2.test | 2 +- ...ncies-option-dont-recommend-to-use-it.test | 2 +- ...sent-in-lock-but-not-at-all-in-remote.test | 52 +++++++++++++++++ ...ut-not-in-remote-due-to-min-stability.test | 54 ++++++++++++++++++ ...age-present-in-lock-but-not-in-remote.test | 53 +++++++++++++++++ ...rio-but-not-main-due-to-min-stability.test | 57 +++++++++++++++++++ 7 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-at-all-in-remote.test create mode 100644 tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-in-remote-due-to-min-stability.test create mode 100644 tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-in-remote.test create mode 100644 tests/Composer/Test/Fixtures/installer/update-package-present-in-lower-repo-prio-but-not-main-due-to-min-stability.test diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index afa1b51b7..c090a34d8 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -268,7 +268,7 @@ class Problem }); if (!$nonLockedPackages) { - return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose).' in lock file but not in remote repositories, make sure you avoid updating this package to keep the one from lock file.'); + return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose).' in the lock file but not in remote repositories, make sure you avoid updating this package to keep the one from the lock file.'); } return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose).' but these were not loaded, likely because '.(self::hasMultipleNames($packages) ? 'they conflict' : 'it conflicts').' with another require.'); @@ -404,6 +404,13 @@ class Problem } } + if ($nextRepo instanceof LockArrayRepository) { + $singular = count($higherRepoPackages) === 1; + + return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', it is ', + 'found '.self::getPackageList($nextRepoPackages, $isVerbose).' in the lock file and '.self::getPackageList($higherRepoPackages, $isVerbose).' from '.reset($higherRepoPackages)->getRepository()->getRepoName().' but ' . ($singular ? 'it does' : 'these do') . ' not match your '.$reason.' and ' . ($singular ? 'is' : 'are') . ' therefore not installable. Make sure you either fix the '.$reason.' or avoid updating this package to keep the one from the lock file.'); + } + 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.'); } diff --git a/tests/Composer/Test/Fixtures/installer/alias-solver-problems2.test b/tests/Composer/Test/Fixtures/installer/alias-solver-problems2.test index 8f21a285a..3e37004d5 100644 --- a/tests/Composer/Test/Fixtures/installer/alias-solver-problems2.test +++ b/tests/Composer/Test/Fixtures/installer/alias-solver-problems2.test @@ -43,7 +43,7 @@ Updating dependencies Your requirements could not be resolved to an installable set of packages. Problem 1 - - locked/pkg dev-master requires locked/dependency 1.0.0 -> found locked/dependency[1.0.0] in lock file but not in remote repositories, make sure you avoid updating this package to keep the one from lock file. + - locked/pkg dev-master requires locked/dependency 1.0.0 -> found locked/dependency[1.0.0] in the lock file but not in remote repositories, make sure you avoid updating this package to keep the one from the lock file. - locked/pkg is locked to version dev-master and an update of this package was not requested. Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions. diff --git a/tests/Composer/Test/Fixtures/installer/conflict-with-all-dependencies-option-dont-recommend-to-use-it.test b/tests/Composer/Test/Fixtures/installer/conflict-with-all-dependencies-option-dont-recommend-to-use-it.test index d1003fd9d..1f5120880 100644 --- a/tests/Composer/Test/Fixtures/installer/conflict-with-all-dependencies-option-dont-recommend-to-use-it.test +++ b/tests/Composer/Test/Fixtures/installer/conflict-with-all-dependencies-option-dont-recommend-to-use-it.test @@ -43,7 +43,7 @@ Updating dependencies Your requirements could not be resolved to an installable set of packages. Problem 1 - - locked/pkg dev-master requires locked/dependency 1.0.0 -> found locked/dependency[1.0.0] in lock file but not in remote repositories, make sure you avoid updating this package to keep the one from lock file. + - locked/pkg dev-master requires locked/dependency 1.0.0 -> found locked/dependency[1.0.0] in the lock file but not in remote repositories, make sure you avoid updating this package to keep the one from the lock file. - locked/pkg is locked to version dev-master and an update of this package was not requested. --EXPECT-- diff --git a/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-at-all-in-remote.test b/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-at-all-in-remote.test new file mode 100644 index 000000000..c98d34dc6 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-at-all-in-remote.test @@ -0,0 +1,52 @@ +--TEST-- +Update package which is in lock file but not in remote repo at all should show this error correctly +--COMPOSER-- +{ + "minimum-stability": "dev", + "repositories": [ + {"type": "package", "package": [ + {"name": "main/dep", "version": "1.0.0", "require": {"locked/dep": "^2.1"}} + ]} + ], + "require": { + "main/dep": "*" + } +} +--LOCK-- +{ + "packages": [ + { + "name": "main/dep", "version": "1.0.0", + "require": {"locked/dep": "^2.1"}, + "type": "library" + }, + { + "name": "locked/dep", "version": "2.1.0", + "type": "library" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} +--RUN-- +update main/dep --with-all-dependencies + +--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 main/dep * -> satisfiable by main/dep[1.0.0]. + - main/dep 1.0.0 requires locked/dep ^2.1 -> found locked/dep[2.1.0] in the lock file but not in remote repositories, make sure you avoid updating this package to keep the one from the lock file. + +--EXPECT-- diff --git a/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-in-remote-due-to-min-stability.test b/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-in-remote-due-to-min-stability.test new file mode 100644 index 000000000..0c66d1dc3 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-in-remote-due-to-min-stability.test @@ -0,0 +1,54 @@ +--TEST-- +Update package which is in lock file but not remote repo due to min-stability should show this error correctly +--COMPOSER-- +{ + "minimum-stability": "stable", + "repositories": [ + {"type": "package", "package": [ + {"name": "main/dep", "version": "1.0.0", "require": {"locked/dep": "^2.1"}}, + {"name": "locked/dep", "version": "2.x-dev"}, + {"name": "locked/dep", "version": "2.0.5"} + ]} + ], + "require": { + "main/dep": "*" + } +} +--LOCK-- +{ + "packages": [ + { + "name": "main/dep", "version": "1.0.0", + "require": {"locked/dep": "^2.1"}, + "type": "library" + }, + { + "name": "locked/dep", "version": "2.1.0", + "type": "library" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} +--RUN-- +update main/dep --with-all-dependencies + +--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 main/dep * -> satisfiable by main/dep[1.0.0]. + - main/dep 1.0.0 requires locked/dep ^2.1 -> found locked/dep[2.1.0] in the lock file and locked/dep[2.x-dev] from package repo (defining 3 packages) but it does not match your minimum-stability and is therefore not installable. Make sure you either fix the minimum-stability or avoid updating this package to keep the one from the lock file. + +--EXPECT-- diff --git a/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-in-remote.test b/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-in-remote.test new file mode 100644 index 000000000..0d1e680e7 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-package-present-in-lock-but-not-in-remote.test @@ -0,0 +1,53 @@ +--TEST-- +Update package which is in lock file but not in remote repo in the correct version should show this error correctly +--COMPOSER-- +{ + "minimum-stability": "dev", + "repositories": [ + {"type": "package", "package": [ + {"name": "main/dep", "version": "1.0.0", "require": {"locked/dep": "^2.1"}}, + {"name": "locked/dep", "version": "2.0.5"} + ]} + ], + "require": { + "main/dep": "*" + } +} +--LOCK-- +{ + "packages": [ + { + "name": "main/dep", "version": "1.0.0", + "require": {"locked/dep": "^2.1"}, + "type": "library" + }, + { + "name": "locked/dep", "version": "2.1.0", + "type": "library" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} +--RUN-- +update main/dep --with-all-dependencies + +--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 main/dep * -> satisfiable by main/dep[1.0.0]. + - main/dep 1.0.0 requires locked/dep ^2.1 -> found locked/dep[2.1.0] in the lock file and locked/dep[2.0.5] from package repo (defining 2 packages) but it does not match your constraint and is therefore not installable. Make sure you either fix the constraint or avoid updating this package to keep the one from the lock file. + +--EXPECT-- diff --git a/tests/Composer/Test/Fixtures/installer/update-package-present-in-lower-repo-prio-but-not-main-due-to-min-stability.test b/tests/Composer/Test/Fixtures/installer/update-package-present-in-lower-repo-prio-but-not-main-due-to-min-stability.test new file mode 100644 index 000000000..2ccd48e80 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-package-present-in-lower-repo-prio-but-not-main-due-to-min-stability.test @@ -0,0 +1,57 @@ +--TEST-- +Update package which is in lower prio repo but not main repo due to min-stability should show this error correctly +--COMPOSER-- +{ + "minimum-stability": "stable", + "repositories": [ + {"type": "package", "package": [ + {"name": "main/dep", "version": "1.0.0", "require": {"lower/dep": "^2.1"}}, + {"name": "lower/dep", "version": "2.x-dev"}, + {"name": "lower/dep", "version": "2.0.5"} + ]}, + {"type": "package", "package": [ + {"name": "lower/dep", "version": "2.1.0"} + ]} + ], + "require": { + "main/dep": "*" + } +} +--LOCK-- +{ + "packages": [ + { + "name": "main/dep", "version": "1.0.0", + "require": {"lower/dep": "^2.1"}, + "type": "library" + }, + { + "name": "lower/dep", "version": "2.1.0", + "type": "library" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} +--RUN-- +update main/dep --with-all-dependencies + +--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 main/dep * -> satisfiable by main/dep[1.0.0]. + - main/dep 1.0.0 requires lower/dep ^2.1 -> satisfiable by lower/dep[2.1.0] from package repo (defining 1 package) but lower/dep[2.x-dev] from package repo (defining 3 packages) 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--