‪TYPO3CMS  11.5
ArrayUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
29 class ‪ArrayUtilityTest extends UnitTestCase
30 {
32  // Tests concerning filterByValueRecursive
34 
42  public function ‪filterByValueRecursive(): array
43  {
44  return [
45  'empty search array' => [
46  'banana',
47  [],
48  [],
49  ],
50  'empty string as needle' => [
51  '',
52  [
53  '',
54  'apple',
55  ],
56  [
57  '',
58  ],
59  ],
60  'flat array searching for string' => [
61  'banana',
62  [
63  'apple',
64  'banana',
65  ],
66  [
67  1 => 'banana',
68  ],
69  ],
70  'flat array searching for string with two matches' => [
71  'banana',
72  [
73  'foo' => 'apple',
74  'firstbanana' => 'banana',
75  'secondbanana' => 'banana',
76  ],
77  [
78  'firstbanana' => 'banana',
79  'secondbanana' => 'banana',
80  ],
81  ],
82  'multi dimensional array searching for string with multiple matches' => [
83  'banana',
84  [
85  'foo' => 'apple',
86  'firstbanana' => 'banana',
87  'grape' => [
88  'foo2' => 'apple2',
89  'secondbanana' => 'banana',
90  'foo3' => [],
91  ],
92  'bar' => 'orange',
93  ],
94  [
95  'firstbanana' => 'banana',
96  'grape' => [
97  'secondbanana' => 'banana',
98  ],
99  ],
100  ],
101  'multi dimensional array searching for integer with multiple matches' => [
102  42,
103  [
104  'foo' => 23,
105  'bar' => 42,
106  [
107  'foo' => 23,
108  'bar' => 42,
109  ],
110  ],
111  [
112  'bar' => 42,
113  [
114  'bar' => 42,
115  ],
116  ],
117  ],
118  'flat array searching for boolean TRUE' => [
119  true,
120  [
121  23 => false,
122  42 => true,
123  ],
124  [
125  42 => true,
126  ],
127  ],
128  'multi dimensional array searching for boolean FALSE' => [
129  false,
130  [
131  23 => false,
132  42 => true,
133  'foo' => [
134  23 => false,
135  42 => true,
136  ],
137  ],
138  [
139  23 => false,
140  'foo' => [
141  23 => false,
142  ],
143  ],
144  ],
145  'flat array searching for array' => [
146  [
147  'foo' => 'bar',
148  ],
149  [
150  'foo' => 'bar',
151  'foobar' => [
152  'foo' => 'bar',
153  ],
154  ],
155  [
156  'foobar' => [
157  'foo' => 'bar',
158  ],
159  ],
160  ],
161  ];
162  }
163 
171  public function ‪filterByValueRecursiveCorrectlyFiltersArray($needle, $haystack, $expectedResult): void
172  {
173  self::assertEquals(
174  $expectedResult,
175  ‪ArrayUtility::filterByValueRecursive($needle, $haystack)
176  );
177  }
178 
183  {
184  $instance = new \stdClass();
185  self::assertEquals(
186  [$instance],
187  ‪ArrayUtility::filterByValueRecursive($instance, [$instance])
188  );
189  }
190 
195  {
196  self::assertEquals(
197  [],
198  ‪ArrayUtility::filterByValueRecursive(new \stdClass(), [new \stdClass()])
199  );
200  }
201 
203  // Tests concerning isValidPath
205 
209  {
210  self::assertTrue(‪ArrayUtility::isValidPath(['foo' => 'bar'], 'foo'));
211  }
212 
217  {
218  self::assertFalse(‪ArrayUtility::isValidPath(['foo' => 'bar'], 'bar'));
219  }
220 
222  // Tests concerning getValueByPath
224 
228  {
229  $this->expectException(\InvalidArgumentException::class);
230  $this->expectExceptionCode(1476557628);
231 
233  }
234 
239  {
240  $this->expectException(\RuntimeException::class);
241  $this->expectExceptionCode(1341397767);
242 
244  }
245 
250  {
251  self::assertSame('foo', ‪ArrayUtility::getValueByPath(['foo'], '0'));
252  }
253 
258  {
259  self::assertSame('bar', ‪ArrayUtility::getValueByPath(['foo' => ['bar']], 'foo/0'));
260  }
261 
271  {
272  return [
273  'not existing index' => [
274  [
275  'foo' => ['foo'],
276  ],
277  'foo/1',
278  false,
279  ],
280  'not existing path 1' => [
281  [
282  'foo' => [],
283  ],
284  'foo/bar/baz',
285  false,
286  ],
287  'not existing path 2' => [
288  [
289  'foo' => [
290  'baz' => 42,
291  ],
292  'bar' => [],
293  ],
294  'foo/bar/baz',
295  false,
296  ],
297  'last segment is not an array' => [
298  [
299  'foo' => [
300  'baz' => 42,
301  ],
302  ],
303  'foo/baz/baz',
304  false,
305  ],
306  // Negative test: This could be improved and the test moved to
307  // the valid data provider if the method supports this
308  'doubletick encapsulated quoted doubletick does not work' => [
309  [
310  '"foo"bar"' => [
311  'baz' => 42,
312  ],
313  'bar' => [],
314  ],
315  '"foo\\"bar"/baz',
316  42,
317  ],
318  // Negative test: Method could be improved here
319  'path with doubletick does not work' => [
320  [
321  'fo"o' => [
322  'bar' => 42,
323  ],
324  ],
325  'fo"o/foobar',
326  42,
327  ],
328  ];
329  }
330 
337  public function ‪getValueByPathThrowsExceptionIfPathNotExists(array $array, $path): void
338  {
339  $this->expectException(\RuntimeException::class);
340  $this->expectExceptionCode(1341397869);
341  ‪ArrayUtility::getValueByPath($array, $path);
342  }
343 
350  public function ‪getValueByPathThrowsSpecificExceptionIfPathNotExists(array $array, string $path): void
351  {
352  $this->expectException(MissingArrayPathException::class);
353  $this->expectExceptionCode(1341397869);
354  ‪ArrayUtility::getValueByPath($array, $path);
355  }
356 
364  public function ‪getValueByPathValidDataProvider(): array
365  {
366  $testObject = new \stdClass();
367  $testObject->foo = 'foo';
368  $testObject->bar = 'bar';
369  return [
370  'integer in multi level array' => [
371  [
372  'foo' => [
373  'bar' => [
374  'baz' => 42,
375  ],
376  'bar2' => [],
377  ],
378  ],
379  'foo/bar/baz',
380  42,
381  ],
382  'zero integer in multi level array' => [
383  [
384  'foo' => [
385  'bar' => [
386  'baz' => 0,
387  ],
388  ],
389  ],
390  'foo/bar/baz',
391  0,
392  ],
393  'NULL value in multi level array' => [
394  [
395  'foo' => [
396  'baz' => null,
397  ],
398  ],
399  'foo/baz',
400  null,
401  ],
402  'get string value' => [
403  [
404  'foo' => [
405  'baz' => 'this is a test string',
406  ],
407  ],
408  'foo/baz',
409  'this is a test string',
410  ],
411  'get boolean value: FALSE' => [
412  [
413  'foo' => [
414  'baz' => false,
415  ],
416  ],
417  'foo/baz',
418  false,
419  ],
420  'get boolean value: TRUE' => [
421  [
422  'foo' => [
423  'baz' => true,
424  ],
425  ],
426  'foo/baz',
427  true,
428  ],
429  'get object value' => [
430  [
431  'foo' => [
432  'baz' => $testObject,
433  ],
434  ],
435  'foo/baz',
436  $testObject,
437  ],
438  'sub array' => [
439  [
440  'foo' => [
441  'bar' => [
442  'baz' => 42,
443  ],
444  ],
445  ],
446  'foo/bar',
447  [
448  'baz' => 42,
449  ],
450  ],
451  'enclosed path' => [
452  [
453  'foo/bar' => [
454  'foobar' => 42,
455  ],
456  ],
457  '"foo/bar"/foobar',
458  42,
459  ],
460  ];
461  }
462 
470  public function ‪getValueByPathGetsCorrectValue(array $array, $path, $expectedResult): void
471  {
472  self::assertEquals($expectedResult, ‪ArrayUtility::getValueByPath($array, $path));
473  }
474 
479  {
480  $input = [
481  'foo' => [
482  'bar' => [
483  'baz' => 42,
484  ],
485  'bar2' => [],
486  ],
487  ];
488  $searchPath = 'foo%bar%baz';
489  $expected = 42;
490  $delimiter = '%';
491  self::assertEquals(
492  $expected,
493  ‪ArrayUtility::getValueByPath($input, $searchPath, $delimiter)
494  );
495  }
496 
498  // Tests concerning setValueByPath
500 
504  {
505  $this->expectException(\RuntimeException::class);
506  $this->expectExceptionCode(1341406194);
507 
508  ‪ArrayUtility::setValueByPath([], '', null);
509  }
510 
515  {
516  $this->expectException(\InvalidArgumentException::class);
517  $this->expectExceptionCode(1478781081);
518 
519  ‪ArrayUtility::setValueByPath([], 123, null);
520  }
521 
526  {
527  $this->expectException(\RuntimeException::class);
528  $this->expectExceptionCode(1341406846);
529 
530  ‪ArrayUtility::setValueByPath(['foo' => 'bar'], '/foo', 'value');
531  }
532 
537  {
538  self::assertSame(['foo' => ['value']], ‪ArrayUtility::setValueByPath(['foo' => []], 'foo/0', 'value'));
539  }
540 
544  public function ‪setValueByPathCanUseZeroAsPath(): void
545  {
546  self::assertSame(['value', 'bar'], ‪ArrayUtility::setValueByPath(['foo', 'bar'], '0', 'value'));
547  }
548 
559  {
560  $testObject = new \stdClass();
561  $testObject->foo = 'foo';
562  $testObject->bar = 'bar';
563  return [
564  'set integer value: 42' => [
565  [
566  'foo' => [
567  'bar' => [
568  'baz' => 0,
569  ],
570  ],
571  ],
572  'foo/bar/baz',
573  42,
574  [
575  'foo' => [
576  'bar' => [
577  'baz' => 42,
578  ],
579  ],
580  ],
581  ],
582  'set integer value: 0' => [
583  [
584  'foo' => [
585  'bar' => [
586  'baz' => 42,
587  ],
588  ],
589  ],
590  'foo/bar/baz',
591  0,
592  [
593  'foo' => [
594  'bar' => [
595  'baz' => 0,
596  ],
597  ],
598  ],
599  ],
600  'set null value' => [
601  [
602  'foo' => [
603  'bar' => [
604  'baz' => 42,
605  ],
606  ],
607  ],
608  'foo/bar/baz',
609  null,
610  [
611  'foo' => [
612  'bar' => [
613  'baz' => null,
614  ],
615  ],
616  ],
617  ],
618  'set array value' => [
619  [
620  'foo' => [
621  'bar' => [
622  'baz' => 42,
623  ],
624  ],
625  ],
626  'foo/bar/baz',
627  [
628  'foo' => 123,
629  ],
630  [
631  'foo' => [
632  'bar' => [
633  'baz' => [
634  'foo' => 123,
635  ],
636  ],
637  ],
638  ],
639  ],
640  'set boolean value: FALSE' => [
641  [
642  'foo' => [
643  'bar' => [
644  'baz' => true,
645  ],
646  ],
647  ],
648  'foo/bar/baz',
649  false,
650  [
651  'foo' => [
652  'bar' => [
653  'baz' => false,
654  ],
655  ],
656  ],
657  ],
658  'set boolean value: TRUE' => [
659  [
660  'foo' => [
661  'bar' => [
662  'baz' => null,
663  ],
664  ],
665  ],
666  'foo/bar/baz',
667  true,
668  [
669  'foo' => [
670  'bar' => [
671  'baz' => true,
672  ],
673  ],
674  ],
675  ],
676  'set object value' => [
677  [
678  'foo' => [
679  'bar' => [
680  'baz' => null,
681  ],
682  ],
683  ],
684  'foo/bar/baz',
685  $testObject,
686  [
687  'foo' => [
688  'bar' => [
689  'baz' => $testObject,
690  ],
691  ],
692  ],
693  ],
694  'multi keys in array' => [
695  [
696  'foo' => [
697  'bar' => [
698  'baz' => 'value',
699  ],
700  'bar2' => [
701  'baz' => 'value',
702  ],
703  ],
704  ],
705  'foo/bar2/baz',
706  'newValue',
707  [
708  'foo' => [
709  'bar' => [
710  'baz' => 'value',
711  ],
712  'bar2' => [
713  'baz' => 'newValue',
714  ],
715  ],
716  ],
717  ],
718  'setting longer path' => [
719  [
720  'foo' => [
721  'bar' => 'value',
722  ],
723  ],
724  'foo/bar/baz/foobar',
725  'newValue',
726  [
727  'foo' => [
728  'bar' => [
729  'baz' => [
730  'foobar' => 'newValue',
731  ],
732  ],
733  ],
734  ],
735  ],
736  'setting longer path in existing array' => [
737  [
738  'foo' => [
739  'bar' => [
740  'existingKey' => 'lolli.did.this',
741  ],
742  ],
743  ],
744  'foo/bar/baz/foobar',
745  'newValue',
746  [
747  'foo' => [
748  'bar' => [
749  'existingKey' => 'lolli.did.this',
750  'baz' => [
751  'foobar' => 'newValue',
752  ],
753  ],
754  ],
755  ],
756  ],
757  ];
758  }
759 
768  public function ‪setValueByPathSetsCorrectValue(array $array, $path, $value, $expectedResult): void
769  {
770  self::assertEquals(
771  $expectedResult,
772  ‪ArrayUtility::setValueByPath($array, $path, $value)
773  );
774  }
775 
776  /**********************
777  /* Tests concerning removeByPath
778  ***********************/
779 
784  {
785  $this->expectException(\RuntimeException::class);
786  $this->expectExceptionCode(1371757718);
787 
789  }
790 
795  {
796  $this->expectException(\RuntimeException::class);
797  $this->expectExceptionCode(1371757719);
798 
799  ‪ArrayUtility::removeByPath([], ['foo']);
800  }
801 
806  {
807  $inputArray = [
808  'foo' => [
809  'bar' => 42,
810  ],
811  ];
812 
813  $this->expectException(\RuntimeException::class);
814  $this->expectExceptionCode(1371757720);
815 
816  ‪ArrayUtility::removeByPath($inputArray, 'foo//bar');
817  }
818 
823  {
824  $inputArray = [
825  'foo' => ['bar'],
826  ];
827 
828  self::assertSame(['foo' => []], ‪ArrayUtility::removeByPath($inputArray, 'foo/0'));
829  }
830 
835  {
836  $inputArray = ['bar'];
837 
838  self::assertSame([], ‪ArrayUtility::removeByPath($inputArray, '0'));
839  }
840 
845  {
846  $inputArray = [
847  'foo' => [
848  'bar' => 42,
849  ],
850  ];
851 
852  $this->expectException(\RuntimeException::class);
853  $this->expectExceptionCode(1371758436);
854 
855  ‪ArrayUtility::removeByPath($inputArray, 'foo/baz');
856  }
857 
862  {
863  $inputArray = [
864  'foo' => [
865  'bar' => 42,
866  ],
867  ];
868 
869  $this->expectException(MissingArrayPathException::class);
870  $this->expectExceptionCode(1371758436);
871 
872  ‪ArrayUtility::removeByPath($inputArray, 'foo/baz');
873  }
874 
878  public function ‪removeByPathAcceptsGivenDelimiter(): void
879  {
880  $inputArray = [
881  'foo' => [
882  'toRemove' => 42,
883  'keep' => 23,
884  ],
885  ];
886  $path = 'foo.toRemove';
887  $expected = [
888  'foo' => [
889  'keep' => 23,
890  ],
891  ];
892  self::assertEquals(
893  $expected,
894  ‪ArrayUtility::removeByPath($inputArray, $path, '.')
895  );
896  }
897 
902  {
903  return [
904  'single value' => [
905  [
906  'foo' => [
907  'toRemove' => 42,
908  'keep' => 23,
909  ],
910  ],
911  'foo/toRemove',
912  [
913  'foo' => [
914  'keep' => 23,
915  ],
916  ],
917  ],
918  'whole array' => [
919  [
920  'foo' => [
921  'bar' => 42,
922  ],
923  ],
924  'foo',
925  [],
926  ],
927  'sub array' => [
928  [
929  'foo' => [
930  'keep' => 23,
931  'toRemove' => [
932  'foo' => 'bar',
933  ],
934  ],
935  ],
936  'foo/toRemove',
937  [
938  'foo' => [
939  'keep' => 23,
940  ],
941  ],
942  ],
943  ];
944  }
945 
953  public function ‪removeByPathRemovesCorrectPath(array $array, $path, $expectedResult): void
954  {
955  self::assertEquals(
956  $expectedResult,
957  ‪ArrayUtility::removeByPath($array, $path)
958  );
959  }
960 
962  // Tests concerning sortByKeyRecursive
964 
968  {
969  $unsortedArray = [
970  'z' => null,
971  'a' => null,
972  'd' => [
973  'c' => null,
974  'b' => null,
975  'd' => null,
976  'a' => null,
977  ],
978  ];
979  $expectedResult = [
980  'a' => null,
981  'd' => [
982  'a' => null,
983  'b' => null,
984  'c' => null,
985  'd' => null,
986  ],
987  'z' => null,
988  ];
989  self::assertSame($expectedResult, ‪ArrayUtility::sortByKeyRecursive($unsortedArray));
990  }
991 
993  // Tests concerning sortArraysByKey
995 
999  {
1000  return [
1001  'assoc array index' => [
1002  [
1003  '22' => [
1004  'uid' => '22',
1005  'title' => 'c',
1006  'dummy' => 2,
1007  ],
1008  '24' => [
1009  'uid' => '24',
1010  'title' => 'a',
1011  'dummy' => 3,
1012  ],
1013  '23' => [
1014  'uid' => '23',
1015  'title' => 'b',
1016  'dummy' => 4,
1017  ],
1018  ],
1019  'title',
1020  true,
1021  [
1022  '24' => [
1023  'uid' => '24',
1024  'title' => 'a',
1025  'dummy' => 3,
1026  ],
1027  '23' => [
1028  'uid' => '23',
1029  'title' => 'b',
1030  'dummy' => 4,
1031  ],
1032  '22' => [
1033  'uid' => '22',
1034  'title' => 'c',
1035  'dummy' => 2,
1036  ],
1037  ],
1038  ],
1039  'numeric array index' => [
1040  [
1041  22 => [
1042  'uid' => '22',
1043  'title' => 'c',
1044  'dummy' => 2,
1045  ],
1046  24 => [
1047  'uid' => '24',
1048  'title' => 'a',
1049  'dummy' => 3,
1050  ],
1051  23 => [
1052  'uid' => '23',
1053  'title' => 'b',
1054  'dummy' => 4,
1055  ],
1056  ],
1057  'title',
1058  true,
1059  [
1060  24 => [
1061  'uid' => '24',
1062  'title' => 'a',
1063  'dummy' => 3,
1064  ],
1065  23 => [
1066  'uid' => '23',
1067  'title' => 'b',
1068  'dummy' => 4,
1069  ],
1070  22 => [
1071  'uid' => '22',
1072  'title' => 'c',
1073  'dummy' => 2,
1074  ],
1075  ],
1076  ],
1077  'numeric array index DESC' => [
1078  [
1079  23 => [
1080  'uid' => '23',
1081  'title' => 'b',
1082  'dummy' => 4,
1083  ],
1084  22 => [
1085  'uid' => '22',
1086  'title' => 'c',
1087  'dummy' => 2,
1088  ],
1089  24 => [
1090  'uid' => '24',
1091  'title' => 'a',
1092  'dummy' => 3,
1093  ],
1094  ],
1095  'title',
1096  false,
1097  [
1098  22 => [
1099  'uid' => '22',
1100  'title' => 'c',
1101  'dummy' => 2,
1102  ],
1103  23 => [
1104  'uid' => '23',
1105  'title' => 'b',
1106  'dummy' => 4,
1107  ],
1108  24 => [
1109  'uid' => '24',
1110  'title' => 'a',
1111  'dummy' => 3,
1112  ],
1113  ],
1114  ],
1115  ];
1116  }
1117 
1126  public function ‪sortArraysByKeyCheckIfSortingIsCorrect(array $array, $key, $ascending, $expectedResult): void
1127  {
1128  $sortedArray = ‪ArrayUtility::sortArraysByKey($array, $key, $ascending);
1129  self::assertSame($expectedResult, $sortedArray);
1130  }
1131 
1136  {
1137  $this->expectException(\RuntimeException::class);
1138  $this->expectExceptionCode(1373727309);
1139 
1140  ‪ArrayUtility::sortArraysByKey([['a'], ['a']], 'dummy');
1141  }
1142 
1144  // Tests concerning arrayExport
1146 
1150  {
1151  $array = [
1152  'foo' => [
1153  'bar' => 42,
1154  'bar2' => [
1155  'baz' => 'val\'ue',
1156  'baz2' => true,
1157  'baz3' => false,
1158  'baz4' => [],
1159  ],
1160  ],
1161  'baz' => 23,
1162  'foobar' => null,
1163  'qux' => 0.1,
1164  'qux2' => 0.000000001,
1165  ];
1166  $expected =
1167  '[' . LF .
1168  ' \'foo\' => [' . LF .
1169  ' \'bar\' => 42,' . LF .
1170  ' \'bar2\' => [' . LF .
1171  ' \'baz\' => \'val\\\'ue\',' . LF .
1172  ' \'baz2\' => true,' . LF .
1173  ' \'baz3\' => false,' . LF .
1174  ' \'baz4\' => [],' . LF .
1175  ' ],' . LF .
1176  ' ],' . LF .
1177  ' \'baz\' => 23,' . LF .
1178  ' \'foobar\' => null,' . LF .
1179  ' \'qux\' => 0.1,' . LF .
1180  ' \'qux2\' => 1.0E-9,' . LF .
1181  ']';
1182  self::assertSame($expected, ‪ArrayUtility::arrayExport($array));
1183  }
1184 
1189  {
1190  $array = [
1191  'foo' => [
1192  'bar' => new \stdClass(),
1193  ],
1194  ];
1195 
1196  $this->expectException(\RuntimeException::class);
1197  $this->expectExceptionCode(1342294987);
1198 
1200  }
1201 
1206  {
1207  $array = [
1208  'foo' => 'string key',
1209  23 => 'integer key',
1210  '42' => 'string key representing integer',
1211  ];
1212  $expected =
1213  '[' . LF .
1214  ' \'foo\' => \'string key\',' . LF .
1215  ' 23 => \'integer key\',' . LF .
1216  ' 42 => \'string key representing integer\',' . LF .
1217  ']';
1218  self::assertSame($expected, ‪ArrayUtility::arrayExport($array));
1219  }
1220 
1225  {
1226  $array = [
1227  0 => 'zero',
1228  1 => 'one',
1229  2 => 'two',
1230  ];
1231  $expected =
1232  '[' . LF .
1233  ' \'zero\',' . LF .
1234  ' \'one\',' . LF .
1235  ' \'two\',' . LF .
1236  ']';
1237  self::assertSame($expected, ‪ArrayUtility::arrayExport($array));
1238  }
1239 
1244  {
1245  $array = [
1246  0 => 'zero',
1247  1 => 'one',
1248  3 => 'three',
1249  4 => 'four',
1250  ];
1251  $expected =
1252  '[' . LF .
1253  ' 0 => \'zero\',' . LF .
1254  ' 1 => \'one\',' . LF .
1255  ' 3 => \'three\',' . LF .
1256  ' 4 => \'four\',' . LF .
1257  ']';
1258  self::assertSame($expected, ‪ArrayUtility::arrayExport($array));
1259  }
1260 
1262  // Tests concerning flatten
1264 
1269  {
1270  return [
1271  'plain array' => [
1272  [
1273  'first' => 1,
1274  'second' => 2,
1275  ],
1276  [
1277  'first' => 1,
1278  'second' => 2,
1279  ],
1280  ],
1281  'plain array with faulty dots' => [
1282  [
1283  'first.' => 1,
1284  'second.' => 2,
1285  ],
1286  [
1287  'first' => 1,
1288  'second' => 2,
1289  ],
1290  ],
1291  'nested array of 2 levels' => [
1292  [
1293  'first.' => [
1294  'firstSub' => 1,
1295  ],
1296  'second.' => [
1297  'secondSub' => 2,
1298  ],
1299  ],
1300  [
1301  'first.firstSub' => 1,
1302  'second.secondSub' => 2,
1303  ],
1304  ],
1305  'nested array of 2 levels with faulty dots' => [
1306  [
1307  'first.' => [
1308  'firstSub.' => 1,
1309  ],
1310  'second.' => [
1311  'secondSub.' => 2,
1312  ],
1313  ],
1314  [
1315  'first.firstSub' => 1,
1316  'second.secondSub' => 2,
1317  ],
1318  ],
1319  'nested array of 3 levels' => [
1320  [
1321  'first.' => [
1322  'firstSub.' => [
1323  'firstSubSub' => 1,
1324  ],
1325  ],
1326  'second.' => [
1327  'secondSub.' => [
1328  'secondSubSub' => 2,
1329  ],
1330  ],
1331  ],
1332  [
1333  'first.firstSub.firstSubSub' => 1,
1334  'second.secondSub.secondSubSub' => 2,
1335  ],
1336  ],
1337  'nested array of 3 levels with faulty dots' => [
1338  [
1339  'first.' => [
1340  'firstSub.' => [
1341  'firstSubSub.' => 1,
1342  ],
1343  ],
1344  'second.' => [
1345  'secondSub.' => [
1346  'secondSubSub.' => 2,
1347  ],
1348  ],
1349  ],
1350  [
1351  'first.firstSub.firstSubSub' => 1,
1352  'second.secondSub.secondSubSub' => 2,
1353  ],
1354  ],
1355  ];
1356  }
1357 
1364  public function ‪flattenCalculatesExpectedResult(array $array, array $expected): void
1365  {
1366  self::assertEquals($expected, ‪ArrayUtility::flatten($array));
1367  }
1368 
1370  // Tests concerning flattenPlain
1372 
1377  {
1378  return [
1379  'plain array' => [
1380  [
1381  'first' => 1,
1382  'second' => 2,
1383  ],
1384  [
1385  'first' => 1,
1386  'second' => 2,
1387  ],
1388  ],
1389  'plain array with trailing dots' => [
1390  [
1391  'first.' => 1,
1392  'second.' => 2,
1393  ],
1394  [
1395  'first\.' => 1,
1396  'second\.' => 2,
1397  ],
1398  ],
1399  'nested array of 2 levels' => [
1400  [
1401  'first' => [
1402  'firstSub' => 1,
1403  ],
1404  'second' => [
1405  'secondSub' => 2,
1406  ],
1407  ],
1408  [
1409  'first.firstSub' => 1,
1410  'second.secondSub' => 2,
1411  ],
1412  ],
1413  'nested array of 2 levels with dots in keys' => [
1414  [
1415  'first.el' => [
1416  'firstSub.' => 1,
1417  ],
1418  'second.el' => [
1419  'secondSub.' => 2,
1420  ],
1421  ],
1422  [
1423  'first\.el.firstSub\.' => 1,
1424  'second\.el.secondSub\.' => 2,
1425  ],
1426  ],
1427  'nested array of 2 levels with dots inside keys' => [
1428  [
1429  'first' => [
1430  'first.sub' => 1,
1431  ],
1432  'second' => [
1433  'second.sub' => 2,
1434  ],
1435  ],
1436  [
1437  'first.first\.sub' => 1,
1438  'second.second\.sub' => 2,
1439  ],
1440  ],
1441  'nested array of 3 levels' => [
1442  [
1443  'first' => [
1444  'firstSub' => [
1445  'firstSubSub' => 1,
1446  ],
1447  ],
1448  'second' => [
1449  'secondSub' => [
1450  'secondSubSub' => 2,
1451  ],
1452  ],
1453  ],
1454  [
1455  'first.firstSub.firstSubSub' => 1,
1456  'second.secondSub.secondSubSub' => 2,
1457  ],
1458  ],
1459  'nested array of 3 levels with dots in keys' => [
1460  [
1461  'first.' => [
1462  'firstSub.' => [
1463  'firstSubSub.' => 1,
1464  ],
1465  ],
1466  'second.' => [
1467  'secondSub.' => [
1468  'secondSubSub.' => 2,
1469  ],
1470  ],
1471  ],
1472  [
1473  'first\..firstSub\..firstSubSub\.' => 1,
1474  'second\..secondSub\..secondSubSub\.' => 2,
1475  ],
1476  ],
1477  'duplicate keys, one with dot, one without' => [
1478  [
1479  'foo' => 'node',
1480  'foo.' => [
1481  'bar' => 'bla',
1482  ],
1483  ],
1484  [
1485  'foo' => 'node',
1486  'foo\..bar' => 'bla',
1487  ],
1488  ],
1489  'duplicate keys, one with dot with scalar value, one without, last wins' => [
1490  [
1491  'foo.' => 'dot',
1492  'foo' => 'node',
1493  ],
1494  [
1495  'foo\.' => 'dot',
1496  'foo' => 'node',
1497  ],
1498  ],
1499  'empty key' => [
1500  [
1501  '' => 'node',
1502  ],
1503  [
1504  '' => 'node',
1505  ],
1506  ],
1507  'dot key' => [
1508  [
1509  '.' => 'node',
1510  ],
1511  [
1512  '\.' => 'node',
1513  ],
1514  ],
1515  'empty array' => [
1516  [],
1517  [],
1518  ],
1519  'nested lists' => [
1520  [
1521  ['foo', 'bar'],
1522  ['bla', 'baz'],
1523  ],
1524  [
1525  '0.0' => 'foo',
1526  '0.1' => 'bar',
1527  '1.0' => 'bla',
1528  '1.1' => 'baz',
1529  ],
1530  ],
1531  ];
1532  }
1533 
1540  public function ‪flattenPlainCalculatesExpectedResult(array $array, array $expected): void
1541  {
1542  self::assertEquals($expected, ‪ArrayUtility::flattenPlain($array));
1543  }
1544 
1549  {
1550  return [
1551  'plain array' => [
1552  [
1553  'first' => 1,
1554  'second' => 2,
1555  ],
1556  [
1557  'first' => 1,
1558  'second' => 2,
1559  ],
1560  ],
1561  'plain array with dots' => [
1562  [
1563  'first.' => 1,
1564  'second.' => 2,
1565  ],
1566  [
1567  'first.' => 1,
1568  'second.' => 2,
1569  ],
1570  ],
1571  'nested array of 2 levels' => [
1572  [
1573  'first.' => [
1574  'firstSub' => 1,
1575  ],
1576  'second.' => [
1577  'secondSub' => 2,
1578  ],
1579  ],
1580  [
1581  'first.firstSub' => 1,
1582  'second.secondSub' => 2,
1583  ],
1584  ],
1585  'nested array of 2 levels with dots' => [
1586  [
1587  'first.' => [
1588  'firstSub.' => 1,
1589  ],
1590  'second.' => [
1591  'secondSub.' => 2,
1592  ],
1593  ],
1594  [
1595  'first.firstSub.' => 1,
1596  'second.secondSub.' => 2,
1597  ],
1598  ],
1599  'nested array of 3 levels' => [
1600  [
1601  'first.' => [
1602  'firstSub.' => [
1603  'firstSubSub' => 1,
1604  ],
1605  ],
1606  'second.' => [
1607  'secondSub.' => [
1608  'secondSubSub' => 2,
1609  ],
1610  ],
1611  ],
1612  [
1613  'first.firstSub.firstSubSub' => 1,
1614  'second.secondSub.secondSubSub' => 2,
1615  ],
1616  ],
1617  'nested array of 3 levels with dots' => [
1618  [
1619  'first.' => [
1620  'firstSub.' => [
1621  'firstSubSub.' => 1,
1622  ],
1623  ],
1624  'second.' => [
1625  'secondSub.' => [
1626  'secondSubSub.' => 2,
1627  ],
1628  ],
1629  ],
1630  [
1631  'first.firstSub.firstSubSub.' => 1,
1632  'second.secondSub.secondSubSub.' => 2,
1633  ],
1634  ],
1635  'nested array of 3 levels with multi dots' => [
1636  [
1637  'first.' => [
1638  'firstSub..' => [
1639  'firstSubSub..' => 1,
1640  ],
1641  ],
1642  'second.' => [
1643  'secondSub..' => [
1644  'secondSubSub.' => 2,
1645  ],
1646  ],
1647  ],
1648  [
1649  'first.firstSub..firstSubSub..' => 1,
1650  'second.secondSub..secondSubSub.' => 2,
1651  ],
1652  ],
1653  ];
1654  }
1655 
1662  public function ‪flattenWithKeepDotsCalculatesExpectedResult(array $array, array $expected): void
1663  {
1664  self::assertEquals($expected, ‪ArrayUtility::flatten($array, '', true));
1665  }
1666 
1668  // Tests concerning intersectRecursive
1670 
1675  {
1676  $sameObject = new \stdClass();
1677  return [
1678  // array($source, $mask, $expected)
1679  'empty array is returned if source is empty array' => [
1680  [],
1681  [
1682  'foo' => 'bar',
1683  ],
1684  [],
1685  ],
1686  'empty array is returned if mask is empty' => [
1687  [
1688  'foo' => 'bar',
1689  ],
1690  [],
1691  [],
1692  ],
1693  'key is kept on first level if exists in mask' => [
1694  [
1695  'foo' => 42,
1696  ],
1697  [
1698  'foo' => 42,
1699  ],
1700  [
1701  'foo' => 42,
1702  ],
1703  ],
1704  'value of key in source is kept if mask has different value' => [
1705  [
1706  'foo' => 42,
1707  ],
1708  [
1709  'foo' => new \stdClass(),
1710  ],
1711  [
1712  'foo' => 42,
1713  ],
1714  ],
1715  'key is kept on first level if according mask value is NULL' => [
1716  [
1717  'foo' => 42,
1718  ],
1719  [
1720  'foo' => null,
1721  ],
1722  [
1723  'foo' => 42,
1724  ],
1725  ],
1726  'null in source value is kept' => [
1727  [
1728  'foo' => null,
1729  ],
1730  [
1731  'foo' => 'bar',
1732  ],
1733  [
1734  'foo' => null,
1735  ],
1736  ],
1737  'mask does not add new keys' => [
1738  [
1739  'foo' => 42,
1740  ],
1741  [
1742  'foo' => 23,
1743  'bar' => [
1744  4711,
1745  ],
1746  ],
1747  [
1748  'foo' => 42,
1749  ],
1750  ],
1751  'mask does not overwrite simple values with arrays' => [
1752  [
1753  'foo' => 42,
1754  ],
1755  [
1756  'foo' => [
1757  'bar' => 23,
1758  ],
1759  ],
1760  [
1761  'foo' => 42,
1762  ],
1763  ],
1764  'key is kept on first level if according mask value is array' => [
1765  [
1766  'foo' => 42,
1767  ],
1768  [
1769  'foo' => [
1770  'bar' => 23,
1771  ],
1772  ],
1773  [
1774  'foo' => 42,
1775  ],
1776  ],
1777  'full array is kept if value is array and mask value is simple type' => [
1778  [
1779  'foo' => [
1780  'bar' => 23,
1781  ],
1782  ],
1783  [
1784  'foo' => 42,
1785  ],
1786  [
1787  'foo' => [
1788  'bar' => 23,
1789  ],
1790  ],
1791  ],
1792  'key handling is type agnostic' => [
1793  [
1794  42 => 'foo',
1795  ],
1796  [
1797  '42' => 'bar',
1798  ],
1799  [
1800  42 => 'foo',
1801  ],
1802  ],
1803  'value is same if value is object' => [
1804  [
1805  'foo' => $sameObject,
1806  ],
1807  [
1808  'foo' => 'something',
1809  ],
1810  [
1811  'foo' => $sameObject,
1812  ],
1813  ],
1814  'mask does not add simple value to result if key does not exist in source' => [
1815  [
1816  'foo' => '42',
1817  ],
1818  [
1819  'foo' => '42',
1820  'bar' => 23,
1821  ],
1822  [
1823  'foo' => '42',
1824  ],
1825  ],
1826  'array of source is kept if value of mask key exists but is no array' => [
1827  [
1828  'foo' => '42',
1829  'bar' => [
1830  'baz' => 23,
1831  ],
1832  ],
1833  [
1834  'foo' => 'value is not significant',
1835  'bar' => null,
1836  ],
1837  [
1838  'foo' => '42',
1839  'bar' => [
1840  'baz' => 23,
1841  ],
1842  ],
1843  ],
1844  'sub arrays are kept if mask has according sub array key and is similar array' => [
1845  [
1846  'first1' => 42,
1847  'first2' => [
1848  'second1' => 23,
1849  'second2' => 4711,
1850  ],
1851  ],
1852  [
1853  'first1' => 42,
1854  'first2' => [
1855  'second1' => 'exists but different',
1856  ],
1857  ],
1858  [
1859  'first1' => 42,
1860  'first2' => [
1861  'second1' => 23,
1862  ],
1863  ],
1864  ],
1865  ];
1866  }
1867 
1875  public function ‪intersectRecursiveCalculatesExpectedResult(array $source, array $mask, array $expected): void
1876  {
1877  self::assertSame($expected, ‪ArrayUtility::intersectRecursive($source, $mask));
1878  }
1879 
1881  // Tests concerning renumberKeysToAvoidLeapsIfKeysAreAllNumeric
1883 
1887  {
1888  return [
1889  'empty array is returned if source is empty array' => [
1890  [],
1891  [],
1892  ],
1893  'returns self if array is already numerically keyed' => [
1894  [1, 2, 3],
1895  [1, 2, 3],
1896  ],
1897  'returns correctly if keys are numeric, but contains a leap' => [
1898  [0 => 'One', 1 => 'Two', 3 => 'Three'],
1899  [0 => 'One', 1 => 'Two', 2 => 'Three'],
1900  ],
1901  'returns correctly even though keys are strings but still numeric' => [
1902  ['0' => 'One', '1' => 'Two', '3' => 'Three'],
1903  [0 => 'One', 1 => 'Two', 2 => 'Three'],
1904  ],
1905  'returns correctly if just a single keys is not numeric' => [
1906  [0 => 'Zero', '1' => 'One', 'Two' => 'Two'],
1907  [0 => 'Zero', '1' => 'One', 'Two' => 'Two'],
1908  ],
1909  'returns unchanged if keys end with a dot' => [
1910  ['2.' => 'Two', '1.' => 'One', '0.' => 'Zero'],
1911  ['2.' => 'Two', '1.' => 'One', '0.' => 'Zero'],
1912  ],
1913  'return self with nested numerically keyed array' => [
1914  [
1915  'One',
1916  'Two',
1917  'Three',
1918  [
1919  'sub.One',
1920  'sub.Two',
1921  ],
1922  ],
1923  [
1924  'One',
1925  'Two',
1926  'Three',
1927  [
1928  'sub.One',
1929  'sub.Two',
1930  ],
1931  ],
1932  ],
1933  'returns correctly with nested numerically keyed array with leaps' => [
1934  [
1935  'One',
1936  'Two',
1937  'Three',
1938  [
1939  0 => 'sub.One',
1940  2 => 'sub.Two',
1941  ],
1942  ],
1943  [
1944  'One',
1945  'Two',
1946  'Three',
1947  [
1948  'sub.One',
1949  'sub.Two',
1950  ],
1951  ],
1952  ],
1953  'returns correctly with nested string-keyed array' => [
1954  [
1955  'One',
1956  'Two',
1957  'Three',
1958  [
1959  'one' => 'sub.One',
1960  'two' => 'sub.Two',
1961  ],
1962  ],
1963  [
1964  'One',
1965  'Two',
1966  'Three',
1967  [
1968  'one' => 'sub.One',
1969  'two' => 'sub.Two',
1970  ],
1971  ],
1972  ],
1973  'returns correctly with deeply nested arrays' => [
1974  [
1975  'One',
1976  'Two',
1977  [
1978  'one' => 1,
1979  'two' => 2,
1980  'three' => [
1981  2 => 'SubSubOne',
1982  5 => 'SubSubTwo',
1983  9 => [0, 1, 2],
1984  [],
1985  ],
1986  ],
1987  ],
1988  [
1989  'One',
1990  'Two',
1991  [
1992  'one' => 1,
1993  'two' => 2,
1994  'three' => [
1995  'SubSubOne',
1996  'SubSubTwo',
1997  [0, 1, 2],
1998  [],
1999  ],
2000  ],
2001  ],
2002  ],
2003  ];
2004  }
2005 
2012  public function ‪renumberKeysToAvoidLeapsIfKeysAreAllNumericReturnsExpectedOrder(array $inputArray, array $expected): void
2013  {
2014  self::assertEquals($expected, ‪ArrayUtility::renumberKeysToAvoidLeapsIfKeysAreAllNumeric($inputArray));
2015  }
2016 
2021  {
2022  return [
2023  'Override array can reset string to array' => [
2024  [
2025  'first' => [
2026  'second' => 'foo',
2027  ],
2028  ],
2029  [
2030  'first' => [
2031  'second' => ['third' => 'bar'],
2032  ],
2033  ],
2034  true,
2035  true,
2036  true,
2037  [
2038  'first' => [
2039  'second' => ['third' => 'bar'],
2040  ],
2041  ],
2042  ],
2043  'Override array does not reset array to string (weird!)' => [
2044  [
2045  'first' => [],
2046  ],
2047  [
2048  'first' => 'foo',
2049  ],
2050  true,
2051  true,
2052  true,
2053  [
2054  'first' => [], // This is rather unexpected, naive expectation: first => 'foo'
2055  ],
2056  ],
2057  'Override array does override string with null' => [
2058  [
2059  'first' => 'foo',
2060  ],
2061  [
2062  'first' => null,
2063  ],
2064  true,
2065  true,
2066  true,
2067  [
2068  'first' => null,
2069  ],
2070  ],
2071  'Override array does override null with string' => [
2072  [
2073  'first' => null,
2074  ],
2075  [
2076  'first' => 'foo',
2077  ],
2078  true,
2079  true,
2080  true,
2081  [
2082  'first' => 'foo',
2083  ],
2084  ],
2085  'Override array does override null with empty string' => [
2086  [
2087  'first' => null,
2088  ],
2089  [
2090  'first' => '',
2091  ],
2092  true,
2093  true,
2094  true,
2095  [
2096  'first' => '',
2097  ],
2098  ],
2099  'Override array does not override string with NULL if requested' => [
2100  [
2101  'first' => 'foo',
2102  ],
2103  [
2104  'first' => null,
2105  ],
2106  true,
2107  false, // no include empty values
2108  true,
2109  [
2110  'first' => 'foo',
2111  ],
2112  ],
2113  'Override array does override null with null' => [
2114  [
2115  'first' => null,
2116  ],
2117  [
2118  'first' => null,
2119  ],
2120  true,
2121  true,
2122  true,
2123  [
2124  'first' => '',
2125  ],
2126  ],
2127  'Override array can __UNSET values' => [
2128  [
2129  'first' => [
2130  'second' => 'second',
2131  'third' => 'third',
2132  ],
2133  'fifth' => [],
2134  ],
2135  [
2136  'first' => [
2137  'second' => 'overrule',
2138  'third' => '__UNSET',
2139  'fourth' => 'overrile',
2140  ],
2141  'fifth' => '__UNSET',
2142  ],
2143  true,
2144  true,
2145  true,
2146  [
2147  'first' => [
2148  'second' => 'overrule',
2149  'fourth' => 'overrile',
2150  ],
2151  ],
2152  ],
2153  'Override can add keys' => [
2154  [
2155  'first' => 'foo',
2156  ],
2157  [
2158  'second' => 'bar',
2159  ],
2160  true,
2161  true,
2162  true,
2163  [
2164  'first' => 'foo',
2165  'second' => 'bar',
2166  ],
2167  ],
2168  'Override does not add key if __UNSET' => [
2169  [
2170  'first' => 'foo',
2171  ],
2172  [
2173  'second' => '__UNSET',
2174  ],
2175  true,
2176  true,
2177  true,
2178  [
2179  'first' => 'foo',
2180  ],
2181  ],
2182  'Override does not add key if not requested' => [
2183  [
2184  'first' => 'foo',
2185  ],
2186  [
2187  'second' => 'bar',
2188  ],
2189  false, // no add keys
2190  true,
2191  true,
2192  [
2193  'first' => 'foo',
2194  ],
2195  ],
2196  'Override does not add key if not requested with add include empty values' => [
2197  [
2198  'first' => 'foo',
2199  ],
2200  [
2201  'second' => 'bar',
2202  ],
2203  false, // no add keys
2204  false, // no include empty values
2205  true,
2206  [
2207  'first' => 'foo',
2208  ],
2209  ],
2210  'Override does not override string with empty string if requested' => [
2211  [
2212  'first' => 'foo',
2213  ],
2214  [
2215  'first' => '',
2216  ],
2217  true,
2218  false, // no include empty values
2219  true,
2220  [
2221  'first' => 'foo',
2222  ],
2223  ],
2224  'Override array does merge instead of __UNSET if requested (weird!)' => [
2225  [
2226  'first' => [
2227  'second' => 'second',
2228  'third' => 'third',
2229  ],
2230  'fifth' => [],
2231  ],
2232  [
2233  'first' => [
2234  'second' => 'overrule',
2235  'third' => '__UNSET',
2236  'fourth' => 'overrile',
2237  ],
2238  'fifth' => '__UNSET',
2239  ],
2240  true,
2241  true,
2242  false,
2243  [
2244  'first' => [
2245  'second' => 'overrule',
2246  'third' => '__UNSET', // overruled
2247  'fourth' => 'overrile',
2248  ],
2249  'fifth' => [], // not overruled with string here, naive expectation: 'fifth' => '__UNSET'
2250  ],
2251  ],
2252  ];
2253  }
2254 
2265  public function ‪mergeRecursiveWithOverruleCalculatesExpectedResult($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature, $expected): void
2266  {
2267  ‪ArrayUtility::mergeRecursiveWithOverrule($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature);
2268  self::assertEquals($expected, $input1);
2269  }
2270 
2272  // Tests concerning removeArrayEntryByValue
2274 
2278  {
2279  $inputArray = [
2280  '0' => 'test1',
2281  '1' => 'test2',
2282  '2' => 'test3',
2283  '3' => 'test2',
2284  ];
2285  $compareValue = 'test2';
2286  $expectedResult = [
2287  '0' => 'test1',
2288  '2' => 'test3',
2289  ];
2290  $actualResult = ‪ArrayUtility::removeArrayEntryByValue($inputArray, $compareValue);
2291  self::assertEquals($expectedResult, $actualResult);
2292  }
2293 
2298  {
2299  $inputArray = [
2300  '0' => 'foo',
2301  '1' => [
2302  '10' => 'bar',
2303  ],
2304  '2' => 'bar',
2305  ];
2306  $compareValue = 'bar';
2307  $expectedResult = [
2308  '0' => 'foo',
2309  '1' => [],
2310  ];
2311  $actualResult = ‪ArrayUtility::removeArrayEntryByValue($inputArray, $compareValue);
2312  self::assertEquals($expectedResult, $actualResult);
2313  }
2314 
2319  {
2320  $inputArray = [
2321  '0' => 'foo',
2322  '1' => '',
2323  '2' => 'bar',
2324  ];
2325  $compareValue = '';
2326  $expectedResult = [
2327  '0' => 'foo',
2328  '2' => 'bar',
2329  ];
2330  $actualResult = ‪ArrayUtility::removeArrayEntryByValue($inputArray, $compareValue);
2331  self::assertEquals($expectedResult, $actualResult);
2332  }
2333 
2335  // Tests concerning keepItemsInArray
2337 
2344  public function ‪keepItemsInArrayWorksWithOneArgument($search, $array, $expected): void
2345  {
2346  self::assertEquals($expected, ‪ArrayUtility::keepItemsInArray($array, $search));
2347  }
2348 
2355  {
2356  $array = [
2357  0 => 0,
2358  'one' => 'one',
2359  'two' => 'two',
2360  'three' => 'three',
2361  ];
2362  return [
2363  'Empty argument will match "all" elements' => [null, $array, $array],
2364  'No match' => ['four', $array, []],
2365  'One match' => ['two', $array, ['two' => 'two']],
2366  'Multiple matches' => ['two,one', $array, ['one' => 'one', 'two' => 'two']],
2367  'Argument can be an array' => [['three'], $array, ['three' => 'three']],
2368  ];
2369  }
2370 
2378  public function ‪keepItemsInArrayCanUseClosure(): void
2379  {
2380  $array = [
2381  'aa' => ['first', 'second'],
2382  'bb' => ['third', 'fourth'],
2383  'cc' => ['fifth', 'sixth'],
2384  ];
2385  $expected = ['bb' => ['third', 'fourth']];
2386  $keepItems = 'third';
2388  $array,
2389  $keepItems,
2390  static function ($value) {
2391  return $value[0];
2392  }
2393  );
2394  self::assertEquals($expected, $match);
2395  }
2396 
2398  // Tests concerning remapArrayKeys
2400 
2404  {
2405  $array = [
2406  'one' => 'one',
2407  'two' => 'two',
2408  'three' => 'three',
2409  ];
2410  $keyMapping = [
2411  'one' => '1',
2412  'two' => '2',
2413  ];
2414  $expected = [
2415  '1' => 'one',
2416  '2' => 'two',
2417  'three' => 'three',
2418  ];
2419  ‪ArrayUtility::remapArrayKeys($array, $keyMapping);
2420  self::assertEquals($expected, $array);
2421  }
2422 
2424  // Tests concerning arrayDiffKeyRecursive
2426 
2430  {
2431  $array1 = [
2432  'key1' => 'value1',
2433  'key2' => 'value2',
2434  'key3' => 'value3',
2435  ];
2436  $array2 = [
2437  'key1' => 'value1',
2438  'key3' => 'value3',
2439  ];
2440  $expectedResult = [
2441  'key2' => 'value2',
2442  ];
2443  $actualResult = ‪ArrayUtility::arrayDiffKeyRecursive($array1, $array2);
2444  self::assertEquals($expectedResult, $actualResult);
2445  }
2446 
2451  {
2452  $array1 = [
2453  'key1' => 'value1',
2454  'key2' => [
2455  'key21' => 'value21',
2456  'key22' => 'value22',
2457  'key23' => [
2458  'key231' => 'value231',
2459  'key232' => 'value232',
2460  ],
2461  ],
2462  ];
2463  $array2 = [
2464  'key1' => 'valueDoesNotMatter',
2465  'key2' => [
2466  'key21' => 'value21',
2467  'key23' => [
2468  'key231' => 'value231',
2469  ],
2470  ],
2471  ];
2472  $expectedResult = [
2473  'key2' => [
2474  'key22' => 'value22',
2475  'key23' => [
2476  'key232' => 'value232',
2477  ],
2478  ],
2479  ];
2480  $actualResult = ‪ArrayUtility::arrayDiffKeyRecursive($array1, $array2);
2481  self::assertEquals($expectedResult, $actualResult);
2482  }
2483 
2488  {
2489  $array1 = [
2490  'key1' => [
2491  'key11' => 'value11',
2492  'key12' => 'value12',
2493  ],
2494  'key2' => 'value2',
2495  'key3' => 'value3',
2496  ];
2497  $array2 = [
2498  'key1' => 'value1',
2499  'key2' => [
2500  'key21' => 'valueDoesNotMatter',
2501  ],
2502  ];
2503  $expectedResult = [
2504  'key3' => 'value3',
2505  ];
2506  $actualResult = ‪ArrayUtility::arrayDiffKeyRecursive($array1, $array2);
2507  self::assertEquals($expectedResult, $actualResult);
2508  }
2509 
2514  {
2515  $array1 = [
2516  'key1' => [
2517  'key11' => 'value11',
2518  'key12' => 'value12',
2519  ],
2520  'key2' => 'value2',
2521  'key3' => 'value3',
2522  ];
2523  $array2 = [
2524  'key1' => [
2525  'key11' => 'valueDoesNotMatter',
2526  'key12' => 'value12',
2527  ],
2528  'key2' => 'value2',
2529  'key3' => 'value3',
2530  ];
2531  $expectedResult = [];
2532  $actualResult = ‪ArrayUtility::arrayDiffKeyRecursive($array1, $array2);
2533  self::assertEquals($expectedResult, $actualResult);
2534  }
2535 
2537  // Tests concerning arrayDiffAssocRecursive
2539 
2543  {
2544  $array1 = [
2545  'key1' => 'value1',
2546  'key2' => 'value2',
2547  'key3' => 'value3',
2548  ];
2549  $array2 = [
2550  'key1' => 'value1',
2551  'key3' => 'value3',
2552  ];
2553  $expectedResult = [
2554  'key2' => 'value2',
2555  ];
2556  $actualResult = ‪ArrayUtility::arrayDiffAssocRecursive($array1, $array2, true);
2557  self::assertEquals($expectedResult, $actualResult);
2558  }
2559 
2564  {
2565  $array1 = [
2566  'key1' => 'value1',
2567  'key2' => [
2568  'key21' => 'value21',
2569  'key22' => 'value22',
2570  'key23' => [
2571  'key231' => 'value231',
2572  'key232' => 'value232',
2573  ],
2574  ],
2575  ];
2576  $array2 = [
2577  'key1' => 'value2',
2578  'key2' => [
2579  'key21' => 'value21',
2580  'key23' => [
2581  'key231' => 'value231',
2582  ],
2583  ],
2584  ];
2585  $expectedResult = [
2586  'key1' => 'value1',
2587  'key2' => [
2588  'key22' => 'value22',
2589  'key23' => [
2590  'key232' => 'value232',
2591  ],
2592  ],
2593  ];
2594  $actualResult = ‪ArrayUtility::arrayDiffAssocRecursive($array1, $array2, true);
2595  self::assertEquals($expectedResult, $actualResult);
2596  }
2597 
2602  {
2603  $array1 = [
2604  'key1' => [
2605  'key11' => 'value11',
2606  'key12' => 'value12',
2607  ],
2608  'key2' => 'value2',
2609  'key3' => 'value3',
2610  ];
2611  $array2 = [
2612  'key1' => 'value1',
2613  'key2' => [
2614  'key21' => 'valueDoesNotMatter',
2615  ],
2616  ];
2617  $expectedResult = [
2618  'key2' => 'value2',
2619  'key3' => 'value3',
2620  ];
2621  $actualResult = ‪ArrayUtility::arrayDiffAssocRecursive($array1, $array2, true);
2622  self::assertEquals($expectedResult, $actualResult);
2623  }
2624 
2629  {
2630  $array1 = [
2631  'key1' => [
2632  'key11' => 'value11',
2633  'key12' => 'value12',
2634  ],
2635  'key2' => 'value2',
2636  'key3' => 'value3',
2637  ];
2638  $array2 = [
2639  'key1' => [
2640  'key11' => 'value11',
2641  'key12' => 'value12',
2642  ],
2643  'key2' => 'value2',
2644  'key3' => 'value3',
2645  ];
2646  $expectedResult = [];
2647  $actualResult = ‪ArrayUtility::arrayDiffAssocRecursive($array1, $array2, true);
2648  self::assertEquals($expectedResult, $actualResult);
2649  }
2650 
2652  // Tests concerning naturalKeySortRecursive
2654 
2659  {
2660  $testArray = [
2661  'bb' => 'bb',
2662  'ab' => 'ab',
2663  '123' => '123',
2664  'aaa' => 'aaa',
2665  'abc' => 'abc',
2666  '23' => '23',
2667  'ba' => 'ba',
2668  'bad' => 'bad',
2669  '2' => '2',
2670  'zap' => 'zap',
2671  '210' => '210',
2672  ];
2673  $expectedResult = [
2674  '2',
2675  '23',
2676  '123',
2677  '210',
2678  'aaa',
2679  'ab',
2680  'abc',
2681  'ba',
2682  'bad',
2683  'bb',
2684  'zap',
2685  ];
2687  self::assertEquals($expectedResult, array_values($testArray));
2688  }
2689 
2694  {
2695  $testArray = [
2696  '2' => '2',
2697  'bb' => 'bb',
2698  'ab' => 'ab',
2699  '23' => '23',
2700  'aaa' => [
2701  'bb' => 'bb',
2702  'ab' => 'ab',
2703  '123' => '123',
2704  'aaa' => 'aaa',
2705  '2' => '2',
2706  'abc' => 'abc',
2707  'ba' => 'ba',
2708  '23' => '23',
2709  'bad' => [
2710  'bb' => 'bb',
2711  'ab' => 'ab',
2712  '123' => '123',
2713  'aaa' => 'aaa',
2714  'abc' => 'abc',
2715  '23' => '23',
2716  'ba' => 'ba',
2717  'bad' => 'bad',
2718  '2' => '2',
2719  'zap' => 'zap',
2720  '210' => '210',
2721  ],
2722  '210' => '210',
2723  'zap' => 'zap',
2724  ],
2725  'abc' => 'abc',
2726  'ba' => 'ba',
2727  '210' => '210',
2728  'bad' => 'bad',
2729  '123' => '123',
2730  'zap' => 'zap',
2731  ];
2732  $expectedResult = [
2733  '2',
2734  '23',
2735  '123',
2736  '210',
2737  'aaa',
2738  'ab',
2739  'abc',
2740  'ba',
2741  'bad',
2742  'bb',
2743  'zap',
2744  ];
2746  self::assertEquals($expectedResult, array_values(array_keys($testArray['aaa']['bad'])));
2747  self::assertEquals($expectedResult, array_values(array_keys($testArray['aaa'])));
2748  self::assertEquals($expectedResult, array_values(array_keys($testArray)));
2749  }
2750 
2757  {
2758  return [
2759  'ordered list of plain numeric keys' => [
2760  'input' => [
2761  '10' => 'foo',
2762  '20' => 'bar',
2763  ],
2764  'expected' => [
2765  10,
2766  20,
2767  ],
2768  ],
2769  'unordered list of plain numeric keys' => [
2770  'input' => [
2771  '20' => 'bar',
2772  '10' => 'foo',
2773  ],
2774  'expected' => [
2775  10,
2776  20,
2777  ],
2778  ],
2779  'list of string keys' => [
2780  'input' => [
2781  '10.' => [
2782  'wrap' => 'foo',
2783  ],
2784  '20.' => [
2785  'wrap' => 'bar',
2786  ],
2787  ],
2788  'expected' => [
2789  10,
2790  20,
2791  ],
2792  ],
2793  'list of mixed keys' => [
2794  'input' => [
2795  '10' => 'foo',
2796  '20.' => [
2797  'wrap' => 'bar',
2798  ],
2799  ],
2800  'expected' => [
2801  10,
2802  20,
2803  ],
2804  ],
2805  'list of mixed keys with one not interpreted as integer' => [
2806  'input' => [
2807  '10' => 'foo',
2808  'bla20.' => [
2809  'wrap' => 'bar',
2810  ],
2811  ],
2812  'expected' => [
2813  0,
2814  10,
2815  ],
2816  ],
2817  'list of mixed keys with more than one not interpreted as integer' => [
2818  'input' => [
2819  '10' => 'foo',
2820  'bla20.' => [
2821  'wrap' => 'bar',
2822  ],
2823  'bla21.' => [
2824  'wrap' => 'foobar',
2825  ],
2826  ],
2827  'expected' => [
2828  0,
2829  10,
2830  ],
2831  ],
2832  ];
2833  }
2834 
2843  {
2844  $result = ‪ArrayUtility::filterAndSortByNumericKeys($input, true);
2845  self::assertEquals($result, $expected);
2846  }
2847 
2854  {
2855  return [
2856  'ordered list of plain numeric keys' => [
2857  'input' => [
2858  '10' => 'foo',
2859  '20' => 'bar',
2860  ],
2861  'expected' => [
2862  10,
2863  20,
2864  ],
2865  ],
2866  'unordered list of plain numeric keys' => [
2867  'input' => [
2868  '20' => 'bar',
2869  '10' => 'foo',
2870  ],
2871  'expected' => [
2872  10,
2873  20,
2874  ],
2875  ],
2876  'list of string keys' => [
2877  'input' => [
2878  '10.' => [
2879  'wrap' => 'foo',
2880  ],
2881  '20.' => [
2882  'wrap' => 'bar',
2883  ],
2884  ],
2885  'expected' => [],
2886  ],
2887  'list of mixed keys' => [
2888  'input' => [
2889  '10' => 'foo',
2890  '20.' => [
2891  'wrap' => 'bar',
2892  ],
2893  ],
2894  'expected' => [
2895  10,
2896  ],
2897  ],
2898  ];
2899  }
2900 
2909  {
2911  self::assertEquals($result, $expected);
2912  }
2913 
2920  {
2921  return [
2922  [
2923  [
2924  '20' => 'test1',
2925  '11' => 'test2',
2926  '16' => 'test3',
2927  ],
2928  [
2929  '11' => 'test2',
2930  '16' => 'test3',
2931  '20' => 'test1',
2932  ],
2933  ],
2934  [
2935  [
2936  '20' => 'test1',
2937  '16.5' => 'test2',
2938  '16' => 'test3',
2939  ],
2940  [
2941  '20' => 'test1',
2942  '16.5' => 'test2',
2943  '16' => 'test3',
2944  ],
2945  ],
2946  [
2947  [
2948  '20' => 'test20',
2949  'somestring' => 'teststring',
2950  '16' => 'test16',
2951  ],
2952  [
2953  '20' => 'test20',
2954  'somestring' => 'teststring',
2955  '16' => 'test16',
2956  ],
2957  ],
2958  ];
2959  }
2960 
2969  public function ‪sortArrayWithIntegerKeysSortsNumericArrays(array $arrayToSort, array $expectedArray): void
2970  {
2971  $sortedArray = ‪ArrayUtility::sortArrayWithIntegerKeys($arrayToSort);
2972  self::assertSame($sortedArray, $expectedArray);
2973  }
2974 
2979  {
2980  $this->expectException(\InvalidArgumentException::class);
2981  $this->expectExceptionCode(1325697085);
2982 
2983  $arrayToTest = [
2984  'roger' => '',
2985  'francine' => '',
2986  'stan' => '',
2987  ];
2988 
2989  $allowedArrayKeys = [
2990  'roger',
2991  'francine',
2992  ];
2993 
2994  ‪ArrayUtility::assertAllArrayKeysAreValid($arrayToTest, $allowedArrayKeys);
2995  }
2996 
3001  {
3002  $arrayToTest = [
3003  'roger' => '',
3004  'francine' => '',
3005  'stan' => '',
3006  ];
3007 
3008  $allowedArrayKeys = [
3009  'roger',
3010  'francine',
3011  'stan',
3012  ];
3013 
3014  ‪ArrayUtility::assertAllArrayKeysAreValid($arrayToTest, $allowedArrayKeys);
3015  }
3016 
3021  {
3022  $input = [
3023  20 => 'b',
3024  10 => 'a',
3025  40 => 'd',
3026  30 => 'c',
3027  50 => [
3028  20 => 'a',
3029  10 => 'b',
3030  ],
3031  ];
3032 
3033  $expected = [
3034  10 => 'a',
3035  20 => 'b',
3036  30 => 'c',
3037  40 => 'd',
3038  50 => [
3039  10 => 'b',
3040  20 => 'a',
3041  ],
3042  ];
3043 
3044  self::assertSame($expected, ‪ArrayUtility::sortArrayWithIntegerKeysRecursive($input));
3045  }
3046 
3051  {
3052  $input = [
3053  'b' => 'b',
3054  10 => 'a',
3055  40 => 'd',
3056  30 => 'c',
3057  ];
3058 
3059  $expected = [
3060  'b' => 'b',
3061  10 => 'a',
3062  40 => 'd',
3063  30 => 'c',
3064  ];
3065 
3066  self::assertSame($expected, ‪ArrayUtility::sortArrayWithIntegerKeysRecursive($input));
3067  }
3068 
3073  {
3074  $input = [
3075  20 => 'b',
3076  10 => 'a',
3077  40 => 'd',
3078  30 => 'c',
3079  50 => [
3080  20 => 'a',
3081  10 => 'b',
3082  ],
3083  ];
3084 
3085  $expected = [
3086  0 => 'b',
3087  1 => 'a',
3088  2 => 'd',
3089  3 => 'c',
3090  4 => [
3091  0 => 'a',
3092  1 => 'b',
3093  ],
3094  ];
3095 
3096  self::assertSame($expected, ‪ArrayUtility::reIndexNumericArrayKeysRecursive($input));
3097  }
3098 
3103  {
3104  $input = [
3105  'a' => 'b',
3106  10 => 'a',
3107  40 => 'd',
3108  30 => 'c',
3109  50 => [
3110  20 => 'a',
3111  10 => 'b',
3112  ],
3113  ];
3114 
3115  $expected = [
3116  'a' => 'b',
3117  10 => 'a',
3118  40 => 'd',
3119  30 => 'c',
3120  50 => [
3121  0 => 'a',
3122  1 => 'b',
3123  ],
3124  ];
3125 
3126  self::assertSame($expected, ‪ArrayUtility::reIndexNumericArrayKeysRecursive($input));
3127  }
3128 
3133  {
3134  $input = [
3135  'a' => 'a',
3136  'b' => [
3137  'c' => null,
3138  'd' => 'd',
3139  ],
3140  ];
3141 
3142  $expected = [
3143  'a' => 'a',
3144  'b' => [
3145  'd' => 'd',
3146  ],
3147  ];
3148 
3149  self::assertSame($expected, ‪ArrayUtility::removeNullValuesRecursive($input));
3150  }
3151 
3156  {
3157  $input = [
3158  'a' => 'a',
3159  'b' => [
3160  'c' => '<b>i am evil</b>',
3161  'd' => 'd',
3162  ],
3163  ];
3164 
3165  $expected = [
3166  'a' => 'a',
3167  'b' => [
3168  'c' => 'i am evil',
3169  'd' => 'd',
3170  ],
3171  ];
3172 
3173  self::assertSame($expected, ‪ArrayUtility::stripTagsFromValuesRecursive($input));
3174  }
3175 
3180  {
3181  $testObject = new \stdClass();
3182 
3183  $input = [
3184  'stringWithTags' => '<b>i am evil</b>',
3185  'boolean' => true,
3186  'integer' => 1,
3187  'float' => 1.9,
3188  'object' => $testObject,
3189  'objectWithStringConversion' => new class () {
3193  public function __toString()
3194  {
3195  return 'i am evil <b>too</b>';
3196  }
3197  },
3198  ];
3199 
3200  $expected = [
3201  'stringWithTags' => 'i am evil',
3202  'boolean' => true,
3203  'integer' => 1,
3204  'float' => 1.9,
3205  'object' => $testObject,
3206  'objectWithStringConversion' => 'i am evil too',
3207  ];
3208 
3209  self::assertSame($expected, ‪ArrayUtility::stripTagsFromValuesRecursive($input));
3210  }
3211 
3216  {
3217  $input = [
3218  'a' => 'a',
3219  'b' => [
3220  'c' => 'true',
3221  'd' => 'd',
3222  ],
3223  ];
3224 
3225  $expected = [
3226  'a' => 'a',
3227  'b' => [
3228  'c' => true,
3229  'd' => 'd',
3230  ],
3231  ];
3232 
3233  self::assertSame($expected, ‪ArrayUtility::convertBooleanStringsToBooleanRecursive($input));
3234  }
3235 
3241  {
3242  return [
3243  'filter all values which will be false when converted to boolean' => [
3244  // input
3245  [
3246  true,
3247  false,
3248  'foo1' => [
3249  'bar' => [
3250  'baz' => [
3251  '1',
3252  null,
3253  '',
3254  ],
3255  '' => 1,
3256  'bbd' => 0,
3257  ],
3258  ],
3259  'foo2' => 'foo',
3260  'foo3' => '',
3261  'foo4' => [
3262  'z' => 'bar',
3263  'bar' => 0,
3264  'baz' => [
3265  'foo' => [
3266  'bar' => '',
3267  'boo' => [],
3268  'bamboo' => 5,
3269  'fooAndBoo' => [0],
3270  ],
3271  ],
3272  ],
3273  ],
3274  // expected
3275  [
3276  true,
3277  'foo1' => [
3278  'bar' => [
3279  'baz' => [
3280  '1',
3281  ],
3282  '' => 1,
3283  ],
3284  ],
3285  'foo2' => 'foo',
3286  'foo4' => [
3287  'z' => 'bar',
3288  'baz' => [
3289  'foo' => [
3290  'bamboo' => 5,
3291  ],
3292  ],
3293  ],
3294  ],
3295  ],
3296  ];
3297  }
3298 
3305  public function ‪filterRecursiveFiltersFalseElements(array $input, array $expectedResult): void
3306  {
3307  // If no callback is supplied, all entries of array equal to FALSE (see converting to boolean) will be removed.
3308  $result = ‪ArrayUtility::filterRecursive($input);
3309  self::assertEquals($expectedResult, $result);
3310  }
3311 
3317  {
3318  return [
3319  'filter empty values, keep zero integers' => [
3320  // input
3321  [
3322  true,
3323  false,
3324  'foo1' => [
3325  'bar' => [
3326  'baz' => [
3327  '1',
3328  null,
3329  '',
3330  ],
3331  '' => 1,
3332  'bbd' => 0,
3333  ],
3334  ],
3335  'foo2' => 'foo',
3336  'foo3' => '',
3337  'foo4' => [
3338  'z' => 'bar',
3339  'bar' => 0,
3340  'baz' => [
3341  'foo' => [
3342  'bar' => '',
3343  'boo' => [],
3344  'bamboo' => 5,
3345  'fooAndBoo' => [0],
3346  ],
3347  ],
3348  ],
3349  ],
3350  // expected
3351  [
3352  true,
3353  false,
3354  'foo1' => [
3355  'bar' => [
3356  'baz' => [
3357  '1',
3358  ],
3359  '' => 1,
3360  'bbd' => 0,
3361  ],
3362  ],
3363  'foo2' => 'foo',
3364  'foo4' => [
3365  'z' => 'bar',
3366  'bar' => 0,
3367  'baz' => [
3368  'foo' => [
3369  'bamboo' => 5,
3370  'fooAndBoo' => [0],
3371  ],
3372  ],
3373  ],
3374  ],
3375  ],
3376  ];
3377  }
3378 
3385  public function ‪filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerByCallback(array $input, array $expectedResult): void
3386  {
3387  // callback filters empty strings, array and null but keeps zero integers
3389  $input,
3390  static function ($item) {
3391  return $item !== '' && $item !== [] && $item !== null;
3392  }
3393  );
3394  self::assertEquals($expectedResult, $result);
3395  }
3396 
3402  {
3403  $input = [
3404  'foo' => 'remove',
3405  'bar' => [
3406  'baz' => 'remove',
3407  'keep1' => 'keep',
3408  ],
3409  'keep2' => 'keep',
3410  ];
3411  $expectedResult = [
3412  'bar' => [
3413  'keep1' => 'keep',
3414  ],
3415  'keep2' => 'keep',
3416  ];
3417 
3418  return [
3419  'filter using a closure' => [
3420  $input,
3421  $expectedResult,
3422  static function ($value): bool {
3423  return is_array($value) || $value === 'keep';
3424  },
3425  ],
3426  'filter using a callable "static class-method call" as string' => [
3427  $input,
3428  $expectedResult,
3429  ArrayUtilityFilterRecursiveCallbackFixture::class . '::callbackViaStaticMethod',
3430  ],
3431  'filter using a callable "static class-method call" as array' => [
3432  $input,
3433  $expectedResult,
3434  [ArrayUtilityFilterRecursiveCallbackFixture::class, 'callbackViaStaticMethod'],
3435  ],
3436  'filter using a callable "instance-method call" as array' => [
3437  $input,
3438  $expectedResult,
3439  [new ‪ArrayUtilityFilterRecursiveCallbackFixture(), 'callbackViaInstanceMethod'],
3440  ],
3441  'only keep2 key is kept' => [
3442  $input,
3443  ['keep2' => 'keep'],
3444  static fn($key): bool => $key === 'keep2',
3445  ARRAY_FILTER_USE_KEY,
3446  ],
3447  'keys baz, keep1 and empty arrays are removed' => [
3448  $input,
3449  ['foo' => 'remove', 'keep2' => 'keep'],
3450  static fn($value, $key): bool => $value !== [] && !in_array($key, ['baz', 'keep1'], true),
3451  ARRAY_FILTER_USE_BOTH,
3452  ],
3453  ];
3454  }
3455 
3466  public function ‪filterRecursiveSupportsCallableCallback(array $input, array $expectedResult, callable $callback, int $mode = 0): void
3467  {
3468  $result = ‪ArrayUtility::filterRecursive($input, $callback, $mode);
3469  self::assertEquals($expectedResult, $result);
3470  }
3471 
3477  {
3478  return [
3479  'array without string keys' => [
3480  [
3481  0 => 'value 0',
3482  1 => 'value 1',
3483  ],
3484  false,
3485  ],
3486  'array with only string keys' => [
3487  [
3488  'key 0' => 'value 0',
3489  'key 1' => 'value 1',
3490  ],
3491  true,
3492  ],
3493  'array with mixed keys' => [
3494  [
3495  0 => 'value 0',
3496  1 => 'value 1',
3497  'key 2' => 'value 2',
3498  'key 3' => 'value 3',
3499  ],
3500  true,
3501  ],
3502  ];
3503  }
3504 
3511  public function ‪isAssociativeCorrectlyFindsStringKeys(array $array, bool $expectedResult): void
3512  {
3513  $result = ‪ArrayUtility::isAssociative($array);
3514  self::assertEquals($expectedResult, $result);
3515  }
3516 
3522  {
3523  return [
3524  'merge simple lists' => [
3525  [
3526  0 => 'keep',
3527  ],
3528  [
3529  0 => 'keep',
3530  ],
3531  [
3532  0 => 'keep',
3533  1 => 'keep',
3534  ],
3535  ],
3536  'merge simple list arrays' => [
3537  [
3538  'foo' => [
3539  0 => 'keep',
3540  ],
3541  ],
3542  [
3543  'foo' => [
3544  0 => 'keep',
3545  ],
3546  ],
3547  [
3548  'foo' => [
3549  0 => 'keep',
3550  1 => 'keep',
3551  ],
3552  ],
3553  ],
3554  'merge array and simple value' => [
3555  [
3556  'foo' => [
3557  0 => 'override',
3558  ],
3559  ],
3560  [
3561  'foo' => 'keep',
3562  ],
3563  [
3564  'foo' => 'keep',
3565  ],
3566  ],
3567  'merge simple values' => [
3568  [
3569  'foo' => 'override',
3570  ],
3571  [
3572  'foo' => 'keep',
3573  ],
3574  [
3575  'foo' => 'keep',
3576  ],
3577  ],
3578  'merge new keys' => [
3579  [
3580  'foo' => 'keep',
3581  ],
3582  [
3583  'bar' => 'keep',
3584  ],
3585  [
3586  'foo' => 'keep',
3587  'bar' => 'keep',
3588  ],
3589  ],
3590  ];
3591  }
3592 
3600  public function ‪replaceAndAppendScalarValuesRecursiveCorrectlyMergesArrays(array $array1, array $array2, array $expectedResult): void
3601  {
3602  $result = ‪ArrayUtility::replaceAndAppendScalarValuesRecursive($array1, $array2);
3603  self::assertEquals($expectedResult, $result);
3604  }
3605 }
‪TYPO3\CMS\Core\Utility\ArrayUtility\flatten
‪static array flatten(array $array, $prefix='', bool $keepDots=false)
Definition: ArrayUtility.php:486
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportReturnsNoKeyIndexForConsecutiveCountedArrays
‪arrayExportReturnsNoKeyIndexForConsecutiveCountedArrays()
Definition: ArrayUtilityTest.php:1224
‪TYPO3\CMS\Core\Utility\ArrayUtility\isAssociative
‪static bool isAssociative(array $array)
Definition: ArrayUtility.php:953
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeNullValuesRecursiveExpectRemoval
‪removeNullValuesRecursiveExpectRemoval()
Definition: ArrayUtilityTest.php:3132
‪TYPO3\CMS\Core\Utility\ArrayUtility\keepItemsInArray
‪static array keepItemsInArray(array $array, $keepItems, $getValueFunc=null)
Definition: ArrayUtility.php:718
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportReturnsNumericArrayKeys
‪arrayExportReturnsNumericArrayKeys()
Definition: ArrayUtilityTest.php:1205
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\assertAllArrayKeysAreValidThrowsExceptionOnNotAllowedArrayKeys
‪assertAllArrayKeysAreValidThrowsExceptionOnNotAllowedArrayKeys()
Definition: ArrayUtilityTest.php:2978
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathRemovesCorrectPathDataProvider
‪removeByPathRemovesCorrectPathDataProvider()
Definition: ArrayUtilityTest.php:901
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsExceptionIfPathIsEmpty
‪getValueByPathThrowsExceptionIfPathIsEmpty()
Definition: ArrayUtilityTest.php:238
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathGetsCorrectValue
‪getValueByPathGetsCorrectValue(array $array, $path, $expectedResult)
Definition: ArrayUtilityTest.php:470
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathThrowsExceptionIfPathSegmentIsEmpty
‪setValueByPathThrowsExceptionIfPathSegmentIsEmpty()
Definition: ArrayUtilityTest.php:525
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathValidDataProvider
‪getValueByPathValidDataProvider()
Definition: ArrayUtilityTest.php:364
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathAcceptsDifferentDelimiter
‪getValueByPathAcceptsDifferentDelimiter()
Definition: ArrayUtilityTest.php:478
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterByValueRecursiveMatchesReferencesToSameObject
‪filterByValueRecursiveMatchesReferencesToSameObject()
Definition: ArrayUtilityTest.php:182
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveSupportsCallableCallback
‪filterRecursiveSupportsCallableCallback(array $input, array $expectedResult, callable $callback, int $mode=0)
Definition: ArrayUtilityTest.php:3466
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathThrowsExceptionIfPathIsNotAString
‪setValueByPathThrowsExceptionIfPathIsNotAString()
Definition: ArrayUtilityTest.php:514
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\reIndexNumericArrayKeysRecursiveExpectNoReindexing
‪reIndexNumericArrayKeysRecursiveExpectNoReindexing()
Definition: ArrayUtilityTest.php:3102
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortByKeyRecursiveCheckIfSortingIsCorrect
‪sortByKeyRecursiveCheckIfSortingIsCorrect()
Definition: ArrayUtilityTest.php:967
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\keepItemsInArrayWorksWithOneArgumentDataProvider
‪array keepItemsInArrayWorksWithOneArgumentDataProvider()
Definition: ArrayUtilityTest.php:2354
‪TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException
Definition: MissingArrayPathException.php:27
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathRemovesFirstIndexWithZeroAsPathSegment
‪removeByPathRemovesFirstIndexWithZeroAsPathSegment()
Definition: ArrayUtilityTest.php:822
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArraysByKeyCheckIfSortingIsCorrect
‪sortArraysByKeyCheckIfSortingIsCorrect(array $array, $key, $ascending, $expectedResult)
Definition: ArrayUtilityTest.php:1126
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathInvalidPathDataProvider
‪array getValueByPathInvalidPathDataProvider()
Definition: ArrayUtilityTest.php:270
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterByValueRecursiveCorrectlyFiltersArray
‪filterByValueRecursiveCorrectlyFiltersArray($needle, $haystack, $expectedResult)
Definition: ArrayUtilityTest.php:171
‪TYPO3\CMS\Core\Utility\ArrayUtility\isValidPath
‪static bool isValidPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:144
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsExceptionIfPathIsNotString
‪getValueByPathThrowsExceptionIfPathIsNotString()
Definition: ArrayUtilityTest.php:227
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArrayWithIntegerKeysDataProvider
‪array sortArrayWithIntegerKeysDataProvider()
Definition: ArrayUtilityTest.php:2919
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveFiltersFalseElementsDataProvider
‪array filterRecursiveFiltersFalseElementsDataProvider()
Definition: ArrayUtilityTest.php:3240
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\keepItemsInArrayWorksWithOneArgument
‪keepItemsInArrayWorksWithOneArgument($search, $array, $expected)
Definition: ArrayUtilityTest.php:2344
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortByKeyRecursive
‪static array sortByKeyRecursive(array $array)
Definition: ArrayUtility.php:354
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsExceptionIfPathNotExists
‪getValueByPathThrowsExceptionIfPathNotExists(array $array, $path)
Definition: ArrayUtilityTest.php:337
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\flattenWithKeepDotsCalculatesExpectedResultDataProvider
‪array flattenWithKeepDotsCalculatesExpectedResultDataProvider()
Definition: ArrayUtilityTest.php:1548
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathCanUseZeroAsPath
‪setValueByPathCanUseZeroAsPath()
Definition: ArrayUtilityTest.php:544
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\mergeRecursiveWithOverruleCalculatesExpectedResult
‪mergeRecursiveWithOverruleCalculatesExpectedResult($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature, $expected)
Definition: ArrayUtilityTest.php:2265
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathRemovesCorrectPath
‪removeByPathRemovesCorrectPath(array $array, $path, $expectedResult)
Definition: ArrayUtilityTest.php:953
‪TYPO3\CMS\Core\Utility\ArrayUtility\arrayExport
‪static string arrayExport(array $array=[], $level=0)
Definition: ArrayUtility.php:402
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\replaceAndAppendScalarValuesRecursiveCorrectlyMergesArraysDataProvider
‪array replaceAndAppendScalarValuesRecursiveCorrectlyMergesArraysDataProvider()
Definition: ArrayUtilityTest.php:3521
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsExceptionIfPathDoesNotExistInArray
‪removeByPathThrowsExceptionIfPathDoesNotExistInArray()
Definition: ArrayUtilityTest.php:844
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffKeyRecursiveReturnsEmptyIfEqual
‪arrayDiffKeyRecursiveReturnsEmptyIfEqual()
Definition: ArrayUtilityTest.php:2513
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest
Definition: ArrayUtilityTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\naturalKeySortRecursiveSortsMultiDimensionalArrayByNaturalOrder
‪naturalKeySortRecursiveSortsMultiDimensionalArrayByNaturalOrder()
Definition: ArrayUtilityTest.php:2693
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArrayWithIntegerKeysSortsNumericArrays
‪sortArrayWithIntegerKeysSortsNumericArrays(array $arrayToSort, array $expectedArray)
Definition: ArrayUtilityTest.php:2969
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportReturnsKeyIndexForNonConsecutiveCountedArrays
‪arrayExportReturnsKeyIndexForNonConsecutiveCountedArrays()
Definition: ArrayUtilityTest.php:1243
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffKeyRecursiveHandlesOneDimensionalArrays
‪arrayDiffKeyRecursiveHandlesOneDimensionalArrays()
Definition: ArrayUtilityTest.php:2429
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathAcceptsGivenDelimiter
‪removeByPathAcceptsGivenDelimiter()
Definition: ArrayUtilityTest.php:878
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\flattenWithKeepDotsCalculatesExpectedResult
‪flattenWithKeepDotsCalculatesExpectedResult(array $array, array $expected)
Definition: ArrayUtilityTest.php:1662
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArrayWithIntegerKeysRecursiveExpectSorting
‪sortArrayWithIntegerKeysRecursiveExpectSorting()
Definition: ArrayUtilityTest.php:3020
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\stripTagsFromValuesRecursiveExpectRemoval
‪stripTagsFromValuesRecursiveExpectRemoval()
Definition: ArrayUtilityTest.php:3155
‪TYPO3\CMS\Core\Utility\ArrayUtility\arrayDiffAssocRecursive
‪static array arrayDiffAssocRecursive(array $array1, array $array2, bool $useArrayDiffAssocBehavior=false)
Definition: ArrayUtility.php:795
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static mixed getValueByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:180
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterByValueRecursive
‪filterByValueRecursive()
Definition: ArrayUtilityTest.php:42
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\reIndexNumericArrayKeysRecursiveExpectReindexing
‪reIndexNumericArrayKeysRecursiveExpectReindexing()
Definition: ArrayUtilityTest.php:3072
‪TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\ArrayUtilityFilterRecursiveCallbackFixture
Definition: ArrayUtilityFilterRecursiveCallbackFixture.php:24
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsTrue
‪filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsTrue($input, $expected)
Definition: ArrayUtilityTest.php:2842
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsExceptionWithEmptyPathSegment
‪removeByPathThrowsExceptionWithEmptyPathSegment()
Definition: ArrayUtilityTest.php:805
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\intersectRecursiveCalculatesExpectedResult
‪intersectRecursiveCalculatesExpectedResult(array $source, array $mask, array $expected)
Definition: ArrayUtilityTest.php:1875
‪TYPO3\CMS\Core\Utility\ArrayUtility\flattenPlain
‪static array flattenPlain(array $array)
Definition: ArrayUtility.php:515
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArraysByKeyThrowsExceptionForNonExistingKey
‪sortArraysByKeyThrowsExceptionForNonExistingKey()
Definition: ArrayUtilityTest.php:1135
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\flattenCalculatesExpectedResult
‪flattenCalculatesExpectedResult(array $array, array $expected)
Definition: ArrayUtilityTest.php:1364
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathRemovesFirstIndexWithZeroAsPath
‪removeByPathRemovesFirstIndexWithZeroAsPath()
Definition: ArrayUtilityTest.php:834
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsSpecificExceptionIfPathNotExists
‪getValueByPathThrowsSpecificExceptionIfPathNotExists(array $array, string $path)
Definition: ArrayUtilityTest.php:350
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathReturnsFirstIndexIfPathSegmentIsZero
‪getValueByPathReturnsFirstIndexIfPathSegmentIsZero()
Definition: ArrayUtilityTest.php:257
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\intersectRecursiveCalculatesExpectedResultDataProvider
‪array intersectRecursiveCalculatesExpectedResultDataProvider()
Definition: ArrayUtilityTest.php:1674
‪TYPO3\CMS\Core\Utility\ArrayUtility\filterByValueRecursive
‪static array filterByValueRecursive($needle='', array $haystack=[])
Definition: ArrayUtility.php:104
‪TYPO3\CMS\Core\Utility\ArrayUtility\arrayDiffKeyRecursive
‪static array arrayDiffKeyRecursive(array $array1, array $array2)
Definition: ArrayUtility.php:768
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\stripTagsFromValuesRecursiveExpectNoTypeCast
‪stripTagsFromValuesRecursiveExpectNoTypeCast()
Definition: ArrayUtilityTest.php:3179
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathThrowsExceptionIfPathIsEmpty
‪setValueByPathThrowsExceptionIfPathIsEmpty()
Definition: ArrayUtilityTest.php:503
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\isAssociativeCorrectlyFindsStringKeys
‪isAssociativeCorrectlyFindsStringKeys(array $array, bool $expectedResult)
Definition: ArrayUtilityTest.php:3511
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffAssocRecursiveHandlesOneDimensionalArrays
‪arrayDiffAssocRecursiveHandlesOneDimensionalArrays()
Definition: ArrayUtilityTest.php:2542
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\convertBooleanStringsToBooleanRecursiveExpectConverting
‪convertBooleanStringsToBooleanRecursiveExpectConverting()
Definition: ArrayUtilityTest.php:3215
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeArrayEntryByValue
‪static array removeArrayEntryByValue(array $array, $cmpValue)
Definition: ArrayUtility.php:683
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsExceptionIfPathIsNotAString
‪removeByPathThrowsExceptionIfPathIsNotAString()
Definition: ArrayUtilityTest.php:794
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerZeroByCallbackDataProvider
‪array filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerZeroByCallbackDataProvider()
Definition: ArrayUtilityTest.php:3316
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathCanUseZeroAsPathSegment
‪setValueByPathCanUseZeroAsPathSegment()
Definition: ArrayUtilityTest.php:536
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\assertAllArrayKeysAreValidReturnsNullOnAllowedArrayKeys
‪assertAllArrayKeysAreValidReturnsNullOnAllowedArrayKeys()
Definition: ArrayUtilityTest.php:3000
‪TYPO3\CMS\Core\Utility\ArrayUtility\intersectRecursive
‪static array intersectRecursive(array $source, array $mask=[])
Definition: ArrayUtility.php:569
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\isValidPathReturnsTrueIfPathExists
‪isValidPathReturnsTrueIfPathExists()
Definition: ArrayUtilityTest.php:208
‪TYPO3\CMS\Core\Utility\ArrayUtility\replaceAndAppendScalarValuesRecursive
‪static array replaceAndAppendScalarValuesRecursive(array $array1, array $array2)
Definition: ArrayUtility.php:967
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArraysByKeyCheckIfSortingIsCorrectDataProvider
‪sortArraysByKeyCheckIfSortingIsCorrectDataProvider()
Definition: ArrayUtilityTest.php:998
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\checkRemoveArrayEntryByValueRemovesEntryWithEmptyString
‪checkRemoveArrayEntryByValueRemovesEntryWithEmptyString()
Definition: ArrayUtilityTest.php:2318
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeByPath
‪static array removeByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:316
‪TYPO3\CMS\Core\Utility\ArrayUtility\stripTagsFromValuesRecursive
‪static array stripTagsFromValuesRecursive(array $array)
Definition: ArrayUtility.php:905
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\flattenPlainCalculatesExpectedResult
‪flattenPlainCalculatesExpectedResult(array $array, array $expected)
Definition: ArrayUtilityTest.php:1540
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterAndSortByNumericKeysWithoutAcceptAnyKey
‪array filterAndSortByNumericKeysWithoutAcceptAnyKey()
Definition: ArrayUtilityTest.php:2853
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsExceptionIfPathIsEmpty
‪removeByPathThrowsExceptionIfPathIsEmpty()
Definition: ArrayUtilityTest.php:783
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportReturnsFormattedMultidimensionalArray
‪arrayExportReturnsFormattedMultidimensionalArray()
Definition: ArrayUtilityTest.php:1149
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterByValueRecursiveDoesNotMatchDifferentInstancesOfSameClass
‪filterByValueRecursiveDoesNotMatchDifferentInstancesOfSameClass()
Definition: ArrayUtilityTest.php:194
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\remapArrayKeysExchangesKeysWithGivenMapping
‪remapArrayKeysExchangesKeysWithGivenMapping()
Definition: ArrayUtilityTest.php:2403
‪TYPO3\CMS\Core\Utility\ArrayUtility\filterRecursive
‪static filterRecursive(array $array, callable $callback=null, int $mode=0)
Definition: ArrayUtility.php:931
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, $path, $value, $delimiter='/')
Definition: ArrayUtility.php:272
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\checkRemoveArrayEntryByValueRemovesEntriesFromOneDimensionalArray
‪checkRemoveArrayEntryByValueRemovesEntriesFromOneDimensionalArray()
Definition: ArrayUtilityTest.php:2277
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathSetsCorrectValueDataProvider
‪setValueByPathSetsCorrectValueDataProvider()
Definition: ArrayUtilityTest.php:558
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\checkRemoveArrayEntryByValueRemovesEntriesFromMultiDimensionalArray
‪checkRemoveArrayEntryByValueRemovesEntriesFromMultiDimensionalArray()
Definition: ArrayUtilityTest.php:2297
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathSetsCorrectValue
‪setValueByPathSetsCorrectValue(array $array, $path, $value, $expectedResult)
Definition: ArrayUtilityTest.php:768
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArrayWithIntegerKeysRecursiveExpectNoSorting
‪sortArrayWithIntegerKeysRecursiveExpectNoSorting()
Definition: ArrayUtilityTest.php:3050
‪TYPO3\CMS\Core\Utility\ArrayUtility\assertAllArrayKeysAreValid
‪static assertAllArrayKeysAreValid(array $arrayToTest, array $allowedArrayKeys)
Definition: ArrayUtility.php:33
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsSpecificExceptionIfPathDoesNotExistInArray
‪removeByPathThrowsSpecificExceptionIfPathDoesNotExistInArray()
Definition: ArrayUtilityTest.php:861
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveFiltersFalseElements
‪filterRecursiveFiltersFalseElements(array $input, array $expectedResult)
Definition: ArrayUtilityTest.php:3305
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeNullValuesRecursive
‪static array removeNullValuesRecursive(array $array)
Definition: ArrayUtility.php:233
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\renumberKeysToAvoidLeapsIfKeysAreAllNumericDataProvider
‪array renumberKeysToAvoidLeapsIfKeysAreAllNumericDataProvider()
Definition: ArrayUtilityTest.php:1886
‪TYPO3\CMS\Core\Utility\ArrayUtility\reIndexNumericArrayKeysRecursive
‪static array reIndexNumericArrayKeysRecursive(array $array)
Definition: ArrayUtility.php:214
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeysRecursive
‪static array sortArrayWithIntegerKeysRecursive(array $array)
Definition: ArrayUtility.php:888
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffKeyRecursiveHandlesMixedArrays
‪arrayDiffKeyRecursiveHandlesMixedArrays()
Definition: ArrayUtilityTest.php:2487
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\flattenPlainCalculatesExpectedResultDataProvider
‪array flattenPlainCalculatesExpectedResultDataProvider()
Definition: ArrayUtilityTest.php:1376
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\keepItemsInArrayCanUseClosure
‪keepItemsInArrayCanUseClosure()
Definition: ArrayUtilityTest.php:2378
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffAssocRecursiveReturnsEmptyIfEqual
‪arrayDiffAssocRecursiveReturnsEmptyIfEqual()
Definition: ArrayUtilityTest.php:2628
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffAssocRecursiveHandlesMixedArrays
‪arrayDiffAssocRecursiveHandlesMixedArrays()
Definition: ArrayUtilityTest.php:2601
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArraysByKey
‪static array sortArraysByKey(array $arrays, $key, $ascending=true)
Definition: ArrayUtility.php:374
‪TYPO3\CMS\Core\Utility\ArrayUtility\renumberKeysToAvoidLeapsIfKeysAreAllNumeric
‪static array renumberKeysToAvoidLeapsIfKeysAreAllNumeric(array $array=[], $level=0)
Definition: ArrayUtility.php:613
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\renumberKeysToAvoidLeapsIfKeysAreAllNumericReturnsExpectedOrder
‪renumberKeysToAvoidLeapsIfKeysAreAllNumericReturnsExpectedOrder(array $inputArray, array $expected)
Definition: ArrayUtilityTest.php:2012
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\naturalKeySortRecursiveSortsOneDimensionalArrayByNaturalOrder
‪naturalKeySortRecursiveSortsOneDimensionalArrayByNaturalOrder()
Definition: ArrayUtilityTest.php:2658
‪TYPO3\CMS\Core\Utility\ArrayUtility\naturalKeySortRecursive
‪static bool naturalKeySortRecursive(array &$array)
Definition: ArrayUtility.php:831
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterAndSortByNumericKeysWithAcceptAnyKey
‪array filterAndSortByNumericKeysWithAcceptAnyKey()
Definition: ArrayUtilityTest.php:2756
‪TYPO3\CMS\Core\Utility\ArrayUtility\remapArrayKeys
‪static remapArrayKeys(array &$array, array $mappingTable)
Definition: ArrayUtility.php:750
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeys
‪static array sortArrayWithIntegerKeys(array $array)
Definition: ArrayUtility.php:873
‪TYPO3\CMS\Core\Utility\ArrayUtility\filterAndSortByNumericKeys
‪static array filterAndSortByNumericKeys($setupArr, $acceptAnyKeys=false)
Definition: ArrayUtility.php:852
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathReturnsFirstIndexIfPathIsZero
‪getValueByPathReturnsFirstIndexIfPathIsZero()
Definition: ArrayUtilityTest.php:249
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffAssocRecursiveHandlesMultiDimensionalArrays
‪arrayDiffAssocRecursiveHandlesMultiDimensionalArrays()
Definition: ArrayUtilityTest.php:2563
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffKeyRecursiveHandlesMultiDimensionalArrays
‪arrayDiffKeyRecursiveHandlesMultiDimensionalArrays()
Definition: ArrayUtilityTest.php:2450
‪TYPO3\CMS\Core\Utility\ArrayUtility\convertBooleanStringsToBooleanRecursive
‪static array convertBooleanStringsToBooleanRecursive(array $array)
Definition: ArrayUtility.php:54
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerByCallback
‪filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerByCallback(array $input, array $expectedResult)
Definition: ArrayUtilityTest.php:3385
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\isAssociativeCorrectlyFindsStringKeysDataProvider
‪array isAssociativeCorrectlyFindsStringKeysDataProvider()
Definition: ArrayUtilityTest.php:3476
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\replaceAndAppendScalarValuesRecursiveCorrectlyMergesArrays
‪replaceAndAppendScalarValuesRecursiveCorrectlyMergesArrays(array $array1, array $array2, array $expectedResult)
Definition: ArrayUtilityTest.php:3600
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsFalse
‪filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsFalse($input, $expected)
Definition: ArrayUtilityTest.php:2908
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveSupportsCallableCallbackDataProvider
‪array filterRecursiveSupportsCallableCallbackDataProvider()
Definition: ArrayUtilityTest.php:3401
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\isValidPathReturnsFalseIfPathDoesNotExist
‪isValidPathReturnsFalseIfPathDoesNotExist()
Definition: ArrayUtilityTest.php:216
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider
‪array mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider()
Definition: ArrayUtilityTest.php:2020
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\flattenCalculatesExpectedResultDataProvider
‪array flattenCalculatesExpectedResultDataProvider()
Definition: ArrayUtilityTest.php:1268
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportThrowsExceptionIfObjectShouldBeExported
‪arrayExportThrowsExceptionIfObjectShouldBeExported()
Definition: ArrayUtilityTest.php:1188