|
2 | 2 | Hash: hash_equals() test
|
3 | 3 | --FILE--
|
4 | 4 | <?php
|
5 |
| -var_dump(hash_equals("same", "same")); |
6 |
| -var_dump(hash_equals("not1same", "not2same")); |
7 |
| -var_dump(hash_equals("short", "longer")); |
8 |
| -var_dump(hash_equals("longer", "short")); |
9 |
| -var_dump(hash_equals("", "notempty")); |
10 |
| -var_dump(hash_equals("notempty", "")); |
11 |
| -var_dump(hash_equals("", "")); |
12 |
| -var_dump(hash_equals(123, "NaN")); |
13 |
| -var_dump(hash_equals("NaN", 123)); |
14 |
| -var_dump(hash_equals(123, 123)); |
15 |
| -var_dump(hash_equals(null, "")); |
16 |
| -var_dump(hash_equals(null, 123)); |
17 |
| -var_dump(hash_equals(null, null)); |
| 5 | + |
| 6 | +function trycatch_dump(...$tests) { |
| 7 | + foreach ($tests as $test) { |
| 8 | + try { |
| 9 | + var_dump($test()); |
| 10 | + } |
| 11 | + catch (\Error $e) { |
| 12 | + echo '[' . get_class($e) . '] ' . $e->getMessage() . "\n"; |
| 13 | + } |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +trycatch_dump( |
| 18 | + fn() => hash_equals("same", "same"), |
| 19 | + fn() => hash_equals("not1same", "not2same"), |
| 20 | + fn() => hash_equals("short", "longer"), |
| 21 | + fn() => hash_equals("longer", "short"), |
| 22 | + fn() => hash_equals("", "notempty"), |
| 23 | + fn() => hash_equals("notempty", ""), |
| 24 | + fn() => hash_equals("", ""), |
| 25 | + fn() => hash_equals(123, "NaN"), |
| 26 | + fn() => hash_equals("NaN", 123), |
| 27 | + fn() => hash_equals(123, 123), |
| 28 | + fn() => hash_equals(null, ""), |
| 29 | + fn() => hash_equals(null, 123), |
| 30 | + fn() => hash_equals(null, null), |
| 31 | +); |
| 32 | + |
18 | 33 | ?>
|
19 |
| ---EXPECTF-- |
| 34 | +--EXPECT-- |
20 | 35 | bool(true)
|
21 | 36 | bool(false)
|
22 | 37 | bool(false)
|
23 | 38 | bool(false)
|
24 | 39 | bool(false)
|
25 | 40 | bool(false)
|
26 | 41 | bool(true)
|
27 |
| - |
28 |
| -Warning: hash_equals(): Expected known_string to be a string, int given in %s on line %d |
29 |
| -bool(false) |
30 |
| - |
31 |
| -Warning: hash_equals(): Expected user_string to be a string, int given in %s on line %d |
32 |
| -bool(false) |
33 |
| - |
34 |
| -Warning: hash_equals(): Expected known_string to be a string, int given in %s on line %d |
35 |
| -bool(false) |
36 |
| - |
37 |
| -Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d |
38 |
| -bool(false) |
39 |
| - |
40 |
| -Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d |
41 |
| -bool(false) |
42 |
| - |
43 |
| -Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d |
44 |
| -bool(false) |
| 42 | +[TypeError] Expected known_string to be a string, int given |
| 43 | +[TypeError] Expected user_string to be a string, int given |
| 44 | +[TypeError] Expected known_string to be a string, int given |
| 45 | +[TypeError] Expected known_string to be a string, null given |
| 46 | +[TypeError] Expected known_string to be a string, null given |
| 47 | +[TypeError] Expected known_string to be a string, null given |
0 commit comments