phpunit / phpcov
php-code-coverage 的命令行前端
10.0.0
2024-02-02 07:34 UTC
Requires
- php: >=8.2
- phpunit/php-code-coverage: ^11.0
- phpunit/php-file-iterator: ^5.0
- phpunit/phpunit: ^11.0
- sebastian/cli-parser: ^3.0
- sebastian/diff: ^6.0
- sebastian/version: ^5.0
README
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
使用方法
执行 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