9
9
10
10
class FunctionalTest extends TestCase
11
11
{
12
- protected static $ loop ;
13
- protected static $ factory ;
12
+ private $ loop ;
13
+ private $ factory ;
14
+ private $ client ;
14
15
15
- public static function setUpBeforeClass ()
16
+ public function setUp ()
16
17
{
17
- self ::$ loop = new React \EventLoop \StreamSelectLoop ();
18
- self ::$ factory = new Factory (self ::$ loop );
18
+ $ this ->loop = new React \EventLoop \StreamSelectLoop ();
19
+ $ this ->factory = new Factory ($ this ->loop );
20
+ $ this ->client = $ this ->createClient ();
19
21
}
20
22
21
23
public function testPing ()
22
24
{
23
- $ client = $ this ->createClient () ;
25
+ $ client = $ this ->client ;
24
26
25
27
$ promise = $ client ->ping ();
26
28
$ this ->assertInstanceOf ('React\Promise\PromiseInterface ' , $ promise );
@@ -35,7 +37,7 @@ public function testPing()
35
37
36
38
public function testMgetIsNotInterpretedAsSubMessage ()
37
39
{
38
- $ client = $ this ->createClient () ;
40
+ $ client = $ this ->client ;
39
41
40
42
$ client ->mset ('message ' , 'message ' , 'channel ' , 'channel ' , 'payload ' , 'payload ' );
41
43
@@ -45,14 +47,9 @@ public function testMgetIsNotInterpretedAsSubMessage()
45
47
$ this ->waitFor ($ client );
46
48
}
47
49
48
- /**
49
- *
50
- * @param StreamingClient $client
51
- * @depends testPing
52
- */
53
- public function testPipeline (StreamingClient $ client )
50
+ public function testPipeline ()
54
51
{
55
- $ this ->assertFalse ( $ client-> isBusy ()) ;
52
+ $ client = $ this ->client ;
56
53
57
54
$ client ->set ('a ' , 1 )->then ($ this ->expectCallableOnce ('OK ' ));
58
55
$ client ->incr ('a ' )->then ($ this ->expectCallableOnce (2 ));
@@ -62,46 +59,27 @@ public function testPipeline(StreamingClient $client)
62
59
$ this ->assertTrue ($ client ->isBusy ());
63
60
64
61
$ this ->waitFor ($ client );
65
-
66
- return $ client ;
67
62
}
68
63
69
- /**
70
- *
71
- * @param StreamingClient $client
72
- * @depends testPipeline
73
- */
74
- public function testInvalidCommand (StreamingClient $ client )
64
+ public function testInvalidCommand ()
75
65
{
76
- $ client ->doesnotexist (1 , 2 , 3 )->then ($ this ->expectCallableNever ());
66
+ $ this -> client ->doesnotexist (1 , 2 , 3 )->then ($ this ->expectCallableNever ());
77
67
78
- $ this ->waitFor ($ client );
79
-
80
- return $ client ;
68
+ $ this ->waitFor ($ this ->client );
81
69
}
82
70
83
- /**
84
- *
85
- * @param StreamingClient $client
86
- * @depends testInvalidCommand
87
- */
88
- public function testMultiExecEmpty (StreamingClient $ client )
71
+ public function testMultiExecEmpty ()
89
72
{
90
- $ client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
91
- $ client ->exec ()->then ($ this ->expectCallableOnce (array ()));
73
+ $ this -> client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
74
+ $ this -> client ->exec ()->then ($ this ->expectCallableOnce (array ()));
92
75
93
- $ this ->waitFor ($ client );
94
-
95
- return $ client ;
76
+ $ this ->waitFor ($ this ->client );
96
77
}
97
78
98
- /**
99
- *
100
- * @param StreamingClient $client
101
- * @depends testMultiExecEmpty
102
- */
103
- public function testMultiExecQueuedExecHasValues (StreamingClient $ client )
79
+ public function testMultiExecQueuedExecHasValues ()
104
80
{
81
+ $ client = $ this ->client ;
82
+
105
83
$ client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
106
84
$ client ->set ('b ' , 10 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
107
85
$ client ->expire ('b ' , 20 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
@@ -110,17 +88,12 @@ public function testMultiExecQueuedExecHasValues(StreamingClient $client)
110
88
$ client ->exec ()->then ($ this ->expectCallableOnce (array ('OK ' , 1 , 12 , 20 )));
111
89
112
90
$ this ->waitFor ($ client );
113
-
114
- return $ client ;
115
91
}
116
92
117
- /**
118
- *
119
- * @param StreamingClient $client
120
- * @depends testPipeline
121
- */
122
- public function testMonitorPing (StreamingClient $ client )
93
+ public function testMonitorPing ()
123
94
{
95
+ $ client = $ this ->client ;
96
+
124
97
$ client ->on ('monitor ' , $ this ->expectCallableOnce ());
125
98
126
99
$ client ->monitor ()->then ($ this ->expectCallableOnce ('OK ' ));
@@ -131,7 +104,7 @@ public function testMonitorPing(StreamingClient $client)
131
104
132
105
public function testPubSub ()
133
106
{
134
- $ consumer = $ this ->createClient () ;
107
+ $ consumer = $ this ->client ;
135
108
$ producer = $ this ->createClient ();
136
109
137
110
$ channel = 'channel:test: ' . mt_rand ();
@@ -148,18 +121,16 @@ public function testPubSub()
148
121
$ this ->waitFor ($ producer );
149
122
150
123
// expect "message" event to take no longer than 0.1s
151
- Block \await ($ deferred ->promise (), self :: $ loop , 0.1 );
124
+ Block \await ($ deferred ->promise (), $ this -> loop , 0.1 );
152
125
}
153
126
154
127
public function testClose ()
155
128
{
156
- $ client = $ this ->createClient ();
157
-
158
- $ client ->get ('willBeCanceledAnyway ' )->then (null , $ this ->expectCallableOnce ());
129
+ $ this ->client ->get ('willBeCanceledAnyway ' )->then (null , $ this ->expectCallableOnce ());
159
130
160
- $ client ->close ();
131
+ $ this -> client ->close ();
161
132
162
- $ client ->get ('willBeRejectedRightAway ' )->then (null , $ this ->expectCallableOnce ());
133
+ $ this -> client ->get ('willBeRejectedRightAway ' )->then (null , $ this ->expectCallableOnce ());
163
134
}
164
135
165
136
public function testInvalidProtocol ()
@@ -191,7 +162,7 @@ public function testInvalidServerRepliesWithDuplicateMessages()
191
162
*/
192
163
protected function createClient ()
193
164
{
194
- return Block \await (self :: $ factory ->createClient (), self :: $ loop );
165
+ return Block \await ($ this -> factory ->createClient (), $ this -> loop );
195
166
}
196
167
197
168
protected function createClientResponse ($ response )
@@ -200,7 +171,7 @@ protected function createClientResponse($response)
200
171
fwrite ($ fp , $ response );
201
172
fseek ($ fp , 0 );
202
173
203
- $ stream = new Stream ($ fp , self :: $ loop );
174
+ $ stream = new Stream ($ fp , $ this -> loop );
204
175
205
176
return new StreamingClient ($ stream );
206
177
}
@@ -217,7 +188,7 @@ protected function waitFor(StreamingClient $client)
217
188
$ this ->assertTrue ($ client ->isBusy ());
218
189
219
190
while ($ client ->isBusy ()) {
220
- self :: $ loop ->tick ();
191
+ $ this -> loop ->tick ();
221
192
}
222
193
}
223
194
}
0 commit comments