Zend framework Zend Framework测试控制器Zend_控制器_异常:没有为此应用程序定义默认模块
我尝试为控制器编写测试。我使用OS Windows、zend framework,我的库位于C:/library中,该库添加到php.ini的include_路径中。 当我运行testLoginAction时,我得到一个没有为应用程序定义默认模块的错误。但我根本不使用模块。你知道如何解决这个问题吗 IndexControllerTest.php ControllerTestCase.php } My phpunit.xml:Zend framework Zend Framework测试控制器Zend_控制器_异常:没有为此应用程序定义默认模块,zend-framework,testing,phpunit,Zend Framework,Testing,Phpunit,我尝试为控制器编写测试。我使用OS Windows、zend framework,我的库位于C:/library中,该库添加到php.ini的include_路径中。 当我运行testLoginAction时,我得到一个没有为应用程序定义默认模块的错误。但我根本不使用模块。你知道如何解决这个问题吗 IndexControllerTest.php ControllerTestCase.php } My phpunit.xml: <?xml version="1.0" encoding="UT
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="./application/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="true"
syntaxCheck="true">
<!-- запускаем все тесты из корневой директории -->
<testsuite name="Main Test Suite">
<directory>./</directory>
</testsuite>
<filter> <!-- смотрим лишь на следующие директории -->
<whitelist>
<directory suffix=".php">../application</directory>
<!-- <directory suffix=".php">../library</directory>-->
<exclude>
<directory suffix=".phtml">../application</directory>
<directory>../application/forms</directory>
<directory>../application/models</directory>
<directory>../library</directory>
<file>../application/Bootstrap.php</file>
</exclude>
</whitelist>
</filter>
<logging>
<!-- логирование и создание отчета -->
<log type="coverage-html" target="./report" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70"/>
</logging>
</phpunit>
我的测试基类:
致以最诚挚的问候,Oleg。请确保您的application.ini不包含诸如resources.frontController.moduledirectory=application\u PATH/modules或resources.frontController.params.prefixDefaultModule=1或resources.modules[]=确保您的application.ini不包含诸如resources.frontController.moduledirectory=application\u PATH/modules或resources.frontController.params.prefixDefaultModule=1或resources.modules[]=/p>您需要在ControllerTestCase类的父::安装行之后修改您的安装方法: $this->getFrontController->setcontrollerdirectoryaapplication\u路径/管制员; 并从appBoostrap方法中删除以下行:
$this->front->setControllerDirectory'../application/controllers' 您需要在ControllerTestCase类的父::设置行之后修改设置方法: $this->getFrontController->setcontrollerdirectoryaapplication\u路径/管制员; 并从appBoostrap方法中删除以下行: $this->front->setControllerDirectory'../application/controllers' $this->front->无法工作,因为front controller属性是$this->frontController->或$this->getFrontController-> 即使如此,由于您的引导方式,您的测试可能无论如何都不会工作。您是否从ini配置文件配置前端控制器?如果是,那么您不需要在测试中配置frontController,您需要通过Zend_应用程序配置引导 您不需要在Zend_应用程序实例上调用bootstrap,因为Zend_Test_PHPUnit_ControllerTestCase将在发送请求时执行此操作 因此,您的基类可能如下所示:
class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
// Assign and instantiate in one step:
$this->bootstrap = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
}
class Controller_IndexControllerTest extends ControllerTestCase
{
public function testIsEverythingOK()
{
$this->assertTrue(true);
}
public function testLoginAction()
{
$this->dispatch('/login/index');
$this->assertModule('default');
$this->assertController('login');
$this->assertAction('index');
}
}
扩展基类的控制器测试将如下所示:
class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
// Assign and instantiate in one step:
$this->bootstrap = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
}
class Controller_IndexControllerTest extends ControllerTestCase
{
public function testIsEverythingOK()
{
$this->assertTrue(true);
}
public function testLoginAction()
{
$this->dispatch('/login/index');
$this->assertModule('default');
$this->assertController('login');
$this->assertAction('index');
}
}
完成了
资源
$this->front->不起作用,因为front controller属性是$this->frontController->或$this->getFrontController->
即使如此,由于您的引导方式,您的测试可能无论如何都不会工作。您是否从ini配置文件配置前端控制器?如果是,那么您不需要在测试中配置frontController,您需要通过Zend_应用程序配置引导
您不需要在Zend_应用程序实例上调用bootstrap,因为Zend_Test_PHPUnit_ControllerTestCase将在发送请求时执行此操作
因此,您的基类可能如下所示:
class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
// Assign and instantiate in one step:
$this->bootstrap = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
}
class Controller_IndexControllerTest extends ControllerTestCase
{
public function testIsEverythingOK()
{
$this->assertTrue(true);
}
public function testLoginAction()
{
$this->dispatch('/login/index');
$this->assertModule('default');
$this->assertController('login');
$this->assertAction('index');
}
}
扩展基类的控制器测试将如下所示:
class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
// Assign and instantiate in one step:
$this->bootstrap = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
}
class Controller_IndexControllerTest extends ControllerTestCase
{
public function testIsEverythingOK()
{
$this->assertTrue(true);
}
public function testLoginAction()
{
$this->dispatch('/login/index');
$this->assertModule('default');
$this->assertController('login');
$this->assertAction('index');
}
}
完成了
资源