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/* Prototype : bool unlink ( string $filename [, resource $context] );
12   Description : Deletes filename
13*/
14
15$file_path = dirname(__FILE__).DIRECTORY_SEPARATOR."私はガラスを食べられます";
16
17@mkdir($file_path);
18
19$filename = "$file_path/unlink_error.tmp";  // temp file name used here
20$fp = fopen($filename, "w");  // create file
21fclose($fp);
22
23// creating a context
24$context = stream_context_create();
25
26echo "*** Testing unlink() : error conditions ***\n";
27
28echo "-- Testing unlink() on unexpected no. of arguments --\n";
29// arg < expected
30var_dump( unlink() );
31// args > expected
32var_dump( unlink($filename, $context, true) );
33var_dump( file_exists($filename) ); // expected: true
34
35echo "\n-- Testing unlink() on invalid arguments --\n";
36// invalid arguments
37var_dump( unlink('') );  // $filename as empty string
38var_dump( file_exists('') );  // confirm file doesnt exist
39
40var_dump( unlink(NULL) );  // $filename as NULL
41var_dump( file_exists(NULL) );  // confirm file doesnt exist
42
43var_dump( unlink(false) );  // $filename as boolean false
44var_dump( file_exists(false) );  // confirm file doesnt exist
45
46var_dump( unlink($filename, '') );  // $context as empty string
47var_dump( unlink($filename, false) );  // $context as boolean false
48var_dump( unlink($filename, NULL) );  // $context as NULL
49
50
51echo "\n-- Testing unlink() on non-existent file --\n";
52var_dump( unlink(dirname(__FILE__)."/non_existent_file.tmp") );
53
54echo "\n-- Testing unlink() on directory --\n";
55// temp directory used here
56$dirname = "$file_path/unlink_error";
57// create temp dir
58mkdir($dirname);
59// unlinking directory
60var_dump( unlink($dirname) );  // expected: false as unlink() does not work on dir
61
62echo "Done\n";
63?>
64--CLEAN--
65<?php
66unlink(dirname(__FILE__)."/私はガラスを食べられます/unlink_error.tmp");
67rmdir(dirname(__FILE__)."/私はガラスを食べられます/unlink_error");
68rmdir(dirname(__FILE__)."/私はガラスを食べられます");
69?>
70--EXPECTF--
71*** Testing unlink() : error conditions ***
72-- Testing unlink() on unexpected no. of arguments --
73
74Warning: unlink() expects at least 1 parameter, 0 given in %s on line %d
75bool(false)
76
77Warning: unlink() expects at most 2 parameters, 3 given in %s on line %d
78bool(false)
79bool(true)
80
81-- Testing unlink() on invalid arguments --
82
83Warning: unlink(): %s in %s on line %d
84bool(false)
85bool(false)
86
87Warning: unlink(): %s in %s on line %d
88bool(false)
89bool(false)
90
91Warning: unlink(): %s in %s on line %d
92bool(false)
93bool(false)
94
95Warning: unlink() expects parameter 2 to be resource, string given in %s on line %d
96bool(false)
97
98Warning: unlink() expects parameter 2 to be resource, boolean given in %s on line %d
99bool(false)
100
101Warning: unlink() expects parameter 2 to be resource, null given in %s on line %d
102bool(false)
103
104-- Testing unlink() on non-existent file --
105
106Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d
107bool(false)
108
109-- Testing unlink() on directory --
110
111Warning: unlink(%s/unlink_error): Permission denied in %s on line %d
112bool(false)
113Done
114