News Feed
Jobs Feed
Sections




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

Brandon Savage:
The myth of the untestable controller
September 23, 2013 @ 11:35:04

In this new post to his site Brandon Savage looks at the "myth of the untestable controller" and gives some tips to help resolve it.

It's a persistent statement: controllers should have as little code as possible because they're difficult, nay impossible, to test. Developers should force most of their code into the models instead, where business, validation and other logic can take place. [...] But this is not true. Controllers are no more or less testable than any other kind of code. What's more, the fact that people believe controllers are largely untestable is an excuse for writing untestable code, not a valid design decision.

He talks briefly about where the myth might have come from (Zend Framework v1, with it's difficult to test controllers) and a note that, really, controllers are as testable as you want them to be. He give three things that could help make them easier to test:

  • Using dependency injection/inversion methods
  • Refactoring to use the Abstract Factory design pattern
  • Using anonymous functions/closures over plain configuration settings
0 comments voice your opinion now!
untestable unittest controller solutions abstractfactory designpattern

Link: http://www.brandonsavage.net/the-myth-of-the-untestable-controller/

blog comments powered by Disqus

Similar Posts

Codeception.com: Testing Emails in PHP. Part 1: PHPUnit

Zend Developer Zone: Using Zend_Tool to start up your ZF Project

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

James Fuller: Use @dataProvider to reduce duplication and improve the maintainability of your tests

Padraic Brady's Blog: The M in MVC: Why Models are Misunderstood and Unappreciated


Community Events











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


code overview language hhvm introduction framework security install component package opinion application example facebook composer podcast symfony2 release hack unittest

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