1--TEST-- 2Hash: hash_hmac() function : basic functionality 3--FILE-- 4<?php 5/* 6* proto string hash_hmac ( string algo, string data, string key [, bool raw_output] ) 7* Function is implemented in ext/hash/hash.c 8*/ 9 10echo "*** Testing hash_hmac() : error conditions ***\n"; 11 12$data = "This is a sample string used to test the hash_hmac function with various hashing algorithms"; 13$key = 'secret'; 14 15echo "\n-- Testing hash_hmac() function with less than expected no. of arguments --\n"; 16var_dump(hash_hmac()); 17var_dump(hash_hmac('md5')); 18var_dump(hash_hmac('md5', $data)); 19 20echo "\n-- Testing hash_hmac() function with more than expected no. of arguments --\n"; 21$extra_arg = 10; 22var_dump(hash_hmac('md5', $data, $key, TRUE, $extra_arg)); 23 24echo "\n-- Testing hash_hmac() function with invalid hash algorithm --\n"; 25var_dump(hash_hmac('foo', $data, $key)); 26 27echo "\n-- Testing hash_hmac() function with non-cryptographic hash algorithm --\n"; 28var_dump(hash_hmac('crc32', $data, $key)); 29 30?> 31===Done=== 32--EXPECTF-- 33*** Testing hash_hmac() : error conditions *** 34 35-- Testing hash_hmac() function with less than expected no. of arguments -- 36 37Warning: hash_hmac() expects at least 3 parameters, 0 given in %s on line %d 38NULL 39 40Warning: hash_hmac() expects at least 3 parameters, 1 given in %s on line %d 41NULL 42 43Warning: hash_hmac() expects at least 3 parameters, 2 given in %s on line %d 44NULL 45 46-- Testing hash_hmac() function with more than expected no. of arguments -- 47 48Warning: hash_hmac() expects at most 4 parameters, 5 given in %s on line %d 49NULL 50 51-- Testing hash_hmac() function with invalid hash algorithm -- 52 53Warning: hash_hmac(): Unknown hashing algorithm: foo in %s on line %d 54bool(false) 55 56-- Testing hash_hmac() function with non-cryptographic hash algorithm -- 57 58Warning: hash_hmac(): Non-cryptographic hashing algorithm: crc32 in %s on line %d 59bool(false) 60===Done=== 61