hash_file_error.phpt 1.9 KB

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