@@ -55,7 +55,7 @@ public function testCrossJoin()
55
55
56
56
public function testDivide ()
57
57
{
58
- list ( $ keys , $ values) = Arr::divide (['name ' => 'ThinkPHP ' ]);
58
+ [ $ keys , $ values] = Arr::divide (['name ' => 'ThinkPHP ' ]);
59
59
$ this ->assertSame (['name ' ], $ keys );
60
60
$ this ->assertSame (['ThinkPHP ' ], $ values );
61
61
}
@@ -109,7 +109,7 @@ public function testFirst()
109
109
public function testLast ()
110
110
{
111
111
$ array = [100 , 200 , 300 ];
112
- $ last = Arr::last ($ array , function ($ value ) {
112
+ $ last = Arr::last ($ array , function ($ value ) {
113
113
return $ value < 250 ;
114
114
});
115
115
$ this ->assertSame (200 , $ last );
@@ -234,17 +234,17 @@ public function testPrepend()
234
234
public function testPull ()
235
235
{
236
236
$ array = ['name ' => 'ThinkPHP ' , 'price ' => 100 ];
237
- $ name = Arr::pull ($ array , 'name ' );
237
+ $ name = Arr::pull ($ array , 'name ' );
238
238
$ this ->assertSame ('ThinkPHP ' , $ name );
239
239
$ this ->assertSame (['price ' => 100 ], $ array );
240
240
// Only works on first level keys
241
241
$ array = [
'[email protected] ' =>
'Joe ' ,
'jack@localhost ' =>
'Jane ' ];
242
- $ name = Arr::
pull (
$ array,
'[email protected] ' );
242
+ $ name = Arr::
pull (
$ array,
'[email protected] ' );
243
243
$ this ->assertSame ('Joe ' , $ name );
244
244
$ this ->assertSame (['jack@localhost ' => 'Jane ' ], $ array );
245
245
// Does not work for nested keys
246
246
$ array = [
'emails ' => [
'[email protected] ' =>
'Joe ' ,
'jack@localhost ' =>
'Jane ' ]];
247
- $ name = Arr::
pull (
$ array,
'[email protected] ' );
247
+ $ name = Arr::
pull (
$ array,
'[email protected] ' );
248
248
$ this ->assertNull ($ name );
249
249
$ this ->
assertSame ([
'emails ' => [
'[email protected] ' =>
'Joe ' ,
'jack@localhost ' =>
'Jane ' ]],
$ array);
250
250
}
@@ -331,12 +331,42 @@ public function testForget()
331
331
332
332
public function testWrap ()
333
333
{
334
- $ string = 'a ' ;
335
- $ array = ['a ' ];
336
- $ object = new stdClass ();
334
+ $ string = 'a ' ;
335
+ $ array = ['a ' ];
336
+ $ object = new stdClass ();
337
337
$ object ->value = 'a ' ;
338
338
$ this ->assertSame (['a ' ], Arr::wrap ($ string ));
339
339
$ this ->assertSame ($ array , Arr::wrap ($ array ));
340
340
$ this ->assertSame ([$ object ], Arr::wrap ($ object ));
341
341
}
342
+
343
+ public function testMergeDeep ()
344
+ {
345
+ $ this ->assertSame (
346
+ [
347
+ 'a ' => [
348
+ 'c ' => [2 ],
349
+ 'e ' => 5 ,
350
+ 'f ' => 4 ,
351
+ ],
352
+ 'x ' => 3 ,
353
+ ],
354
+ Arr::mergeDeep (
355
+ [
356
+ 'a ' => [
357
+ 'c ' => [1 ],
358
+ 'e ' => 5 ,
359
+ ],
360
+ 'x ' => 4 ,
361
+ ],
362
+ [
363
+ 'a ' => [
364
+ 'c ' => [2 ],
365
+ 'f ' => 4 ,
366
+ ],
367
+ 'x ' => 3 ,
368
+ ]
369
+ )
370
+ );
371
+ }
342
372
}
0 commit comments