From 1bc3cff1cf47a4217a312ef01cb40d7ab0ab0a3c Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Thu, 3 Feb 2022 17:34:07 +0100 Subject: [PATCH] Fixed MultiConstraint with MatchAllConstraint --- src/Constraint/MultiConstraint.php | 7 +++++-- tests/Constraint/MultiConstraintTest.php | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) 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