33namespace Clue \Tests \React \Redis ;
44
55use Clue \React \Redis \RedisClient ;
6- use React \EventLoop \StreamSelectLoop ;
6+ use React \EventLoop \Loop ;
77use React \Promise \Deferred ;
88use React \Promise \PromiseInterface ;
99use function Clue \React \Block \await ;
10+ use function React \Promise \Timer \timeout ;
1011
1112class FunctionalTest extends TestCase
1213{
13- /** @var StreamSelectLoop */
14- private $ loop ;
1514
1615 /** @var string */
1716 private $ uri ;
@@ -22,30 +21,28 @@ public function setUp(): void
2221 if ($ this ->uri === '' ) {
2322 $ this ->markTestSkipped ('No REDIS_URI environment variable given ' );
2423 }
25-
26- $ this ->loop = new StreamSelectLoop ();
2724 }
2825
2926 public function testPing (): void
3027 {
31- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
28+ $ redis = new RedisClient ($ this ->uri );
3229
3330 $ promise = $ redis ->ping ();
3431 $ this ->assertInstanceOf (PromiseInterface::class, $ promise );
3532
36- $ ret = await ($ promise, $ this -> loop );
33+ $ ret = await ($ promise );
3734
3835 $ this ->assertEquals ('PONG ' , $ ret );
3936 }
4037
4138 public function testPingLazy (): void
4239 {
43- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
40+ $ redis = new RedisClient ($ this ->uri );
4441
4542 $ promise = $ redis ->ping ();
4643 $ this ->assertInstanceOf (PromiseInterface::class, $ promise );
4744
48- $ ret = await ($ promise, $ this -> loop );
45+ $ ret = await ($ promise );
4946
5047 $ this ->assertEquals ('PONG ' , $ ret );
5148 }
@@ -55,70 +52,70 @@ public function testPingLazy(): void
5552 */
5653 public function testPingLazyWillNotBlockLoop (): void
5754 {
58- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
55+ $ redis = new RedisClient ($ this ->uri );
5956
6057 $ redis ->ping ();
6158
62- $ this -> loop -> run ();
59+ Loop:: run ();
6360 }
6461
6562 /**
6663 * @doesNotPerformAssertions
6764 */
6865 public function testLazyClientWithoutCommandsWillNotBlockLoop (): void
6966 {
70- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
67+ $ redis = new RedisClient ($ this ->uri );
7168
72- $ this -> loop -> run ();
69+ Loop:: run ();
7370
7471 unset($ redis );
7572 }
7673
7774 public function testMgetIsNotInterpretedAsSubMessage (): void
7875 {
79- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
76+ $ redis = new RedisClient ($ this ->uri );
8077
8178 $ redis ->mset ('message ' , 'message ' , 'channel ' , 'channel ' , 'payload ' , 'payload ' );
8279
8380 $ promise = $ redis ->mget ('message ' , 'channel ' , 'payload ' )->then ($ this ->expectCallableOnce ());
8481 $ redis ->on ('message ' , $ this ->expectCallableNever ());
8582
86- await ($ promise, $ this -> loop );
83+ await ($ promise );
8784 }
8885
8986 public function testPipeline (): void
9087 {
91- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
88+ $ redis = new RedisClient ($ this ->uri );
9289
9390 $ redis ->set ('a ' , 1 )->then ($ this ->expectCallableOnceWith ('OK ' ));
9491 $ redis ->incr ('a ' )->then ($ this ->expectCallableOnceWith (2 ));
9592 $ redis ->incr ('a ' )->then ($ this ->expectCallableOnceWith (3 ));
9693 $ promise = $ redis ->get ('a ' )->then ($ this ->expectCallableOnceWith ('3 ' ));
9794
98- await ($ promise, $ this -> loop );
95+ await ($ promise );
9996 }
10097
10198 public function testInvalidCommand (): void
10299 {
103- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
100+ $ redis = new RedisClient ($ this ->uri );
104101 $ promise = $ redis ->doesnotexist (1 , 2 , 3 );
105102
106103 $ this ->expectException (\Exception::class);
107- await ($ promise, $ this -> loop );
104+ await ($ promise );
108105 }
109106
110107 public function testMultiExecEmpty (): void
111108 {
112- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
109+ $ redis = new RedisClient ($ this ->uri );
113110 $ redis ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
114111 $ promise = $ redis ->exec ()->then ($ this ->expectCallableOnceWith ([]));
115112
116- await ($ promise, $ this -> loop );
113+ await ($ promise );
117114 }
118115
119116 public function testMultiExecQueuedExecHasValues (): void
120117 {
121- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
118+ $ redis = new RedisClient ($ this ->uri );
122119
123120 $ redis ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
124121 $ redis ->set ('b ' , 10 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
@@ -127,13 +124,13 @@ public function testMultiExecQueuedExecHasValues(): void
127124 $ redis ->ttl ('b ' )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
128125 $ promise = $ redis ->exec ()->then ($ this ->expectCallableOnceWith (['OK ' , 1 , 12 , 20 ]));
129126
130- await ($ promise, $ this -> loop );
127+ await ($ promise );
131128 }
132129
133130 public function testPubSub (): void
134131 {
135- $ consumer = new RedisClient ($ this ->uri , null , $ this -> loop );
136- $ producer = new RedisClient ($ this ->uri , null , $ this -> loop );
132+ $ consumer = new RedisClient ($ this ->uri );
133+ $ producer = new RedisClient ($ this ->uri );
137134
138135 $ channel = 'channel:test: ' . mt_rand ();
139136
@@ -148,12 +145,15 @@ public function testPubSub(): void
148145 })->then ($ this ->expectCallableOnce ());
149146
150147 // expect "message" event to take no longer than 0.1s
151- await ($ deferred ->promise (), $ this ->loop , 0.1 );
148+
149+ await (timeout ($ deferred ->promise (), 0.1 ));
150+
151+ await ($ consumer ->unsubscribe ($ channel ));
152152 }
153153
154154 public function testClose (): void
155155 {
156- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
156+ $ redis = new RedisClient ($ this ->uri );
157157
158158 $ redis ->get ('willBeCanceledAnyway ' )->then (null , $ this ->expectCallableOnce ());
159159
0 commit comments