@@ -30,11 +30,10 @@ public function testPing()
30
30
31
31
$ promise = $ client ->ping ();
32
32
$ this ->assertInstanceOf ('React\Promise\PromiseInterface ' , $ promise );
33
- $ promise ->then ($ this ->expectCallableOnce ('PONG ' ));
34
33
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 );
38
37
39
38
return $ client ;
40
39
}
@@ -45,10 +44,10 @@ public function testMgetIsNotInterpretedAsSubMessage()
45
44
46
45
$ client ->mset ('message ' , 'message ' , 'channel ' , 'channel ' , 'payload ' , 'payload ' );
47
46
48
- $ client ->mget ('message ' , 'channel ' , 'payload ' )->then ($ this ->expectCallableOnce ());
47
+ $ promise = $ client ->mget ('message ' , 'channel ' , 'payload ' )->then ($ this ->expectCallableOnce ());
49
48
$ client ->on ('message ' , $ this ->expectCallableNever ());
50
49
51
- $ this ->waitFor ( $ client );
50
+ Block \await ( $ promise , $ this ->loop );
52
51
}
53
52
54
53
public function testPipeline ()
@@ -58,26 +57,25 @@ public function testPipeline()
58
57
$ client ->set ('a ' , 1 )->then ($ this ->expectCallableOnce ('OK ' ));
59
58
$ client ->incr ('a ' )->then ($ this ->expectCallableOnce (2 ));
60
59
$ 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 ' ));
64
61
65
- $ this ->waitFor ( $ client );
62
+ Block \await ( $ promise , $ this ->loop );
66
63
}
67
64
68
65
public function testInvalidCommand ()
69
66
{
70
- $ this ->client ->doesnotexist (1 , 2 , 3 )-> then ( $ this -> expectCallableNever () );
67
+ $ promise = $ this ->client ->doesnotexist (1 , 2 , 3 );
71
68
72
- $ this ->waitFor ($ this ->client );
69
+ $ this ->setExpectedException ('Exception ' );
70
+ Block \await ($ promise , $ this ->loop );
73
71
}
74
72
75
73
public function testMultiExecEmpty ()
76
74
{
77
75
$ this ->client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
78
- $ this ->client ->exec ()->then ($ this ->expectCallableOnce (array ()));
76
+ $ promise = $ this ->client ->exec ()->then ($ this ->expectCallableOnce (array ()));
79
77
80
- $ this -> waitFor ( $ this ->client );
78
+ Block \await ( $ promise , $ this ->loop );
81
79
}
82
80
83
81
public function testMultiExecQueuedExecHasValues ()
@@ -89,9 +87,9 @@ public function testMultiExecQueuedExecHasValues()
89
87
$ client ->expire ('b ' , 20 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
90
88
$ client ->incrBy ('b ' , 2 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
91
89
$ 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 )));
93
91
94
- $ this ->waitFor ( $ client );
92
+ Block \await ( $ promise , $ this ->loop );
95
93
}
96
94
97
95
public function testPubSub ()
@@ -106,11 +104,9 @@ public function testPubSub()
106
104
$ consumer ->on ('message ' , $ this ->expectCallableOnce ());
107
105
$ consumer ->on ('message ' , array ($ deferred , 'resolve ' ));
108
106
$ consumer ->subscribe ($ channel )->then ($ this ->expectCallableOnce ());
109
- $ this ->waitFor ($ consumer );
110
107
111
108
// 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 ));
114
110
115
111
// expect "message" event to take no longer than 0.1s
116
112
Block \await ($ deferred ->promise (), $ this ->loop , 0.1 );
@@ -132,9 +128,10 @@ public function testInvalidProtocol()
132
128
$ client ->on ('error ' , $ this ->expectCallableOnce ());
133
129
$ client ->on ('close ' , $ this ->expectCallableOnce ());
134
130
135
- $ client ->get ('willBeRejectedDueToClosing ' )-> then ( null , $ this -> expectCallableOnce () );
131
+ $ promise = $ client ->get ('willBeRejectedDueToClosing ' );
136
132
137
- $ this ->waitFor ($ client );
133
+ $ this ->setExpectedException ('Exception ' );
134
+ Block \await ($ promise , $ this ->loop );
138
135
}
139
136
140
137
public function testInvalidServerRepliesWithDuplicateMessages ()
@@ -144,9 +141,9 @@ public function testInvalidServerRepliesWithDuplicateMessages()
144
141
$ client ->on ('error ' , $ this ->expectCallableOnce ());
145
142
$ client ->on ('close ' , $ this ->expectCallableOnce ());
146
143
147
- $ client ->set ('a ' , 0 )->then ($ this ->expectCallableOnce ('OK ' ));
144
+ $ promise = $ client ->set ('a ' , 0 )->then ($ this ->expectCallableOnce ('OK ' ));
148
145
149
- $ this ->waitFor ( $ client );
146
+ Block \await ( $ promise , $ this ->loop );
150
147
}
151
148
152
149
/**
@@ -175,13 +172,4 @@ protected function createServer($response)
175
172
$ cmd = 'echo -e " ' . str_replace ("\r\n" , '\r\n ' , $ response ) . '" | nc -lC ' . $ port ;
176
173
177
174
}
178
-
179
- protected function waitFor (StreamingClient $ client )
180
- {
181
- $ this ->assertTrue ($ client ->isBusy ());
182
-
183
- while ($ client ->isBusy ()) {
184
- $ this ->loop ->tick ();
185
- }
186
- }
187
175
}
0 commit comments