Frage

I have a method that is supposed to use an array it gets somehow, and then call another method (lets call it fooBar) for each element, passing the element as argument to the method.

This is the code I currently I have, and works:

    foreach ( $names as $index => $name ) {
        $parser->expects( $this->at( $index ) )
            ->method( 'setFunctionHook' )
            ->with(
                $this->equalTo( $name ),
                $this->isType( 'callable' )
            );
    }

This is quite verbose though. Is there a shorter way of doing this?

War es hilfreich?

Lösung

Assuming you know what values to expect in your test:

foreach($expected_values as $value){
    $myMock->expects( $this->once())
        ->method('fooBar')
        ->with($value);
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top