I am trying to declare an expectation that has two possible values as a parameter, based on the value I want the return value to be different.
Here is what I tried
$mock = m::mock('FooBar\ClassA');
$mock->shouldReceive('has')->with('foo')->andReturn(false);
$mock->shouldReceive('has')->with('bar')->andReturn(true);
I get this error
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_2__FooBar_ClassA::has("bar")
I read through http://docs.mockery.io/en/latest/reference/expectations.html
but I am unable to find the answer. I am trying to resort to solving the problem with andReturnUsing
which is straight-forward. Is there a way to solve the problem without using andReturnUsing
?
$mock->shouldReceive('has')->andReturnUsing(function ($value) {
switch ($value) {
case 'foo': return false;
case 'bar': return true;
}
});
I also read Mockery specifying expected arguments for multiple calls
But that's the same thing I have tried, it forces validation on parameter type.