@@ -674,6 +674,52 @@ function test($arg = 0)
674674 $ this ->assertSame ([3 , 3 , 3 ], $ this ->callMethod ([$ class , 'mapObjects ' ], $ array , 'test ' , 2 ));
675675 }
676676
677+ /**
678+ * @param $class string|ArrObj
679+ * @dataProvider arrayClassProvider
680+ */
681+ public function testEach ($ class )
682+ {
683+ foreach ($ this ->arrayProvider () as [$ array ]) {
684+
685+ // Check both pure array and iterable object
686+ foreach ([$ array , new ArrayObject ($ array )] as $ iterable ) {
687+ // Just value
688+ $ index = 0 ;
689+ $ values = array_values ($ iterable instanceof ArrayObject ? $ iterable ->getArrayCopy () : $ iterable );
690+ $ this ->callMethod ([$ class , 'each ' ], $ iterable , function ($ value ) use ($ values , &$ index ) {
691+ $ this ->assertSame ($ values [$ index ++], $ value );
692+ }, Arr::EACH_VALUE );
693+
694+ // Also check default
695+ $ index = 0 ;
696+ $ this ->callMethod ([$ class , 'each ' ], $ iterable , function ($ value ) use ($ values , &$ index ) {
697+ $ this ->assertSame ($ values [$ index ++], $ value );
698+ });
699+
700+ // Key, Value
701+ $ this ->callMethod ([$ class , 'each ' ], $ iterable , function ($ key , $ value ) use ($ iterable ) {
702+ $ this ->assertSame ($ iterable [$ key ], $ value );
703+ }, Arr::EACH_KEY_VALUE );
704+
705+ // Value, Key
706+ $ this ->callMethod ([$ class , 'each ' ], $ iterable , function ($ value , $ key ) use ($ iterable ) {
707+ $ this ->assertSame ($ iterable [$ key ], $ value );
708+ }, Arr::EACH_VALUE_KEY );
709+ }
710+
711+ // Value, Keys list
712+ $ this ->callMethod ([$ class , 'each ' ], $ array , function ($ value , ...$ keys ) use ($ class , $ array ) {
713+ $ this ->assertSame ($ this ->callMethod ([$ class , 'get ' ], $ array , $ keys ), $ value );
714+ }, Arr::EACH_VALUE_KEYS_LIST );
715+
716+ // Keys array, Value
717+ $ this ->callMethod ([$ class , 'each ' ], $ array , function ($ keys , $ value ) use ($ class , $ array ) {
718+ $ this ->assertSame ($ this ->callMethod ([$ class , 'get ' ], $ array , $ keys ), $ value );
719+ }, Arr::EACH_KEYS_ARRAY_VALUE );
720+ }
721+ }
722+
677723 /**
678724 * @param $class string|ArrObj
679725 *
0 commit comments