@@ -94,8 +94,7 @@ public function testCreateClientTcp4UnboundFails()
9494 {
9595 try {
9696 $ this ->factory ->createClient ('tcp://localhost:2 ' );
97- }
98- catch (Exception $ e ) {
97+ } catch (Exception $ e ) {
9998 if ($ e ->getCode () === SOCKET_ECONNREFUSED ) {
10099 return ;
101100 }
@@ -160,13 +159,18 @@ public function testCreateServerUdp4Random()
160159 */
161160 public function testCreateServerUnix ()
162161 {
163- $ path = '/tmp/randomfactorytests.sock ' ;
162+ if (DIRECTORY_SEPARATOR !== '\\' ) {
163+ $ path = sys_get_temp_dir () . DIRECTORY_SEPARATOR . 'test- ' . md5 (microtime (true )) . '.sock ' ;
164+ } else {
165+ // create test socket in local directory on Windows
166+ $ path = 'test- ' . md5 (microtime (true )) . '.sock ' ;
167+ }
164168
165169 $ socket = $ this ->factory ->createServer ('unix:// ' . $ path );
166170
167171 $ this ->assertInstanceOf ('Socket\Raw\Socket ' , $ socket );
168172
169- unlink ($ path );
173+ $ this -> assertTrue ( unlink ($ path ), ' Unable to remove temporary socket ' . $ path );
170174 }
171175
172176 /**
@@ -179,8 +183,7 @@ public function testCreateServerUnixFailInvalidPath()
179183
180184 try {
181185 $ this ->factory ->createServer ('unix:// ' . $ path );
182- }
183- catch (Exception $ e ) {
186+ } catch (Exception $ e ) {
184187 return ;
185188 }
186189
@@ -192,7 +195,10 @@ public function testCreateServerUnixFailInvalidPath()
192195 */
193196 public function testCreateServerUdg ()
194197 {
195- // skip if not unix
198+ if (DIRECTORY_SEPARATOR === '\\' ) {
199+ // https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
200+ $ this ->markTestSkipped ('Unix datagram sockets not supported on Windows ' );
201+ }
196202
197203 $ path = '/tmp/randomfactorytests.sock ' ;
198204
@@ -207,8 +213,7 @@ public function testCreateServerIcmp4()
207213 {
208214 try {
209215 $ socket = $ this ->factory ->createServer ('icmp://0.0.0.0 ' );
210- }
211- catch (Exception $ e ) {
216+ } catch (Exception $ e ) {
212217 if ($ e ->getCode () === SOCKET_EPERM ) {
213218 // skip if not root
214219 return $ this ->markTestSkipped ('No access to ICMPv4 socket (only root can do so) ' );
@@ -226,8 +231,7 @@ public function testCreateServerIcmp6()
226231 {
227232 try {
228233 $ socket = $ this ->factory ->createServer ('icmp6://[::1] ' );
229- }
230- catch (Exception $ e ) {
234+ } catch (Exception $ e ) {
231235 if ($ e ->getCode () === SOCKET_EPERM ) {
232236 // skip if not root
233237 return $ this ->markTestSkipped ('No access to ICMPv6 socket (only root can do so) ' );
@@ -287,6 +291,11 @@ public function testCreateUnix()
287291 */
288292 public function testCreateUdg ()
289293 {
294+ if (DIRECTORY_SEPARATOR === '\\' ) {
295+ // https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
296+ $ this ->markTestSkipped ('Unix datagram sockets not supported on Windows ' );
297+ }
298+
290299 $ socket = $ this ->factory ->createUdg ();
291300
292301 $ this ->assertInstanceOf ('Socket\Raw\Socket ' , $ socket );
@@ -296,8 +305,7 @@ public function testCreateIcmp4()
296305 {
297306 try {
298307 $ socket = $ this ->factory ->createIcmp4 ();
299- }
300- catch (Exception $ e ) {
308+ } catch (Exception $ e ) {
301309 if ($ e ->getCode () === SOCKET_EPERM ) {
302310 // skip if not root
303311 return $ this ->markTestSkipped ('No access to ICMPv4 socket (only root can do so) ' );
@@ -315,8 +323,7 @@ public function testCreateIcmp6()
315323 {
316324 try {
317325 $ socket = $ this ->factory ->createIcmp6 ();
318- }
319- catch (Exception $ e ) {
326+ } catch (Exception $ e ) {
320327 if ($ e ->getCode () === SOCKET_EPERM ) {
321328 // skip if not root
322329 return $ this ->markTestSkipped ('No access to ICMPv6 socket (only root can do so) ' );
@@ -353,8 +360,7 @@ public function testCreateInvalid()
353360 {
354361 try {
355362 $ this ->factory ->create (0 , 1 , 2 );
356- }
357- catch (Exception $ e ) {
363+ } catch (Exception $ e ) {
358364 return ;
359365 }
360366 $ this ->fail ();
@@ -365,6 +371,10 @@ public function testCreateInvalid()
365371 */
366372 public function testCreatePair ()
367373 {
374+ if (DIRECTORY_SEPARATOR === '\\' ) {
375+ $ this ->markTestSkipped ('Unix socket pair not supported on Windows ' );
376+ }
377+
368378 $ sockets = $ this ->factory ->createPair (AF_UNIX , SOCK_STREAM , 0 );
369379
370380 $ this ->assertCount (2 , $ sockets );
@@ -379,8 +389,7 @@ public function testCreatePairInvalid()
379389 {
380390 try {
381391 $ this ->factory ->createPair (0 , 1 , 2 );
382- }
383- catch (Exception $ e ) {
392+ } catch (Exception $ e ) {
384393 return ;
385394 }
386395 $ this ->fail ();
@@ -473,8 +482,7 @@ public function testCreateFromStringInvalid()
473482 $ address = 'invalid://whatever ' ;
474483 try {
475484 $ this ->factory ->createFromString ($ address , $ scheme );
476- }
477- catch (Exception $ e ) {
485+ } catch (Exception $ e ) {
478486 return ;
479487 }
480488 $ this ->fail ('Creating socket for invalid scheme should fail ' );
0 commit comments