1--TEST-- 2Hash: hash_file() function : error conditions 3--CREDITS-- 4Felix De Vliegher <felix.devliegher@gmail.com> 5--FILE-- 6<?php 7echo "*** Testing hash_file() : error conditions ***\n"; 8 9// Set up file 10$filename = 'hash_file_error_example.txt'; 11file_put_contents( $filename, 'The quick brown fox jumped over the lazy dog.' ); 12 13 14// hash_file() error tests 15echo "\n-- Testing hash_file() function with an unknown algorithm --\n"; 16try { 17 hash_file('foobar', $filename); 18} catch (ValueError $exception) { 19 echo $exception->getMessage() . "\n"; 20} 21 22echo "\n-- Testing hash_file() function with a non-existent file --\n"; 23var_dump(hash_file('md5', 'nonexistent.txt')); 24 25?> 26--CLEAN-- 27<?php 28 29$filename = 'hash_file_error_example.txt'; 30unlink( $filename ); 31 32?> 33--EXPECTF-- 34*** Testing hash_file() : error conditions *** 35 36-- Testing hash_file() function with an unknown algorithm -- 37hash_file(): Argument #1 ($algo) must be a valid hashing algorithm 38 39-- Testing hash_file() function with a non-existent file -- 40 41Warning: hash_file(%s): Failed to open stream: No such file or directory in %s on line %d 42bool(false) 43