PHPUnit – “Stubbing a method call to return the value from a map”


The PHPUnit method returnValueMap() made me think a bit about how it works.

The following definition, taken from the official PHPUnit documentation, is not too verbose and I had to do few searches and few tests on my own before coming to an acceptable conclusion.

Sometimes a stubbed method should return different values depending on a predefined list of arguments. You can use returnValueMap() to create a map that associates arguments with corresponding return values. See Example 10.6 for an example.
(source PHPUnit Manual Test Doubles Stubs Example 10.6 )

Continue reading