title: Zend_Test: No default module defined for this application
body: <h2>UPDATE 23 Dec</h2>
  
  <p>I had the problem where Zend Framework complains about "No default module defined for this application". I didn't use Modules and the main app works fine. </p>
  
  <p>I finally solved the problem with the help from <a href="http://weierophinney.net/matthew/archives/182-Testing-Zend-Framework-MVC-Applications.html#c22838" rel="nofollow">weierophinney.net</a></p>
  
  <blockquote>
    <p>Your bootstrap needs to minimally set the controller directory -- do a call to <code>$this-&gt;frontController-&gt;addControllerDirectory(...)</code> in your <code>appBootstrap()</code> method. I didn't in my example, as my Initialization plugin does that sort of thing for me.</p>
  </blockquote>
  
  <p>The problem is solved by adding the below to <code>setUp()</code></p>
  
  <pre><code>$this-&gt;getFrontController()-&gt;setControllerDirectory(APPLICATION_PATH . '/controllers');
  </code></pre>
  
  <p>But now, I have afew other questions: </p>
  
  <p><strong>1. Why does that value not get initialized by <code>application.ini</code>?</strong></p>
  
  <p>In <code>application.ini</code>, I have </p>
  
  <pre><code>[production]
  resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
  
  [testing : production]
  // didn't change anything regarding modules nor controllers
  </code></pre>
  
  <p><strong>2. I tried setting the <code>controllerDirectory</code> in <code>bootstrap.php</code> of my unit test, but it does not work</strong></p>
  
  <pre><code>$front = Zend_Controller_Front::getInstance();
  $front-&gt;setControllerDirectory(APPLICATION_PATH . '/controllers');
  </code></pre>
  
  <p>The only way that works is using <code>setUp()</code>. Why is that?</p>
  
  <p><strong>END UPDATE 23 Dec</strong></p>
  
  <hr>
  
  <p>I am getting the above error when unit testing my controller plugins. I am not using any modules. in my bootstrap.php for unit testing, I even tried adding</p>
  
  <pre><code>$front = Zend_Controller_Front::getInstance();
  $front-&gt;setDefaultModule('default');
  </code></pre>
  
  <p>But it still does not work. Anyways my bootstrap.php looks like <strong><a href="http://pastebin.com/HPYjMbbL" rel="nofollow">this</a></strong></p>
  
  <p><strong>UPDATE</strong>: the error looks something like</p>
  
  <p>There were 2 errors:</p>
  
  <pre><code>1) Application_Controller_Plugin_AclTest::testAccessToUnauthorizedPageRedirectsToLogin
  Zend_Controller_Exception: No default module defined for this application
  
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:391
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:204
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:244
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Front.php:954
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Test\PHPUnit\ControllerTestCase.php:205
  D:\Projects\Tickle\tests\application\controllers\plugins\aclTest.php:6
  
  2) Application_Controller_Plugin_AclTest::testAccessToAllowedPageWorks
  Zend_Controller_Exception: No default module defined for this application
  
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:391
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:204
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:244
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Front.php:954
  D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Test\PHPUnit\ControllerTestCase.php:205
  D:\Projects\Tickle\tests\application\controllers\plugins\aclTest.php:16
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I tried adding </p>
  
  <pre><code>public function setUp() {
    $front = Zend_Controller_Front::getInstance();
    $front-&gt;setDefaultModule('default');
  }
  </code></pre>
  
  <p>then 1 part works. </p>
  
  <pre><code>public function testAccessToUnauthorizedPageRedirectsToLogin() { // this fails with exception "Zend_Controller_Exception: No default module defined for this application"
    $this-&gt;dispatch('/projects');
    $this-&gt;assertController('auth');
    $this-&gt;assertAction('login');
  }
  
  public function testAccessToAllowedPageWorks() { // this passes
    $auth = Zend_Auth::getInstance();
    $authAdapter = new Application_Auth_Adapter('jiewmeng', 'password');
    $auth-&gt;authenticate($authAdapter);
  
    $this-&gt;dispatch('/projects');
    $this-&gt;assertController('projects');
    $this-&gt;assertAction('index');
  }
  </code></pre>