Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_1_::make

Viewed 2836

I have written this test that is returning the following error:

Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_1_My_Class::make(array('valid_until'=>'2020-03-04',)). Either the method was unexpected or its arguments matched no expected argument list for this method

Now I have this code in my test:

$rateValidator->shouldReceive('make')->once()
            ->withArgs([$attributes])->andReturn(mockery::self());

$rateValidator->shouldReceive('addContext')
            ->withArgs(['update_rate_validity'])->andReturn(mockery::self());

And This is the code this test is testing:

$attributes = [
    'valid_until' => $command->validUntilDate
];

$validator = $this->rateValidator->make($attributes)->addContext('update_rate_validity');

What am I doing wrong here? For me the only problem could be in the arguments ($attributes) that the method make is receiving but I cant figure out what that could be?

1 Answers

You need to be sure about data you sent as a mock. Your sending data type and expected data type by called function must be same.

For example : Your function expect data as below :

[
'test' => 'test',
]

You must sent same data to function by mock.

$validator->shouldReceive('theFunction')->with(['test' => 'test'])->andRetun('xx');
Related