joomla/joomla-cms — pull request #920 by Paladin (2013-03-30 14:54:15+00:00)
Title: Mod random image testable rewrite

OK, version 2 of my new approach for testability.

Gone is the glue file, replaced by a mechanism that is almost dependency injection, letting the testing fixtures supply the test doubles for the calls. (There's a baseline feature improvement I've created for my own use of this module, which I'll file a PR to -- or add to this one -- once I know if this approach is accepted.)

This means the actual code is shorter than with the glue file, but a handful of lines longer than current production, added to accommodate the dependency injection properly.

I'd appreciate it if someone besides me would test this out and make sure it's serviceable. I've written a fairly complete set of unit tests for it, but there's always the possibility I've either overlooked something or made a wrong assumption; the more eyes, the less likely that will happen.

The main advantage of this approach is it gives us a "bridge" out of static-land. It's a way to slide tests under existing code to help us take some of the speed bumps out of the transition. It increases code complexity to do it, so it's not a solution, merely a temporary safety net.

Side note: In my standalone version of this code, I did not inherit from JModuleHelper, but in this version I did. (My standalone version exists to prove the point I could create a module with 100% test coverage without loading one byte of Joomla code.) Doing that required a single change to the default value of one of the optional constructor arguments. The object of decoupling is to make changes that easy, or even easier.