In Zend 1, the controller is a normal class. You can create an instance of it, you can call methods on it (for example, replacing your default repository with the PHPUnit mock of your repository:
class MyController extends Zend_Controller_Action { public functioni init() { $this->repository = new MyRepository(); } public function setRepository($repository) { $this->repository = $repository; } public function saveAction() { $dataToWrite = manipulate in some way $this->getRequest()->getParams(); $this->repository->update($dataToWrite, ...); } }
But you must also enter a request and send it in order to get a response.
Personally, for controllers, I prefer to write functional tests rather than unit tests (with Zend_Test ). This is slower, you probably need a sqlite database in memory and so on. But you will know if your application really works: you can unit test each class, but if the factory that forces your objects erroneously, you will continue to get the green PHPUnit panel with the broken application.
source share