1--TEST--
2Test stream_set_timeout() function : error conditions
3--FILE--
4<?php
5/* Prototype  : proto bool stream_set_timeout(resource stream, int seconds, int microseconds)
6 * Description: Set timeout on stream read to seconds + microseonds
7 * Source code: ext/standard/streamsfuncs.c
8 * Alias to functions: socket_set_timeout
9 */
10
11echo "*** Testing stream_set_timeout() : error conditions ***\n";
12
13//Test stream_set_timeout with one more than the expected number of arguments
14echo "\n-- Testing stream_set_timeout() function with more than expected no. of arguments --\n";
15
16/* Setup socket server */
17$server = stream_socket_server('tcp://127.0.0.1:31337');
18/* Connect to it */
19$client = fsockopen('tcp://127.0.0.1:31337');
20
21$seconds = 10;
22$microseconds = 10;
23$extra_arg = 10;
24var_dump( stream_set_timeout($client, $seconds, $microseconds, $extra_arg) );
25
26// Testing stream_set_timeout with one less than the expected number of arguments
27echo "\n-- Testing stream_set_timeout() function with less than expected no. of arguments --\n";
28
29$seconds = 10;
30var_dump( stream_set_timeout($client) );
31
32
33echo "\n-- Testing stream_set_timeout() function with a closed socket --\n";
34fclose($client);
35var_dump( stream_set_timeout($client, $seconds) );
36
37echo "\n-- Testing stream_set_timeout() function with an invalid stream --\n";
38var_dump( stream_set_timeout($seconds, $seconds) );
39
40echo "\n-- Testing stream_set_timeout() function with a stream that does not support timeouts --\n";
41$filestream = fopen(__FILE__, "r");
42var_dump( stream_set_timeout($filestream, $seconds) );
43
44fclose($filestream);
45fclose($server);
46
47echo "Done";
48?>
49--EXPECTF--
50*** Testing stream_set_timeout() : error conditions ***
51
52-- Testing stream_set_timeout() function with more than expected no. of arguments --
53
54Warning: stream_set_timeout() expects at most 3 parameters, 4 given in %s on line %i
55NULL
56
57-- Testing stream_set_timeout() function with less than expected no. of arguments --
58
59Warning: stream_set_timeout() expects at least 2 parameters, 1 given in %s on line %i
60NULL
61
62-- Testing stream_set_timeout() function with a closed socket --
63
64Warning: stream_set_timeout(): %i is not a valid stream resource in %s on line %i
65bool(false)
66
67-- Testing stream_set_timeout() function with an invalid stream --
68
69Warning: stream_set_timeout() expects parameter 1 to be resource, integer given in %s on line %i
70NULL
71
72-- Testing stream_set_timeout() function with a stream that does not support timeouts --
73bool(false)
74Done
75