【问题标题】:How to prevent module from being loaded in Zend Framework 2 phpunit test如何防止模块在 Zend Framework 2 phpunit 测试中被加载
【发布时间】:2013-07-04 11:09:04
【问题描述】:

我编写了一个带有 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 模块中的函数抛出的异常,所以我认为它无论如何都被加载了。

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

【问题讨论】:

    标签: php zend-framework phpunit zend-framework2


    【解决方案1】:

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

    public function setUp()
    {
        $config = include '/path/to/config/application.config.php';
        $config['modules'] = array('Application');
    
        $this->setApplicationConfig($config);
    
        parent::setUp();
    }
    

    数组可以包含其他模块。

    【讨论】:

      猜你喜欢
      • 2012-11-18
      • 1970-01-01
      • 2012-10-10
      • 2013-10-03
      • 2015-07-26
      • 1970-01-01
      • 2012-10-30
      • 2013-05-13
      • 1970-01-01
      相关资源
      最近更新 更多