Hello, i have tried setting up a unit test with zend framework. The project
has been created by zend studio and also the tests. So the whole project
structure is a very standard setup.
The Problem
Ive first created a very simple test case which should dispatch to a given
controller and action and then successfully ends.
That worked. Then ive added another testcase which should the the same but
to a different action. This does not work as phpunit then outputs
[Zend_Controller_Exception: No default module defined for this application]
Ive then changed the second testcase to do the same like the first one. I
also get the same Zend_Exception. So i started to check my initializer.php
to see if there are some errors. It looks like, that when disabling the
session, the unit test runs through well. That is really weird. Ive also
tried to force an fail on each test and output the frontControllerDirectory
but each test then will fail without output me the frontControllerDirectory.
Here are parts of my initializer
public function __construct($env = 'production', $root = null)
{
$this->_setEnv($env);
if (null === $root) {
$root = realpath(dirname(__FILE__) . '/../');
}
$this->_root = $root;
$this->frontController = Zend_Controller_Front::getInstance();
$this->_auth = Zend_Auth::getInstance();
$this->_enableCache = true;
$this->_enableLogging = false;
// set the test environment parameters
if ($env == 'test' OR $env == 'development') {
$this->_enableCache = true;
$this->_enableLogging = true;
// Enable all errors so we'll know when something goes
wrong.
error_reporting(E_ALL);
ini_set('display_startupinitView_errors', 1);
ini_set('display_errors', 1);
$this->frontController->throwExceptions(false);
}
}
public function initSession()
{
// if session storage is set to db, initialize session table
if ($this->_serverconfig->session->storage == "db") {
Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('db'));
$config = array (
'name' => 'session',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime'
);
Zend_Session::setSaveHandler(new
Zend_Session_SaveHandler_DbTable($config));
}
// load session
Zend_Session::rememberMe(2678400);
Zend_Session::start();
$session = new Zend_Session_Namespace('Portal_Namespace', true);
if (!isset($sessionPortalNamespace->initialized)) {
Zend_Session::regenerateId();
$sessionPortalNamespace->initialized = true;
}
Zend_Registry::set('session_portal', $sessionPortalNamespace);
}
public function initControllers()
{
$this->frontController->addControllerDirectory($this->_root .
'/application/modules/' . $this->_config->general->modules. '/controllers',
'default');
$this->frontController->addControllerDirectory($this->_root .
'/application/modules/admin/controllers', 'admin');
}
And this is the testCase
<?
/**
* IndexControllerTest - Test the default index controller
*
* @author Don Bosco van Hoi <[email protected]>
* @version $Id: IndexControllerTest.php 3311 2009-01-07 16:21:48Z donbosco
$
*/
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once '../application/Initializer.php';
/**
* SearchController test case.
*/
class StaticControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {
/**
* Prepares the environment before running a test.
*/
protected function setUp() {
$this->bootstrap = array ($this, 'appBootstrap' );
parent::setUp ();
// TODO Auto-generated SearchControllerTest::setUp()
}
/**
* Prepares the environment before running a test.
*/
public function appBootstrap() {
$this->frontController->registerPlugin ( new Initializer (
'test' ) );
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown() {
// TODO Auto-generated SearchControllerTest::tearDown()
parent::tearDown ();
}
/**
* Constructs the test case.
*/
public function __construct() {
// TODO Auto-generated constructor
#print_r($controllerDirs =
$this->frontController->getControllerDirectory());
# print_r($this->getRequest()->getModuleName());
}
/**
* Tests SearchController->indexAction()
*/
public function testIndexAction() {
// TODO Auto-generated SearchControllerTest->testIndexAction()
$this->fail(var_export($this->frontController->getControllerDirectory(),
1));
$this->dispatch ( '/static/index' );
$this->assertController ( 'static' );
$this->assertAction ( 'index' );
}
public function testAboutAction() {
$this->fail(var_export($this->frontController->getControllerDirectory(),
1));
$this->dispatch ( '/static/index' );
$this->assertController ( 'static' );
$this->assertAction ( 'index' );
}
public function testImprintAction() {
$this->fail(var_export($this->frontController->getControllerDirectory(),
1));
$this->dispatch ( '/static/imprint' );
$this->assertController ( 'static' );
$this->assertAction ( 'imprint' );
}
}
http://www.nabble.com/file/p21829320/Initializer.php Initializer.php
http://www.nabble.com/file/p21829320/AllTests.php AllTests.php
http://www.nabble.com/file/p21829320/StaticControllerTest.php
StaticControllerTest.php
http://www.nabble.com/file/p21829320/BaseController.php BaseController.php
http://www.nabble.com/file/p21829320/StaticController.php
StaticController.php
--
View this message in context:
http://www.nabble.com/phpunit-%3A--no-default-module-defined--in-unittest-in-second-testcase-tp21829320p21829320.html
Sent from the Zend Framework mailing list archive at Nabble.com.