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 ;
9- use function Clue \React \Block \await ;
9+ use function React \Async \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
30+ /** @var PromiseInterface<string> */
3331 $ promise = $ redis ->ping ();
34- $ 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
42+ /** @var PromiseInterface<string> */
4543 $ promise = $ redis ->ping ();
46- $ this ->assertInstanceOf (PromiseInterface::class, $ promise );
4744
48- $ ret = await ($ promise, $ this -> loop );
45+ $ ret = await ($ promise );
4946
5047 $ this ->assertEquals ('PONG ' , $ ret );
5148 }
@@ -55,89 +52,99 @@ 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
80+ /** @var PromiseInterface<never> */
8381 $ promise = $ redis ->mget ('message ' , 'channel ' , 'payload ' )->then ($ this ->expectCallableOnce ());
8482 $ redis ->on ('message ' , $ this ->expectCallableNever ());
8583
86- await ($ promise, $ this -> loop );
84+ await ($ promise );
8785 }
8886
8987 public function testPipeline (): void
9088 {
91- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
89+ $ redis = new RedisClient ($ this ->uri );
9290
9391 $ redis ->set ('a ' , 1 )->then ($ this ->expectCallableOnceWith ('OK ' ));
9492 $ redis ->incr ('a ' )->then ($ this ->expectCallableOnceWith (2 ));
9593 $ redis ->incr ('a ' )->then ($ this ->expectCallableOnceWith (3 ));
94+
95+ /** @var PromiseInterface<void> */
9696 $ promise = $ redis ->get ('a ' )->then ($ this ->expectCallableOnceWith ('3 ' ));
9797
98- await ($ promise, $ this -> loop );
98+ await ($ promise );
9999 }
100100
101101 public function testInvalidCommand (): void
102102 {
103- $ redis = new RedisClient ($ this ->uri , null , $ this ->loop );
103+ $ redis = new RedisClient ($ this ->uri );
104+
105+ /** @var PromiseInterface<never> */
104106 $ promise = $ redis ->doesnotexist (1 , 2 , 3 );
105107
106108 $ this ->expectException (\Exception::class);
107- await ($ promise, $ this -> loop );
109+ await ($ promise );
108110 }
109111
110112 public function testMultiExecEmpty (): void
111113 {
112- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
114+ $ redis = new RedisClient ($ this ->uri );
113115 $ redis ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
116+
117+ /** @var PromiseInterface<void> */
114118 $ promise = $ redis ->exec ()->then ($ this ->expectCallableOnceWith ([]));
115119
116- await ($ promise, $ this -> loop );
120+ await ($ promise );
117121 }
118122
119123 public function testMultiExecQueuedExecHasValues (): void
120124 {
121- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
125+ $ redis = new RedisClient ($ this ->uri );
122126
123127 $ redis ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
124128 $ redis ->set ('b ' , 10 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
125129 $ redis ->expire ('b ' , 20 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
126130 $ redis ->incrBy ('b ' , 2 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
127131 $ redis ->ttl ('b ' )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
132+
133+ /** @var PromiseInterface<void> */
128134 $ promise = $ redis ->exec ()->then ($ this ->expectCallableOnceWith (['OK ' , 1 , 12 , 20 ]));
129135
130- await ($ promise, $ this -> loop );
136+ await ($ promise );
131137 }
132138
133139 public function testPubSub (): void
134140 {
135- $ consumer = new RedisClient ($ this ->uri , null , $ this -> loop );
136- $ producer = new RedisClient ($ this ->uri , null , $ this -> loop );
141+ $ consumer = new RedisClient ($ this ->uri );
142+ $ producer = new RedisClient ($ this ->uri );
137143
138144 $ channel = 'channel:test: ' . mt_rand ();
139145
140146 // consumer receives a single message
147+ /** @var Deferred<void> */
141148 $ deferred = new Deferred ();
142149 $ consumer ->on ('message ' , $ this ->expectCallableOnce ());
143150 $ consumer ->on ('message ' , [$ deferred , 'resolve ' ]);
@@ -148,12 +155,17 @@ public function testPubSub(): void
148155 })->then ($ this ->expectCallableOnce ());
149156
150157 // expect "message" event to take no longer than 0.1s
151- await ($ deferred ->promise (), $ this ->loop , 0.1 );
158+
159+ await (timeout ($ deferred ->promise (), 0.1 ));
160+
161+ /** @var PromiseInterface<array{0:"unsubscribe",1:string,2:0}> */
162+ $ promise = $ consumer ->unsubscribe ($ channel );
163+ await ($ promise );
152164 }
153165
154166 public function testClose (): void
155167 {
156- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
168+ $ redis = new RedisClient ($ this ->uri );
157169
158170 $ redis ->get ('willBeCanceledAnyway ' )->then (null , $ this ->expectCallableOnce ());
159171
0 commit comments