1--TEST--
2Test file-get_contents() and file_put_contents() functions : error conditions
3--FILE--
4<?php
5/* Prototype: string file_get_contents( string $filename{, bool $use_include_path[,
6 *                                      resource $context[, int $offset[, int $maxlen]]]] )
7 * Description: Reads entire file into a string
8 */
9
10/* Prototype: int file_put_contents( string $filename, mixed $data[, int $flags[, resource $context]] )
11 * Description: Write a string to a file
12 */
13
14echo "*** Testing error conditions ***\n";
15
16$file_path = dirname(__FILE__);
17
18echo "\n-- Testing with  Non-existing file --\n";
19print( file_get_contents("/no/such/file/or/dir") );
20
21echo "\n-- Testing No.of arguments less than expected --\n";
22print( file_get_contents() );
23print( file_put_contents() );
24print( file_put_contents($file_path."/".__FILE__) );
25
26$file_handle = fopen($file_path."/file_put_contents.tmp", "w");
27echo "\n-- Testing No.of arguments greater than expected --\n";
28print( file_put_contents("abc.tmp", 12345, 1, $file_handle, "extra_argument") );
29print( file_get_contents("abc.tmp", false, $file_handle, 1, 2, "extra_argument") );
30
31echo "\n-- Testing for invalid negative maxlen values --";
32file_put_contents($file_path."/file_put_contents1.tmp", "Garbage data in the file");
33var_dump( file_get_contents($file_path."/file_put_contents1.tmp", FALSE, NULL, 0, -5) );
34
35fclose($file_handle);
36
37echo "\n*** Done ***\n";
38?>
39--CLEAN--
40<?php
41$file_path = dirname(__FILE__);
42unlink($file_path."/file_put_contents.tmp");
43unlink($file_path."/file_put_contents1.tmp");
44
45?>
46--EXPECTF--
47*** Testing error conditions ***
48
49-- Testing with  Non-existing file --
50
51Warning: file_get_contents(/no/such/file/or/dir): failed to open stream: No such file or directory in %s on line %d
52
53-- Testing No.of arguments less than expected --
54
55Warning: file_get_contents() expects at least 1 parameter, 0 given in %s on line %d
56
57Warning: file_put_contents() expects at least 2 parameters, 0 given in %s on line %d
58
59Warning: file_put_contents() expects at least 2 parameters, 1 given in %s on line %d
60
61-- Testing No.of arguments greater than expected --
62
63Warning: file_put_contents() expects at most 4 parameters, 5 given in %s on line %d
64
65Warning: file_get_contents() expects at most 5 parameters, 6 given in %s on line %d
66
67-- Testing for invalid negative maxlen values --
68Warning: file_get_contents(): length must be greater than or equal to zero in %s on line %d
69bool(false)
70
71*** Done ***
72