From 17ed09be2ee33afaf9838f82ed01eccf6fd3c7db Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 20 Apr 2020 21:46:56 +0200 Subject: [PATCH] Add failing test showing that packages fail to be installed if they match a previous alias which was not removed yet --- .../installer/update-alias-lock2.test | 84 +++++++++++++++++++ .../Test/Mock/InstallationManagerMock.php | 4 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Fixtures/installer/update-alias-lock2.test diff --git a/tests/Composer/Test/Fixtures/installer/update-alias-lock2.test b/tests/Composer/Test/Fixtures/installer/update-alias-lock2.test new file mode 100644 index 000000000..b06ce3119 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-alias-lock2.test @@ -0,0 +1,84 @@ +--TEST-- +Updating an aliased package where the old alias matches the new package should not fail +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { + "name": "a/a", "version": "1.10.x-dev", + "extra": { "branch-alias": { "dev-master": "1.10.x-dev" } }, + "source": { "type": "git", "url": "", "reference": "downgradedref" } + }, + { + "name": "a/a", "version": "dev-master", + "extra": { "branch-alias": { "dev-master": "2.x-dev" } }, + "source": { "type": "git", "url": "", "reference": "newref" } + } + ] + } + ], + "require": { + "a/a": "^1.0" + }, + "minimum-stability": "dev" +} +--LOCK-- +{ + "_": "outdated lock file, should not have to be loaded in an update", + "packages": [ + { + "name": "a/a", "version": "dev-master", + "extra": { "branch-alias": { "dev-master": "1.10.x-dev" } }, + "source": { "type": "git", "url": "", "reference": "installedref" } + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false +} +--INSTALLED-- +[ + { + "name": "a/a", "version": "dev-master", + "extra": { "branch-alias": { "dev-master": "1.10.x-dev" } }, + "source": { "type": "git", "url": "", "reference": "installedref" } + } +] +--RUN-- +update +--EXPECT-LOCK-- +{ + "packages": [ + { + "name": "a/a", "version": "1.10.x-dev", + "extra": { "branch-alias": { "dev-master": "1.10.x-dev" } }, + "source": { "type": "git", "url": "", "reference": "downgradedref" }, + "type": "library" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} +--EXPECT-INSTALLED-- +[ + { + "name": "a/a", "version": "1.10.x-dev", + "source": { "type": "git", "url": "", "reference": "downgradedref" }, + "type": "library", + "extra": { "branch-alias": { "dev-master": "1.10.x-dev" } } + } +] +--EXPECT-- +Marking a/a (1.10.x-dev installedref) as uninstalled, alias of a/a (dev-master installedref) +Downgrading a/a (dev-master installedref => 1.10.x-dev downgradedref) diff --git a/tests/Composer/Test/Mock/InstallationManagerMock.php b/tests/Composer/Test/Mock/InstallationManagerMock.php index 2d4a8781b..1d1dfef8c 100644 --- a/tests/Composer/Test/Mock/InstallationManagerMock.php +++ b/tests/Composer/Test/Mock/InstallationManagerMock.php @@ -66,7 +66,9 @@ class InstallationManagerMock extends InstallationManager $this->updated[] = array($operation->getInitialPackage(), $operation->getTargetPackage()); $this->trace[] = strip_tags((string) $operation); $repo->removePackage($operation->getInitialPackage()); - $repo->addPackage(clone $operation->getTargetPackage()); + if (!$repo->hasPackage($operation->getTargetPackage())) { + $repo->addPackage(clone $operation->getTargetPackage()); + } } public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)