hash_hmac_error.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. Test hash_hmac() function : basic functionality
  3. --SKIPIF--
  4. <?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?>
  5. --FILE--
  6. <?php
  7. /*
  8. * proto string hash_hmac ( string algo, string data, string key [, bool raw_output] )
  9. * Function is implemented in ext/hash/hash.c
  10. */
  11. echo "*** Testing hash_hmac() : error conditions ***\n";
  12. $data = "This is a sample string used to test the hash_hmac function with various hashing algorithms";
  13. $key = 'secret';
  14. echo "\n-- Testing hash_hmac() function with less than expected no. of arguments --\n";
  15. var_dump(hash_hmac());
  16. var_dump(hash_hmac('crc32'));
  17. var_dump(hash_hmac('crc32', $data));
  18. echo "\n-- Testing hash_hmac() function with more than expected no. of arguments --\n";
  19. $extra_arg = 10;
  20. var_dump(hash_hmac('crc32', $data, $key, TRUE, $extra_arg));
  21. echo "\n-- Testing hash_hmac() function with invalid hash algorithm --\n";
  22. var_dump(hash_hmac('foo', $data, $key));
  23. ?>
  24. ===Done===
  25. --EXPECTF--
  26. *** Testing hash_hmac() : error conditions ***
  27. -- Testing hash_hmac() function with less than expected no. of arguments --
  28. Warning: hash_hmac() expects at least 3 parameters, 0 given in %s on line %d
  29. NULL
  30. Warning: hash_hmac() expects at least 3 parameters, 1 given in %s on line %d
  31. NULL
  32. Warning: hash_hmac() expects at least 3 parameters, 2 given in %s on line %d
  33. NULL
  34. -- Testing hash_hmac() function with more than expected no. of arguments --
  35. Warning: hash_hmac() expects at most 4 parameters, 5 given in %s on line %d
  36. NULL
  37. -- Testing hash_hmac() function with invalid hash algorithm --
  38. Warning: hash_hmac(): Unknown hashing algorithm: foo in %s on line %d
  39. bool(false)
  40. ===Done===