Skip to content

Commit a3c610e

Browse files
committed
Added Array test for flatten function
1 parent 942ddc9 commit a3c610e

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

tests/Unit/Support/ArrTest.php

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class ArrTest extends UnitCase
2626
#[Test]
2727
#[DataProvider('get_arr_provider')]
2828
#[DataProvider('is_array_of_class_strings_provider')]
29+
#[DataProvider('flatten_provider')]
2930
public function arr_helper_functions(
3031
string $functionName,
3132
array $parameters,
@@ -374,4 +375,124 @@ public static function is_array_of_class_strings_provider(): array
374375
],
375376
];
376377
}
378+
379+
/**
380+
* @return array<string, mixed>
381+
*/
382+
public static function flatten_provider(): array
383+
{
384+
return [
385+
'flatten, empty array' => [
386+
'flatten',
387+
[
388+
'array' => [],
389+
],
390+
[]
391+
],
392+
'flatten array, one depth' => [
393+
'flatten',
394+
[
395+
'array' => [
396+
'a' => [
397+
'a1' => 1.1,
398+
'a2' => 1.2
399+
],
400+
'b' => 2,
401+
],
402+
],
403+
[
404+
'a1' => 1.1,
405+
'a2' => 1.2,
406+
'b' => 2
407+
]
408+
],
409+
'flatten array, multiple depths' => [
410+
'flatten',
411+
[
412+
'array' => [
413+
'a' => [
414+
'a1' => [
415+
'a1.1' => 1.1,
416+
'a1.2' => 1.2
417+
],
418+
'a2' => 2
419+
],
420+
'b' => 3,
421+
],
422+
],
423+
[
424+
'a1.1' => 1.1,
425+
'a1.2' => 1.2,
426+
'a2' => 2,
427+
'b' => 3
428+
]
429+
],
430+
'flatten array, and resets array keys' => [
431+
'flatten',
432+
[
433+
'array' => [
434+
'a' => [
435+
'a1' => 1.1,
436+
'a2' => 1.2
437+
],
438+
'b' => 2,
439+
],
440+
'depth' => 1.0,
441+
'preserveKeys' => false,
442+
],
443+
[
444+
1.1,
445+
1.2,
446+
2
447+
]
448+
],
449+
'flatten array, and resets array keys, multiple depths' => [
450+
'flatten',
451+
[
452+
'array' => [
453+
'a' => [
454+
'a1' => [
455+
'a1.1' => 1.1,
456+
'a1.2' => 1.2
457+
],
458+
'a2' => 2
459+
],
460+
'b' => 3,
461+
],
462+
'preserveKeys' => false,
463+
],
464+
[
465+
1.1,
466+
1.2,
467+
2,
468+
3
469+
]
470+
],
471+
'flatten array, one depth, not enough' => [
472+
'flatten',
473+
[
474+
'array' => [
475+
'a' => [
476+
'a1' => [
477+
'a1.1' => 1.1,
478+
'a1.2' => 1.2
479+
],
480+
'a2' => 2
481+
],
482+
'b' => 3,
483+
],
484+
'depth' => 1,
485+
'preserveKeys' => false,
486+
],
487+
[
488+
[
489+
'a1.1' => 1.1,
490+
'a1.2' => 1.2
491+
],
492+
2,
493+
3
494+
]
495+
]
496+
];
497+
}
377498
}

0 commit comments

Comments
 (0)