【问题标题】:Generating code coverage report in Clover XML format ... Fatal error: Cannot redeclare preprocessGrammar()以 Clover XML 格式生成代码覆盖率报告...致命错误:无法重新声明 preprocessGrammar()
【发布时间】:2021-12-31 19:52:33
【问题描述】:

我遇到了错误:Generating code coverage report in Clover XML format ... 致命错误:Cannot redeclare preprocessGrammar()(之前在 /app/vendor/nikic/php-parser/grammar/phpyLang. php:22) 在 /app/vendor/nikic/php-parser/grammar/phpyLang.php 第 22 行

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         cacheResultFile=".phpunit.cache/test-results">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">.</directory>
        </include>
        <report>
            <clover outputFile="phpunit.coverage.xml"/>
        </report>
    </coverage>

    <logging>
        <junit outputFile="phpunit.report.xml"/>
    </logging>
</phpunit>

只有在使用测试覆盖率时才会出现此错误。

【问题讨论】:

    标签: php phpunit code-coverage test-coverage


    【解决方案1】:

    我的错误在这里:

    <include>
        <directory suffix=".php">.</directory>
    </include>
    

    我想覆盖所有文件,它们位于src 和项目的根目录中。

    在根目录中有tests,它们被包含在测试覆盖范围内。它进行了递归调用。

    为了解决这个问题,我设置了具体目录 (src) 和文件 (.php-cs-fixer.)。我用过这个指令:

    <include>
        <directory suffix=".php">src</directory>
        <directory prefix=".php-cs-fixer.">.</directory>
    </include>
    

    我也可以使用&lt;file&gt;,但我有几个文件,使用directory 对我来说更有用。 https://phpunit.readthedocs.io/en/9.5/configuration.html#the-file-element

    &lt;exclude&gt; 指令不适合我。

    我的最终配置。

    <?xml version="1.0" encoding="UTF-8"?>
    <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
             bootstrap="vendor/autoload.php"
             cacheResultFile=".phpunit.cache/test-results">
        <testsuites>
            <testsuite name="default">
                <directory>tests</directory>
            </testsuite>
        </testsuites>
    
        <coverage processUncoveredFiles="true">
            <include>
                <directory suffix=".php">src</directory>
                <directory prefix=".php-cs-fixer.">.</directory>
            </include>
            <report>
                <clover outputFile="phpunit.coverage.xml"/>
            </report>
        </coverage>
    
        <logging>
            <junit outputFile="phpunit.report.xml"/>
        </logging>
    </phpunit>
    

    【讨论】:

      猜你喜欢
      • 2021-05-21
      • 2011-02-18
      • 1970-01-01
      • 2021-02-24
      • 2020-05-20
      • 1970-01-01
      • 2011-11-26
      • 1970-01-01
      • 2017-02-11
      相关资源
      最近更新 更多