digitalpianism/testframework

Test doubles for helper classes

Opened this issue · 4 comments

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

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?

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.

  • First of all you need to add the prefix _helper/ manually when "overriding" the helper in the registry.
  • Second of all, if the concrete helper is resolved in another test first, you won't be able to set the helper test double, without unregistering it every time (I think)...

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

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 :)

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