1--TEST-- 2Hash: hash_file() function : error conditions 3--CREDITS-- 4Felix De Vliegher <felix.devliegher@gmail.com> 5--FILE-- 6<?php 7/* Prototype : string hash_file(string algo, string filename[, bool raw_output = false]) 8 * Description: Generate a hash of a given file 9 * Source code: ext/hash/hash.c 10 * Alias to functions: 11 */ 12 13echo "*** Testing hash_file() : error conditions ***\n"; 14 15// Set up file 16$filename = 'hash_file_error_example.txt'; 17file_put_contents( $filename, 'The quick brown fox jumped over the lazy dog.' ); 18 19 20// hash_file() error tests 21echo "\n-- Testing hash_file() function with an unknown algorithm --\n"; 22var_dump( hash_file( 'foobar', $filename ) ); 23 24echo "\n-- Testing hash_file() function with a non-existent file --\n"; 25var_dump( hash_file( 'md5', 'nonexistent.txt' ) ); 26 27echo "\n-- Testing hash_file() function with less than expected no. of arguments --\n"; 28var_dump( hash_file( 'md5' ) ); 29 30echo "\n-- Testing hash_file() function with more than expected no. of arguments --\n"; 31$extra_arg = 10; 32var_dump( hash_file( 'md5', $filename, false, $extra_arg ) ); 33 34?> 35===DONE=== 36--CLEAN-- 37<?php 38 39$filename = 'hash_file_error_example.txt'; 40unlink( $filename ); 41 42?> 43--EXPECTF-- 44*** Testing hash_file() : error conditions *** 45 46-- Testing hash_file() function with an unknown algorithm -- 47 48Warning: hash_file(): Unknown hashing algorithm: %s in %s on line %d 49bool(false) 50 51-- Testing hash_file() function with a non-existent file -- 52 53Warning: hash_file(%s): failed to open stream: No such file or directory in %s on line %d 54bool(false) 55 56-- Testing hash_file() function with less than expected no. of arguments -- 57 58Warning: hash_file() expects at least 2 parameters, 1 given in %s on line %d 59NULL 60 61-- Testing hash_file() function with more than expected no. of arguments -- 62 63Warning: hash_file() expects at most 3 parameters, 4 given in %s on line %d 64NULL 65===DONE=== 66