News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tom Oram's Blog:
Unit testing a Zend Framework 2 Controller
July 11, 2012 @ 10:54:01

In this recent post Tom Oram looks at a method he's put together for unit testing a controller in a Zend Framework v2-based application (using PHPUnit).

So far I've got a basic Zend Framework 2 Application up and running and got PHPUnit running & testing one of my models. Next up I wanted to try and workout how to test a controller. I had come to the conclusion that what I needed to do was create an instance of my controller in an environment where it I could get it to run each action I wanted to test.

He finally consulted how the actual framework's tests were doing it and borrowed the setup from that - including several packages (via a "use") and the creation of the controller instance inside the setUp() method of the test set. Some other basic config is set up too including routing and event handling. He also includes examples of how to test this instance effectively - one showing a request with a parameter and another checking to ensure the 404 handler works when a non-existant resource is called.

0 comments voice your opinion now!
zendframework2 controller unittest phpunit


blog comments powered by Disqus

Similar Posts

Sebastian Bergamnn's Blog: SeleniumTestCase Improvements in PHPUnit 3.2

Community News: Packagist Latest Releases for 03.06.2014

Mike Purcell's Blog: PHPUnit - Constant Already Defined - -process-isolation

Mike Lively's Blog: Adding Database Tests to Existing PHPUnit Test Cases

SitePoint.com: Be More Asssertive: Getting to Know PHPUnit's Assertions


Community Events

Don't see your event here?
Let us know!


laravel extension podcast unittest release community series introduction framework library wordpress api psr7 laravel5 language conference development interview voicesoftheelephpant opinion

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework