xref: /PHP-7.4/ext/hash/tests/hash_init_error.phpt (revision f73c0102)
1--TEST--
2Hash: hash_init() function - errors test
3--FILE--
4<?php
5echo "*** Testing hash_init(): error conditions ***\n";
6
7echo "-- Testing hash_init() function with no parameters --\n";
8var_dump(hash_init());
9
10echo "-- Testing hash_init() function with unknown algorithms --\n";
11var_dump(hash_init('dummy'));
12
13echo "-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --\n";
14var_dump(hash_init('crc32', HASH_HMAC));
15
16echo "-- Testing hash_init() function with HASH_HMAC and no key --\n";
17var_dump(hash_init('md5', HASH_HMAC));
18var_dump(hash_init('md5', HASH_HMAC, null));
19?>
20--EXPECTF--
21*** Testing hash_init(): error conditions ***
22-- Testing hash_init() function with no parameters --
23
24Warning: hash_init() expects at least 1 parameter, 0 given in %s on line %d
25NULL
26-- Testing hash_init() function with unknown algorithms --
27
28Warning: hash_init(): Unknown hashing algorithm: dummy in %s on line %d
29bool(false)
30-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --
31
32Warning: hash_init(): HMAC requested with a non-cryptographic hashing algorithm: crc32 in %s on line %d
33bool(false)
34-- Testing hash_init() function with HASH_HMAC and no key --
35
36Warning: hash_init(): HMAC requested without a key %s on line %d
37bool(false)
38
39Warning: hash_init(): HMAC requested without a key %s on line %d
40bool(false)
41