正在生成 Clover XML 格式的代码覆盖率报告...语法错误

Generating code coverage report in Clover XML format ... syntax error

我正在使用 phpstorm 并在我的 laravel 应用程序中编写了一些测试。 phpunit.xml 几乎是默认值。

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true"
>
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./app</directory>
        </include>
    </coverage>
    <php>
        <server name="APP_ENV" value="testing"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="DB_CONNECTION" value="sqlite"/>
        <server name="DB_DATABASE" value=":memory:"/>
        <server name="MAIL_MAILER" value="array"/>
        <server name="QUEUE_CONNECTION" value="sync"/>
        <server name="SESSION_DRIVER" value="array"/>
        <server name="TELESCOPE_ENABLED" value="false"/>
    </php>
</phpunit>

最后我收到以下错误:

Time: 00:15.742, Memory: 58.00 MB

OK (26 tests, 69 assertions)

Generating code coverage report in Clover XML format ... syntax error, unexpected '-', expecting '{'

Process finished with exit code 2

我不知道我应该从哪里开始看。感谢任何帮助!

更新:

尝试生成 html 报告时遇到同样的问题

❯ .\vendor\bin\phpunit --coverage-html ./coverage.html
PHPUnit 9.5.5 by Sebastian Bergmann and contributors.

............................                                      28 / 28 (100%)

Time: 00:23.702, Memory: 74.00 MB

OK (28 tests, 125 assertions)

Generating code coverage report in HTML format ... syntax error, unexpected '-', expecting '{'

更新 2:

运行 减少最小再现测试用例:

class MinimalTest extends TestCase
{
    /**
     * A basic feature test example.
     *
     * @return void
     */
    public function test_example()
    {
        $response = $this->get('https://google.com');

        $response->assertStatus(200);
    }
}

❯ .\vendor\bin\phpunit --filter MinimalTest --coverage-html ./coverage.html

❯ .\vendor\bin\phpunit --debug --filter MinimalTest --coverage-html ./coverage.html
PHPUnit 9.5.5 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.16 with Xdebug 3.0.4
Configuration: C:\Users\***\localGit\xampp\htdocs\oneup\app\phpunit.xml

Test 'Tests\Feature\MinimalTest::test_example' started
Test 'Tests\Feature\MinimalTest::test_example' ended


Time: 00:01.242, Memory: 42.00 MB

OK (1 test, 1 assertion)

Generating code coverage report in HTML format ... syntax error, unexpected '-', expecting '{'

我终于找到问题了。我通过排除 Laravel 的目录来隔离根本原因。错误的目录实际上是 app/View,因为我在生成 laravel components Laravel 时犯了一个早期错误,生成 viewcontroller 个组件文件。如果不需要 php 逻辑,并不总是需要触摸控制器,这就是为什么我没有看到问题。

这些时候我用错误的模式创建了组件,这导致 Laravel 生成损坏的 类(我的错,不是 Laravel 的)。通过清除这些,覆盖率报告成功生成,没有任何排除。

感谢@hakre,我知道我的问题非常普遍,无法重现。