phpunit/phpcov

php-code-coverage 的命令行前端

10.0.0 2024-02-02 07:34 UTC

README

Latest Stable Version CI Status Type Coverage codecov

phpcov

phpcov 是 php-code-coverage 库的命令行前端。

安装

此工具以 PHP 归档 (PHAR) 的形式分发

$ wget https://phar.phpunit.de/phpcov.phar

$ php phpcov.phar --version

使用 Phive 管理项目工具依赖是推荐的方式

$ phive install phpcov

$ ./tools/phpcov --version

不建议使用 Composer 下载和安装此工具。

使用方法

执行 PHP 脚本并生成 Clover XML 格式的代码覆盖率

$ phpcov execute --clover coverage.xml script.php
phpcov 8.1.0 by Sebastian Bergmann.

Generating code coverage report in Clover XML format ... done

合并存储在 *.cov 文件中的导出 php-code-coverage 对象

$ parallel --gnu :::                                                 \
    'phpunit --coverage-php /tmp/coverage/FooTest.cov tests/FooTest' \
    'phpunit --coverage-php /tmp/coverage/BarTest.cov tests/BarTest'
$ phpcov merge --clover /tmp/clover.xml /tmp/coverage
phpcov 8.1.0 by Sebastian Bergmann.

Generating code coverage report in Clover XML format ... done

补丁覆盖率

$ git diff HEAD^1 > /tmp/patch.txt
$ phpunit --coverage-php /tmp/coverage.cov
$ phpcov patch-coverage --path-prefix /path/to/project /tmp/coverage.cov /tmp/patch.txt
phpcov 8.1.0 by Sebastian Bergmann.

1 / 2 changed executable lines covered (50.00%)

Changed executable lines that are not covered:

  Example.php:11