Skip to content

Commit cc04c3d

Browse files
authored
Update codebase to PHP 7.4 (#11)
1 parent eb68a80 commit cc04c3d

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
php: [7.1, 7.2, 7.3, 7.4, 8.0]
17+
php: [7.4, 8.0, 8.1]
1818

1919
steps:
2020
- name: Checkout code

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"minimum-stability": "RC",
1717
"require": {
18-
"php": "^7.1 || ^8.0",
18+
"php": "^7.4 || ^8.0",
1919
"codeception/codeception": "^4.0",
2020
"predis/predis": "^1.0"
2121
},
@@ -26,5 +26,8 @@
2626
},
2727
"config": {
2828
"classmap-authoritative": true
29+
},
30+
"require-dev": {
31+
"codeception/stub": "^3.7"
2932
}
3033
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Redis module for Codeception
99

1010
## Requirements
1111

12-
* `PHP 7.1` or higher.
12+
* `PHP 7.4` or higher.
1313

1414
## Installation
1515

src/Codeception/Module/Redis.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ class Redis extends Module implements RequiresPackage
7676

7777
/**
7878
* The Redis driver
79-
*
80-
* @var RedisDriver
8179
*/
82-
public $driver;
80+
public ?RedisDriver $driver = null;
8381

84-
public function _requires()
82+
public function _requires(): array
8583
{
8684
return [\Predis\Client::class => '"predis/predis": "^1.0"'];
8785
}
@@ -95,10 +93,10 @@ public function _initialize()
9593
{
9694
try {
9795
$this->driver = new RedisDriver($this->config);
98-
} catch (Exception $e) {
96+
} catch (Exception $exception) {
9997
throw new ModuleException(
10098
__CLASS__,
101-
$e->getMessage()
99+
$exception->getMessage()
102100
);
103101
}
104102
}
@@ -205,10 +203,11 @@ public function grabFromRedis(string $key)
205203
} else {
206204
$reply = $this->driver->lrange(
207205
$key,
208-
isset($args[1]) ? $args[1] : 0,
209-
isset($args[2]) ? $args[2] : -1
206+
$args[1] ?? 0,
207+
$args[2] ?? -1
210208
);
211209
}
210+
212211
break;
213212

214213
case 'set':
@@ -222,10 +221,11 @@ public function grabFromRedis(string $key)
222221
'The method grabFromRedis(), when used with sorted sets, expects either one argument or three'
223222
);
224223
}
224+
225225
$reply = $this->driver->zrange(
226226
$key,
227227
isset($args[2]) ? $args[1] : 0,
228-
isset($args[2]) ? $args[2] : -1,
228+
$args[2] ?? -1,
229229
'WITHSCORES'
230230
);
231231
break;
@@ -287,6 +287,7 @@ public function haveInRedis(string $type, string $key, $value): void
287287
'If second argument of haveInRedis() method is "string", third argument must be a scalar'
288288
);
289289
}
290+
290291
$this->driver->set($key, $value);
291292
break;
292293

@@ -305,6 +306,7 @@ public function haveInRedis(string $type, string $key, $value): void
305306
'If second argument of haveInRedis() method is "zset", third argument must be an (associative) array'
306307
);
307308
}
309+
308310
$this->driver->zadd($key, $value);
309311
break;
310312

@@ -315,6 +317,7 @@ public function haveInRedis(string $type, string $key, $value): void
315317
'If second argument of haveInRedis() method is "hash", third argument must be an array'
316318
);
317319
}
320+
318321
$this->driver->hmset($key, $value);
319322
break;
320323

@@ -467,7 +470,6 @@ public function seeInRedis(string $key, $value = null): void
467470
* ```
468471
*
469472
* @param string $command The command name
470-
*
471473
* @return mixed
472474
*/
473475
public function sendCommandToRedis(string $command)
@@ -528,7 +530,6 @@ public function seeRedisKeyContains(string $key, $item, $itemValue = null): void
528530
* Converts boolean values to "0" and "1"
529531
*
530532
* @param mixed $var The variable
531-
*
532533
* @return mixed
533534
*/
534535
private function boolToString($var)
@@ -569,7 +570,7 @@ private function checkKeyContains(string $key, $item, $itemValue = null): bool
569570
switch ($this->driver->type($key)) {
570571
case 'string':
571572
$reply = $this->driver->get($key);
572-
$result = strpos($reply, $item) !== false;
573+
$result = strpos($reply, (string) $item) !== false;
573574
break;
574575

575576
case 'list':
@@ -591,6 +592,7 @@ private function checkKeyContains(string $key, $item, $itemValue = null): bool
591592
} else {
592593
$result = true;
593594
}
595+
594596
break;
595597

596598
case 'hash':

tests/unit/Codeception/Module/RedisTest.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,21 @@
66
use Codeception\Lib\ModuleContainer;
77
use Codeception\Module\Redis;
88
use Codeception\Test\Unit;
9-
use Codeception\Util\Stub;
9+
use Codeception\Stub;
10+
use PHPUnit\Framework\AssertionFailedError;
1011

1112
final class RedisTest extends Unit
1213
{
13-
/**
14-
* @var array
15-
*/
16-
protected static $config = [
14+
protected static array $config = [
1715
'database' => 15
1816
];
1917

20-
/**
21-
* @var Redis
22-
*/
23-
protected $module;
18+
protected ?Redis $module = null;
2419

2520
/**
2621
* Keys that will be created for the tests
27-
*
28-
* @var array
2922
*/
30-
protected static $keys = [
23+
protected static array $keys = [
3124
'string' => [
3225
'name' => 'test:string',
3326
'value' => 'hello'
@@ -60,6 +53,7 @@ protected function _setUp()
6053
if (!class_exists(\Predis\Client::class)) {
6154
$this->markTestSkipped('Predis is not installed');
6255
}
56+
6357
/** @var ModuleContainer $container */
6458
$container = Stub::make(ModuleContainer::class);
6559

@@ -69,8 +63,8 @@ protected function _setUp()
6963
$this->module->_initialize();
7064

7165
$this->module->driver->flushDb();
72-
} catch (Predis\Connection\ConnectionException $e) {
73-
$this->markTestSkipped($e->getMessage());
66+
} catch (Predis\Connection\ConnectionException $exception) {
67+
$this->markTestSkipped($exception->getMessage());
7468
}
7569

7670
$addMethods = [
@@ -96,7 +90,7 @@ protected function _setUp()
9690
protected function shouldFail($exceptionClass = null)
9791
{
9892
if (!$exceptionClass) {
99-
$exceptionClass = \PHPUnit\Framework\AssertionFailedError::class;
93+
$exceptionClass = AssertionFailedError::class;
10094
}
10195

10296
$this->expectException($exceptionClass);
@@ -1354,8 +1348,6 @@ public function testSendCommandToRedis()
13541348
* Explicitely cast the scores of a Zset associative array as float/double
13551349
*
13561350
* @param array $arr The ZSet associative array
1357-
*
1358-
* @return array
13591351
*/
13601352
private function scoresToFloat(array $arr): array
13611353
{

0 commit comments

Comments
 (0)