@@ -51,7 +51,7 @@ public function testCtorThrowsForInvalidUrl()
51
51
new FdServer ('tcp://127.0.0.1:8080 ' , $ loop );
52
52
}
53
53
54
- public function testCtorThrowsForUnknownFd ()
54
+ public function testCtorThrowsForUnknownFdWithoutCallingCustomErrorHandler ()
55
55
{
56
56
if (!is_dir ('/dev/fd ' ) || defined ('HHVM_VERSION ' )) {
57
57
$ this ->markTestSkipped ('Not supported on your platform ' );
@@ -62,12 +62,27 @@ public function testCtorThrowsForUnknownFd()
62
62
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
63
63
$ loop ->expects ($ this ->never ())->method ('addReadStream ' );
64
64
65
+ $ error = null ;
66
+ set_error_handler (function ($ _ , $ errstr ) use (&$ error ) {
67
+ $ error = $ errstr ;
68
+ });
69
+
65
70
$ this ->setExpectedException (
66
71
'RuntimeException ' ,
67
72
'Failed to listen on FD ' . $ fd . ': ' . (function_exists ('socket_strerror ' ) ? socket_strerror (SOCKET_EBADF ) . ' (EBADF) ' : 'Bad file descriptor ' ),
68
73
defined ('SOCKET_EBADF ' ) ? SOCKET_EBADF : 9
69
74
);
70
- new FdServer ($ fd , $ loop );
75
+
76
+ try {
77
+ new FdServer ($ fd , $ loop );
78
+
79
+ restore_error_handler ();
80
+ } catch (\Exception $ e ) {
81
+ restore_error_handler ();
82
+ $ this ->assertNull ($ error );
83
+
84
+ throw $ e ;
85
+ }
71
86
}
72
87
73
88
public function testCtorThrowsIfFdIsAFileAndNotASocket ()
@@ -319,7 +334,7 @@ public function testServerEmitsConnectionEventForNewConnection()
319
334
$ server ->close ();
320
335
}
321
336
322
- public function testEmitsErrorWhenAcceptListenerFails ()
337
+ public function testEmitsErrorWhenAcceptListenerFailsWithoutCallingCustomErrorHandler ()
323
338
{
324
339
if (!is_dir ('/dev/fd ' ) || defined ('HHVM_VERSION ' )) {
325
340
$ this ->markTestSkipped ('Not supported on your platform ' );
@@ -346,10 +361,18 @@ public function testEmitsErrorWhenAcceptListenerFails()
346
361
$ this ->assertNotNull ($ listener );
347
362
$ socket = stream_socket_server ('tcp://127.0.0.1:0 ' );
348
363
364
+ $ error = null ;
365
+ set_error_handler (function ($ _ , $ errstr ) use (&$ error ) {
366
+ $ error = $ errstr ;
367
+ });
368
+
349
369
$ time = microtime (true );
350
370
$ listener ($ socket );
351
371
$ time = microtime (true ) - $ time ;
352
372
373
+ restore_error_handler ();
374
+ $ this ->assertNull ($ error );
375
+
353
376
$ this ->assertLessThan (1 , $ time );
354
377
355
378
$ this ->assertInstanceOf ('RuntimeException ' , $ exception );
@@ -362,7 +385,7 @@ public function testEmitsErrorWhenAcceptListenerFails()
362
385
/**
363
386
* @param \RuntimeException $e
364
387
* @requires extension sockets
365
- * @depends testEmitsErrorWhenAcceptListenerFails
388
+ * @depends testEmitsErrorWhenAcceptListenerFailsWithoutCallingCustomErrorHandler
366
389
*/
367
390
public function testEmitsTimeoutErrorWhenAcceptListenerFails (\RuntimeException $ exception )
368
391
{
0 commit comments