diff --git a/src/Constraint/MultiConstraint.php b/src/Constraint/MultiConstraint.php index 1cb14e4d..388db67e 100644 --- a/src/Constraint/MultiConstraint.php +++ b/src/Constraint/MultiConstraint.php @@ -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]); } } diff --git a/tests/Constraint/MultiConstraintTest.php b/tests/Constraint/MultiConstraintTest.php index ccce2c72..07a7ceab 100644 --- a/tests/Constraint/MultiConstraintTest.php +++ b/tests/Constraint/MultiConstraintTest.php @@ -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