@@ -30,17 +30,45 @@ class PHPRedisMutexTest extends TestCase
3030 * @var PHPRedisMutex The SUT.
3131 */
3232 private $ mutex ;
33-
33+
3434 protected function setUp ()
3535 {
3636 parent ::setUp ();
37-
37+
3838 $ uris = explode (", " , getenv ("REDIS_URIS " ) ?: "redis://localhost " );
3939
4040 foreach ($ uris as $ redisUri ) {
4141 $ uri = parse_url ($ redisUri );
4242
43- $ connection = new Redis ();
43+ // original Redis::set and Redis::eval calls will reopen the connection
44+ $ connection = new class extends Redis
45+ {
46+ private $ is_closed = false ;
47+
48+ public function close ()
49+ {
50+ parent ::close ();
51+ $ this ->is_closed = true ;
52+ }
53+
54+ public function set ($ key , $ value , $ timeout = 0 )
55+ {
56+ if ($ this ->is_closed ) {
57+ throw new \RedisException ('Connection is closed ' );
58+ }
59+
60+ return parent ::set ($ key , $ value , $ timeout );
61+ }
62+
63+ public function eval ($ script , $ args = array (), $ numKeys = 0 )
64+ {
65+ if ($ this ->is_closed ) {
66+ throw new \RedisException ('Connection is closed ' );
67+ }
68+
69+ return parent ::eval ($ script , $ args , $ numKeys );
70+ }
71+ };
4472
4573 if (!empty ($ uri ["port " ])) {
4674 $ connection ->connect ($ uri ["host " ], $ uri ["port " ]);
@@ -65,7 +93,7 @@ private function closeMajorityConnections()
6593 }
6694 }
6795
68- private function closeMinortyConnections ()
96+ private function closeMinorityConnections ()
6997 {
7098 if (count ($ this ->connections ) === 1 ) {
7199 $ this ->markTestSkipped ("Cannot test this with only a single Redis server " );
@@ -120,7 +148,7 @@ public function testSynchronizedWorks($serialization)
120148
121149 public function testResistantToPartialClusterFailuresForAcquiringLock ()
122150 {
123- $ this ->closeMinortyConnections ();
151+ $ this ->closeMinorityConnections ();
124152
125153 $ this ->assertSame ("test " , $ this ->mutex ->synchronized (function (): string {
126154 return "test " ;
@@ -130,7 +158,7 @@ public function testResistantToPartialClusterFailuresForAcquiringLock()
130158 public function testResistantToPartialClusterFailuresForReleasingLock ()
131159 {
132160 $ this ->assertNull ($ this ->mutex ->synchronized (function () {
133- $ this ->closeMinortyConnections ();
161+ $ this ->closeMinorityConnections ();
134162 return null ;
135163 }));
136164 }
0 commit comments