1
0
Fork 0

Fix whatProvides returning too many results when no constraint is given

pull/2175/head
Jordi Boggiano 2013-08-12 18:37:34 +02:00
parent 3346609c5d
commit 051d219438
2 changed files with 9 additions and 14 deletions

View File

@ -250,14 +250,6 @@ class Pool
$candidates = array_merge($candidates, $this->packageByName[$name]);
}
if (null === $constraint) {
foreach ($candidates as $key => $candidate) {
$candidates[$key] = $this->ensurePackageIsLoaded($candidate);
}
return $candidates;
}
$matches = $provideMatches = array();
$nameMatch = false;
@ -369,7 +361,7 @@ class Pool
* @param LinkConstraintInterface $constraint The constraint to verify
* @return int One of the MATCH* constants of this class or 0 if there is no match
*/
private function match($candidate, $name, LinkConstraintInterface $constraint)
private function match($candidate, $name, LinkConstraintInterface $constraint = null)
{
// handle array packages
if (is_array($candidate)) {
@ -382,6 +374,9 @@ class Pool
}
if ($candidateName === $name) {
if ($constraint === null) {
return self::MATCH;
}
return $constraint->matches(new VersionConstraint('==', $candidateVersion)) ? self::MATCH : self::MATCH_NAME;
}
@ -400,13 +395,13 @@ class Pool
// aliases create multiple replaces/provides for one target so they can not use the shortcut
if (isset($replaces[0]) || isset($provides[0])) {
foreach ($provides as $link) {
if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
return self::MATCH_PROVIDE;
}
}
foreach ($replaces as $link) {
if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
return self::MATCH_REPLACE;
}
}
@ -414,11 +409,11 @@ class Pool
return self::MATCH_NONE;
}
if (isset($provides[$name]) && $constraint->matches($provides[$name]->getConstraint())) {
if (isset($provides[$name]) && ($constraint === null || $constraint->matches($provides[$name]->getConstraint()))) {
return self::MATCH_PROVIDE;
}
if (isset($replaces[$name]) && $constraint->matches($replaces[$name]->getConstraint())) {
if (isset($replaces[$name]) && ($constraint === null || $constraint->matches($replaces[$name]->getConstraint()))) {
return self::MATCH_REPLACE;
}

View File

@ -405,7 +405,7 @@ class SolverTest extends TestCase
{
$this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$packageB->setReplaces(array('a' => new Link('B', 'A', null)));
$packageB->setReplaces(array('a' => new Link('B', 'A', new MultiConstraint(array()))));
$this->reposComplete();