I wrote the following unit test case:
class Ggv_LoginTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public $bootstrap = '/Library/WebServer/Documents/GGV/www/index.php';
public function testCallWithoutActionShouldPullFromIndexAction()
{
$this->dispatch('/');
$this->assertResponseCode(200);
}
public function testValidLoginShouldGoToIndexPage()
{
$this->request->setMethod('POST')
->setPost(array(
'user_name' => TESTS_LOGIN_NAME,
'user_password' => TESTS_LOGIN_PASSWORD
));
$this->dispatch('/GGV/www/user/login/');
$this->assertResponseCode(200);
}
}
The first test case that dispatches to '/' works. The second test case that
dispatches to throws Zend_Controller_Exception: No default module defined
for this application. I use the same index.php bootstrap file for running
the application and testing the application. Here is a relevant excerpt:
defined('GGV_DISPATCH_FRONT_CONTROLLER') or
define('GGV_DISPATCH_FRONT_CONTROLLER', true);
// Set the session into the registry
Zend_Registry::set('session', $session);
// Set up the front controller and dispatch
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new LoggerPlugin());
$front->throwExceptions(false);
$front->setControllerDirectory(GGV_PATH_ROOT .
'/application/controllers');
$front->setBaseUrl($config->www->baseurl);
if (GGV_DISPATCH_FRONT_CONTROLLER)
{
$front->dispatch();
}
the only difference is that in my test case I require_once a test
configuration PHP file that defines GGV_DISPATCH_FRONT_CONTROLLER to false
as per the documentation the bootstrap file must not dispatch the front
controller. Unlike all the samples given, I don't use a Bootstrap class or
callback in my testcase. It appears that Zend_Test does not use the $front
controller I setup in my index.php but creates it's own which isn't
initialized and throws the error.
I have also experimented with adding a setUp
public function setUp()
{
// Execute any startup code here
parent::setUp();
}
method into my testcase and trying to set the $this->frontController=$front
but the global variable that gets set in index.php is not available. What am
I doing wrong here? Any help is appreciated.
Thanks,
Peter
--
View this message in context:
http://www.nabble.com/Zend_Test_PHPUnit_ControllerTestCase-with-bootstrap-php-file-tp19247111p19247111.html
Sent from the Zend Framework mailing list archive at Nabble.com.