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(NULL) );  // $filename as NULL
29var_dump( file_exists(NULL) );  // confirm file doesn't exist
30
31var_dump( unlink(false) );  // $filename as boolean false
32var_dump( file_exists(false) );  // confirm file doesn't exist
33
34
35echo "\n-- Testing unlink() on non-existent file --\n";
36var_dump( unlink(__DIR__."/non_existent_file.tmp") );
37
38echo "\n-- Testing unlink() on directory --\n";
39// temp directory used here
40$dirname = "$file_path/unlink_error";
41// create temp dir
42mkdir($dirname);
43// unlinking directory
44var_dump( unlink($dirname) );  // expected: false as unlink() does not work on dir
45
46echo "Done\n";
47?>
48--CLEAN--
49<?php
50unlink(__DIR__."/unlink_error.tmp");
51rmdir(__DIR__."/unlink_error");
52?>
53--EXPECTF--
54*** Testing unlink() : error conditions ***
55
56-- Testing unlink() on invalid arguments --
57
58Warning: unlink(): %s in %s on line %d
59bool(false)
60bool(false)
61
62Warning: unlink(): %s in %s on line %d
63bool(false)
64bool(false)
65
66Warning: unlink(): %s in %s on line %d
67bool(false)
68bool(false)
69
70-- Testing unlink() on non-existent file --
71
72Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d
73bool(false)
74
75-- Testing unlink() on directory --
76
77Warning: unlink(%s/unlink_error): Is a directory in %s on line %d
78bool(false)
79Done
80