1
votes

I'm trying to setup unit testing for a controller class in the Zend Framework.

I'd like to write multiple tests for the same controller, and keep them all in the same test class. But when I follow the directions on the home page, I get the following exception when the second test function runs:

Zend_Controller_Exception: No default module defined for this application

When I comment out the first test function, so only one test functions runs, the error goes away.

I've used PHPUnit with other frameworks and not had this problem. Does anyone know why this is happening only when I try running multiple test methods within the same class?

UPDATE:

Managed to fix the exception by following the bootstrapping method outlined here: http://kelmadics.blogspot.com/2011/07/setting-up-phpunit-in-zend-framework.html

1
Are your controllers or their tests doing anything to alter the front controller? Clearly, it finds the controller for the first test method, but then when setUp() is called again to bootstrap the application, the second time around it fails to setup the modules correctly. - David Harkness

1 Answers

0
votes

It sounds like to me that you have modules enabled but don't have a /application/modules/default/ module. So you either need to create a module called default, or in your bootstrap somewhere add:

$front->setControllerDirectory(array(
     'default' => '/path/to/application/controllers',
));

For more clarity, post some of your application.ini, especially if there's anything about modules in there.