如何在 Laravel 中为“app”以外的文件夹生成代码覆盖率

问题描述 投票:0回答:2

我在 Laravel v9.15.0PHP v8.1 上有一个项目,我更改了

phpunit.xml
文件,为我项目中的
modules
文件夹生成代码覆盖率,该文件夹与默认
app
文件夹,但生成的 HTML 报告只是空的。

  • 我当前的 Xdebug 设置中的
    app
    文件夹没有问题。
  • 我使用
    php artisan test --coverage-html reports
    reports
    文件夹中生成结果。

这是我

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="Unit">
            <directory suffix="">./modules/*/tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="">./modules/*/tests/Feature</directory>
        </testsuite>
    </testsuites>
    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./modules</directory>
        </include>
    </coverage>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="DB_CONNECTION" value="testing"/>
        <env name="DB_DATABASE" value=":memory:"/>
        <!-- <env name="MAIL_MAILER" value="array"/> -->
        <env name="QUEUE_CONNECTION" value="sync"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="TELESCOPE_ENABLED" value="false"/>
    </php>
</phpunit>
laravel phpunit code-coverage xdebug laravel-artisan
2个回答
1
投票

改变

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

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

0
投票

尝试删除

processUncoveredFiles="true"
。我曾经在使用 homestead 时保留它,但如果使用 sail,你宁愿将其删除。

© www.soinside.com 2019 - 2024. All rights reserved.