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