Skip to content

Commit

Permalink
Fixed MultiConstraint with MatchAllConstraint
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Feb 3, 2022
1 parent 3fee760 commit 1bc3cff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/Constraint/MultiConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ public static function create(array $constraints, $conjunctive = true)
return $constraints[0];
}

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

Expand Down
8 changes: 4 additions & 4 deletions tests/Constraint/MultiConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ public function testCreatesMatchAllConstraintIfNoneGiven()
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(array()));
}

public function testCreatesMatchAllConstraintIfConjunctiveAndCombinedWithAnotherONe()
public function testRemovesMatchAllConstraintIfConjunctiveAndCombinedWithOtherConstraints()
{
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(
array(new Constraint('>=', '2.5.0.0-dev'), new MatchAllConstraint())
$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()
public function testCreatesMatchAllConstraintIfDisjunctiveAndCombinedWithAnotherOne()
{
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(
array(new Constraint('>=', '2.5.0.0-dev'), new MatchAllConstraint()), false
Expand Down

0 comments on commit 1bc3cff

Please sign in to comment.