2
2
3
3
namespace React \Tests \Socket ;
4
4
5
- use React \EventLoop \StreamSelectLoop ;
5
+ use Clue \React \Block ;
6
+ use React \EventLoop \Factory ;
6
7
use React \Socket \UnixServer ;
7
8
use React \Stream \DuplexResourceStream ;
8
9
@@ -12,17 +13,12 @@ class UnixServerTest extends TestCase
12
13
private $ server ;
13
14
private $ uds ;
14
15
15
- private function createLoop ()
16
- {
17
- return new StreamSelectLoop ();
18
- }
19
-
20
16
/**
21
17
* @covers React\Socket\UnixServer::__construct
22
18
*/
23
19
public function setUp ()
24
20
{
25
- $ this ->loop = $ this -> createLoop ();
21
+ $ this ->loop = Factory:: create ();
26
22
$ this ->uds = $ this ->getRandomSocketUri ();
27
23
$ this ->server = new UnixServer ($ this ->uds , $ this ->loop );
28
24
}
@@ -43,7 +39,7 @@ public function testConnection()
43
39
$ client = stream_socket_client ($ this ->uds );
44
40
45
41
$ this ->server ->on ('connection ' , $ this ->expectCallableOnce ());
46
- $ this ->loop -> tick ();
42
+ $ this ->tick ();
47
43
}
48
44
49
45
/**
@@ -56,9 +52,9 @@ public function testConnectionWithManyClients()
56
52
$ client3 = stream_socket_client ($ this ->uds );
57
53
58
54
$ this ->server ->on ('connection ' , $ this ->expectCallableExactly (3 ));
59
- $ this ->loop -> tick ();
60
- $ this ->loop -> tick ();
61
- $ this ->loop -> tick ();
55
+ $ this ->tick ();
56
+ $ this ->tick ();
57
+ $ this ->tick ();
62
58
}
63
59
64
60
public function testDataEventWillNotBeEmittedWhenClientSendsNoData ()
@@ -70,8 +66,8 @@ public function testDataEventWillNotBeEmittedWhenClientSendsNoData()
70
66
$ this ->server ->on ('connection ' , function ($ conn ) use ($ mock ) {
71
67
$ conn ->on ('data ' , $ mock );
72
68
});
73
- $ this ->loop -> tick ();
74
- $ this ->loop -> tick ();
69
+ $ this ->tick ();
70
+ $ this ->tick ();
75
71
}
76
72
77
73
public function testDataWillBeEmittedWithDataClientSends ()
@@ -85,8 +81,8 @@ public function testDataWillBeEmittedWithDataClientSends()
85
81
$ this ->server ->on ('connection ' , function ($ conn ) use ($ mock ) {
86
82
$ conn ->on ('data ' , $ mock );
87
83
});
88
- $ this ->loop -> tick ();
89
- $ this ->loop -> tick ();
84
+ $ this ->tick ();
85
+ $ this ->tick ();
90
86
}
91
87
92
88
public function testDataWillBeEmittedEvenWhenClientShutsDownAfterSending ()
@@ -100,8 +96,8 @@ public function testDataWillBeEmittedEvenWhenClientShutsDownAfterSending()
100
96
$ this ->server ->on ('connection ' , function ($ conn ) use ($ mock ) {
101
97
$ conn ->on ('data ' , $ mock );
102
98
});
103
- $ this ->loop -> tick ();
104
- $ this ->loop -> tick ();
99
+ $ this ->tick ();
100
+ $ this ->tick ();
105
101
}
106
102
107
103
public function testLoopWillEndWhenServerIsClosed ()
@@ -184,8 +180,8 @@ public function testConnectionDoesNotEndWhenClientDoesNotClose()
184
180
$ this ->server ->on ('connection ' , function ($ conn ) use ($ mock ) {
185
181
$ conn ->on ('end ' , $ mock );
186
182
});
187
- $ this ->loop -> tick ();
188
- $ this ->loop -> tick ();
183
+ $ this ->tick ();
184
+ $ this ->tick ();
189
185
}
190
186
191
187
/**
@@ -202,8 +198,8 @@ public function testConnectionDoesEndWhenClientCloses()
202
198
$ this ->server ->on ('connection ' , function ($ conn ) use ($ mock ) {
203
199
$ conn ->on ('end ' , $ mock );
204
200
});
205
- $ this ->loop -> tick ();
206
- $ this ->loop -> tick ();
201
+ $ this ->tick ();
202
+ $ this ->tick ();
207
203
}
208
204
209
205
public function testCtorAddsResourceToLoop ()
@@ -304,4 +300,9 @@ private function getRandomSocketUri()
304
300
{
305
301
return "unix:// " . sys_get_temp_dir () . DIRECTORY_SEPARATOR . uniqid (rand (), true ) . '.sock ' ;
306
302
}
303
+
304
+ private function tick ()
305
+ {
306
+ Block \sleep (0 , $ this ->loop );
307
+ }
307
308
}
0 commit comments