thor-juhasz/phpunit-coverage-check
Composer 安装命令:
composer require thor-juhasz/phpunit-coverage-check
包简介
A PHPUnit test coverage checker
README 文档
README
A PHPUnit test coverage checker.
This command will parse a clover.xml report file (generated by PHPUnit), to check that the test coverage meets a certain threshold (80% by default).
This library is loosely based on johanvanhelden's test coverage check.
Installation
Run this in your projects root directory:
composer require --dev thor-juhasz/phpunit-coverage-check
This will add a new PHP binary to your vendor/bin/ directory, named phpunit-coverage-check.
Usage
Use in GitHub workflow
To use this library in a GitHub CI workflow, make sure to generate a clover.xml report file when running phpunit:
- name: Run PHPUnit Tests run: ./vendor/bin/phpunit --coverage-clover clover.xml
Then simply add this after the step than runs phpunit:
- name: Test coverage run: ./vendor/bin/phpunit-coverage-check -t 100 clover.xml
Run manually
Generate a clover.xml report file with PHPUnit:
./vendor/bin/phpunit --coverage-clover clover.xml
Then you can run the binary provided by this library, passing the name of the clover.xml file as the first argument:
./vendor/bin/phpunit-coverage-check clover.xml
Arguments
filename (required)
The filename of the clover coverage XML file.
Example:
./vendor/bin/phpunit-coverage-check clover.xml
Options
threshold (optional)
Default value: 80
The threshold determines the lower value of acceptable test coverage. You can pass your desired threshold using
--threshold N or -t N for short, where N is a number ranging from 0 to 100:
Example:
# Requires 100% coverage ./vendor/bin/phpunit-coverage-check --threshold 100 clover.xml # Requires 50% coverage ./vendor/bin/phpunit-coverage-check -t 50 clover.xml # By default when passing no threshold option, it will require 80% coverage ./vendor/bin/phpunit-coverage-check clover.xml
metric (optional)
Default value: elements
You can specify here which metric you want to use to read the code coverage. The supported metrics are:
- elements
- statements
- methods
Example:
./vendor/bin/phpunit-coverage-check --metric statements clover.xml
./vendor/bin/phpunit-coverage-check -m methods clover.xml
# By default when passing no metric option, it will use elements
./vendor/bin/phpunit-coverage-check clover.xml
suppress-errors (optional)
When the code coverage reported in the clover XML report is under the specified threshold, the command will exit with code 1. When used in a CI workflow, this results in that job failing.
If you would like to use this tool in a CI workflow, without failing the job, you can pass the --suppress-errors
option (or -s for short).
Example:
# Even if the coverage is under the threshold, this will not fail the job - name: Test coverage run: ./vendor/bin/phpunit-coverage-check -t 100 clover.xml
Output
Example outputs:
# When coverage is 100%, and default threshold used. $ ./vendor/bin/phpunit-clover-test-coverage-check clover.xml [OK] Code coverage is 100%, which is acceptable (requires >= 80% coverage) # When coverage is 100%, and threshold is set to 100%. $ ./vendor/bin/phpunit-clover-test-coverage-check clover.xml [OK] Code coverage is 100%, which is acceptable (requires full coverage) # When coverage is 1%, and default threshold used. $ ./src/test-coverage-checker.php clover.xml [ERROR] Code coverage is 1%, which is not acceptable (requires >= 80% coverage) # When coverage is 1%, and threshold is set to 100%. $ ./src/test-coverage-checker.php clover.xml [ERROR] Code coverage is 1%, which is not acceptable (requires full coverage)
thor-juhasz/phpunit-coverage-check 适用场景与选型建议
thor-juhasz/phpunit-coverage-check 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.09M 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 thor-juhasz/phpunit-coverage-check 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thor-juhasz/phpunit-coverage-check 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.09M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-04