xref: /PHP-5.5/ext/hash/tests/hash_hmac_error.phpt (revision c41cc6aa)
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('crc32'));
20var_dump(hash_hmac('crc32', $data));
21
22echo "\n-- Testing hash_hmac() function with more than expected no. of arguments --\n";
23$extra_arg = 10;
24var_dump(hash_hmac('crc32', $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
29?>
30===Done===
31--EXPECTF--
32*** Testing hash_hmac() : error conditions ***
33
34-- Testing hash_hmac() function with less than expected no. of arguments --
35
36Warning: hash_hmac() expects at least 3 parameters, 0 given in %s on line %d
37NULL
38
39Warning: hash_hmac() expects at least 3 parameters, 1 given in %s on line %d
40NULL
41
42Warning: hash_hmac() expects at least 3 parameters, 2 given in %s on line %d
43NULL
44
45-- Testing hash_hmac() function with more than expected no. of arguments --
46
47Warning: hash_hmac() expects at most 4 parameters, 5 given in %s on line %d
48NULL
49
50-- Testing hash_hmac() function with invalid hash algorithm --
51
52Warning: hash_hmac(): Unknown hashing algorithm: foo in %s on line %d
53bool(false)
54===Done===