【问题标题】:Why Doesn't PHPUnit 9 expect the log child element of logging phpunit.xml.dist为什么 PHPUnit 9 不期望日志记录 phpunit.xml.dist 的日志子元素
【发布时间】:2020-08-19 07:29:41
【问题描述】:

我目前正在将一个旧的 PHP 应用程序(超过 10 年)过渡到 PHP 7.4,我们目前正在应用程序的 PHP 7.4 分支上实现持续集成。我们决定使用 PHP 当前稳定版本支持的 PHPUnit 版本。所以我们将 PHP 7.4 分支的 ci 测试作业升级到 PHPUnit 9.3。

我们根据文档进行了所有必要的更改,但我们因一个不知道如何修复的警告而被阻止(假设已执行测试并且报告已在正确的位置发布) 警告 - 配置文件未通过验证!

  The following problems have been detected:

  Line 38:
  - Element 'log': This element is not expected..

我在下面分享我们的 PHPUnit 配置,并使用我们用来启动它的命令,任何人都可以发现它有什么问题吗?

phpunit -c phpunit.xml.dist


<?xml version="1.0" encoding="UTF-8"?>
<phpunit
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.3/phpunit.xsd"
         colors                      = "true"
         bootstrap                   = "tests/bootstrap.php"
         >

    <testsuites>
        <testsuite name="Unit Tests">
            <directory>tests/</directory>
        </testsuite>
    </testsuites>
    <coverage>
        <include>
            <directory suffix=".php">api</directory>
        </include>
    </coverage>
    <logging>
        <log type="junit" target="build/unit_report.xml"/>
    </logging>
</phpunit>

【问题讨论】:

    标签: php phpunit


    【解决方案1】:

    &lt;log&gt; 元素在 PHPUnit 9.3 中也有 changed

    你需要改变

    <logging>
      <log type="junit" target="build/unit_report.xml"/>
    </logging>
    

    <logging>
      <junit outputFile="build/unit_report.xml"/>
    </logging>
    

    话虽如此,我强烈建议使用 PHPUnit 的 --migrate-configuration CLI 选项自动将您的配置文件转换为新格式。

    【讨论】:

    • 谢谢,我确实查看了文档是否提到了任何更改并且没有看到任何内容,所以我很困惑。那我就用干净的。
    • @sebastian-bergmann 更改日志的链接已损坏,我似乎无法在文档中找到相关信息?我错过了什么吗:)
    • 对于遇到此问题的任何人,报道现在在&lt;coverage&gt;&lt;report&gt;&lt;clover outputFile="build/coverage/clover.xml"/&gt;,不再在&lt;logging&gt;。见phpunit.readthedocs.io/en/9.5/…
    • 我刚刚检查过:相关变更日志条目的链接工作正常。
    • $ vendor/bin/phpunit --migrate-configuration --verbose PHPUnit 9.5.13,作者是 Sebastian Bergmann 和贡献者。 phpunit.xml 不需要迁移。我的 phpunit.xml 来自: vendor/bin/phpunit --generate-configuration 并且它的日志记录部分是这样的:
    猜你喜欢
    • 2020-08-16
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 2019-04-18
    • 2013-10-29
    • 2016-06-04
    • 2017-06-04
    • 1970-01-01
    相关资源
    最近更新 更多