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