From b4698568d2575a3f3d0851a38d27cf8a5cccb706 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 17 Feb 2015 14:37:33 +0000 Subject: [PATCH] Adjust tests and fix installer code to create the pool using locked requirements and not the composer.json reqs --- src/Composer/Installer.php | 38 ++++++++++++------- ...e-installed-when-installing-from-lock.test | 8 ++-- ...aced-packages-should-not-be-installed.test | 19 +++++++++- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index e3e380f07..518f6c20d 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -33,6 +33,7 @@ use Composer\Json\JsonFile; use Composer\Package\AliasPackage; use Composer\Package\CompletePackage; use Composer\Package\Link; +use Composer\Package\LinkConstraint\EmptyConstraint; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Package\Locker; use Composer\Package\PackageInterface; @@ -355,9 +356,6 @@ class Installer $installFromLock = false; if (!$this->update && $this->locker->isLocked()) { $installFromLock = true; - // we are removing all requirements from the root package so only the lock file is relevant for installation rules - $this->package->setRequires(array()); - $this->package->setDevRequires(array()); try { $lockedRepository = $this->locker->getLockedRepository($withDevReqs); } catch (\RuntimeException $e) { @@ -381,7 +379,7 @@ class Installer // creating repository pool $policy = $this->createPolicy(); - $pool = $this->createPool($withDevReqs); + $pool = $this->createPool($withDevReqs, $lockedRepository); $pool->addRepository($installedRepo, $aliases); if ($installFromLock) { $pool->addRepository($lockedRepository, $aliases); @@ -674,27 +672,39 @@ class Installer return array_merge($uninstOps, $operations); } - private function createPool($withDevReqs) + private function createPool($withDevReqs, RepositoryInterface $lockedRepository = null) { - $minimumStability = $this->package->getMinimumStability(); - $stabilityFlags = $this->package->getStabilityFlags(); - - if (!$this->update && $this->locker->isLocked()) { + if (!$this->update && $this->locker->isLocked()) { // install from lock $minimumStability = $this->locker->getMinimumStability(); $stabilityFlags = $this->locker->getStabilityFlags(); + + $requires = array(); + foreach ($lockedRepository->getPackages() as $package) { + $constraint = new VersionConstraint('=', $package->getVersion()); + $constraint->setPrettyString($package->getPrettyVersion()); + $requires[$package->getName()] = $constraint; + } + } else { + $minimumStability = $this->package->getMinimumStability(); + $stabilityFlags = $this->package->getStabilityFlags(); + + $requires = $this->package->getRequires(); + if ($withDevReqs) { + $requires = array_merge($requires, $this->package->getDevRequires()); + } } - $requires = $this->package->getRequires(); - if ($withDevReqs) { - $requires = array_merge($requires, $this->package->getDevRequires()); - } $rootConstraints = array(); foreach ($requires as $req => $constraint) { // skip platform requirements from the root package to avoid filtering out existing platform packages if ($this->ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req)) { continue; } - $rootConstraints[$req] = $constraint->getConstraint(); + if ($constraint instanceof Link) { + $rootConstraints[$req] = $constraint->getConstraint(); + } else { + $rootConstraints[$req] = $constraint; + } } return new Pool($minimumStability, $stabilityFlags, $rootConstraints); diff --git a/tests/Composer/Test/Fixtures/installer/replaced-packages-should-not-be-installed-when-installing-from-lock.test b/tests/Composer/Test/Fixtures/installer/replaced-packages-should-not-be-installed-when-installing-from-lock.test index 6d0602159..6e1783b58 100644 --- a/tests/Composer/Test/Fixtures/installer/replaced-packages-should-not-be-installed-when-installing-from-lock.test +++ b/tests/Composer/Test/Fixtures/installer/replaced-packages-should-not-be-installed-when-installing-from-lock.test @@ -20,8 +20,8 @@ Requiring a replaced package in a version, that is not provided by the replacing --LOCK-- { "packages": [ - { "name": "foo/original", "version": "1.0.0", "replace": {"foo/replaced": "1.0.0"} }, - { "name": "foo/replaced", "version": "2.0.0" } + { "name": "foo/original", "version": "1.0.0", "replace": {"foo/replaced": "1.0.0"}, "type": "library" }, + { "name": "foo/replaced", "version": "2.0.0", "type": "library" } ], "packages-dev": [], "aliases": [], @@ -35,5 +35,7 @@ Requiring a replaced package in a version, that is not provided by the replacing --RUN-- install --EXPECT-EXIT-CODE-- -2 +0 --EXPECT-- +Installing foo/original (1.0.0) +Installing foo/replaced (2.0.0) diff --git a/tests/Composer/Test/Fixtures/installer/replaced-packages-should-not-be-installed.test b/tests/Composer/Test/Fixtures/installer/replaced-packages-should-not-be-installed.test index 0d1ea7701..78979eeac 100644 --- a/tests/Composer/Test/Fixtures/installer/replaced-packages-should-not-be-installed.test +++ b/tests/Composer/Test/Fixtures/installer/replaced-packages-should-not-be-installed.test @@ -19,6 +19,23 @@ Requiring a replaced package in a version, that is not provided by the replacing } --RUN-- install +--EXPECT-LOCK-- +{ + "packages": [ + { "name": "foo/original", "version": "1.0.0", "replace": {"foo/replaced": "1.0.0"}, "type": "library" }, + { "name": "foo/replaced", "version": "2.0.0", "type": "library" } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": {}, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} --EXPECT-EXIT-CODE-- -2 +0 --EXPECT-- +Installing foo/original (1.0.0) +Installing foo/replaced (2.0.0)