diff --git a/src/Constraint/MultiConstraint.php b/src/Constraint/MultiConstraint.php index 1f4c0061..28dc0a7b 100644 --- a/src/Constraint/MultiConstraint.php +++ b/src/Constraint/MultiConstraint.php @@ -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; diff --git a/tests/Constraint/MultiConstraintTest.php b/tests/Constraint/MultiConstraintTest.php index 40c83908..7eab3f10 100644 --- a/tests/Constraint/MultiConstraintTest.php +++ b/tests/Constraint/MultiConstraintTest.php @@ -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 *