php - Laravel 不生成代码覆盖率报告

标签 php laravel phpunit laravel-testing

我正在使用 Laravel 8 并测试我的应用程序,我正在运行

php artisan test --coverage-html reports
测试正在成功运行。问题是没有生成覆盖率报告。我已经在 SO 上浏览了答案,据说解决方案会将以下内容添加到我的 phpunit.xml
 <logging>
    <log type="coverage-html" target="tests/coverage" showUncoveredFiles="true"/>
    <log type="coverage-clover" target="build/logs/clover.xml"/>
  </logging>
那行不通。我也试过
    <coverage processUncoveredFiles="true">
      <include>
        <directory suffix=".php">./app</directory>
      </include>
      <report>
        <html outputDirectory="tests/reports/coverage"/>
      </report>
    </coverage>
依然没有;下面是我的 phpunit.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
  <testsuites>
    <testsuite name="Unit">
      <directory suffix="Test.php">./tests/Unit</directory>
      <directory suffix="Test.php">./packages/okotieno</directory>
    </testsuite>

    <testsuite name="Feature">
      <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
  </testsuites>
  <filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
      <directory suffix=".php">./app</directory>
    </whitelist>
  </filter>
  <logging>
    <log type="coverage-html" target="tests/coverage" showUncoveredFiles="true"/>
    <log type="coverage-clover" target="build/logs/clover.xml"/>
  </logging>
  <php>
    <server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="MAIL_DRIVER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
    <env name="DB_DATABASE" value="testing_db"/>
  </php>

</phpunit>

我也跑了php artisan test --help查看有效标志,--coverage-html不在列表中,但它运行。我怎样才能解决这个问题?

最佳答案

我有同样的问题。是php.ini文件中xdebug的配置引起的。
就我而言,我有 xdebug 3.0.4。您可以使用 php -v 进行检查。
您必须在 php.ini 文件中包含以下几行:

[XDebug]
zend_extension = "c:\xampp8\php\ext\php_xdebug-3.0.4-7.4-vc15-x86_64.dll"
xdebug.mode=debug,coverage
xdebug.client_host=127.0.0.1
xdebug.client_port=9000

关于php - Laravel 不生成代码覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66876314/

相关文章:

php - 在 PHPUnit 中测试工作链接

PHP 将对象转换为数组的数组

php - 如何使用 PHPUnit 处理失败的 PHP 断言?

php - redis pub/sub 订阅返回连接错误

mysql - 为 Laravel 中的所有 SQL 请求添加 WHERE 条件

Laravel Blade @include 到 Javascript 变量中?

php - Laravel 辅助函数 base_path() 失败

PHPUnit 给我 autoload.php not found 异常

php - 如何更新 MySql 和 PHP 中的日期时间单元格?

php - jsonObjectRequest 错误消息为空