@@ -149,7 +149,7 @@ public function testSetNestedElement($class)
149
149
150
150
$ this ->assertSame ([[['test ' ]]], $ this ->callMethod ([$ class , 'set ' ], [], '[].[].[] ' , 'test ' ));
151
151
$ this ->assertSame ([[[[]]]], $ this ->callMethod ([$ class , 'set ' ], [], '[].[].[] ' , []));
152
- $ this ->assertSame ([[[[]]]], $ this ->callMethod ([$ class , 'set ' ], [], ['[] ' ,'[] ' ,'[] ' ], []));
152
+ $ this ->assertSame ([[[[]]]], $ this ->callMethod ([$ class , 'set ' ], [], ['[] ' , '[] ' , '[] ' ], []));
153
153
$ this ->assertSame ([], $ this ->callMethod ([$ class , 'set ' ], [], [], 'test ' ));
154
154
$ this ->assertSame ([], $ this ->callMethod ([$ class , 'set ' ], [], [null ], 'test ' ));
155
155
@@ -661,8 +661,7 @@ public function testMapObjects($class)
661
661
$ this ->assertSame (['test ' , 2 , 4 , '2 ' ], $ this ->callMethod ([$ class , 'mapObjects ' ], $ array , 'test ' , 2 ));
662
662
$ this ->assertSame ([], $ this ->callMethod ([$ class , 'mapObjects ' ], [], 'test ' ));
663
663
664
- $ object = new class ()
665
- {
664
+ $ object = new class () {
666
665
function test ($ arg = 0 )
667
666
{
668
667
return 1 + $ arg ;
@@ -744,6 +743,35 @@ public function testFilterByKeys($class)
744
743
$ this ->assertSame ($ array , $ this ->callMethod ([$ class , 'filterByKeys ' ], $ array , [null , 0 ], true ));
745
744
}
746
745
746
+ /**
747
+ * @param $class string|ArrObj
748
+ *
749
+ * @dataProvider arrayClassProvider
750
+ */
751
+ public function testFilter ($ class )
752
+ {
753
+ $ callback1 = function ($ value ) {
754
+ return boolval ($ value );
755
+ };
756
+ $ callback2 = function ($ value ) {
757
+ return !$ value ;
758
+ };
759
+ $ callback3 = function ($ value , $ key ) {
760
+ return $ key == $ value ;
761
+ };
762
+ $ callback4 = function ($ key ) {
763
+ return boolval ($ key );
764
+ };
765
+
766
+ foreach ($ this ->arrayProvider () as [$ array ]) {
767
+ $ this ->assertSame (array_filter ($ array ), $ this ->callMethod ([$ class , 'filter ' ], $ array ));
768
+ $ this ->assertSame (array_filter ($ array , $ callback1 ), $ this ->callMethod ([$ class , 'filter ' ], $ array , $ callback1 ));
769
+ $ this ->assertSame (array_filter ($ array , $ callback2 ), $ this ->callMethod ([$ class , 'filter ' ], $ array , $ callback2 ));
770
+ $ this ->assertSame (array_filter ($ array , $ callback3 , ARRAY_FILTER_USE_BOTH ), $ this ->callMethod ([$ class , 'filter ' ], $ array , $ callback3 , ARRAY_FILTER_USE_BOTH ));
771
+ $ this ->assertSame (array_filter ($ array , $ callback4 , ARRAY_FILTER_USE_KEY ), $ this ->callMethod ([$ class , 'filter ' ], $ array , $ callback4 , ARRAY_FILTER_USE_KEY ));
772
+ }
773
+ }
774
+
747
775
/**
748
776
* @param $class string|ArrObj
749
777
*
@@ -1019,7 +1047,8 @@ public function testSortObjects($class)
1019
1047
$ object1 = new class () {
1020
1048
public $ i = 1 ;
1021
1049
1022
- public function getValue (bool $ reverse = false ) {
1050
+ public function getValue (bool $ reverse = false )
1051
+ {
1023
1052
return $ reverse ? 1 / $ this ->i : $ this ->i ;
1024
1053
}
1025
1054
};
@@ -1039,7 +1068,7 @@ public function getValue(bool $reverse = false) {
1039
1068
$ array = $ proto ;
1040
1069
1041
1070
$ this ->assertSame ([1 , 2 , 3 , 4 , 5 ], $ this ->callMethod ([$ class , 'mapObjects ' ], $ array , 'getValue ' ));
1042
- $ this ->assertSame ([1 , 1 / 2 , 1 / 3 , 1 / 4 , 1 / 5 ], $ this ->callMethod ([$ class , 'mapObjects ' ], $ array , 'getValue ' , true ));
1071
+ $ this ->assertSame ([1 , 1 / 2 , 1 / 3 , 1 / 4 , 1 / 5 ], $ this ->callMethod ([$ class , 'mapObjects ' ], $ array , 'getValue ' , true ));
1043
1072
1044
1073
// Ensure order is not the same
1045
1074
do {
@@ -1465,8 +1494,7 @@ public function testClone($class)
1465
1494
{
1466
1495
$ object = new stdClass ();
1467
1496
$ object2 = new ArrayObject ();
1468
- $ object3 = new class ()
1469
- {
1497
+ $ object3 = new class () {
1470
1498
public $ counter = 1 ;
1471
1499
1472
1500
function __clone ()
0 commit comments