8
8
9
9
class UnixServerTest extends TestCase
10
10
{
11
+ /** @var ?UnixServer */
11
12
private $ server ;
13
+
14
+ /** @var ?string */
12
15
private $ uds ;
13
16
14
17
/**
@@ -28,7 +31,10 @@ public function setUpServer()
28
31
29
32
public function testConstructWithoutLoopAssignsLoopAutomatically ()
30
33
{
31
- $ server = new UnixServer ($ this ->getRandomSocketUri ());
34
+ unlink (str_replace ('unix:// ' , '' , $ this ->uds ));
35
+ $ this ->uds = $ this ->getRandomSocketUri ();
36
+
37
+ $ server = new UnixServer ($ this ->uds );
32
38
33
39
$ ref = new \ReflectionProperty ($ server , 'loop ' );
34
40
$ ref ->setAccessible (true );
@@ -45,9 +51,11 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
45
51
public function testConnection ()
46
52
{
47
53
$ client = stream_socket_client ($ this ->uds );
54
+ assert (is_resource ($ client ));
48
55
49
56
$ this ->server ->on ('connection ' , $ this ->expectCallableOnce ());
50
57
$ this ->tick ();
58
+ $ this ->tick ();
51
59
}
52
60
53
61
/**
@@ -56,8 +64,11 @@ public function testConnection()
56
64
public function testConnectionWithManyClients ()
57
65
{
58
66
$ client1 = stream_socket_client ($ this ->uds );
67
+ assert (is_resource ($ client1 ));
59
68
$ client2 = stream_socket_client ($ this ->uds );
69
+ assert (is_resource ($ client2 ));
60
70
$ client3 = stream_socket_client ($ this ->uds );
71
+ assert (is_resource ($ client3 ));
61
72
62
73
$ this ->server ->on ('connection ' , $ this ->expectCallableExactly (3 ));
63
74
$ this ->tick ();
@@ -68,6 +79,7 @@ public function testConnectionWithManyClients()
68
79
public function testDataEventWillNotBeEmittedWhenClientSendsNoData ()
69
80
{
70
81
$ client = stream_socket_client ($ this ->uds );
82
+ assert (is_resource ($ client ));
71
83
72
84
$ mock = $ this ->expectCallableNever ();
73
85
@@ -81,6 +93,7 @@ public function testDataEventWillNotBeEmittedWhenClientSendsNoData()
81
93
public function testDataWillBeEmittedWithDataClientSends ()
82
94
{
83
95
$ client = stream_socket_client ($ this ->uds );
96
+ assert (is_resource ($ client ));
84
97
85
98
fwrite ($ client , "foo \n" );
86
99
@@ -138,6 +151,7 @@ public function testGetAddressAfterCloseReturnsNull()
138
151
public function testLoopWillEndWhenServerIsClosedAfterSingleConnection ()
139
152
{
140
153
$ client = stream_socket_client ($ this ->uds );
154
+ assert (is_resource ($ client ));
141
155
142
156
// explicitly unset server because we only accept a single connection
143
157
// and then already call close()
@@ -191,6 +205,7 @@ public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmo
191
205
public function testConnectionDoesNotEndWhenClientDoesNotClose ()
192
206
{
193
207
$ client = stream_socket_client ($ this ->uds );
208
+ assert (is_resource ($ client ));
194
209
195
210
$ mock = $ this ->expectCallableNever ();
196
211
@@ -221,10 +236,13 @@ public function testConnectionDoesEndWhenClientCloses()
221
236
222
237
public function testCtorAddsResourceToLoop ()
223
238
{
239
+ unlink (str_replace ('unix:// ' , '' , $ this ->uds ));
240
+ $ this ->uds = $ this ->getRandomSocketUri ();
241
+
224
242
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
225
243
$ loop ->expects ($ this ->once ())->method ('addReadStream ' );
226
244
227
- $ server = new UnixServer ($ this ->getRandomSocketUri () , $ loop );
245
+ new UnixServer ($ this ->uds , $ loop );
228
246
}
229
247
230
248
public function testCtorThrowsForInvalidAddressScheme ()
@@ -264,51 +282,66 @@ public function testCtorThrowsWhenPathIsNotWritableWithoutCallingCustomErrorHand
264
282
265
283
public function testResumeWithoutPauseIsNoOp ()
266
284
{
285
+ unlink (str_replace ('unix:// ' , '' , $ this ->uds ));
286
+ $ this ->uds = $ this ->getRandomSocketUri ();
287
+
267
288
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
268
289
$ loop ->expects ($ this ->once ())->method ('addReadStream ' );
269
290
270
- $ server = new UnixServer ($ this ->getRandomSocketUri () , $ loop );
291
+ $ server = new UnixServer ($ this ->uds , $ loop );
271
292
$ server ->resume ();
272
293
}
273
294
274
295
public function testPauseRemovesResourceFromLoop ()
275
296
{
297
+ unlink (str_replace ('unix:// ' , '' , $ this ->uds ));
298
+ $ this ->uds = $ this ->getRandomSocketUri ();
299
+
276
300
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
277
301
$ loop ->expects ($ this ->once ())->method ('removeReadStream ' );
278
302
279
- $ server = new UnixServer ($ this ->getRandomSocketUri () , $ loop );
303
+ $ server = new UnixServer ($ this ->uds , $ loop );
280
304
$ server ->pause ();
281
305
}
282
306
283
307
public function testPauseAfterPauseIsNoOp ()
284
308
{
309
+ unlink (str_replace ('unix:// ' , '' , $ this ->uds ));
310
+ $ this ->uds = $ this ->getRandomSocketUri ();
311
+
285
312
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
286
313
$ loop ->expects ($ this ->once ())->method ('removeReadStream ' );
287
314
288
- $ server = new UnixServer ($ this ->getRandomSocketUri () , $ loop );
315
+ $ server = new UnixServer ($ this ->uds , $ loop );
289
316
$ server ->pause ();
290
317
$ server ->pause ();
291
318
}
292
319
293
320
public function testCloseRemovesResourceFromLoop ()
294
321
{
322
+ unlink (str_replace ('unix:// ' , '' , $ this ->uds ));
323
+ $ this ->uds = $ this ->getRandomSocketUri ();
324
+
295
325
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
296
326
$ loop ->expects ($ this ->once ())->method ('removeReadStream ' );
297
327
298
- $ server = new UnixServer ($ this ->getRandomSocketUri () , $ loop );
328
+ $ server = new UnixServer ($ this ->uds , $ loop );
299
329
$ server ->close ();
300
330
}
301
331
302
332
public function testEmitsErrorWhenAcceptListenerFailsWithoutCallingCustomErrorHandler ()
303
333
{
334
+ unlink (str_replace ('unix:// ' , '' , $ this ->uds ));
335
+ $ this ->uds = $ this ->getRandomSocketUri ();
336
+
304
337
$ listener = null ;
305
338
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
306
339
$ loop ->expects ($ this ->once ())->method ('addReadStream ' )->with ($ this ->anything (), $ this ->callback (function ($ cb ) use (&$ listener ) {
307
340
$ listener = $ cb ;
308
341
return true ;
309
342
}));
310
343
311
- $ server = new UnixServer ($ this ->getRandomSocketUri () , $ loop );
344
+ $ server = new UnixServer ($ this ->uds , $ loop );
312
345
313
346
$ exception = null ;
314
347
$ server ->on ('error ' , function ($ e ) use (&$ exception ) {
@@ -361,7 +394,7 @@ public function testListenOnBusyPortThrows()
361
394
}
362
395
363
396
$ this ->setExpectedException ('RuntimeException ' );
364
- $ another = new UnixServer ($ this ->uds );
397
+ new UnixServer ($ this ->uds );
365
398
}
366
399
367
400
/**
@@ -372,7 +405,11 @@ public function tearDownServer()
372
405
{
373
406
if ($ this ->server ) {
374
407
$ this ->server ->close ();
408
+ $ this ->server = null ;
375
409
}
410
+
411
+ assert (is_string ($ this ->uds ));
412
+ unlink (str_replace ('unix:// ' , '' , $ this ->uds ));
376
413
}
377
414
378
415
private function getRandomSocketUri ()
0 commit comments