PHP luminary Ryan Mauger posted an interesting article recently…well, interesting to Zend Framework developers. The post, titled “Controller Testing with the FlashMessenger in Zend Framework” describes a problem that Mauger ran into while writing unit tests and how he solved it.
During a recent project, I encountered problems with the flash messenger not playing ball with PHPUnit. The problem, the FlashMessenger using a session namespace, and trying to start the session.
Additionally to this problem, how do you test that the flash message is set as you’d expect (or not as the case may be)
The answer to both of these problems, lies in the same solution. a Mock Object.
Mauger does a good job of laying out the problem and then showing the details of his solution. If you are working with Zend Framework and building unit tests, the article is worth a quick read.
If you are working with Zend Framework and not building unit tests, you are doing it wrong.