@@ -103,21 +103,21 @@ public function connectionToTcpServerShouldFailIfFileDescriptorsAreExceeded()
103103 /** @test */
104104 public function connectionToInvalidNetworkShouldFailWithUnreachableError ()
105105 {
106- if (! defined ( ' SOCKET_ENETUNREACH ' ) || !function_exists ('socket_import_stream ' )) {
107- $ this ->markTestSkipped ('Test requires ext-socket on PHP 5.4+ ' );
106+ if (PHP_OS !== ' Linux ' && !function_exists ('socket_import_stream ' )) {
107+ $ this ->markTestSkipped ('Test requires either Linux or ext-sockets on PHP 5.4+ ' );
108108 }
109109
110+ $ enetunreach = defined ('SOCKET_ENETUNREACH ' ) ? SOCKET_ENETUNREACH : 101 ;
111+
110112 // try to find an unreachable network by trying a couple of private network addresses
111- $ errno = 0 ; $ errstr = '' ;
112- for ($ i = 0 ; $ i < 20 ; ++$ i ) {
113+ $ errno = 0 ;
114+ $ errstr = '' ;
115+ for ($ i = 0 ; $ i < 20 && $ errno !== $ enetunreach ; ++$ i ) {
113116 $ address = 'tcp://192.168. ' . mt_rand (0 , 255 ) . '. ' . mt_rand (1 , 254 ) . ':8123 ' ;
114117 $ client = @stream_socket_client ($ address , $ errno , $ errstr , 0.1 * $ i );
115- if ($ errno === SOCKET_ENETUNREACH ) {
116- break ;
117- }
118118 }
119- if ($ client || $ errno !== SOCKET_ENETUNREACH ) {
120- $ this ->markTestSkipped ('Expected error ' . SOCKET_ENETUNREACH . ' but got ' . $ errno . ' ( ' . $ errstr . ') for ' . $ address );
119+ if ($ client || $ errno !== $ enetunreach ) {
120+ $ this ->markTestSkipped ('Expected error ' . $ enetunreach . ' but got ' . $ errno . ' ( ' . $ errstr . ') for ' . $ address );
121121 }
122122
123123 $ loop = Factory::create ();
@@ -127,8 +127,8 @@ public function connectionToInvalidNetworkShouldFailWithUnreachableError()
127127
128128 $ this ->setExpectedException (
129129 'RuntimeException ' ,
130- 'Connection to ' . $ address . ' failed: ' . socket_strerror ( SOCKET_ENETUNREACH ),
131- SOCKET_ENETUNREACH
130+ 'Connection to ' . $ address . ' failed: ' . ( function_exists ( ' socket_strerror ' ) ? socket_strerror ( $ enetunreach ) : ' Network is unreachable ' ),
131+ $ enetunreach
132132 );
133133 Block \await ($ promise , $ loop , self ::TIMEOUT );
134134 }
0 commit comments