Annotation of embedaddon/php/ext/standard/tests/file/file_get_contents_file_put_contents_error.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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:
14: echo "*** Testing error conditions ***\n";
15:
16: $file_path = dirname(__FILE__);
17:
18: echo "\n-- Testing with Non-existing file --\n";
19: print( file_get_contents("/no/such/file/or/dir") );
20:
21: echo "\n-- Testing No.of arguments less than expected --\n";
22: print( file_get_contents() );
23: print( file_put_contents() );
24: print( file_put_contents($file_path."/".__FILE__) );
25:
26: $file_handle = fopen($file_path."/file_put_contents.tmp", "w");
27: echo "\n-- Testing No.of arguments greater than expected --\n";
28: print( file_put_contents("abc.tmp", 12345, 1, $file_handle, "extra_argument") );
29: print( file_get_contents("abc.tmp", false, $file_handle, 1, 2, "extra_argument") );
30:
31: echo "\n-- Testing for invalid negative maxlen values --";
32: file_put_contents($file_path."/file_put_contents1.tmp", "Garbage data in the file");
33: var_dump( file_get_contents($file_path."/file_put_contents1.tmp", FALSE, NULL, 0, -5) );
34:
35: fclose($file_handle);
36:
37: echo "\n*** Done ***\n";
38: ?>
39: --CLEAN--
40: <?php
41: $file_path = dirname(__FILE__);
42: unlink($file_path."/file_put_contents.tmp");
43: unlink($file_path."/file_put_contents1.tmp");
44:
45: ?>
46: --EXPECTF--
47: *** Testing error conditions ***
48:
49: -- Testing with Non-existing file --
50:
51: Warning: 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:
55: Warning: file_get_contents() expects at least 1 parameter, 0 given in %s on line %d
56:
57: Warning: file_put_contents() expects at least 2 parameters, 0 given in %s on line %d
58:
59: Warning: 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:
63: Warning: file_put_contents() expects at most 4 parameters, 5 given in %s on line %d
64:
65: Warning: file_get_contents() expects at most 5 parameters, 6 given in %s on line %d
66:
67: -- Testing for invalid negative maxlen values --
68: Warning: file_get_contents(): length must be greater than or equal to zero in %s on line %d
69: bool(false)
70:
71: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>