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 48 49 50echo "\n-- Testing unlink() on non-existent file --\n"; 51var_dump( unlink(dirname(__FILE__)."/non_existent_file.tmp") ); 52 53echo "\n-- Testing unlink() on directory --\n"; 54// temp directory used here 55$dirname = "$file_path/unlink_error"; 56// create temp dir 57mkdir($dirname); 58// unlinking directory 59var_dump( unlink($dirname) ); // expected: false as unlink() does not work on dir 60 61echo "Done\n"; 62?> 63--CLEAN-- 64<?php 65unlink(dirname(__FILE__)."/私はガラスを食べられます/unlink_error.tmp"); 66rmdir(dirname(__FILE__)."/私はガラスを食べられます/unlink_error"); 67rmdir(dirname(__FILE__)."/私はガラスを食べられます"); 68?> 69--EXPECTF-- 70*** Testing unlink() : error conditions *** 71-- Testing unlink() on unexpected no. of arguments -- 72 73Warning: unlink() expects at least 1 parameter, 0 given in %s on line %d 74bool(false) 75 76Warning: unlink() expects at most 2 parameters, 3 given in %s on line %d 77bool(false) 78bool(true) 79 80-- Testing unlink() on invalid arguments -- 81 82Warning: unlink(): %s in %s on line %d 83bool(false) 84bool(false) 85 86Warning: unlink(): %s in %s on line %d 87bool(false) 88bool(false) 89 90Warning: unlink(): %s in %s on line %d 91bool(false) 92bool(false) 93 94Warning: unlink() expects parameter 2 to be resource, string given in %s on line %d 95bool(false) 96 97Warning: unlink() expects parameter 2 to be resource, bool given in %s on line %d 98bool(false) 99 100-- Testing unlink() on non-existent file -- 101 102Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d 103bool(false) 104 105-- Testing unlink() on directory -- 106 107Warning: unlink(%s/unlink_error): Is a directory in %s on line %d 108bool(false) 109Done 110