Annotation of embedaddon/php/ext/standard/tests/file/fread_error.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fread() function : error conditions
3: --FILE--
4: <?php
5: /*
6: Prototype: string fread ( resource $handle [, int $length] );
7: Description: reads up to length bytes from the file pointer referenced by handle.
8: Reading stops when up to length bytes have been read, EOF (end of file) is
9: reached, (for network streams) when a packet becomes available, or (after
10: opening userspace stream) when 8192 bytes have been read whichever comes first.
11: */
12:
13: echo "*** Testing error conditions ***\n";
14: $filename = __FILE__;
15: $file_handle = fopen($filename, "r");
16:
17: // zero argument
18: echo "-- Testing fread() with zero argument --\n";
19: var_dump( fread() );
20:
21: // more than expected no. of args
22: echo "-- Testing fread() with more than expected number of arguments --\n";
23: var_dump( fread($file_handle, 10, $file_handle) );
24:
25: // invalid length argument
26: echo "-- Testing fread() with invalid length arguments --\n";
27: $len = 0;
28: var_dump( fread($file_handle, $len) );
29: $len = -10;
30: var_dump( fread($file_handle, $len) );
31:
32: // test invalid arguments : non-resources
33: echo "-- Testing fread() with invalid arguments --\n";
34: $invalid_args = array (
35: "string",
36: 10,
37: 10.5,
38: true,
39: array(1,2,3),
40: new stdclass,
41: );
42: /* loop to test fread() with different invalid type of args */
43: for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
44: echo "-- Iteration $loop_counter --\n";
45: var_dump( fread($invalid_args[$loop_counter - 1], 10) );
46: }
47:
48: // fwrite() on a file handle which is already closed
49: echo "-- Testing fwrite() with closed/unset file handle --\n";
50: fclose($file_handle);
51: var_dump( fread($file_handle,$file_content_type) );
52:
53: // fwrite on a file handle which is unset
54: $fp = fopen($filename, "r");
55: unset($fp); //unset file handle
56: var_dump( fread(@$fp,10) );
57: var_dump( fclose(@$fp) );
58:
59: echo "Done\n";
60: --EXPECTF--
61: *** Testing error conditions ***
62: -- Testing fread() with zero argument --
63:
64: Warning: fread() expects exactly 2 parameters, 0 given in %s on line %d
65: bool(false)
66: -- Testing fread() with more than expected number of arguments --
67:
68: Warning: fread() expects exactly 2 parameters, 3 given in %s on line %d
69: bool(false)
70: -- Testing fread() with invalid length arguments --
71:
72: Warning: fread(): Length parameter must be greater than 0 in %s on line %d
73: bool(false)
74:
75: Warning: fread(): Length parameter must be greater than 0 in %s on line %d
76: bool(false)
77: -- Testing fread() with invalid arguments --
78: -- Iteration 1 --
79:
80: Warning: fread() expects parameter 1 to be resource, string given in %s on line %d
81: bool(false)
82: -- Iteration 2 --
83:
84: Warning: fread() expects parameter 1 to be resource, integer given in %s on line %d
85: bool(false)
86: -- Iteration 3 --
87:
88: Warning: fread() expects parameter 1 to be resource, double given in %s on line %d
89: bool(false)
90: -- Iteration 4 --
91:
92: Warning: fread() expects parameter 1 to be resource, boolean given in %s on line %d
93: bool(false)
94: -- Iteration 5 --
95:
96: Warning: fread() expects parameter 1 to be resource, array given in %s on line %d
97: bool(false)
98: -- Iteration 6 --
99:
100: Warning: fread() expects parameter 1 to be resource, object given in %s on line %d
101: bool(false)
102: -- Testing fwrite() with closed/unset file handle --
103:
104: Notice: Undefined variable: file_content_type in %s on line %d
105:
106: Warning: fread(): %d is not a valid stream resource in %s on line %d
107: bool(false)
108:
109: Warning: fread() expects parameter 1 to be resource, null given in %s on line %d
110: bool(false)
111:
112: Warning: fclose() expects parameter 1 to be resource, null given in %s on line %d
113: bool(false)
114: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>