1--TEST--
2Testing unlink() function : error conditions
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip.. only on Windows');
7}
8?>
9--FILE--
10<?php
11
12$file_path = __DIR__;
13
14$filename = "$file_path/unlink_error.tmp";  // temp file name used here
15$fp = fopen($filename, "w");  // create file
16fclose($fp);
17
18// creating a context
19$context = stream_context_create();
20
21echo "*** Testing unlink() : error conditions ***\n";
22
23echo "\n-- Testing unlink() on invalid arguments --\n";
24// invalid arguments
25var_dump( unlink('') );  // $filename as empty string
26var_dump( file_exists('') );  // confirm file doesn't exist
27
28var_dump( unlink(false) );  // $filename as boolean false
29var_dump( file_exists(false) );  // confirm file doesn't exist
30
31
32echo "\n-- Testing unlink() on non-existent file --\n";
33var_dump( unlink(__DIR__."/non_existent_file.tmp") );
34
35echo "\n-- Testing unlink() on directory --\n";
36// temp directory used here
37$dirname = "$file_path/unlink_error";
38// create temp dir
39mkdir($dirname);
40// unlinking directory
41var_dump( unlink($dirname) );  // expected: false as unlink() does not work on dir
42
43echo "Done\n";
44?>
45--CLEAN--
46<?php
47unlink(__DIR__."/unlink_error.tmp");
48rmdir(__DIR__."/unlink_error");
49?>
50--EXPECTF--
51*** Testing unlink() : error conditions ***
52
53-- Testing unlink() on invalid arguments --
54
55Warning: unlink(): %s in %s on line %d
56bool(false)
57bool(false)
58
59Warning: unlink(): %s in %s on line %d
60bool(false)
61bool(false)
62
63-- Testing unlink() on non-existent file --
64
65Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d
66bool(false)
67
68-- Testing unlink() on directory --
69
70Warning: unlink(%s/unlink_error): Is a directory in %s on line %d
71bool(false)
72Done
73