1--TEST--
2Test hash_hmac_file() function : basic functionality
3--SKIPIF--
4<?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?>
5--FILE--
6<?php
7
8/* Prototype  : string hash_hmac_file ( string algo, string filename, string key [, bool raw_output] )
9 * Description: Generate a keyed hash value using the HMAC method and the contents of a given file
10 * Source code: ext/hash/hash.c
11 * Alias to functions:
12*/
13
14echo "*** Testing hash() : error conditions ***\n";
15
16$file = dirname(__FILE__) . "hash_file.txt";
17$key = 'secret';
18
19echo "\n-- Testing hash_hmac_file() function with less than expected no. of arguments --\n";
20var_dump(hash_hmac_file());
21var_dump(hash_hmac_file('crc32'));
22var_dump(hash_hmac_file('crc32', $file));
23
24echo "\n-- Testing hash_hmac_file() function with more than expected no. of arguments --\n";
25$extra_arg = 10;
26hash_hmac_file('crc32', $file, $key, TRUE, $extra_arg);
27
28echo "\n-- Testing hash_hmac_file() function with invalid hash algorithm --\n";
29hash_hmac_file('foo', $file, $key, TRUE);
30
31echo "\n-- Testing hash_hmac_file() function with bad path --\n";
32hash_hmac_file('crc32', $file.chr(0).$file, $key, TRUE);
33
34?>
35===Done===
36--EXPECTF--
37*** Testing hash() : error conditions ***
38
39-- Testing hash_hmac_file() function with less than expected no. of arguments --
40
41Warning: hash_hmac_file() expects at least 3 parameters, 0 given in %s on line %d
42NULL
43
44Warning: hash_hmac_file() expects at least 3 parameters, 1 given in %s on line %d
45NULL
46
47Warning: hash_hmac_file() expects at least 3 parameters, 2 given in %s on line %d
48NULL
49
50-- Testing hash_hmac_file() function with more than expected no. of arguments --
51
52Warning: hash_hmac_file() expects at most 4 parameters, 5 given in %s on line %d
53
54-- Testing hash_hmac_file() function with invalid hash algorithm --
55
56Warning: hash_hmac_file(): Unknown hashing algorithm: foo in %s on line %d
57
58-- Testing hash_hmac_file() function with bad path --
59
60Warning: hash_hmac_file(): Invalid path in %s on line %d
61===Done===