I’ve implemented the mockiterator solution from http://www.davegardner.me.uk/blog/2011/03/04/mocking-iterator-with-phpunit/ by creating classes that extend the Zend_Test_PHPUnit_DatabaseTestCase and Zend_Test_PHPUnit_ControllerTestCase and dropping in the the method to each child class.
However, I also ended up adding a few tweaks along the way, but it is a pain to have to make the same changes in each class to prevent divergent behaviour.
Both of the Zend classes inherit directly from the PHPUnit_Framework_TestCase is there a way of easily inserting a class between the PHPUnit and Zend classes which does not involve modifying the Zend library code directly? I guess I’m looking for an easy way to do something like this:
+-- PHPUnit_Framework_TestCase
|
+-- My_PHPUnit_Framework_TestCase
|
+-- Zend_Test_PHPUnit_ControllerTestCase
+-- Zend_Test_PHPUnit_DatabaseTestCase
I guess, as an alternative, I could replicate the two Zend classes in my library – but again, there could be problems whenever the Zend framework is uploaded, requiring my library to be rewritten from the new Zend testcase classes.
In PHP you have linear, single parent inheritance. Unfortunately, that means that you can’t insert a middle, proxy class without modifying the source of the Zend class.
If necessary (say, you have something which needs to be a child of two different DO classes, for example), there are ways to fake multiple inheritance, however.
Using, magic methods, for instance, you can create a multi-proxy: