assertInstanceOf( MappingIterator::class, new MappingIterator( [], static function () { } ) ); } public function testInvalidConstructorArgumentThrowsException() { $this->expectException( 'RuntimeException' ); $instance = new MappingIterator( 2, static function () { } ); } public function testdoIterateOnArray() { $expected = [ 1, 42 ]; $mappingIterator = new MappingIterator( $expected, static function ( $counter ) { return $counter; } ); foreach ( $mappingIterator as $key => $value ) { $this->assertEquals( $expected[$key], $value ); } } public function testdoIterateOnArrayIterator() { $expected = [ 1001, 42 ]; $mappingIterator = new MappingIterator( new ArrayIterator( $expected ), static function ( $counter ) { return $counter; } ); $this->assertCount( 2, $mappingIterator ); foreach ( $mappingIterator as $key => $value ) { $this->assertEquals( $expected[$key], $value ); } } }