Federico Cargnelutti’s Blog: Testing Zend Framework Action Controllers With Mocks

Testing Zend Framework can be very tricky. The team tries to make framework based applications as much testable as possible, but there are still parts of Zend Framework’s written the way it’s hard to test code based on it. Recently Georgio Sironi was writing about testing view helpers. Today Federico Cargnelutti writes about testing action controllers using mocks.

Unit testing controllers independently has a number of advantages:

  1. You can develop controllers test-first (TDD).
  2. It allows you to develop and test all of your controller code before developing any of the view scripts.
  3. It helps you quickly identify problems in the controller, rather than problems in one of the combination of Model, View and Controller.

What is very interesting about Federico’s post, is that he not only shows example test, but also points reader to some framework’s known issues preventing developers to test particular things. Naturally solution for mention issues is also provided.