我将 PHPUnit 配置为使用 XDebug 生成代码覆盖率统计信息。看到 PCOV 更快,我禁用xdebug.so
并安装了pcov.so
.
现在,每当我运行单元测试时,生成的覆盖率报告都没有数字或名称或任何东西:
这是调用 phpunit 的脚本:
#!/bin/bash
script_dir=$(dirname $0);
php $script_dir/phpunit.phar --coverage-html ../../public/coverage
这是我的 phpunit.xml,它在从 XDebug 迁移到 PCOV 的过程中没有改变:
<?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="bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">../../app/</directory>
</include>
<exclude>
<directory suffix=".php">../../app/config/</directory>
<directory suffix=".php">../../app/libs/</directory>
<directory suffix=".php">../../app/views/</directory>
</exclude>
</coverage>
</phpunit>
这是输出:
PHPUnit 9.5.6 by Sebastian Bergmann and contributors.
Runtime: PHP 7.3.11 with PCOV 1.0.9
Configuration: /path/to/phpunit.xml
.............. 14 / 14 (100%)
Time: 00:00.751, Memory: 20.00 MB
OK (14 tests, 38 assertions)
Generating code coverage report in HTML format ... done [00:00.074]
PHP 版本:7.3.11
PHPUnit 版本:9.5.6
PCOV 版本:1.09
是否需要为 PCOV 或 PHPUnit 进行一些额外的配置才能使覆盖率报告有用?