From 266e1ca42c463244b4bd34fe01d502f85fb56ea4 Mon Sep 17 00:00:00 2001 From: Baptiste Lafontaine Date: Mon, 19 Aug 2019 10:31:00 +0200 Subject: [PATCH] Zset methods returns score as string --- src/M6Web/Component/RedisMock/RedisMock.php | 9 +++---- tests/units/RedisMock.php | 30 ++++++++++----------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/M6Web/Component/RedisMock/RedisMock.php b/src/M6Web/Component/RedisMock/RedisMock.php index 69f8e5a..cf5829d 100644 --- a/src/M6Web/Component/RedisMock/RedisMock.php +++ b/src/M6Web/Component/RedisMock/RedisMock.php @@ -910,7 +910,7 @@ protected function zrangebyscoreHelper($key, $min, $max, array $options = array( if ($min == '-inf' && $max == '+inf') { $slice = array_slice(self::$dataValues[$this->storage][$key], $options['limit'][0], $options['limit'][1], true); if (isset($options['withscores']) && $options['withscores']) { - return $this->returnPipedInfo($slice); + return $this->returnPipedInfo(array_map('strval', $slice)); } else { return $this->returnPipedInfo(array_keys($slice)); } @@ -947,14 +947,12 @@ protected function zrangebyscoreHelper($key, $min, $max, array $options = array( $slice = array_slice($results, $options['limit'][0], $options['limit'][1], true); if (isset($options['withscores']) && $options['withscores']) { - return $this->returnPipedInfo($slice); + return $this->returnPipedInfo(array_map('strval', $slice)); } else { return $this->returnPipedInfo(array_keys($slice)); } } - - public function zrangebyscore($key, $min, $max, array $options = array()) { return $this->zrangebyscoreHelper($key, $min, $max, $options, false); @@ -965,7 +963,6 @@ public function zrevrangebyscore($key, $max, $min, array $options = array()) return $this->zrangebyscoreHelper($key, $min, $max, $options, true); } - public function zadd($key, ...$args) { if (count($args) === 1) { if (count($args[0]) > 1) { @@ -1006,7 +1003,7 @@ public function zscore($key, $member) return $this->returnPipedInfo(null); } - return $this->returnPipedInfo(self::$dataValues[$this->storage][$key][$member]); + return $this->returnPipedInfo((string) self::$dataValues[$this->storage][$key][$member]); } public function zcard($key) diff --git a/tests/units/RedisMock.php b/tests/units/RedisMock.php index e77c09e..2e3b708 100644 --- a/tests/units/RedisMock.php +++ b/tests/units/RedisMock.php @@ -717,11 +717,11 @@ public function testZScore() $redisMock->zadd('test', 15, 'test2'); $this->assert - ->integer($redisMock->zscore('test', 'test4')) + ->string($redisMock->zscore('test', 'test4')) ->isEqualTo(1); $this->assert - ->integer($redisMock->zscore('test', 'test2')) + ->string($redisMock->zscore('test', 'test2')) ->isEqualTo(15); $this->assert @@ -948,10 +948,10 @@ public function testZRevRange() 'test6', )) ->array($redisMock->zrevrange('test', 1, -3, true)) - ->isEqualTo(array( - 'test2' => 15, - 'test3' => 2, - 'test4' => 1, + ->isIdenticalTo(array( + 'test2' => '15', + 'test3' => '2', + 'test4' => '1', )) ->integer($redisMock->del('test')) ->isEqualTo(6) @@ -1046,10 +1046,10 @@ public function testZRangeByScore() 'test3', )) ->array($redisMock->zrangebyscore('test', '-inf', '15', array('limit' => array(1, 3), 'withscores' => true))) - ->isEqualTo(array( - 'test1' => 1, - 'test4' => 1, - 'test3' => 2, + ->isIdenticalTo(array( + 'test1' => '1', + 'test4' => '1', + 'test3' => '2', )) ->integer($redisMock->del('test')) ->isEqualTo(6) @@ -1143,10 +1143,10 @@ public function testZRevRangeByScore() 'test1', )) ->array($redisMock->zrevrangebyscore('test', '15', '-inf', array('limit' => array(1, 3), 'withscores' => true))) - ->isEqualTo(array( - 'test3' => 2, - 'test4' => 1, - 'test1' => 1, + ->isIdenticalTo(array( + 'test3' => '2', + 'test4' => '1', + 'test1' => '1', )) ->integer($redisMock->del('test')) ->isEqualTo(6) @@ -1159,7 +1159,7 @@ public function testZRevRangeByScore() sleep(2); $this->assert ->array($redisMock->zrevrangebyscore('test', '1', '0')) - ->isEmpty();; + ->isEmpty(); } public function testHSetHMSetHGetHDelHExistsHKeysHLenHGetAll()