rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / libs / ArrayUtilsTest.php
blob21472d551ba13f1a73ac3682f6352826d92d6eeb
1 <?php
2 /**
3 * Test class for ArrayUtils class
5 * @group Database
6 */
8 class ArrayUtilsTest extends PHPUnit_Framework_TestCase {
9 private $search;
11 /**
12 * @covers ArrayUtils::findLowerBound
13 * @dataProvider provideFindLowerBound
15 function testFindLowerBound(
16 $valueCallback, $valueCount, $comparisonCallback, $target, $expected
17 ) {
18 $this->assertSame(
19 ArrayUtils::findLowerBound(
20 $valueCallback, $valueCount, $comparisonCallback, $target
21 ), $expected
25 function provideFindLowerBound() {
26 $indexValueCallback = function ( $size ) {
27 return function ( $val ) use ( $size ) {
28 $this->assertTrue( $val >= 0 );
29 $this->assertTrue( $val < $size );
30 return $val;
33 $comparisonCallback = function ( $a, $b ) {
34 return $a - $b;
37 return [
39 $indexValueCallback( 0 ),
41 $comparisonCallback,
43 false,
46 $indexValueCallback( 1 ),
48 $comparisonCallback,
49 -1,
50 false,
53 $indexValueCallback( 1 ),
55 $comparisonCallback,
60 $indexValueCallback( 1 ),
62 $comparisonCallback,
67 $indexValueCallback( 2 ),
69 $comparisonCallback,
70 -1,
71 false,
74 $indexValueCallback( 2 ),
76 $comparisonCallback,
81 $indexValueCallback( 2 ),
83 $comparisonCallback,
84 0.5,
88 $indexValueCallback( 2 ),
90 $comparisonCallback,
95 $indexValueCallback( 2 ),
97 $comparisonCallback,
98 1.5,
102 $indexValueCallback( 3 ),
104 $comparisonCallback,
109 $indexValueCallback( 3 ),
111 $comparisonCallback,
112 1.5,
116 $indexValueCallback( 3 ),
118 $comparisonCallback,
123 $indexValueCallback( 3 ),
125 $comparisonCallback,
133 * @covers ArrayUtils::arrayDiffAssocRecursive
134 * @dataProvider provideArrayDiffAssocRecursive
136 function testArrayDiffAssocRecursive( $expected ) {
137 $args = func_get_args();
138 array_shift( $args );
139 $this->assertEquals( call_user_func_array(
140 'ArrayUtils::arrayDiffAssocRecursive', $args
141 ), $expected );
144 function provideArrayDiffAssocRecursive() {
145 return [
158 [ 1 ],
159 [ 1 ],
163 [ 1 ],
164 [ 1 ],
171 [ 1 ],
176 [ 1 ],
177 [ 2 ],
180 [ '' => 1 ],
181 [ '' => 1 ],
187 [ '' => 1 ],
190 [ 1 ],
191 [ 1 ],
192 [ 2 ],
196 [ 1 ],
197 [ 2 ],
198 [ 1 ],
202 [ 1 ],
203 [ 1, 2 ],
206 [ 1 => 1 ],
207 [ 1 => 1 ],
208 [ 1 ],
212 [ 1 => 1 ],
213 [ 1 ],
214 [ 1 => 1 ],
218 [ 1 => 1 ],
219 [ 1, 1, 1 ],
223 [ [] ],
228 [ [ [] ] ],
232 [ 1, [ 1 ] ],
233 [ 1, [ 1 ] ],
237 [ 1 ],
238 [ 1, [ 1 ] ],
239 [ 2, [ 1 ] ],
243 [ 1, [ 1 ] ],
244 [ 2, [ 1 ] ],
245 [ 1, [ 2 ] ],
248 [ 1 ],
249 [ 1, [] ],
250 [ 2 ],
254 [ 1, [] ],
255 [ 2 ],
256 [ 1 ],
259 [ 1, [ 1 => 2 ] ],
260 [ 1, [ 1, 2 ] ],
261 [ 2, [ 1 ] ],
264 [ 1 ],
265 [ 1, [ 1, 2 ] ],
266 [ 2, [ 1 ] ],
267 [ 2, [ 1 => 2 ] ],
270 [ 1 => [ 1, 2 ] ],
271 [ 1, [ 1, 2 ] ],
272 [ 1, [ 2 ] ],
275 [ 1 => [ [ 2, 3 ], 2 ] ],
276 [ 1, [ [ 2, 3 ], 2 ] ],
277 [ 1, [ 2 ] ],
280 [ 1 => [ [ 2 ], 2 ] ],
281 [ 1, [ [ 2, 3 ], 2 ] ],
282 [ 1, [ [ 1 => 3 ] ] ],
285 [ 1 => [ 1 => 2 ] ],
286 [ 1, [ [ 2, 3 ], 2 ] ],
287 [ 1, [ [ 1 => 3, 0 => 2 ] ] ],
290 [ 1 => [ 1 => 2 ] ],
291 [ 1, [ [ 2, 3 ], 2 ]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