Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: see/save for serialized values, see any value #19

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/Context/RedisContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
$this->redis->set($key, $value);
}

/**
* @When /^I save serialized value "([^"]*)" to redis by "([^"]*)"$/
*/
public function iSaveSerializedParamsToRedis(string $value, string $key): void

Check warning on line 53 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L53

Added line #L53 was not covered by tests
{
$this->redis->set($key, serialize($value));

Check warning on line 55 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L55

Added line #L55 was not covered by tests
}

/**
* @param string $value
* @param string $key
Expand Down Expand Up @@ -106,4 +114,42 @@
throw new RuntimeException($message);
}
}

/**
* @throws InvalidArgumentException
*
* @When /^I see in redis any value by key "([^"]*)"$/
*/
public function iSeeInRedisAnyValueByKey(string $key): void

Check warning on line 123 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L123

Added line #L123 was not covered by tests
{
$found = $this->redis->get($key);

Check warning on line 125 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L125

Added line #L125 was not covered by tests

if (null === $found) {
throw new InvalidArgumentException(sprintf('In Redis does not exist data for key "%s"', $key));

Check warning on line 128 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L127-L128

Added lines #L127 - L128 were not covered by tests
}
}

/**
* @When /^I see in redis serialized value "([^"]*)" by key "([^"]*)"$/
*/
public function iSeeInRedisSerializedValueByKey(string $value, string $key): void

Check warning on line 135 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L135

Added line #L135 was not covered by tests
{
$found = $this->redis->get($key);

Check warning on line 137 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L137

Added line #L137 was not covered by tests

if (null === $found) {
throw new InvalidArgumentException(sprintf('In Redis does not exist data for key "%s"', $key));

Check warning on line 140 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L139-L140

Added lines #L139 - L140 were not covered by tests
}

/** @var string $found */
$found = unserialize($found);

Check warning on line 144 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L144

Added line #L144 was not covered by tests

if ($value !== $found) {
throw new InvalidArgumentException(sprintf(
'Value in key "%s" do not match "%s" actual "%s"',
$key,
$value,
$found,
));

Check warning on line 152 in src/Context/RedisContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/RedisContext.php#L146-L152

Added lines #L146 - L152 were not covered by tests
}
}
}
Loading