hash_error.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Test hash() function : error conditions
  3. --SKIPIF--
  4. <?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?>
  5. --FILE--
  6. <?php
  7. /* Prototype : string hash ( string $algo , string $data [, bool $raw_output ] )
  8. * Description: Generate a hash value (message digest)
  9. * Source code: ext/hash/hash.c
  10. * Alias to functions:
  11. */
  12. echo "*** Testing hash() : error conditions ***\n";
  13. echo "\n-- Testing hash() function with less than expected no. of arguments --\n";
  14. var_dump(hash());
  15. var_dump(hash('adler32'));
  16. echo "\n-- Testing hash() function with more than expected no. of arguments --\n";
  17. $extra_arg= 10;
  18. var_dump(hash('adler32', '', false, $extra_arg));
  19. echo "\n-- Testing hash() function with invalid hash algorithm --\n";
  20. var_dump(hash('foo', ''));
  21. ?>
  22. ===Done===
  23. --EXPECTF--
  24. *** Testing hash() : error conditions ***
  25. -- Testing hash() function with less than expected no. of arguments --
  26. Warning: hash() expects at least 2 parameters, 0 given in %s on line %d
  27. NULL
  28. Warning: hash() expects at least 2 parameters, 1 given in %s on line %d
  29. NULL
  30. -- Testing hash() function with more than expected no. of arguments --
  31. Warning: hash() expects at most 3 parameters, 4 given in %s on line %d
  32. NULL
  33. -- Testing hash() function with invalid hash algorithm --
  34. Warning: hash(): Unknown hashing algorithm: foo in %s on line %d
  35. bool(false)
  36. ===Done===