diff --git a/src/M6Web/Component/RedisMock/RedisMock.php b/src/M6Web/Component/RedisMock/RedisMock.php index dd17ae8..a8aafb4 100644 --- a/src/M6Web/Component/RedisMock/RedisMock.php +++ b/src/M6Web/Component/RedisMock/RedisMock.php @@ -492,7 +492,7 @@ public function sscan($key, $cursor = 0, array $options = []) // Matched values. $values = []; // Pattern, for find matched values. - $pattern = str_replace('*', '.*', sprintf('/^%s$/', $match)); + $pattern = sprintf('/^%s$/', str_replace(['*', '/'], ['.*', '\/'], $match)); for($i = $cursor; $i <= $maximumValue; $i++) { diff --git a/tests/units/RedisMock.php b/tests/units/RedisMock.php index c09a12b..de0a9e8 100644 --- a/tests/units/RedisMock.php +++ b/tests/units/RedisMock.php @@ -1925,18 +1925,22 @@ public function testSscanCommand() $redisMock->sadd('myKey', 'a1'); $redisMock->sadd('myKey', ['b1', 'b2', 'b3', 'b4', 'b5', 'b6']); $redisMock->sadd('myKey', ['c1', 'c2', 'c3']); + $redisMock->sadd('a/b', 'c/d'); // It must return no values, as the key is unknown. $this->assert ->array($redisMock->sscan('unknown', 1, ['COUNT' => 2])) ->isEqualTo([0, []]); + $this->assert + ->array($redisMock->sscan('a/b', 0, ['MATCH' => 'c/*'])) + ->isEqualTo([0, [0 => 'c/d']]); + // It must return two values, start cursor after the first value of the list. $this->assert ->array($redisMock->sscan('myKey', 1, ['COUNT' => 2])) ->isEqualTo([3, [0 => 'b1', 1 => 'b2']]); - // It must return all the values with match with the regex 'our' (2 keys). // And the cursor is defined after the default count (10) => the match has not terminate all the list. $this->assert