PHPUnit mock same function with different parameters

When writing unit tests, sometimes mock a function with different parameters and expect different return value(s). For example in magento Model product class has a getData function. Using this function you can get different value(s) from the model getData function.

Example code

We expect that our mock will return value 'red' when $product->getData('color') will be called from our code and 's' will be returned when we call $product->getData('size')

            ['color', null, 'red'],
            ['size', null, 's'],
what clients say about us

Client testimonials

Our sites look great and run smoothly. Thanks for all your hard work and patience in getting us to where we are today.

contact us

Contact Us

If you have questions or want us to send you a quote for project please email us.

latest news


PHPUnit mock magic functions
Learn more about PHPUnit Partial Mock.