Skip to content

Commit

Permalink
Handling / in match pattern as inspired from #101.
Browse files Browse the repository at this point in the history
  • Loading branch information
thirsch committed Dec 28, 2022
1 parent 52c0fc3 commit 6b74103
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/M6Web/Component/RedisMock/RedisMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
6 changes: 5 additions & 1 deletion tests/units/RedisMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b74103

Please sign in to comment.