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__.DIRECTORY_SEPARATOR."unlinkErr私はガラスを食べられます";
13
14@mkdir($file_path);
15
16$filename = "$file_path/unlink_error.tmp";  // temp file name used here
17$fp = fopen($filename, "w");  // create file
18fclose($fp);
19
20// creating a context
21$context = stream_context_create();
22
23echo "*** Testing unlink() : error conditions ***\n";
24
25echo "\n-- Testing unlink() on invalid arguments --\n";
26// invalid arguments
27var_dump( unlink('') );  // $filename as empty string
28var_dump( file_exists('') );  // confirm file doesn't exist
29
30var_dump( unlink(false) );  // $filename as boolean false
31var_dump( file_exists(false) );  // confirm file doesn't exist
32
33
34echo "\n-- Testing unlink() on non-existent file --\n";
35var_dump( unlink(__DIR__."/non_existent_file.tmp") );
36
37echo "\n-- Testing unlink() on directory --\n";
38// temp directory used here
39$dirname = "$file_path/unlink_error";
40// create temp dir
41mkdir($dirname);
42// unlinking directory
43var_dump( unlink($dirname) );  // expected: false as unlink() does not work on dir
44
45echo "Done\n";
46?>
47--CLEAN--
48<?php
49unlink(__DIR__."/unlinkErr私はガラスを食べられます/unlink_error.tmp");
50rmdir(__DIR__."/unlinkErr私はガラスを食べられます/unlink_error");
51rmdir(__DIR__."/unlinkErr私はガラスを食べられます");
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
66-- Testing unlink() on non-existent file --
67
68Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d
69bool(false)
70
71-- Testing unlink() on directory --
72
73Warning: unlink(%s/unlink_error): Is a directory in %s on line %d
74bool(false)
75Done
76