Skip to content

Commit 1bc3cff

Browse files
committed
Fixed MultiConstraint with MatchAllConstraint
1 parent 3fee760 commit 1bc3cff

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Constraint/MultiConstraint.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,12 @@ public static function create(array $constraints, $conjunctive = true)
207207
return $constraints[0];
208208
}
209209

210-
foreach ($constraints as $constraint) {
210+
foreach ($constraints as $k => $constraint) {
211211
if ($constraint instanceof MatchAllConstraint) {
212-
return new MatchAllConstraint();
212+
if (!$conjunctive) {
213+
return new MatchAllConstraint();
214+
}
215+
unset($constraints[$k]);
213216
}
214217
}
215218

tests/Constraint/MultiConstraintTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,14 @@ public function testCreatesMatchAllConstraintIfNoneGiven()
275275
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(array()));
276276
}
277277

278-
public function testCreatesMatchAllConstraintIfConjunctiveAndCombinedWithAnotherONe()
278+
public function testRemovesMatchAllConstraintIfConjunctiveAndCombinedWithOtherConstraints()
279279
{
280-
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(
281-
array(new Constraint('>=', '2.5.0.0-dev'), new MatchAllConstraint())
280+
$this->assertSame('[>= 2.5.0.0-dev <= 3.0.0.0-dev]', (string) MultiConstraint::create(
281+
array(new Constraint('>=', '2.5.0.0-dev'), new Constraint('<=', '3.0.0.0-dev'), new MatchAllConstraint())
282282
));
283283
}
284284

285-
public function testCreatesMatchAllConstraintIfDisjunctiveAndCombinedWithAnotherONe()
285+
public function testCreatesMatchAllConstraintIfDisjunctiveAndCombinedWithAnotherOne()
286286
{
287287
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(
288288
array(new Constraint('>=', '2.5.0.0-dev'), new MatchAllConstraint()), false

0 commit comments

Comments
 (0)