[英]How to prevent module from being loaded in Zend Framework 2 phpunit test
I wrote a ZF2 application with an Auth module. 我编写了带有Auth模块的ZF2应用程序。 The setup of this Auth module is done in its Module.php file. Auth模块的设置在其Module.php文件中完成。
I set up a test like in the Zend Framework 2 Unit Testing Tutorial ( http://framework.zend.com/manual/2.2/en/tutorials/unittesting.html ) but with the Application module to test. 我在Zend Framework 2单元测试教程( http://framework.zend.com/manual/2.2/en/tutorials/unittesting.html )中进行了测试,但是使用了应用程序模块进行测试。 In the test's bootstrap.php I only include the Application module in the config: 在测试的bootstrap.php中,我仅在配置中包含Application模块:
$config = array(
'module_listener_options' => array(
'module_paths' => $zf2ModulePaths,
),
'modules' => array(
'Application',
)
);
And in the phpunit.xml I only included this test directory: 在phpunit.xml中,我仅包含此测试目录:
<phpunit bootstrap="Bootstrap.php">
<testsuites>
<testsuite name="myApplication">
<directory>./ApplicationTest</directory>
</testsuite>
</testsuites>
</phpunit>
I expect not to have the Auth module being loaded and so it should be disabled for the test. 我希望未加载Auth模块,因此应在测试中将其禁用。 But I get an Exception thrown by a function in the Auth module so I think it is loaded anyhow. 但是我在Auth模块中的某个函数引发了一个异常,因此我认为无论如何都将其加载。
Do I misunderstand the bootstrapping and is there a way to prevent that module from being loaded? 我是否误解了引导程序,有没有办法防止该模块被加载?
Maybe it is not the perfect solution, but the following works: replace the method setUp with 也许这不是完美的解决方案,但是可以完成以下工作:将方法setUp替换为
public function setUp()
{
$config = include '/path/to/config/application.config.php';
$config['modules'] = array('Application');
$this->setApplicationConfig($config);
parent::setUp();
}
The array can include other modules. 该阵列可以包括其他模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.