PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Rob Allen's Blog: Unit testing controller actions with Zend_Test_PHPUnit_ControllerTestCase

Note: This article was originally published at PHPDeveloper on 7 September 2010.
PHPDeveloper

Rob Allen has a new post for all of the unit test fans out there wanting to test their Zend Framework controllers. He show how to make it worlds easier with the help of Zend_Test_PHPUnit_ControllerTestCase.

Testing controllers has traditionally been a hassle due to the requirements of setting up the bootstrap, the front controller and initiating the dispatch cycle. In June, Matthew addressed this with the release of Zend_Test_PHPUnit_ControllerTestCase way back in 2008. Later, Matthew helpfully wrote an article on how to use it and I have used that as a starting point for the information here.

He illustrates with the TodoIt application and shows how to correctly set up PHPUnit including a TestHelper file that acts as a bootstrap when running the tests. Rob gives the code for a sample controller and a basic tests to run against it - checking for an "h1" element containing "Login".