Warning! This page has the following tags:
- This page is deprecated, and is only useful for developers using Agavi 0.9.
- This page exists for reference purposes only.
Unit Testing of Agavi
trials and tribulations of unit testing the legacy code...
One of the first things we sought out to do, was provide unit tests for the framework itself. Initially we had hoped to integrate an abstracted interface to the actual testing framework so that developers werent bound to any particular framework. But in practice, it didnt seem feasible. So, given that we are also trying to pimp php5 adoption as well, we decided to use phpUnit2 over simpleTest which we had been using for our internal applications previously. It wasnt nearly as convenient as simpleTest had been, however. And after a week we decided to go back to using simpleTest for a variety of reasons.
- We can simply glob for files like *Test.php and give them to simpletest and it'll parse them, where as with phpUnit2 you needed to give it an actual class.
- Mock objects
- there's no assertNotEquals in phpUnit2?
- only allowed to pass objects to assertSame in phpUnit2?
- The overhead of setting up the actual tests seems lighter with simpletest and we like to keep things light and simple
That being said, using phpUnit2 left us envious in at least one area. That being the way it does it's reporting using the observer pattern allowing multiple reporters to be observing the test runs simultaneously.
Through writing the tests, we began to notice some smells?. First, that there seem to be some feature envy going on between the controller and context, so it was decided that the responsability of creating and handling component objects would be given completely to the context and it would be made into a singleton, proper. This made things much more flexible, as we could then mock the context object and successfully control the interactions with the rest of the framework through it.
Currently, there's still an issue of dealing with constants in tests, I refere again to the SmellsAndItches? page which better describes the actual issue.
Update
Wow, just wanted to note that Sebastian Bergmann caught wind of this page (it was really just meant as a reminder to ourselves why we had done what we did, honest!) and responded to some of the issues we noted above in his blog! Neat. :) It was also mentioned on the simpletest mailing list and evolved into a thread discussing the two projects. Good stuff, it'd be great to see more common grounds developed between the two camps. It has me inspired to do something, but I havent manifested the inspiration into anything useful, yet.

