forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayLast.php
More file actions
84 lines (80 loc) · 1.77 KB
/
arrayLast.php
File metadata and controls
84 lines (80 loc) · 1.77 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
81
82
83
84
<?php
/**
* @group compat
*
* @covers ::array_last
*/
class Tests_Compat_arrayLast extends WP_UnitTestCase {
/**
* @ticket 63853
*
* Test that array_last() is always available (either from PHP or WP).
*/
public function test_array_last_availability(): void {
$this->assertTrue( function_exists( 'array_last' ) );
}
/**
* @ticket 63853
*
* @dataProvider data_array_last
*
* @param mixed $expected The expected last value.
* @param array $arr The array to get the last value from.
*/
public function test_array_last( $expected, $arr ): void {
$this->assertSame( $expected, array_last( $arr ) );
}
/**
* Data provider for array_last().
*
* @return array[]
*/
public function data_array_last(): array {
$obj = new \stdClass();
return array(
'string values' => array(
'expected' => 'c',
'arr' => array( 'a', 'b', 'c' ),
),
'associative array' => array(
'expected' => 20,
'arr' => array(
'foo' => 10,
'bar' => 20,
),
),
'empty array' => array(
'expected' => null,
'arr' => array(),
),
'single element array' => array(
'expected' => 42,
'arr' => array( 42 ),
),
'null values' => array(
'expected' => null,
'arr' => array( 'a', 'b', null ),
),
'objects' => array(
'expected' => $obj,
'arr' => array(
1,
2,
$obj,
),
),
'boolean values' => array(
'expected' => false,
'arr' => array( true, false ),
),
'null values in between' => array(
'expected' => 'c',
'arr' => array( 'a', null, 'b', 'c' ),
),
'empty string values' => array(
'expected' => '',
'arr' => array( 'a', 'b', '' ),
),
);
}
}