88use PHPUnit \Framework \TestCase ;
99use Redis ;
1010
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+
1145/**
1246 * Tests for PHPRedisMutex.
1347 *
@@ -41,17 +75,19 @@ protected function setUp(): void
4175
4276 // original Redis::set and Redis::eval calls will reopen the connection
4377 $ connection = new class extends Redis {
78+ use RedisTestTrait;
79+
4480 private $ is_closed = false ;
4581
46- public function close ()
82+ public function close (): bool
4783 {
4884 $ res = parent ::close ();
4985 $ this ->is_closed = true ;
5086
5187 return $ res ;
5288 }
5389
54- public function set ($ key , $ value , $ timeout = 0 )
90+ private function _set ($ key , $ value , $ timeout = 0 )
5591 {
5692 if ($ this ->is_closed ) {
5793 throw new \RedisException ('Connection is closed ' );
@@ -60,7 +96,7 @@ public function set($key, $value, $timeout = 0)
6096 return parent ::set ($ key , $ value , $ timeout );
6197 }
6298
63- public function eval ($ script , $ args = [], $ numKeys = 0 )
99+ private function _eval ($ script , $ args = [], $ numKeys = 0 )
64100 {
65101 if ($ this ->is_closed ) {
66102 throw new \RedisException ('Connection is closed ' );
0 commit comments