digitalpianism / testframework

A simple test framework repo for Magento 1
49 stars 14 forks source link

Test doubles for helper classes #10

Open shineability opened 6 years ago

shineability commented 6 years ago

You can set test doubles for models and resource models. How would you do this for helpers? Shouldn't there be a setHelperTestDouble like method that deals with the registry? Or can I just use Mage::register('vendor_module/helper', $helperDouble, true)?

Vinai commented 6 years ago

You an use the latter, but a setHelperTestDouble would be a convenient wrapper for manipulating the registry manually. Would you consider making a small PR out of that?

shineability commented 6 years ago

I gladly would, but I see no way to do it at this point without hacking the core :/ All the code related to resolve helper classes seems to be tied to the Mage class and its static registry methods. Implementing test doubles for model (resources) is possible because you can override the config_model.

The solution I proposed...

Mage::register('vendor_module/helper', $helperDouble, true)

... is not really convenient, after looking into it a bit more.

My suggestion would be:

Mage::setHelperTestDouble($groupedClassName, $testDouble)

But that won't be possible without hacking the Mage class.

Any thoughts on this @Vinai?

Vinai commented 6 years ago

What I thought of was that the method setHelperTestDouble is part of the DigitalPianism_TestFramework_Model_Config simply for convenience.
In that method it would build the helper registry key, Mage::unregister() it - just in case - and then set the test double into the registry.
The whole M1 testframework is hacky, so this change would be continuing that tradition :)

shineability commented 6 years ago

That’ll work :) I’ll give it a shot...