PHPUnit mock magento magic functions

In magento it often happens that when you are writing code in block, that product model uses magic function, for the new product attribute created by you.

How can we mock these functions so that we can test our class efficiently

$map = [
    ['getFrontendLabel', [], 'Frontend Label']

getFrontendLabel is function name,
[] is array parameter,
'Frontend Label' is return


Map call functions with parameters

code in model will look like: $product->setCollectShippingRates(true);

unit test code will look like below
// true is the first parameter passed to function setCollectShippingRates
$map = [ ['setCollectShippingRates', [true], 'some return'], ]; $mock->method('__call')->willReturnMap($map);
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.