繁体   English   中英

如何防止模块在Zend Framework 2 phpunit测试中加载

[英]How to prevent module from being loaded in Zend Framework 2 phpunit test

我编写了带有Auth模块的ZF2应用程序。 Auth模块的设置在其Module.php文件中完成。

我在Zend Framework 2单元测试教程( http://framework.zend.com/manual/2.2/en/tutorials/unittesting.html )中进行了测试,但是使用了应用程序模块进行测试。 在测试的bootstrap.php中,我仅在配置中包含Application模块:

$config = array(
    'module_listener_options' => array(
        'module_paths' => $zf2ModulePaths,
    ),
    'modules' => array(
        'Application',
    )
);

在phpunit.xml中,我仅包含此测试目录:

<phpunit bootstrap="Bootstrap.php">
    <testsuites>
        <testsuite name="myApplication">
            <directory>./ApplicationTest</directory>
        </testsuite>
    </testsuites>
</phpunit>

我希望未加载Auth模块,因此应在测试中将其禁用。 但是我在Auth模块中的某个函数引发了一个异常,因此我认为无论如何都将其加载。

我是否误解了引导程序,有没有办法防止该模块被加载?

也许这不是完美的解决方案,但是可以完成以下工作:将方法setUp替换为

public function setUp()
{
    $config = include '/path/to/config/application.config.php';
    $config['modules'] = array('Application');

    $this->setApplicationConfig($config);

    parent::setUp();
}

该阵列可以包括其他模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM