1

我正在使用 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 '{'
4

1 回答 1

1

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

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

多亏了@hakre,我知道我的问题非常笼统,不能真正重现。

于 2021-06-29T18:34:45.173 回答