Question

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?

Était-ce utile?

La solution

Assuming you know what values to expect in your test:

foreach($expected_values as $value){
    $myMock->expects( $this->once())
        ->method('fooBar')
        ->with($value);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top