Hello,
I've been trying to implement a testing environment for my project but I've
been having some issues with testing Controllers that are in a different
module then the default one. I was wondering if anyone can help me out to
tell me what I'm doing wrong.
My project contains the default module and an admin module which I can
access through my webbrowser just fine. Every module has its own config and
bootstrap which gets loaded properly. So far so good.
I've setup my testenvironment with the help of Matthew Weier 'O Phinney's
blog post and some other resources found online and I came up with the
following:
*TestHelper.php*
<?php
date_default_timezone_set('Europe/Amsterdam');
define('BASE_PATH', realpath(dirname(__FILE__) . '/../'));
define('APPLICATION_PATH', BASE_PATH . '/application');
// Include path
set_include_path(
'.'
. PATH_SEPARATOR . BASE_PATH . '/library'
. PATH_SEPARATOR . get_include_path()
);
/** Zend_Application */
require_once 'Zend/Application.php';
require_once 'Zend/Loader/Autoloader.php';
// Define application environment
define('APPLICATION_ENV', 'unittesting');
require_once 'ControllerTestCase.php';
Zend_Loader_Autoloader::getInstance();
*phpunit.xml*
<phpunit bootstrap="./TestHelper.php" colors="true">
<testsuite name="MyProject">
<directory>./</directory>
</testsuite>
</phpunit>
*ControllerTestCase.php*
<?php
require_once 'Zend/Application.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
abstract class ControllerTestCase extends
Zend_Test_PHPUnit_ControllerTestCase{
protected $application;
public function setUp(){
$this->bootstrap = array($this, 'appBootstrap');
parent::setUp();
}
public function appBootstrap(){
$this->application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini');
return $this->application->getBootstrap()->bootstrap();
}
public function tearDown() {
$this->resetRequest();
$this->resetResponse();
parent::tearDown();
}
}
*IndexControllerTest.php*
<?php
class IndexControllerTest extends ControllerTestCase{
public function testDefaultIndexTest(){
$this->dispatch('/index/test');
$this->assertModule('default');
$this->assertController('index');
$this->assertAction('test');
$this->assertResponseCode(200);
}
public function testAdminIndexTest(){
$this->dispatch('admin/index/test');
$this->assertModule('admin');
$this->assertController('index');
$this->assertAction('test');
$this->assertResponseCode(200);
}
}
The weird thing is that the first unit tests works just fine and passes and
the second errors out because it'll be redirected to my ErrorController. The
assertModule will return default and the controller will return Error so for
some reason it just can't get to the other modules.
So what am I missing? Please help me in the right direction.
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/ZF1-Problems-unit-testing-controllers-in-a-multi-module-project-tp4659285.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]