@@ -30,11 +30,10 @@ public function testPing()
3030
3131 $ promise = $ client ->ping ();
3232 $ this ->assertInstanceOf ('React\Promise\PromiseInterface ' , $ promise );
33- $ promise ->then ($ this ->expectCallableOnce ('PONG ' ));
3433
35- $ this -> assertTrue ( $ client -> isBusy () );
36- $ this -> waitFor ( $ client );
37- $ this ->assertFalse ( $ client -> isBusy () );
34+ $ ret = Block \await ( $ promise , $ this -> loop );
35+
36+ $ this ->assertEquals ( ' PONG ' , $ ret );
3837
3938 return $ client ;
4039 }
@@ -45,10 +44,10 @@ public function testMgetIsNotInterpretedAsSubMessage()
4544
4645 $ client ->mset ('message ' , 'message ' , 'channel ' , 'channel ' , 'payload ' , 'payload ' );
4746
48- $ client ->mget ('message ' , 'channel ' , 'payload ' )->then ($ this ->expectCallableOnce ());
47+ $ promise = $ client ->mget ('message ' , 'channel ' , 'payload ' )->then ($ this ->expectCallableOnce ());
4948 $ client ->on ('message ' , $ this ->expectCallableNever ());
5049
51- $ this ->waitFor ( $ client );
50+ Block \await ( $ promise , $ this ->loop );
5251 }
5352
5453 public function testPipeline ()
@@ -58,26 +57,25 @@ public function testPipeline()
5857 $ client ->set ('a ' , 1 )->then ($ this ->expectCallableOnce ('OK ' ));
5958 $ client ->incr ('a ' )->then ($ this ->expectCallableOnce (2 ));
6059 $ client ->incr ('a ' )->then ($ this ->expectCallableOnce (3 ));
61- $ client ->get ('a ' )->then ($ this ->expectCallableOnce ('3 ' ));
62-
63- $ this ->assertTrue ($ client ->isBusy ());
60+ $ promise = $ client ->get ('a ' )->then ($ this ->expectCallableOnce ('3 ' ));
6461
65- $ this ->waitFor ( $ client );
62+ Block \await ( $ promise , $ this ->loop );
6663 }
6764
6865 public function testInvalidCommand ()
6966 {
70- $ this ->client ->doesnotexist (1 , 2 , 3 )-> then ( $ this -> expectCallableNever () );
67+ $ promise = $ this ->client ->doesnotexist (1 , 2 , 3 );
7168
72- $ this ->waitFor ($ this ->client );
69+ $ this ->setExpectedException ('Exception ' );
70+ Block \await ($ promise , $ this ->loop );
7371 }
7472
7573 public function testMultiExecEmpty ()
7674 {
7775 $ this ->client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
78- $ this ->client ->exec ()->then ($ this ->expectCallableOnce (array ()));
76+ $ promise = $ this ->client ->exec ()->then ($ this ->expectCallableOnce (array ()));
7977
80- $ this -> waitFor ( $ this ->client );
78+ Block \await ( $ promise , $ this ->loop );
8179 }
8280
8381 public function testMultiExecQueuedExecHasValues ()
@@ -89,9 +87,9 @@ public function testMultiExecQueuedExecHasValues()
8987 $ client ->expire ('b ' , 20 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
9088 $ client ->incrBy ('b ' , 2 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
9189 $ client ->ttl ('b ' )->then ($ this ->expectCallableOnce ('QUEUED ' ));
92- $ client ->exec ()->then ($ this ->expectCallableOnce (array ('OK ' , 1 , 12 , 20 )));
90+ $ promise = $ client ->exec ()->then ($ this ->expectCallableOnce (array ('OK ' , 1 , 12 , 20 )));
9391
94- $ this ->waitFor ( $ client );
92+ Block \await ( $ promise , $ this ->loop );
9593 }
9694
9795 public function testPubSub ()
@@ -106,11 +104,9 @@ public function testPubSub()
106104 $ consumer ->on ('message ' , $ this ->expectCallableOnce ());
107105 $ consumer ->on ('message ' , array ($ deferred , 'resolve ' ));
108106 $ consumer ->subscribe ($ channel )->then ($ this ->expectCallableOnce ());
109- $ this ->waitFor ($ consumer );
110107
111108 // producer sends a single message
112- $ producer ->publish ($ channel , 'hello world ' )->then ($ this ->expectCallableOnce ());
113- $ this ->waitFor ($ producer );
109+ $ producer ->publish ($ channel , 'hello world ' )->then ($ this ->expectCallableOnce (1 ));
114110
115111 // expect "message" event to take no longer than 0.1s
116112 Block \await ($ deferred ->promise (), $ this ->loop , 0.1 );
@@ -132,9 +128,10 @@ public function testInvalidProtocol()
132128 $ client ->on ('error ' , $ this ->expectCallableOnce ());
133129 $ client ->on ('close ' , $ this ->expectCallableOnce ());
134130
135- $ client ->get ('willBeRejectedDueToClosing ' )-> then ( null , $ this -> expectCallableOnce () );
131+ $ promise = $ client ->get ('willBeRejectedDueToClosing ' );
136132
137- $ this ->waitFor ($ client );
133+ $ this ->setExpectedException ('Exception ' );
134+ Block \await ($ promise , $ this ->loop );
138135 }
139136
140137 public function testInvalidServerRepliesWithDuplicateMessages ()
@@ -144,9 +141,9 @@ public function testInvalidServerRepliesWithDuplicateMessages()
144141 $ client ->on ('error ' , $ this ->expectCallableOnce ());
145142 $ client ->on ('close ' , $ this ->expectCallableOnce ());
146143
147- $ client ->set ('a ' , 0 )->then ($ this ->expectCallableOnce ('OK ' ));
144+ $ promise = $ client ->set ('a ' , 0 )->then ($ this ->expectCallableOnce ('OK ' ));
148145
149- $ this ->waitFor ( $ client );
146+ Block \await ( $ promise , $ this ->loop );
150147 }
151148
152149 /**
@@ -175,13 +172,4 @@ protected function createServer($response)
175172 $ cmd = 'echo -e " ' . str_replace ("\r\n" , '\r\n ' , $ response ) . '" | nc -lC ' . $ port ;
176173
177174 }
178-
179- protected function waitFor (StreamingClient $ client )
180- {
181- $ this ->assertTrue ($ client ->isBusy ());
182-
183- while ($ client ->isBusy ()) {
184- $ this ->loop ->tick ();
185- }
186- }
187175}
0 commit comments