Pregunta

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?

¿Fue útil?

Solución

Assuming you know what values to expect in your test:

foreach($expected_values as $value){
    $myMock->expects( $this->once())
        ->method('fooBar')
        ->with($value);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top