【问题标题】:Cakephp phpunit.xml blacklist gets ignored while testingCakephp phpunit.xml 黑名单在测试时被忽略
【发布时间】:2017-09-26 14:28:56
【问题描述】:

当我在 cakephp 2.6 上运行我的测试时,/plugin 文件夹测试被包括在内。我尝试在phpunit.xml 中设置黑名单选项,测试使用该文件,但插件仍会包含在内。

我正在使用的命令以及命令 promt 中的以下文本

$ Console/cake test app All --stderr --configuration phpunit.xml

Welcome to CakePHP v2.6.13 Console
---------------------------------------------------------------
App : site
Path: /var/www/MYPAGE/site/
---------------------------------------------------------------
CakePHP Test Shell
---------------------------------------------------------------
PHPUnit 3.7.38 by Sebastian Bergmann.

Configuration read from /var/www/MYPAGE/phpunit.xml

我的phpunit.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
    <php>
        <ini name="memory_limit" value="2048M" />
    </php>
    <filter>
        <blacklist>
            <directory suffix=".php">./plugins</directory>
            <directory suffix=".ctp">./plugins</directory>
            <directory suffix=".php">./vendor</directory>
        </blacklist>
    </filter>
</phpunit>

如您所见,我想忽略 app/src 文件夹旁边的 vendorplugin 文件夹中的测试。

我也试过不带配置选项

$ Console/cake test App all --stderr

自动调用的插件有:

/插件
--认证
--克鲁德
--DebugKit
--..
/src

【问题讨论】:

    标签: cakephp phpunit cakephp-2.0 cakephp-2.6


    【解决方案1】:

    &lt;filter&gt; 部分仅用于从代码覆盖分析中过滤文件/位置。

    如果您要缩小 PHPUnit 配置文件中测试的范围,则需要相应地配置 &lt;testsuites&gt;。但是,如您所知,在 CakePHP 2.x 中,您不直接运行 PHPUnit,而是使用 CakePHP 测试 shell,这需要以编程方式创建测试套件 - 这似乎存在于您的设置中,否则通过 all 应该会导致一个错误(至少在最新的 2.x 中是这样)。

    取自文档,仅测试您的应用测试的测试套件可能如下所示:

    // app/Test/Case/AllModelTest.php
    
    class AllTestsTest extends CakeTestSuite {
        public static function suite() {
            $suite = new CakeTestSuite('All tests');
            $suite->addTestDirectoryRecursive(TESTS . 'Case');
            return $suite;
        }
    }
    

    你会像这样运行它:

    Console/cake test app AllTests
    

    另见

    【讨论】:

    • 谢谢。我正在使用一个名为`AllTest`的测试套件,我可以使用`$ Console/cake test app All --stderr`调用它,这里我不包含任何插件。我的插件,我要测试的插件位于 app/src 文件夹中。但是自动测试的是根目录下的 ./plugin
    • @ChrissPony 抱歉,我无法重现,此处和文档中显示的示例按预期工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2021-02-18
    • 2020-01-01
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    相关资源
    最近更新 更多