8
8
use PHPUnit \Framework \TestCase ;
9
9
use Redis ;
10
10
11
+ if (PHP_MAJOR_VERSION >= 8 ) {
12
+ trait RedisTestTrait
13
+ {
14
+ public function eval ($ script , $ args = [], $ numKeys = 0 ): mixed
15
+ {
16
+ return $ this ->_eval ($ script , $ args , $ numKeys );
17
+ }
18
+
19
+ public function set ($ key , $ value , $ options = null ): /* Redis|string| */ bool
20
+ {
21
+ return $ this ->_set ($ key , $ value , $ options );
22
+ }
23
+ }
24
+ } else {
25
+ trait RedisTestTrait
26
+ {
27
+ /**
28
+ * @return mixed
29
+ */
30
+ public function eval ($ script , $ args = [], $ numKeys = 0 )
31
+ {
32
+ return $ this ->_eval ($ script , $ args , $ numKeys );
33
+ }
34
+
35
+ /**
36
+ * @return Redis|string|bool
37
+ */
38
+ public function set ($ key , $ value , $ options = null )
39
+ {
40
+ return $ this ->_set ($ key , $ value , $ options );
41
+ }
42
+ }
43
+ }
44
+
11
45
/**
12
46
* Tests for PHPRedisMutex.
13
47
*
@@ -41,17 +75,19 @@ protected function setUp(): void
41
75
42
76
// original Redis::set and Redis::eval calls will reopen the connection
43
77
$ connection = new class extends Redis {
78
+ use RedisTestTrait;
79
+
44
80
private $ is_closed = false ;
45
81
46
- public function close ()
82
+ public function close (): bool
47
83
{
48
84
$ res = parent ::close ();
49
85
$ this ->is_closed = true ;
50
86
51
87
return $ res ;
52
88
}
53
89
54
- public function set ($ key , $ value , $ timeout = 0 )
90
+ private function _set ($ key , $ value , $ timeout = 0 )
55
91
{
56
92
if ($ this ->is_closed ) {
57
93
throw new \RedisException ('Connection is closed ' );
@@ -60,7 +96,7 @@ public function set($key, $value, $timeout = 0)
60
96
return parent ::set ($ key , $ value , $ timeout );
61
97
}
62
98
63
- public function eval ($ script , $ args = [], $ numKeys = 0 )
99
+ private function _eval ($ script , $ args = [], $ numKeys = 0 )
64
100
{
65
101
if ($ this ->is_closed ) {
66
102
throw new \RedisException ('Connection is closed ' );
0 commit comments