Skip to content

Commit

Permalink
Merge pull request #129 from Toflar/fix-concunctive-multi-with-matchall
Browse files Browse the repository at this point in the history
Fixed MultiConstraint with MatchAllConstraint
  • Loading branch information
Seldaek authored Feb 4, 2022
2 parents a3e5e14 + 1bc3cff commit 3976a9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Constraint/MultiConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ public static function create(array $constraints, $conjunctive = true)
return $constraints[0];
}

foreach ($constraints as $k => $constraint) {
if ($constraint instanceof MatchAllConstraint) {
if (!$conjunctive) {
return new MatchAllConstraint();
}
unset($constraints[$k]);
}
}

$optimized = self::optimizeConstraints($constraints, $conjunctive);
if ($optimized !== null) {
list($constraints, $conjunctive) = $optimized;
Expand Down
14 changes: 14 additions & 0 deletions tests/Constraint/MultiConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ public function testCreatesMatchAllConstraintIfNoneGiven()
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(array()));
}

public function testRemovesMatchAllConstraintIfConjunctiveAndCombinedWithOtherConstraints()
{
$this->assertSame('[>= 2.5.0.0-dev <= 3.0.0.0-dev]', (string) MultiConstraint::create(
array(new Constraint('>=', '2.5.0.0-dev'), new Constraint('<=', '3.0.0.0-dev'), new MatchAllConstraint())
));
}

public function testCreatesMatchAllConstraintIfDisjunctiveAndCombinedWithAnotherOne()
{
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(
array(new Constraint('>=', '2.5.0.0-dev'), new MatchAllConstraint()), false
));
}

/**
* @dataProvider multiConstraintOptimizations
*
Expand Down

0 comments on commit 3976a9e

Please sign in to comment.