1
0
Fork 0

Adjust tests and fix installer code to create the pool using locked requirements and not the composer.json reqs

pull/3758/head
Jordi Boggiano 2015-02-17 14:37:33 +00:00
parent df23836a0e
commit b4698568d2
3 changed files with 47 additions and 18 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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)