xref: /PHP-7.4/ext/standard/tests/file/006_error.phpt (revision 8b5c3511)
1--TEST--
2Test fileperms(), chmod() functions: error conditions
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip Not on Windows');
7}
8require __DIR__ . '/../skipif_root.inc';
9?>
10--FILE--
11<?php
12/*
13  Prototype: int fileperms ( string $filename )
14  Description: Returns the permissions on the file, or FALSE in case of an error
15
16  Prototype: bool chmod ( string $filename, int $mode )
17  Description: Attempts to change the mode of the file specified by
18    filename to that given in mode
19*/
20
21echo "*** Testing error conditions for fileperms(), chmod() ***\n";
22
23/* With standard files and dirs */
24var_dump( chmod("/etc/passwd", 0777) );
25printf("%o", fileperms("/etc/passwd") );
26echo "\n";
27clearstatcache();
28
29var_dump( chmod("/etc", 0777) );
30printf("%o", fileperms("/etc") );
31echo "\n";
32clearstatcache();
33
34/* With non-existing file or dir */
35var_dump( chmod("/no/such/file/dir", 0777) );
36var_dump( fileperms("/no/such/file/dir") );
37echo "\n";
38
39/* With args less than expected */
40$fp = fopen(__DIR__."/006_error.tmp", "w");
41fclose($fp);
42var_dump( chmod(__DIR__."/006_error.tmp") );
43var_dump( chmod("nofile") );
44var_dump( chmod() );
45var_dump( fileperms() );
46
47/* With args greater than expected */
48var_dump( chmod(__DIR__."/006_error.tmp", 0755, TRUE) );
49var_dump( fileperms(__DIR__."/006_error.tmp", 0777) );
50var_dump( fileperms("nofile", 0777) );
51
52echo "\n*** Done ***\n";
53?>
54--CLEAN--
55<?php
56unlink( __DIR__."/006_error.tmp");
57?>
58--EXPECTF--
59*** Testing error conditions for fileperms(), chmod() ***
60
61Warning: chmod(): %s in %s on line %d
62bool(false)
63100%d44
64
65Warning: chmod(): %s in %s on line %d
66bool(false)
6740755
68
69Warning: chmod(): No such file or directory in %s on line %d
70bool(false)
71
72Warning: fileperms(): stat failed for /no/such/file/dir in %s on line %d
73bool(false)
74
75
76Warning: chmod() expects exactly 2 parameters, 1 given in %s on line %d
77NULL
78
79Warning: chmod() expects exactly 2 parameters, 1 given in %s on line %d
80NULL
81
82Warning: chmod() expects exactly 2 parameters, 0 given in %s on line %d
83NULL
84
85Warning: fileperms() expects exactly 1 parameter, 0 given in %s on line %d
86NULL
87
88Warning: chmod() expects exactly 2 parameters, 3 given in %s on line %d
89NULL
90
91Warning: fileperms() expects exactly 1 parameter, 2 given in %s on line %d
92NULL
93
94Warning: fileperms() expects exactly 1 parameter, 2 given in %s on line %d
95NULL
96
97*** Done ***
98