From 7d7c1784bbc8e33e4bf5c30bce10c4e2431fc159 Mon Sep 17 00:00:00 2001 From: Vladyslav Pozdniakov Date: Mon, 17 Jun 2024 11:33:01 +0300 Subject: [PATCH] feat: see/save for serialized values, see any value --- src/Context/RedisContext.php | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/Context/RedisContext.php b/src/Context/RedisContext.php index cdc3c29..debee4b 100644 --- a/src/Context/RedisContext.php +++ b/src/Context/RedisContext.php @@ -47,6 +47,14 @@ public function iSaveStringParamsToRedis(string $value, string $key): void $this->redis->set($key, $value); } + /** + * @When /^I save serialized value "([^"]*)" to redis by "([^"]*)"$/ + */ + public function iSaveSerializedParamsToRedis(string $value, string $key): void + { + $this->redis->set($key, serialize($value)); + } + /** * @param string $value * @param string $key @@ -106,4 +114,42 @@ public function iSeeInRedisArrayByKey(string $key, PyStringNode $string): void throw new RuntimeException($message); } } + + /** + * @throws InvalidArgumentException + * + * @When /^I see in redis any value by key "([^"]*)"$/ + */ + public function iSeeInRedisAnyValueByKey(string $key): void + { + $found = $this->redis->get($key); + + if (null === $found) { + throw new InvalidArgumentException(sprintf('In Redis does not exist data for key "%s"', $key)); + } + } + + /** + * @When /^I see in redis serialized value "([^"]*)" by key "([^"]*)"$/ + */ + public function iSeeInRedisSerializedValueByKey(string $value, string $key): void + { + $found = $this->redis->get($key); + + if (null === $found) { + throw new InvalidArgumentException(sprintf('In Redis does not exist data for key "%s"', $key)); + } + + /** @var string $found */ + $found = unserialize($found); + + if ($value !== $found) { + throw new InvalidArgumentException(sprintf( + 'Value in key "%s" do not match "%s" actual "%s"', + $key, + $value, + $found, + )); + } + } }