1--TEST--
2Test array_all() function : basic functionality
3--FILE--
4<?php
5$array1 = [
6    "a" => 1,
7    "b" => 2,
8    "c" => 3,
9    "d" => 4,
10    "e" => 5,
11];
12
13$array2 = [
14    1, 2, 3, 4, 5
15];
16
17function even($input) {
18  return $input % 2 === 0;
19}
20
21class SmallerTenClass {
22    public static function smallerTen($input) {
23        return $input < 10;
24    }
25}
26
27var_dump(array_all($array1, fn($value) => $value > 0));
28var_dump(array_all($array2, fn($value) => $value > 0));
29var_dump(array_all($array2, fn($value) => $value > 1));
30var_dump(array_all([], fn($value) => true));
31
32echo '*** Test Exception after false result ***' . PHP_EOL;
33try {
34    var_dump(array_all($array2, function ($value) {
35        if ($value > 1) {
36            throw new Exception("Test-Exception");
37        }
38
39        return false;
40    }));
41} catch (Exception) {
42    var_dump("Unexpected Exception");
43}
44
45echo '*** Test aborting with exception ***' . PHP_EOL;
46try {
47    var_dump(array_all($array2, function ($value) {
48        if ($value === 2) {
49            throw new Exception("Test-Exception");
50        }
51
52        var_dump($value);
53
54        return true;
55    }));
56} catch (Exception) {
57    var_dump("Catched Exception");
58}
59
60var_dump(array_all($array1, 'even'));
61
62var_dump(array_all($array1, function($value) {
63    // return nothing
64}));
65
66var_dump(array_all($array1, [
67    'SmallerTenClass',
68    'smallerTen'
69]));
70
71var_dump(array_all($array1, "SmallerTenClass::smallerTen"));
72?>
73--EXPECT--
74bool(true)
75bool(true)
76bool(false)
77bool(true)
78*** Test Exception after false result ***
79bool(false)
80*** Test aborting with exception ***
81int(1)
82string(17) "Catched Exception"
83bool(false)
84bool(false)
85bool(true)
86bool(true)
87