I have a unit test which uses the following mocked class
$this->stubHandle = $this->getMockBuilder(Handle::class)->disableOriginalConstructor()->getMock();
When I run
$key = new Key($this->stubHandle);
$this->stubHandle->method('__call')->will($this->returnCallback('var_dump'));
$key->nonExistingMethod('element0', 'element1', []);
it outputs
string(17) "nonExistingMethod"
and
array(3) {
[0] =>
string(8) "element0"
[1] =>
string(8) "element1"
[2] =>
array(0) {
}
}
which I think it means the first argument of method __call is a string and the second argument is an array. No more arguments passed.
When I mock the return value of method __call like
$this->stubHandle->method('__call')->willReturn(1);
The return value is always 1 as expected.
When I mock the return value of method __call like
$this->stubHandle->method('__call')->willReturnMap(
[
['argument1', null, 'returnValue'],
]
);
I expect the return value to be 'returnValue' when the first argument of method __call is 'argument1' while the seconds argument doesn't care.
If the first argument isn't 'argument1', I expect a return value of null.
Are these expectations correct?
No matter what I try, the return value is always null when I mock this value with method willReturnMap.
If my expectations are wrong, please lead me to a way to accomplish my goals to mock the return value, depending on the first argument (only) and also explain to me how to apply willReturnMap.