Skip to content

Commit 3976a9e

Browse files
authored
Merge pull request #129 from Toflar/fix-concunctive-multi-with-matchall
Fixed MultiConstraint with MatchAllConstraint
2 parents a3e5e14 + 1bc3cff commit 3976a9e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Constraint/MultiConstraint.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ public static function create(array $constraints, $conjunctive = true)
228228
return $constraints[0];
229229
}
230230

231+
foreach ($constraints as $k => $constraint) {
232+
if ($constraint instanceof MatchAllConstraint) {
233+
if (!$conjunctive) {
234+
return new MatchAllConstraint();
235+
}
236+
unset($constraints[$k]);
237+
}
238+
}
239+
231240
$optimized = self::optimizeConstraints($constraints, $conjunctive);
232241
if ($optimized !== null) {
233242
list($constraints, $conjunctive) = $optimized;

tests/Constraint/MultiConstraintTest.php

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

293+
public function testRemovesMatchAllConstraintIfConjunctiveAndCombinedWithOtherConstraints()
294+
{
295+
$this->assertSame('[>= 2.5.0.0-dev <= 3.0.0.0-dev]', (string) MultiConstraint::create(
296+
array(new Constraint('>=', '2.5.0.0-dev'), new Constraint('<=', '3.0.0.0-dev'), new MatchAllConstraint())
297+
));
298+
}
299+
300+
public function testCreatesMatchAllConstraintIfDisjunctiveAndCombinedWithAnotherOne()
301+
{
302+
$this->assertInstanceOf('Composer\Semver\Constraint\MatchAllConstraint', MultiConstraint::create(
303+
array(new Constraint('>=', '2.5.0.0-dev'), new MatchAllConstraint()), false
304+
));
305+
}
306+
293307
/**
294308
* @dataProvider multiConstraintOptimizations
295309
*

0 commit comments

Comments
 (0)