Domanda

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?

È stato utile?

Soluzione

Assuming you know what values to expect in your test:

foreach($expected_values as $value){
    $myMock->expects( $this->once())
        ->method('fooBar')
        ->with($value);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top