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