xref: /PHP-5.4/ext/hash/tests/hash_file_error.phpt (revision e9a95d78)
1--TEST--
2Test hash_file() function : error conditions
3--SKIPIF--
4<?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?>
5--CREDITS--
6Felix De Vliegher <felix.devliegher@gmail.com>
7--FILE--
8<?php
9/* Prototype  : string hash_file(string algo, string filename[, bool raw_output = false])
10 * Description: Generate a hash of a given file
11 * Source code: ext/hash/hash.c
12 * Alias to functions:
13 */
14
15echo "*** Testing hash_file() : error conditions ***\n";
16
17// Set up file
18$filename = 'hash_file_example.txt';
19file_put_contents( $filename, 'The quick brown fox jumped over the lazy dog.' );
20
21
22// hash_file() error tests
23echo "\n-- Testing hash_file() function with an unknown algorithm --\n";
24var_dump( hash_file( 'foobar', $filename ) );
25
26echo "\n-- Testing hash_file() function with a non-existent file --\n";
27var_dump( hash_file( 'md5', 'nonexistent.txt' ) );
28
29echo "\n-- Testing hash_file() function with less than expected no. of arguments --\n";
30var_dump( hash_file( 'md5' ) );
31
32echo "\n-- Testing hash_file() function with more than expected no. of arguments --\n";
33$extra_arg = 10;
34var_dump( hash_file( 'md5', $filename, false, $extra_arg ) );
35
36?>
37===DONE===
38--CLEAN--
39<?php
40
41$filename = 'hash_file_example.txt';
42unlink( $filename );
43
44?>
45--EXPECTF--
46*** Testing hash_file() : error conditions ***
47
48-- Testing hash_file() function with an unknown algorithm --
49
50Warning: hash_file(): Unknown hashing algorithm: %s in %s on line %d
51bool(false)
52
53-- Testing hash_file() function with a non-existent file --
54
55Warning: hash_file(%s): failed to open stream: No such file or directory in %s on line %d
56bool(false)
57
58-- Testing hash_file() function with less than expected no. of arguments --
59
60Warning: hash_file() expects at least 2 parameters, 1 given in %s on line %d
61NULL
62
63-- Testing hash_file() function with more than expected no. of arguments --
64
65Warning: hash_file() expects at most 3 parameters, 4 given in %s on line %d
66NULL
67===DONE===
68