I'm breaking my head for hours now over a simple thing I've done hundreds of times: mocking another model. Can anyone see what's wrong with this?

$mockedRequest = $this
    ->will($this->returnValueMap([['a', 'b']]));


You would expect the result to be b right? WRONG! It returns NULL! And I can't for the love of God figure out why...

If anyone can point me in the right direction I would be so happy... It's probably a small thing, but I can't see it ...

1 Answer 1


The getParam method accepts 2 parameters, the second one defaulting to null

public function getParam($key, $defaultValue = null); 

returnValueMap works like this. the first N-1 values in the array are treated as the parameters for the method and the Nth value is the returned result.
So in your case it looks in the map for an array like this [a, null, return value here].
And you don't have such an sub-array in your array map. So it returns by default null.
make the return map like this:

->will($this->returnValueMap([['a', null, 'b']]));
  • Thanks. I knew it had to be something simple like this. Sounds like a case of code-blindness to me... Nov 21, 2016 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.