News Feed
Sections




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

Federico Cargnelutti's Blog:
Testing Zend Framework Action Controllers With Mocks
November 02, 2009 @ 07:58:44

In this new post to his blog today Federico Cargnelutti shows you how to use mock objects to unit test controllers in your Zend Framework application.

In this post I'll demonstrate a unit test technique for testing Zend Framework Action Controllers using Mock Objects. Unit testing controllers independently has a number of advantages: you can develop controllers test-first (TDD), develop and test all of your controller code before developing any of the view scripts and helps you quickly identify problems in the controller, rather than problems in one of the combination of Model, View and Controller.

He sets up a sample user controller and a test case to go along with it. Drop in a test for the user controller class that uses a "getMock" method to define a mock controller object for the "render" method. He also points out a few issues with this sort of testing in the Zend Framework - the return value of the Zend_Test_PHPUnit_ControllerTestCase, issues throwing exceptions with the Front Controller and a problem with the dispatcher's storage of the Action Controller.

0 comments voice your opinion now!
action controller zendframework test mock object


blog comments powered by Disqus

Similar Posts

Ivan Iordanov's Blog: extending Zend_Db_Table to create NestedSet models

Raphael Stolt's Blog: Zend Framework in Action Pre-review

TechChorus Blog: Create RESTful Applications Using The Zend Framework - Part II: Using HTTP Response

Developer.com: Fat Models and Skinny Controllers Bring Out the Best in Your MVC Framework

Wojciech Sznapka's Blog: Why Mockery is better than PHPUnit Mock Builder (with Symfony2)


Community Events

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


symfony2 composer api laravel community release library version interview podcast introduction example framework performance series testing application voicesoftheelephpant opinion php7

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