Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Davva's avatar
Level 10

Mockery with() - inspect parameters?

I'm trying to verify that the passed parameters to a method call are correct. I am using PHPUnit and Mockery.

I want to make sure that not only is a specific method called, but I also want to verify that the passed params have the correct values.

How can I inspect/verify that the $refunder below gets the correct parameter input?

// Code to be tested
$refund = $refunder->refundBooking( $booking, [
    ’amount’ => $this->getSuggestedRefund( $bookingSettings )
]);

// testing code
$refunder = Mockery::mock( ’Refunder’ );
$refunder
    ->shouldReceive(’refundBooking’)
    ->with( WHAT DO I PUT HERE? ) // want to verify that second param has [ ’amount’ => 200 ]
    ->once();
0 likes
3 replies
Davva's avatar
Davva
OP
Best Answer
Level 10

So I found the answer myself eventually by digging through the Mockery docs about argument validation (http://docs.mockery.io/en/latest/reference/argument_validation.html)

So for anyone else that might want to know, here is what worked for me:

// testing code
$refunder = Mockery::mock( ’Refunder’ );
$refunder
    ->shouldReceive(’refundBooking’)
    ->withArgs([ Mockery::any(), Mockery::subset( ['amount' => 200 ])])
    ->once();
3 likes
rhei's avatar

The link isn't dead, it just has an extra parenthesis at the end.

I'm not allowed to post a link because it's my first day as a member of this site, so I can't paste the working one here. Just click the link above and get rid of the ")" at the end and hit "enter" and you'll see the docs.

Please or to participate in this conversation.