【问题标题】:PHPUnit test files using prefix使用前缀的 PHPUnit 测试文件
【发布时间】:2012-08-29 09:18:55
【问题描述】:

我需要测试一系列子文件夹中的所有类。但是,在完成大型重构之前,我不想测试这些子文件夹中的其他文件。

我要测试的文件都以class.开头,例如class.apis.phpclass.something.php

所以,为了运行我的测试,我有以下 PHPUnit 配置:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="true" backupStaticAttributes="true" colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true" convertWarningsToExceptions="true"
    processIsolation="false"
    stopOnFailure="false" syntaxCheck="true" verbose="true"
    strict="true">
    <php>
        <includePath>../</includePath>
    </php>

    <testsuites>
        <testsuite name="MSBO Test Suite">
            <directory>PHPUnit</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">../classes/</directory>
            <directory suffix=".php">../modules/</directory>
            <exclude>
                <directory>../classes/external/</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

但我找不到任何关于如何向白名单添加前缀的信息。有什么想法吗?

【问题讨论】:

  • @lkessler - 请不要为此使用 cmets。这些是题外话,并在整个网站上被标记。我会删除其他的。
  • ? ^^'

标签: php unit-testing testing phpunit


【解决方案1】:

我们使用不同的扩展名,而不是前缀,所以我们有:

<directory suffix=".class">lib/UTIL</directory>

您也许可以在文件名过滤器中使用通配符,尽管我没有尝试过。

<file>lib/UTIL/AJAX*.class</file>

【讨论】:

  • 有机会从前缀重命名为后缀吗?如果没有,是否可以在 PHPUnit 的 bug 列表中添加请求以支持前缀?
  • 如果没有其他解决方案,那么是的......我想应该这样做。
【解决方案2】:

相当老的线程,但只是为了补充以前的回复。此功能是为 PHPUnit 6.5.10 添加的。您可以在以下位置查看相关更新:

也可以在phpunit &gt;v7.2 获得(在v7.5.17 上测试并且工作正常)。不确定添加了哪个特定版本。

【讨论】:

    猜你喜欢
    • 2015-11-10
    • 2014-08-21
    • 2014-03-15
    • 2016-04-16
    • 2015-05-31
    • 2016-01-21
    • 1970-01-01
    • 2014-10-31
    • 1970-01-01
    相关资源
    最近更新 更多