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

Bogardo's avatar

Mockery::withArgs() won't match with array

I'm passing an array to the withArgs() method which should match but I keep getting the following error message:

Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_0_Class::send("string", array('key'=>'value'), array()). Either the method was unexpected or its arguments matched no expected argument list for this method

I also tried using the Mockery::on() method with a closure but the closure never seems to get triggered.

Pseudo code:

$args = [
    'string',
    [
        'key' => 'value'
    ],
    []
];

$class->shouldReceive('send')->once()->withArgs($args)->andReturn('Success');

Also tried:

$class->shouldReceive('send')->once()->with(Mockery::on(function($data){
   dd($data); //this never gets executed.
}))->andReturn('Success');
0 likes
1 reply
Bogardo's avatar
Bogardo
OP
Best Answer
Level 8

The problem was caused by a missing new-line character. Modifying the expected array to the following resolved my issue:

$args = [
    'string',
    [
        'key' => 'value' . PHP_EOL
    ],
    []
];

Please or to participate in this conversation.