forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayAll.php
More file actions
80 lines (76 loc) · 1.65 KB
/
arrayAll.php
File metadata and controls
80 lines (76 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* @group compat
*
* @covers ::array_all
*/
class Test_Compat_arrayAll extends WP_UnitTestCase {
/**
* Test that array_all() is always available (either from PHP or WP).
*
* @ticket 62558
*/
public function test_array_all_availability() {
$this->assertTrue( function_exists( 'array_all' ) );
}
/**
* @dataProvider data_array_all
*
* @ticket 62558
*
* @param bool $expected The expected value.
* @param array $arr The array.
* @param callable $callback The callback.
*/
public function test_array_all( bool $expected, array $arr, callable $callback ) {
$this->assertSame( $expected, array_all( $arr, $callback ) );
}
/**
* Data provider.
*
* @return array[]
*/
public function data_array_all(): array {
return array(
'empty array' => array(
'expected' => true,
'arr' => array(),
'callback' => function ( $value ) {
return 1 === $value;
},
),
'no match' => array(
'expected' => false,
'arr' => array( 2, 3, 4 ),
'callback' => function ( $value ) {
return 1 === $value;
},
),
'not all match' => array(
'expected' => false,
'arr' => array( 2, 3, 4 ),
'callback' => function ( $value ) {
return 0 === $value % 2;
},
),
'match' => array(
'expected' => true,
'arr' => array( 2, 4, 6 ),
'callback' => function ( $value ) {
return 0 === $value % 2;
},
),
'key match' => array(
'expected' => true,
'arr' => array(
'a' => 2,
'b' => 4,
'c' => 6,
),
'callback' => function ( $value, $key ) {
return strlen( $key ) === 1;
},
),
);
}
}