Annotation of embedaddon/php/ext/standard/tests/file/unlink_error-win32.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Testing unlink() function : error conditions
3: --SKIPIF--
4: <?php
5: if (substr(PHP_OS, 0, 3) != 'WIN') {
6: die('skip.. only on Windows');
7: }
8: ?>
9: --FILE--
10: <?php
11: /* Prototype : bool unlink ( string $filename [, resource $context] );
12: Description : Deletes filename
13: */
14:
15: $file_path = dirname(__FILE__);
16:
17: $filename = "$file_path/unlink_error.tmp"; // temp file name used here
18: $fp = fopen($filename, "w"); // create file
19: fclose($fp);
20:
21: // creating a context
22: $context = stream_context_create();
23:
24: echo "*** Testing unlink() : error conditions ***\n";
25:
26: echo "-- Testing unlink() on unexpected no. of arguments --\n";
27: // arg < expected
28: var_dump( unlink() );
29: // args > expected
30: var_dump( unlink($filename, $context, true) );
31: var_dump( file_exists($filename) ); // expected: true
32:
33: echo "\n-- Testing unlink() on invalid arguments --\n";
34: // invalid arguments
35: var_dump( unlink('') ); // $filename as empty string
36: var_dump( file_exists('') ); // confirm file doesnt exist
37:
38: var_dump( unlink(NULL) ); // $filename as NULL
39: var_dump( file_exists(NULL) ); // confirm file doesnt exist
40:
41: var_dump( unlink(false) ); // $filename as boolean false
42: var_dump( file_exists(false) ); // confirm file doesnt exist
43:
44: var_dump( unlink($filename, '') ); // $context as empty string
45: var_dump( unlink($filename, false) ); // $context as boolean false
46: var_dump( unlink($filename, NULL) ); // $context as NULL
47:
48:
49: echo "\n-- Testing unlink() on non-existent file --\n";
50: var_dump( unlink(dirname(__FILE__)."/non_existent_file.tmp") );
51:
52: echo "\n-- Testing unlink() on directory --\n";
53: // temp directory used here
54: $dirname = "$file_path/unlink_error";
55: // create temp dir
56: mkdir($dirname);
57: // unlinking directory
58: var_dump( unlink($dirname) ); // expected: false as unlink() does not work on dir
59:
60: echo "Done\n";
61: ?>
62: --CLEAN--
63: <?php
64: unlink(dirname(__FILE__)."/unlink_error.tmp");
65: rmdir(dirname(__FILE__)."/unlink_error");
66: ?>
67: --EXPECTF--
68: *** Testing unlink() : error conditions ***
69: -- Testing unlink() on unexpected no. of arguments --
70:
71: Warning: unlink() expects at least 1 parameter, 0 given in %s on line %d
72: bool(false)
73:
74: Warning: unlink() expects at most 2 parameters, 3 given in %s on line %d
75: bool(false)
76: bool(true)
77:
78: -- Testing unlink() on invalid arguments --
79:
80: Warning: unlink(): %s in %s on line %d
81: bool(false)
82: bool(false)
83:
84: Warning: unlink(): %s in %s on line %d
85: bool(false)
86: bool(false)
87:
88: Warning: unlink(): %s in %s on line %d
89: bool(false)
90: bool(false)
91:
92: Warning: unlink() expects parameter 2 to be resource, string given in %s on line %d
93: bool(false)
94:
95: Warning: unlink() expects parameter 2 to be resource, boolean given in %s on line %d
96: bool(false)
97:
98: Warning: unlink() expects parameter 2 to be resource, null given in %s on line %d
99: bool(false)
100:
101: -- Testing unlink() on non-existent file --
102:
103: Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d
104: bool(false)
105:
106: -- Testing unlink() on directory --
107:
108: Warning: unlink(%s/unlink_error): Permission denied in %s on line %d
109: bool(false)
110: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>