Skip to content

Commit

Permalink
Merge pull request #16 from Codeception/codecept5
Browse files Browse the repository at this point in the history
Support Codeception 5
  • Loading branch information
Naktibalda authored Feb 20, 2022
2 parents a0f2680 + 2bed8e2 commit 9d2d7a3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
php: [7.4, 8.0, 8.1]
php: [8.0, 8.1]

steps:
- name: Checkout code
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"name": "Dmitriy Maltsev"
}
],
"minimum-stability": "RC",
"minimum-stability": "dev",
"require": {
"php": "^7.4 | ^8.0",
"codeception/codeception": "^4.1",
"php": "^8.0",
"codeception/codeception": "^5.0.0-alpha2",
"predis/predis": "^1.1",
"sebastian/comparator": "^4.0"
"sebastian/comparator": "^4.0 | ^5.0"
},
"autoload": {
"classmap": [
Expand Down
51 changes: 23 additions & 28 deletions src/Codeception/Module/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class Redis extends Module implements RequiresPackage
*
* No default value is set for the database, using this parameter.
*
* @var array
* @var array>string, mixed>
*/
protected $config = [
protected array $config = [
'host' => '127.0.0.1',
'port' => 6379,
'cleanupBefore' => 'never'
Expand All @@ -73,7 +73,7 @@ class Redis extends Module implements RequiresPackage
*
* @var string[]
*/
protected $requiredFields = [
protected array $requiredFields = [
'database'
];

Expand All @@ -82,6 +82,9 @@ class Redis extends Module implements RequiresPackage
*/
public ?RedisDriver $driver = null;

/**
* @return array<string, string>
*/
public function _requires(): array
{
return [\Predis\Client::class => '"predis/predis": "^1.0"'];
Expand All @@ -92,7 +95,7 @@ public function _requires(): array
*
* @throws ModuleException
*/
public function _initialize()
public function _initialize(): void
{
try {
$this->driver = new RedisDriver($this->config);
Expand All @@ -107,9 +110,9 @@ public function _initialize()
/**
* Code to run before each suite
*
* @param array $settings
* @param array<string, mixed> $settings
*/
public function _beforeSuite($settings = [])
public function _beforeSuite($settings = []): void
{
if ($this->config['cleanupBefore'] === 'suite') {
$this->cleanup();
Expand All @@ -119,7 +122,7 @@ public function _beforeSuite($settings = [])
/**
* Code to run before each test
*/
public function _before(TestInterface $test)
public function _before(TestInterface $test): void
{
if ($this->config['cleanupBefore'] === 'test') {
$this->cleanup();
Expand Down Expand Up @@ -181,11 +184,9 @@ public function cleanup(): void
*
* @param string $key The key name
*
* @return array|string|null
*
* @throws ModuleException if the key does not exist
*/
public function grabFromRedis(string $key)
public function grabFromRedis(string $key): array|string|null
{
$args = func_get_args();

Expand Down Expand Up @@ -280,7 +281,7 @@ public function grabFromRedis(string $key)
*
* @throws ModuleException
*/
public function haveInRedis(string $type, string $key, $value): void
public function haveInRedis(string $type, string $key, mixed $value): void
{
switch (strtolower($type)) {
case 'string':
Expand Down Expand Up @@ -364,7 +365,7 @@ public function haveInRedis(string $type, string $key, $value): void
* @param mixed $value Optional. If specified, also checks the key has this
* value. Booleans will be converted to 1 and 0 (even inside arrays)
*/
public function dontSeeInRedis(string $key, $value = null): void
public function dontSeeInRedis(string $key, mixed $value = null): void
{
try {
$this->assertFalse(
Expand Down Expand Up @@ -408,10 +409,10 @@ public function dontSeeInRedis(string $key, $value = null): void
*
* @param string $key The key
* @param mixed $item The item
* @param null $itemValue Optional and only used for zsets and hashes. If
* @param mixed $itemValue Optional and only used for zsets and hashes. If
* specified, the method will also check that the $item has this value/score
*/
public function dontSeeRedisKeyContains(string $key, $item, $itemValue = null): void
public function dontSeeRedisKeyContains(string $key, mixed $item, mixed $itemValue = null): void
{
$this->assertFalse(
$this->checkKeyContains($key, $item, $itemValue),
Expand Down Expand Up @@ -453,7 +454,7 @@ public function dontSeeRedisKeyContains(string $key, $item, $itemValue = null):
* @param mixed $value Optional. If specified, also checks the key has this
* value. Booleans will be converted to 1 and 0 (even inside arrays)
*/
public function seeInRedis(string $key, $value = null): void
public function seeInRedis(string $key, mixed $value = null): void
{
try {
$this->assertTrue(
Expand Down Expand Up @@ -487,7 +488,7 @@ public function seeInRedis(string $key, $value = null): void
* @param string $command The command name
* @return mixed
*/
public function sendCommandToRedis(string $command)
public function sendCommandToRedis(string $command): mixed
{
return call_user_func_array(
[$this->driver, $command],
Expand Down Expand Up @@ -526,10 +527,10 @@ public function sendCommandToRedis(string $command)
*
* @param string $key The key
* @param mixed $item The item
* @param null $itemValue Optional and only used for zsets and hashes. If
* @param mixed $itemValue Optional and only used for zsets and hashes. If
* specified, the method will also check that the $item has this value/score
*/
public function seeRedisKeyContains(string $key, $item, $itemValue = null): void
public function seeRedisKeyContains(string $key, mixed $item, mixed $itemValue = null): void
{
$this->assertTrue(
$this->checkKeyContains($key, $item, $itemValue),
Expand All @@ -543,11 +544,8 @@ public function seeRedisKeyContains(string $key, $item, $itemValue = null): void

/**
* Converts boolean values to "0" and "1"
*
* @param mixed $var The variable
* @return mixed
*/
private function boolToString($var)
private function boolToString(mixed $var): mixed
{
$copy = is_array($var) ? $var : [$var];

Expand All @@ -565,13 +563,12 @@ private function boolToString($var)
*
* @param string $key The key
* @param mixed $item The item
* @param null $itemValue Optional and only used for zsets and hashes. If
* @param mixed $itemValue Optional and only used for zsets and hashes. If
* specified, the method will also check that the $item has this value/score
*
* @return bool
* @throws ModuleException
*/
private function checkKeyContains(string $key, $item, $itemValue = null): bool
private function checkKeyContains(string $key, mixed $item, mixed $itemValue = null): bool
{
$result = null;

Expand Down Expand Up @@ -635,7 +632,7 @@ private function checkKeyContains(string $key, $item, $itemValue = null): bool
* @param mixed $value Optional. If specified, also checks the key has this
* value. Booleans will be converted to 1 and 0 (even inside arrays)
*/
private function checkKeyExists(string $key, $value): bool
private function checkKeyExists(string $key, mixed $value): bool
{
$type = $this->driver->type($key);

Expand Down Expand Up @@ -718,8 +715,6 @@ private function checkKeyExists(string $key, $value): bool
* Explicitly cast the scores of a Zset associative array as float/double
*
* @param array $arr The ZSet associative array
*
* @return array
*/
private function scoresToFloat(array $arr): array
{
Expand Down

0 comments on commit 9d2d7a3

Please sign in to comment.