1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\ArrayMerger\Test\Unit; |
4
|
|
|
|
5
|
|
|
use Graze\ArrayMerger\Test\FakeSequential; |
6
|
|
|
use Graze\ArrayMerger\Test\TestCase; |
7
|
|
|
|
8
|
|
|
class SequentialTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @dataProvider sequentialArrayData |
12
|
|
|
* |
13
|
|
|
* @param array $input |
14
|
|
|
* @param bool $expected |
15
|
|
|
*/ |
16
|
|
|
public function testArray(array $input, $expected) |
17
|
|
|
{ |
18
|
|
|
$sequential = new FakeSequential(); |
19
|
|
|
$this->assertEquals($expected, $sequential->isSequentialPublic($input)); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
public function sequentialArrayData() |
26
|
|
|
{ |
27
|
|
|
return [ |
28
|
|
|
[ |
29
|
|
|
[ |
30
|
|
|
[ |
31
|
|
|
'foo' => 'bar', |
32
|
|
|
], |
33
|
|
|
], |
34
|
|
|
true, |
35
|
|
|
], |
36
|
|
|
[ |
37
|
|
|
[ |
38
|
|
|
[ |
39
|
|
|
'bar', |
40
|
|
|
'foo' => 'bar', |
41
|
|
|
'baz', |
42
|
|
|
], |
43
|
|
|
], |
44
|
|
|
true, |
45
|
|
|
], |
46
|
|
|
[[null], true], |
47
|
|
|
[[true], true], |
48
|
|
|
[[false], true], |
49
|
|
|
[[0], true], |
50
|
|
|
[[1], true], |
51
|
|
|
[[0.0], true], |
52
|
|
|
[[1.0], true], |
53
|
|
|
[['string'], true], |
54
|
|
|
[[[0, 1, 2]], true], |
55
|
|
|
[[new \stdClass()], true], |
56
|
|
|
[['a' => 'b'], false], |
57
|
|
|
[[1 => 'a'], false], |
58
|
|
|
[[1 => 'a', 'c'], false], |
59
|
|
|
[array_fill(0, 1000, uniqid()), true], // big numeric array |
60
|
|
|
[array_fill_keys(range(2, 1000, 3), uniqid()), false], // big misaligned numeric array (=associative) |
61
|
|
|
[ |
62
|
|
|
array_fill_keys( // big associative array |
63
|
|
|
str_split( |
64
|
|
|
str_repeat(uniqid('', true), 100), |
65
|
|
|
3 |
66
|
|
|
), |
67
|
|
|
true |
68
|
|
|
), |
69
|
|
|
false, |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @dataProvider multipleArrayData |
76
|
|
|
* |
77
|
|
|
* @param array $inputs |
78
|
|
|
* @param bool $expected |
79
|
|
|
*/ |
80
|
|
|
public function testMultipleArrays(array $inputs, $expected) |
81
|
|
|
{ |
82
|
|
|
$sequential = new FakeSequential(); |
83
|
|
|
$this->assertEquals($expected, $sequential->areSequentialPublic($inputs)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
|
|
public function multipleArrayData() |
90
|
|
|
{ |
91
|
|
|
return [ |
92
|
|
|
[[['a', 'b'], ['c', 'd']], true], |
93
|
|
|
[[['a', 'b'], ['c', 'd'], ['e', 'f']], true], |
94
|
|
|
[[['a', 'b']], true], |
95
|
|
|
[[['a' => 'b']], false], |
96
|
|
|
[[['a' => 'b'], ['c', 'd']], false], |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|