From eca295aff9162e7924ecaba5a5f6404a59f1a3bd Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Wed, 16 Mar 2022 11:20:00 +0100 Subject: [PATCH] Fix result cache key in CompilingMatcher --- src/CompilingMatcher.php | 2 +- tests/CompilingMatcherTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CompilingMatcher.php b/src/CompilingMatcher.php index 3565bfdc7..45bce70a6 100644 --- a/src/CompilingMatcher.php +++ b/src/CompilingMatcher.php @@ -68,7 +68,7 @@ public static function clear() */ public static function match(ConstraintInterface $constraint, $operator, $version) { - $resultCacheKey = $operator.$constraint.$version; + $resultCacheKey = $operator.$constraint.';'.$version; if (isset(self::$resultCache[$resultCacheKey])) { return self::$resultCache[$resultCacheKey]; diff --git a/tests/CompilingMatcherTest.php b/tests/CompilingMatcherTest.php index 01af2bc65..dd932a11d 100644 --- a/tests/CompilingMatcherTest.php +++ b/tests/CompilingMatcherTest.php @@ -21,4 +21,10 @@ public function testMatch() { $this->assertTrue(CompilingMatcher::match(new Constraint('>=', '1'), Constraint::OP_EQ, '2')); } + + public function testCacheKey() + { + $this->assertFalse(CompilingMatcher::match(new Constraint('>=', '2.11'), Constraint::OP_EQ, '1.0')); + $this->assertTrue(CompilingMatcher::match(new Constraint('>=', '2.1'), Constraint::OP_EQ, '11.0')); + } }