From 0827c62f196a9d1204d16c823ae0d2683813cb48 Mon Sep 17 00:00:00 2001 From: NickSdot Date: Wed, 19 Aug 2026 13:27:32 +0000 Subject: [PATCH] ext/sockets: applied fixers to improve test robustness --- ext/sockets/tests/gh16267.phpt | 6 +- ext/sockets/tests/gh20532.phpt | 1 - ext/sockets/tests/mcast_ipv4_send_error.phpt | 12 ++-- ext/sockets/tests/mcast_sockettype_error.phpt | 6 +- ext/sockets/tests/socket_addrinfo_lookup.phpt | 6 +- .../tests/socket_bind_invalid_port.phpt | 12 ++-- .../tests/socket_cmsg_udp_segment.phpt | 12 ++-- ext/sockets/tests/socket_connect_params.phpt | 12 ++-- .../socket_create_listen_invalid_port.phpt | 12 ++-- .../tests/socket_create_pair-wrongparams.phpt | 12 ++-- .../tests/socket_create_pair_sockexec.phpt | 18 +++--- ext/sockets/tests/socket_export_stream-2.phpt | 18 +++--- ext/sockets/tests/socket_export_stream-4.phpt | 12 ++-- .../tests/socket_getaddrinfo_error.phpt | 60 +++++++++---------- ext/sockets/tests/socket_import_stream-2.phpt | 12 ++-- ext/sockets/tests/socket_import_stream-4.phpt | 12 ++-- ext/sockets/tests/socket_reuseport_cbpf.phpt | 4 +- .../tests/socket_select-wrongparams-2.phpt | 6 +- ext/sockets/tests/socket_select_error.phpt | 6 +- ext/sockets/tests/socket_send_params.phpt | 6 +- .../tests/socket_sendto_invalid_port.phpt | 12 ++-- ext/sockets/tests/socket_sendto_params.phpt | 6 +- .../socket_sendto_unix_addr_too_long.phpt | 6 +- .../tests/socket_set_block-retval.phpt | 6 +- .../tests/socket_set_nonblock-retval.phpt | 6 +- .../tests/socket_set_option_mcast_error.phpt | 12 ++-- .../tests/socket_set_option_rcvtimeo.phpt | 6 +- .../tests/socket_set_option_seolinger.phpt | 12 ++-- .../tests/socket_set_option_sndtimeo.phpt | 6 +- .../tests/socket_set_option_timeo_error.phpt | 46 +++++++------- ...socket_setoption_tcpusertimeout_64bit.phpt | 12 ++-- 31 files changed, 187 insertions(+), 188 deletions(-) diff --git a/ext/sockets/tests/gh16267.phpt b/ext/sockets/tests/gh16267.phpt index de3e1b657fbc..f6e18148cffa 100644 --- a/ext/sockets/tests/gh16267.phpt +++ b/ext/sockets/tests/gh16267.phpt @@ -9,10 +9,10 @@ sockets var_dump(socket_strerror(-2147483648)); try { socket_strerror(2147483648); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECTF-- string(%d) "%S" -socket_strerror(): Argument #1 ($error_code) must be between %i and %d +ValueError: socket_strerror(): Argument #1 ($error_code) must be between %i and %d diff --git a/ext/sockets/tests/gh20532.phpt b/ext/sockets/tests/gh20532.phpt index 360f9e7e11a8..2bec6953dac4 100644 --- a/ext/sockets/tests/gh20532.phpt +++ b/ext/sockets/tests/gh20532.phpt @@ -13,4 +13,3 @@ var_dump(socket_addrinfo_lookup("example.com", "http", ['ai_socktype' => SOCK_RA bool(true) bool(true) bool(true) - diff --git a/ext/sockets/tests/mcast_ipv4_send_error.phpt b/ext/sockets/tests/mcast_ipv4_send_error.phpt index 94148df1c4cb..c19264f0dcc9 100644 --- a/ext/sockets/tests/mcast_ipv4_send_error.phpt +++ b/ext/sockets/tests/mcast_ipv4_send_error.phpt @@ -42,8 +42,8 @@ echo "Setting IP_MULTICAST_TTL with 256\n"; try { $r = socket_set_option($s, $level, IP_MULTICAST_TTL, 256); var_dump($r); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } $r = socket_get_option($s, $level, IP_MULTICAST_TTL); var_dump($r); @@ -61,8 +61,8 @@ echo "Setting IP_MULTICAST_TTL with -1\n"; try { $r = socket_set_option($s, $level, IP_MULTICAST_TTL, -1); var_dump($r); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } $r = socket_get_option($s, $level, IP_MULTICAST_TTL); var_dump($r); @@ -78,7 +78,7 @@ bool(true) int(0) Setting IP_MULTICAST_TTL with 256 -socket_set_option(): Argument #4 ($value) must be between 0 and 255 +ValueError: socket_set_option(): Argument #4 ($value) must be between 0 and 255 int(1) Setting IP_MULTICAST_TTL with "254" @@ -86,5 +86,5 @@ bool(true) int(254) Setting IP_MULTICAST_TTL with -1 -socket_set_option(): Argument #4 ($value) must be between 0 and 255 +ValueError: socket_set_option(): Argument #4 ($value) must be between 0 and 255 int(254) diff --git a/ext/sockets/tests/mcast_sockettype_error.phpt b/ext/sockets/tests/mcast_sockettype_error.phpt index 56308534ebc4..7747e7435221 100644 --- a/ext/sockets/tests/mcast_sockettype_error.phpt +++ b/ext/sockets/tests/mcast_sockettype_error.phpt @@ -22,9 +22,9 @@ try { "group" => '127.0.0.1', "interface" => "lo", )); -} catch (\ValueError $e) { - echo $e->getMessage(), PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- -IP address used in the context of an unexpected type of socket +ValueError: IP address used in the context of an unexpected type of socket diff --git a/ext/sockets/tests/socket_addrinfo_lookup.phpt b/ext/sockets/tests/socket_addrinfo_lookup.phpt index 42745f36978d..5dfcd809acc2 100644 --- a/ext/sockets/tests/socket_addrinfo_lookup.phpt +++ b/ext/sockets/tests/socket_addrinfo_lookup.phpt @@ -11,9 +11,9 @@ try { 'invalid' => null, )); var_dump($addrinfo[0]); -} catch (\ValueError $e) { - echo $e->getMessage(), \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- -socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family" +ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family" diff --git a/ext/sockets/tests/socket_bind_invalid_port.phpt b/ext/sockets/tests/socket_bind_invalid_port.phpt index b70900f68620..3bf3bd8789ac 100644 --- a/ext/sockets/tests/socket_bind_invalid_port.phpt +++ b/ext/sockets/tests/socket_bind_invalid_port.phpt @@ -8,16 +8,16 @@ sockets try { socket_bind($s_c, '0.0.0.0', -1); - } catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; + } catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_bind($s_c, '0.0.0.0', 65536); - } catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; + } catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- -socket_bind(): Argument #3 ($port) must be between 0 and 65535 -socket_bind(): Argument #3 ($port) must be between 0 and 65535 +ValueError: socket_bind(): Argument #3 ($port) must be between 0 and 65535 +ValueError: socket_bind(): Argument #3 ($port) must be between 0 and 65535 diff --git a/ext/sockets/tests/socket_cmsg_udp_segment.phpt b/ext/sockets/tests/socket_cmsg_udp_segment.phpt index 38a914066510..24e9e731d1dd 100644 --- a/ext/sockets/tests/socket_cmsg_udp_segment.phpt +++ b/ext/sockets/tests/socket_cmsg_udp_segment.phpt @@ -12,15 +12,15 @@ $src = socket_create(AF_UNIX, SOCK_DGRAM, 0); try { socket_setopt($src, SOL_UDP, UDP_SEGMENT, -1); -} catch (\ValueError $e) { - echo $e->getMessage(), PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_setopt($src, SOL_UDP, UDP_SEGMENT, 65536); -} catch (\ValueError $e) { - echo $e->getMessage(), PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- -socket_setopt(): Argument #4 ($value) must be between 0 and 65535 -socket_setopt(): Argument #4 ($value) must be between 0 and 65535 +ValueError: socket_setopt(): Argument #4 ($value) must be between 0 and 65535 +ValueError: socket_setopt(): Argument #4 ($value) must be between 0 and 65535 diff --git a/ext/sockets/tests/socket_connect_params.phpt b/ext/sockets/tests/socket_connect_params.phpt index 683b8e9d919f..6e79bb89df01 100644 --- a/ext/sockets/tests/socket_connect_params.phpt +++ b/ext/sockets/tests/socket_connect_params.phpt @@ -14,20 +14,20 @@ socket_getsockname($s_c, $addr, $port); // wrong parameter count try { socket_connect($s_c); -} catch (\ArgumentCountError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_connect($s_c, '0.0.0.0'); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } $s_w = socket_connect($s_c, '0.0.0.0', $port); socket_close($s_c); ?> --EXPECTF-- -socket_connect() expects at least 2 arguments, 1 given -socket_connect(): Argument #3 ($port) cannot be null when the socket type is AF_INET +ArgumentCountError: socket_connect() expects at least 2 arguments, 1 given +ValueError: socket_connect(): Argument #3 ($port) cannot be null when the socket type is AF_INET Warning: socket_connect(): unable to connect [%i]: %a in %s on line %d diff --git a/ext/sockets/tests/socket_create_listen_invalid_port.phpt b/ext/sockets/tests/socket_create_listen_invalid_port.phpt index 35182139ee6f..8aa577b1de12 100644 --- a/ext/sockets/tests/socket_create_listen_invalid_port.phpt +++ b/ext/sockets/tests/socket_create_listen_invalid_port.phpt @@ -8,17 +8,17 @@ var_dump(socket_create_listen(0)); try { socket_create_listen(-1); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_create_listen(65536); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- object(Socket)#1 (0) { } -socket_create_listen(): Argument #1 ($port) must be between 0 and 65535 -socket_create_listen(): Argument #1 ($port) must be between 0 and 65535 +ValueError: socket_create_listen(): Argument #1 ($port) must be between 0 and 65535 +ValueError: socket_create_listen(): Argument #1 ($port) must be between 0 and 65535 diff --git a/ext/sockets/tests/socket_create_pair-wrongparams.phpt b/ext/sockets/tests/socket_create_pair-wrongparams.phpt index 1d0a6540841d..957828ddfc01 100644 --- a/ext/sockets/tests/socket_create_pair-wrongparams.phpt +++ b/ext/sockets/tests/socket_create_pair-wrongparams.phpt @@ -15,22 +15,22 @@ var_dump(socket_create_pair(AF_INET, 0, 0, $sockets)); try { var_dump(socket_create_pair(31337, 0, 0, $sockets)); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { var_dump(socket_create_pair(AF_INET, 31337, 0, $sockets)); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECTF-- Warning: socket_create_pair(): Unable to create socket pair [%d]: %s %r(not supported|wrong type for socket)%r in %s on line %d bool(false) -socket_create_pair(): Argument #1 ($domain) must be one of AF_UNIX, AF_INET6, or AF_INET -socket_create_pair(): Argument #2 ($type) must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, or SOCK_RDM%A +ValueError: socket_create_pair(): Argument #1 ($domain) must be one of AF_UNIX, AF_INET6, or AF_INET +ValueError: socket_create_pair(): Argument #2 ($type) must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, or SOCK_RDM%A --CREDITS-- Till Klampaeckel, till@php.net Berlin TestFest 2009 diff --git a/ext/sockets/tests/socket_create_pair_sockexec.phpt b/ext/sockets/tests/socket_create_pair_sockexec.phpt index 5e31b1550340..9e4ff0e76fa7 100644 --- a/ext/sockets/tests/socket_create_pair_sockexec.phpt +++ b/ext/sockets/tests/socket_create_pair_sockexec.phpt @@ -12,23 +12,23 @@ if (!defined('SOCK_NONBLOCK')) die("skip SOCK_NONBLOCK"); $sockets = array(); try { socket_create_pair(AF_UNIX, 11 | SOCK_CLOEXEC, 0, $sockets); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_create_pair(AF_UNIX, 11 | SOCK_NONBLOCK, 0, $sockets); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_create_pair(AF_UNIX, 11 | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, $sockets); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } var_dump(socket_create_pair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, $sockets)); ?> --EXPECTF-- -socket_create_pair(): Argument #2 ($type) must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, or SOCK_RDM%A -socket_create_pair(): Argument #2 ($type) must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, or SOCK_RDM%A -socket_create_pair(): Argument #2 ($type) must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, or SOCK_RDM%A +ValueError: socket_create_pair(): Argument #2 ($type) must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, or SOCK_RDM%A +ValueError: socket_create_pair(): Argument #2 ($type) must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, or SOCK_RDM%A +ValueError: socket_create_pair(): Argument #2 ($type) must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RAW, or SOCK_RDM%A bool(true) diff --git a/ext/sockets/tests/socket_export_stream-2.phpt b/ext/sockets/tests/socket_export_stream-2.phpt index 0a83ef485ba8..638b17ed41cd 100644 --- a/ext/sockets/tests/socket_export_stream-2.phpt +++ b/ext/sockets/tests/socket_export_stream-2.phpt @@ -7,13 +7,13 @@ sockets try { socket_export_stream(fopen(__FILE__, "rb")); -} catch (TypeError $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_export_stream(stream_socket_server("udp://127.0.0.1:0", $errno, $errstr, STREAM_SERVER_BIND)); -} catch (TypeError $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); var_dump($s); @@ -21,16 +21,16 @@ socket_close($s); try { var_dump(socket_export_stream($s)); -} catch (Error $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } echo "Done."; ?> --EXPECTF-- -socket_export_stream(): Argument #1 ($socket) must be of type Socket, resource given -socket_export_stream(): Argument #1 ($socket) must be of type Socket, resource given +TypeError: socket_export_stream(): Argument #1 ($socket) must be of type Socket, resource given +TypeError: socket_export_stream(): Argument #1 ($socket) must be of type Socket, resource given object(Socket)#%d (0) { } -socket_export_stream(): Argument #1 ($socket) has already been closed +Error: socket_export_stream(): Argument #1 ($socket) has already been closed Done. diff --git a/ext/sockets/tests/socket_export_stream-4.phpt b/ext/sockets/tests/socket_export_stream-4.phpt index 168671138680..4512ea837b58 100644 --- a/ext/sockets/tests/socket_export_stream-4.phpt +++ b/ext/sockets/tests/socket_export_stream-4.phpt @@ -17,8 +17,8 @@ function test($stream, $sock) { echo "stream_set_blocking "; try { print_r(stream_set_blocking($stream, false)); - } catch (Error $e) { - echo get_class($e), ": ", $e->getMessage(), "\n"; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } echo "\n"; } @@ -26,8 +26,8 @@ function test($stream, $sock) { echo "socket_set_block "; try { print_r(socket_set_block($sock)); - } catch (Error $e) { - echo get_class($e), ": ", $e->getMessage(), "\n"; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } echo "\n"; echo "socket_get_option "; @@ -35,8 +35,8 @@ function test($stream, $sock) { // Solaris uses different numeric values for SOCK_* constants $opt = socket_get_option($sock, SOL_SOCKET, SO_TYPE); print_r($opt === SOCK_DGRAM ? "DGRAM" : $opt); - } catch (Error $e) { - echo get_class($e), ": ", $e->getMessage(), "\n"; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } echo "\n"; } diff --git a/ext/sockets/tests/socket_getaddrinfo_error.phpt b/ext/sockets/tests/socket_getaddrinfo_error.phpt index a2455821e70e..9875e1894d3e 100644 --- a/ext/sockets/tests/socket_getaddrinfo_error.phpt +++ b/ext/sockets/tests/socket_getaddrinfo_error.phpt @@ -11,8 +11,8 @@ try { 'ai_flags' => 0, 'ai_protocol' => 0, )); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, array( @@ -21,8 +21,8 @@ try { 'ai_flags' => 0, 'ai_protocol' => 0, )); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, array( @@ -31,8 +31,8 @@ try { 'ai_flags' => new stdClass(), 'ai_protocol' => 0, )); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, array( @@ -41,8 +41,8 @@ try { 'ai_flags' => 0, 'ai_protocol' => new stdClass(), )); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, array( @@ -51,8 +51,8 @@ try { 'ai_flags' => 0, 'ai_protocol' => 0, )); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, array( @@ -61,8 +61,8 @@ try { 'ai_flags' => 0, 'ai_protocol' => 0, )); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, array( @@ -71,8 +71,8 @@ try { 'ai_flags' => -256, 'ai_protocol' => 0, )); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, array( @@ -81,8 +81,8 @@ try { 'ai_flags' => 0, 'ai_protocol' => PHP_INT_MIN, )); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, [ @@ -91,8 +91,8 @@ try { 0, 0, ]); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_addrinfo_lookup('127.0.0.1', 2000, array( @@ -101,18 +101,18 @@ try { 0, 0, )); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECTF-- -socket_addrinfo_lookup(): Argument #3 ($hints) "ai_family" key must be of type int, stdClass given -socket_addrinfo_lookup(): Argument #3 ($hints) "ai_socktype" key must be of type int, stdClass given -socket_addrinfo_lookup(): Argument #3 ($hints) "ai_flags" key must be of type int, stdClass given -socket_addrinfo_lookup(): Argument #3 ($hints) "ai_protocol" key must be of type int, stdClass given -socket_addrinfo_lookup(): Argument #3 ($hints) "ai_family" key must be AF_INET%A -socket_addrinfo_lookup(): Argument #3 ($hints) "ai_socktype" key must be between 0 and %d -socket_addrinfo_lookup(): Argument #3 ($hints) "ai_flags" key must be between 0 and %d -socket_addrinfo_lookup(): Argument #3 ($hints) "ai_protocol" key must be between 0 and %d -socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family" -socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family" +TypeError: socket_addrinfo_lookup(): Argument #3 ($hints) "ai_family" key must be of type int, stdClass given +TypeError: socket_addrinfo_lookup(): Argument #3 ($hints) "ai_socktype" key must be of type int, stdClass given +TypeError: socket_addrinfo_lookup(): Argument #3 ($hints) "ai_flags" key must be of type int, stdClass given +TypeError: socket_addrinfo_lookup(): Argument #3 ($hints) "ai_protocol" key must be of type int, stdClass given +ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) "ai_family" key must be AF_INET%A +ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) "ai_socktype" key must be between 0 and %d +ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) "ai_flags" key must be between 0 and %d +ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) "ai_protocol" key must be between 0 and %d +ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family" +ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family" diff --git a/ext/sockets/tests/socket_import_stream-2.phpt b/ext/sockets/tests/socket_import_stream-2.phpt index 7d3b492a85e1..271aab935922 100644 --- a/ext/sockets/tests/socket_import_stream-2.phpt +++ b/ext/sockets/tests/socket_import_stream-2.phpt @@ -8,16 +8,16 @@ sockets var_dump(socket_import_stream(fopen(__FILE__, "rb"))); try { socket_import_stream(socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)); -} catch (TypeError $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } $s = stream_socket_server("udp://127.0.0.1:0", $errno, $errstr, STREAM_SERVER_BIND); var_dump($s); var_dump(fclose($s)); try { socket_import_stream($s); -} catch (TypeError $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } echo "Done."; @@ -25,8 +25,8 @@ echo "Done."; --EXPECTF-- Warning: socket_import_stream(): Cannot represent a stream of type STDIO as a Socket Descriptor in %s on line %d bool(false) -socket_import_stream(): Argument #1 ($stream) must be of type resource, Socket given +TypeError: socket_import_stream(): Argument #1 ($stream) must be of type resource, Socket given resource(%d) of type (stream) bool(true) -socket_import_stream(): supplied resource is not a valid stream resource +TypeError: socket_import_stream(): supplied resource is not a valid stream resource Done. diff --git a/ext/sockets/tests/socket_import_stream-4.phpt b/ext/sockets/tests/socket_import_stream-4.phpt index 87ca608b862b..585c18285b6d 100644 --- a/ext/sockets/tests/socket_import_stream-4.phpt +++ b/ext/sockets/tests/socket_import_stream-4.phpt @@ -16,8 +16,8 @@ function test($stream, $sock) { echo "stream_set_blocking "; try { print_r(stream_set_blocking($stream, false)); - } catch (Error $e) { - echo get_class($e), ": ", $e->getMessage(), "\n"; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } echo "\n"; } @@ -25,8 +25,8 @@ function test($stream, $sock) { echo "socket_set_block "; try { print_r(socket_set_block($sock)); - } catch (Error $e) { - echo get_class($e), ": ", $e->getMessage(), "\n"; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } echo "\n"; echo "socket_get_option "; @@ -34,8 +34,8 @@ function test($stream, $sock) { // Solaris uses different numeric values for SOCK_* constants $opt = socket_get_option($sock, SOL_SOCKET, SO_TYPE); print_r($opt === SOCK_DGRAM ? "DGRAM" : $opt); - } catch (Error $e) { - echo get_class($e), ": ", $e->getMessage(), "\n"; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } echo "\n"; } diff --git a/ext/sockets/tests/socket_reuseport_cbpf.phpt b/ext/sockets/tests/socket_reuseport_cbpf.phpt index 2210c4438f00..f3bbb2727372 100644 --- a/ext/sockets/tests/socket_reuseport_cbpf.phpt +++ b/ext/sockets/tests/socket_reuseport_cbpf.phpt @@ -20,8 +20,8 @@ var_dump(socket_set_option( $socket, SOL_SOCKET, SO_REUSEADDR, true)); var_dump(socket_set_option( $socket, SOL_SOCKET, SO_REUSEPORT, true)); try { socket_set_option( $socket, SOL_SOCKET, SO_ATTACH_REUSEPORT_CBPF, array()); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } var_dump(socket_set_option( $socket, SOL_SOCKET, SO_ATTACH_REUSEPORT_CBPF, SKF_AD_CPU)); var_dump(socket_bind($socket, '0.0.0.0')); diff --git a/ext/sockets/tests/socket_select-wrongparams-2.phpt b/ext/sockets/tests/socket_select-wrongparams-2.phpt index f2d3799e7570..0e86e924f019 100644 --- a/ext/sockets/tests/socket_select-wrongparams-2.phpt +++ b/ext/sockets/tests/socket_select-wrongparams-2.phpt @@ -11,12 +11,12 @@ $time = 0; try { socket_select($sockets, $write, $except, $time); -} catch (ValueError $exception) { - echo $exception->getMessage() . "\n"; +} catch (Throwable $exception) { + echo $exception::class, ': ', $exception->getMessage(), "\n"; } ?> --EXPECT-- -socket_select(): At least one array argument must be passed +ValueError: socket_select(): At least one array argument must be passed --CREDITS-- Till Klampaeckel, till@php.net Berlin TestFest 2009 diff --git a/ext/sockets/tests/socket_select_error.phpt b/ext/sockets/tests/socket_select_error.phpt index 143351dd427d..d9c103b1d353 100644 --- a/ext/sockets/tests/socket_select_error.phpt +++ b/ext/sockets/tests/socket_select_error.phpt @@ -7,9 +7,9 @@ sockets $r = $w = $e = ['no resource']; try { socket_select($r, $w, $e, 1); -} catch (TypeError $ex) { - echo $ex->getMessage(), PHP_EOL; +} catch (Throwable $ex) { + echo $ex::class, ': ', $ex->getMessage(), "\n"; } ?> --EXPECT-- -socket_select(): Argument #1 ($read) must only have elements of type Socket, string given +TypeError: socket_select(): Argument #1 ($read) must only have elements of type Socket, string given diff --git a/ext/sockets/tests/socket_send_params.phpt b/ext/sockets/tests/socket_send_params.phpt index d6294c490105..c3171ebc566c 100644 --- a/ext/sockets/tests/socket_send_params.phpt +++ b/ext/sockets/tests/socket_send_params.phpt @@ -7,10 +7,10 @@ sockets $s_c = socket_create_listen(0); try { $s_w = socket_send($s_c, "foo", -1, MSG_OOB); - } catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; + } catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } socket_close($s_c); ?> --EXPECT-- -socket_send(): Argument #3 ($length) must be greater than or equal to 0 +ValueError: socket_send(): Argument #3 ($length) must be greater than or equal to 0 diff --git a/ext/sockets/tests/socket_sendto_invalid_port.phpt b/ext/sockets/tests/socket_sendto_invalid_port.phpt index 9ff81ff5e15b..d0778ca9817a 100644 --- a/ext/sockets/tests/socket_sendto_invalid_port.phpt +++ b/ext/sockets/tests/socket_sendto_invalid_port.phpt @@ -7,16 +7,16 @@ sockets $s_c = socket_create_listen(0); try { $s_w = socket_sendto($s_c, "foo", 0, MSG_OOB, '127.0.0.1', 65536); - } catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; + } catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { $s_w = socket_sendto($s_c, "foo", 0, MSG_OOB, '127.0.0.1', -1); - } catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; + } catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } socket_close($s_c); ?> --EXPECT-- -socket_sendto(): Argument #6 ($port) must be between 0 and 65535 -socket_sendto(): Argument #6 ($port) must be between 0 and 65535 +ValueError: socket_sendto(): Argument #6 ($port) must be between 0 and 65535 +ValueError: socket_sendto(): Argument #6 ($port) must be between 0 and 65535 diff --git a/ext/sockets/tests/socket_sendto_params.phpt b/ext/sockets/tests/socket_sendto_params.phpt index ed805ee9be7d..78db7cb95dce 100644 --- a/ext/sockets/tests/socket_sendto_params.phpt +++ b/ext/sockets/tests/socket_sendto_params.phpt @@ -7,10 +7,10 @@ sockets $s_c = socket_create_listen(0); try { $s_w = socket_sendto($s_c, "foo", -1, MSG_OOB, '127.0.0.1'); - } catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; + } catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } socket_close($s_c); ?> --EXPECT-- -socket_sendto(): Argument #3 ($length) must be greater than or equal to 0 +ValueError: socket_sendto(): Argument #3 ($length) must be greater than or equal to 0 diff --git a/ext/sockets/tests/socket_sendto_unix_addr_too_long.phpt b/ext/sockets/tests/socket_sendto_unix_addr_too_long.phpt index f2b62527e337..7203308d742b 100644 --- a/ext/sockets/tests/socket_sendto_unix_addr_too_long.phpt +++ b/ext/sockets/tests/socket_sendto_unix_addr_too_long.phpt @@ -19,11 +19,11 @@ $long_addr = str_repeat('a', 512); try { socket_sendto($socket, "data", 4, 0, $long_addr); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } socket_close($socket); ?> --EXPECTF-- -socket_sendto(): Argument #5 ($address) must be less than %d +ValueError: socket_sendto(): Argument #5 ($address) must be less than %d diff --git a/ext/sockets/tests/socket_set_block-retval.phpt b/ext/sockets/tests/socket_set_block-retval.phpt index 04f980416835..648847b539b3 100644 --- a/ext/sockets/tests/socket_set_block-retval.phpt +++ b/ext/sockets/tests/socket_set_block-retval.phpt @@ -13,11 +13,11 @@ $socket2 = socket_create_listen(0); socket_close($socket2); try { var_dump(socket_set_block($socket2)); -} catch (Error $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- bool(true) -socket_set_block(): Argument #1 ($socket) has already been closed +Error: socket_set_block(): Argument #1 ($socket) has already been closed diff --git a/ext/sockets/tests/socket_set_nonblock-retval.phpt b/ext/sockets/tests/socket_set_nonblock-retval.phpt index b92a75e17c2c..bc32f79782b0 100644 --- a/ext/sockets/tests/socket_set_nonblock-retval.phpt +++ b/ext/sockets/tests/socket_set_nonblock-retval.phpt @@ -13,11 +13,11 @@ $socket2 = socket_create_listen(0); socket_close($socket2); try { var_dump(socket_set_nonblock($socket2)); -} catch (Error $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- bool(true) -socket_set_nonblock(): Argument #1 ($socket) has already been closed +Error: socket_set_nonblock(): Argument #1 ($socket) has already been closed diff --git a/ext/sockets/tests/socket_set_option_mcast_error.phpt b/ext/sockets/tests/socket_set_option_mcast_error.phpt index 0d7630fb279c..0fdb4ed8f5ba 100644 --- a/ext/sockets/tests/socket_set_option_mcast_error.phpt +++ b/ext/sockets/tests/socket_set_option_mcast_error.phpt @@ -21,16 +21,16 @@ $iwanttoleavenow = true; try { socket_set_option($s, $level, MCAST_LEAVE_GROUP, $iwanttoleavenow); -} catch (\TypeError $e) { - echo $e->getMessage(), PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option($s, $level, MCAST_LEAVE_SOURCE_GROUP, $iwanttoleavenow); -} catch (\TypeError $e) { - echo $e->getMessage(); +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- -socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_GROUP, true given -socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_SOURCE_GROUP, true given +TypeError: socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_GROUP, true given +TypeError: socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_SOURCE_GROUP, true given diff --git a/ext/sockets/tests/socket_set_option_rcvtimeo.phpt b/ext/sockets/tests/socket_set_option_rcvtimeo.phpt index ef75ee025378..411f6da2af39 100644 --- a/ext/sockets/tests/socket_set_option_rcvtimeo.phpt +++ b/ext/sockets/tests/socket_set_option_rcvtimeo.phpt @@ -16,8 +16,8 @@ socket_set_block($socket); //wrong params try { $retval_1 = socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, []); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } //set/get comparison @@ -30,6 +30,6 @@ var_dump($retval_3 === $options); socket_close($socket); ?> --EXPECT-- -socket_set_option(): Argument #4 ($value) must have key "sec" +ValueError: socket_set_option(): Argument #4 ($value) must have key "sec" bool(true) bool(true) diff --git a/ext/sockets/tests/socket_set_option_seolinger.phpt b/ext/sockets/tests/socket_set_option_seolinger.phpt index 0450c7525099..62b79629c3cf 100644 --- a/ext/sockets/tests/socket_set_option_seolinger.phpt +++ b/ext/sockets/tests/socket_set_option_seolinger.phpt @@ -16,8 +16,8 @@ if (!$socket) { // wrong params try { $retval_1 = socket_set_option( $socket, SOL_SOCKET, SO_LINGER, []); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } // set/get comparison @@ -29,8 +29,8 @@ $retval_3 = socket_get_option( $socket, SOL_SOCKET, SO_LINGER); $options_2 = array("l_onoff" => 1); try { var_dump(socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_2)); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } var_dump($retval_2); @@ -41,8 +41,8 @@ var_dump((bool)$retval_3["l_onoff"] === (bool)$options["l_onoff"]); socket_close($socket); ?> --EXPECT-- -socket_set_option(): Argument #4 ($value) must have key "l_onoff" -socket_set_option(): Argument #4 ($value) must have key "l_linger" +ValueError: socket_set_option(): Argument #4 ($value) must have key "l_onoff" +ValueError: socket_set_option(): Argument #4 ($value) must have key "l_linger" bool(true) bool(true) bool(true) diff --git a/ext/sockets/tests/socket_set_option_sndtimeo.phpt b/ext/sockets/tests/socket_set_option_sndtimeo.phpt index e7487f75b05c..ec162b4dbd78 100644 --- a/ext/sockets/tests/socket_set_option_sndtimeo.phpt +++ b/ext/sockets/tests/socket_set_option_sndtimeo.phpt @@ -16,8 +16,8 @@ socket_set_block($socket); //wrong params try { $retval_1 = socket_set_option( $socket, SOL_SOCKET, SO_SNDTIMEO, []); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } //set/get comparison @@ -30,6 +30,6 @@ var_dump($retval_3 === $options); socket_close($socket); ?> --EXPECT-- -socket_set_option(): Argument #4 ($value) must have key "sec" +ValueError: socket_set_option(): Argument #4 ($value) must have key "sec" bool(true) bool(true) diff --git a/ext/sockets/tests/socket_set_option_timeo_error.phpt b/ext/sockets/tests/socket_set_option_timeo_error.phpt index befdfb095855..5e95dd65a811 100644 --- a/ext/sockets/tests/socket_set_option_timeo_error.phpt +++ b/ext/sockets/tests/socket_set_option_timeo_error.phpt @@ -17,57 +17,57 @@ $options_6 = array("l_onoff" => "1", "l_linger" => PHP_INT_MAX); try { socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, new stdClass); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, $options_1); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option( $socket, SOL_SOCKET, SO_SNDTIMEO, $options_2); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, "not good"); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option( $socket, SOL_SOCKET, SO_LINGER, "not good neither"); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_3); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_4); -} catch (\TypeError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_5); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_6); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECTF-- -socket_set_option(): Argument #4 ($value) must have key "sec" +ValueError: socket_set_option(): Argument #4 ($value) must have key "sec" Warning: Object of class stdClass could not be converted to int in %s on line %d -socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_RCVTIMEO, string given -socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_LINGER, string given -socket_set_option(): Argument #4 ($value) "l_onoff" must be between 0 and %d -socket_set_option(): Argument #4 ($value) "l_linger" must be between 0 and %d +TypeError: socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_RCVTIMEO, string given +TypeError: socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_LINGER, string given +ValueError: socket_set_option(): Argument #4 ($value) "l_onoff" must be between 0 and %d +ValueError: socket_set_option(): Argument #4 ($value) "l_linger" must be between 0 and %d diff --git a/ext/sockets/tests/socket_setoption_tcpusertimeout_64bit.phpt b/ext/sockets/tests/socket_setoption_tcpusertimeout_64bit.phpt index 894a24d2a49b..624911545230 100644 --- a/ext/sockets/tests/socket_setoption_tcpusertimeout_64bit.phpt +++ b/ext/sockets/tests/socket_setoption_tcpusertimeout_64bit.phpt @@ -17,14 +17,14 @@ socket_set_block($socket); try { socket_setopt($socket, SOL_TCP, TCP_USER_TIMEOUT, -1); -} catch (\ValueError $e) { - echo $e->getMessage(), PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { socket_setopt($socket, SOL_TCP, TCP_USER_TIMEOUT, PHP_INT_MAX); -} catch (\ValueError $e) { - echo $e->getMessage(), PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } $timeout = 200; @@ -35,7 +35,7 @@ var_dump($retval_3 === $timeout); socket_close($socket); ?> --EXPECTF-- -socket_setopt(): Argument #4 ($value) must be between 0 and %d -socket_setopt(): Argument #4 ($value) must be between 0 and %d +ValueError: socket_setopt(): Argument #4 ($value) must be between 0 and %d +ValueError: socket_setopt(): Argument #4 ($value) must be between 0 and %d bool(true) bool(true)