@@ -51,7 +51,7 @@ public function testCtorThrowsForInvalidUrl()
5151 new FdServer ('tcp://127.0.0.1:8080 ' , $ loop );
5252 }
5353
54- public function testCtorThrowsForUnknownFd ()
54+ public function testCtorThrowsForUnknownFdWithoutCallingCustomErrorHandler ()
5555 {
5656 if (!is_dir ('/dev/fd ' ) || defined ('HHVM_VERSION ' )) {
5757 $ this ->markTestSkipped ('Not supported on your platform ' );
@@ -62,12 +62,27 @@ public function testCtorThrowsForUnknownFd()
6262 $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
6363 $ loop ->expects ($ this ->never ())->method ('addReadStream ' );
6464
65+ $ error = null ;
66+ set_error_handler (function ($ _ , $ errstr ) use (&$ error ) {
67+ $ error = $ errstr ;
68+ });
69+
6570 $ this ->setExpectedException (
6671 'RuntimeException ' ,
6772 'Failed to listen on FD ' . $ fd . ': ' . (function_exists ('socket_strerror ' ) ? socket_strerror (SOCKET_EBADF ) . ' (EBADF) ' : 'Bad file descriptor ' ),
6873 defined ('SOCKET_EBADF ' ) ? SOCKET_EBADF : 9
6974 );
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+ }
7186 }
7287
7388 public function testCtorThrowsIfFdIsAFileAndNotASocket ()
@@ -319,7 +334,7 @@ public function testServerEmitsConnectionEventForNewConnection()
319334 $ server ->close ();
320335 }
321336
322- public function testEmitsErrorWhenAcceptListenerFails ()
337+ public function testEmitsErrorWhenAcceptListenerFailsWithoutCallingCustomErrorHandler ()
323338 {
324339 if (!is_dir ('/dev/fd ' ) || defined ('HHVM_VERSION ' )) {
325340 $ this ->markTestSkipped ('Not supported on your platform ' );
@@ -346,10 +361,18 @@ public function testEmitsErrorWhenAcceptListenerFails()
346361 $ this ->assertNotNull ($ listener );
347362 $ socket = stream_socket_server ('tcp://127.0.0.1:0 ' );
348363
364+ $ error = null ;
365+ set_error_handler (function ($ _ , $ errstr ) use (&$ error ) {
366+ $ error = $ errstr ;
367+ });
368+
349369 $ time = microtime (true );
350370 $ listener ($ socket );
351371 $ time = microtime (true ) - $ time ;
352372
373+ restore_error_handler ();
374+ $ this ->assertNull ($ error );
375+
353376 $ this ->assertLessThan (1 , $ time );
354377
355378 $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
@@ -362,7 +385,7 @@ public function testEmitsErrorWhenAcceptListenerFails()
362385 /**
363386 * @param \RuntimeException $e
364387 * @requires extension sockets
365- * @depends testEmitsErrorWhenAcceptListenerFails
388+ * @depends testEmitsErrorWhenAcceptListenerFailsWithoutCallingCustomErrorHandler
366389 */
367390 public function testEmitsTimeoutErrorWhenAcceptListenerFails (\RuntimeException $ exception )
368391 {
0 commit comments