What does invocationMocker::with() actually do?
You can use withConsecutive
and willReturnOnConsecutiveCall
to put multiple withs and returns into the same function. I'm not exactly sure what happens when you write it like you did.
Your code would look something like this:
$this->vacancyRepositoryMock->method('findOneBy')->expects($this->exactly(2)) ->withConsecutive([['id' => 5000]],[['id' => 50]]) //array in array is on purpose ->willReturnOnConsecutiveCalls(null, $myVacancy);
As for your question on what the with
function exactly does and why your way doesn't work... I'm not sure.