Skip to content

Commit 3fee760

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

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Constraint/MultiConstraint.php

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

210+
foreach ($constraints as $constraint) {
211+
if ($constraint instanceof MatchAllConstraint) {
212+
return new MatchAllConstraint();
213+
}
214+
}
215+
210216
$optimized = self::optimizeConstraints($constraints, $conjunctive);
211217
if ($optimized !== null) {
212218
list($constraints, $conjunctive) = $optimized;

tests/Constraint/MultiConstraintTest.php

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

278+
public function testCreatesMatchAllConstraintIfConjunctiveAndCombinedWithAnotherONe()
279+
{
280+
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(
281+
array(new Constraint('>=', '2.5.0.0-dev'), new MatchAllConstraint())
282+
));
283+
}
284+
285+
public function testCreatesMatchAllConstraintIfDisjunctiveAndCombinedWithAnotherONe()
286+
{
287+
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(
288+
array(new Constraint('>=', '2.5.0.0-dev'), new MatchAllConstraint()), false
289+
));
290+
}
291+
278292
/**
279293
* @dataProvider multiConstraintOptimizations
280294
*

0 commit comments

Comments
 (0)