mjkruszewski / phpspec-code-coverage
为 PhpSpec 测试生成代码覆盖率报告
Requires
- php: ^7.1
- phpspec/phpspec: ^4.2||^5.0
- phpunit/php-code-coverage: ^5.0||^6.0||^7.0
Requires (Dev)
Suggests
- ext-xdebug: Install Xdebug to generate phpspec code coverage if you are not using phpdbg
README
phpspec-code-coverage 是一个 PhpSpec 扩展,用于生成 PhpSpec 测试的代码覆盖率报告。
生成代码覆盖率报告可以让您分析代码库中哪些部分被测试以及测试效果如何。然而,代码覆盖率本身不应作为衡量测试质量的单项指标。
注意! 这是一个由 henrikbjorn/phpspec-code-coverage 包维护的分支,适用于稳定版本,版本号兼容。
要求
- PHP 7+(适用于 PhpSpec v4+)或 PHP 5.6+(适用于 PhpSpec v3)
- Xdebug 或 phpdbg 扩展启用(PHP 7+是使用 phpdbg 进行代码生成所必需的)。
变更日志
有关最近更改的信息,请参阅 CHANGELOG.md。
安装
将此包作为项目中的开发依赖项安装
$ composer require --dev leanphp/phpspec-code-coverage
通过编辑项目的 phpspec.yml 文件启用扩展
extensions: LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension: ~
这足以通过扩展提供的默认值启用代码覆盖率生成。此扩展支持各种 配置选项。有关完整的示例配置文件,请参阅 配置部分。
使用方法
如果您执行 phpspec run 命令,您将在 coverage 目录中看到生成的代码覆盖率(以 html 格式)
$ bin/phpspec run
注意! 在生成代码覆盖率报告时,请确保通过 CLI 运行的 PHP 进程不受内存限制(即在 /etc/php/cli/php.ini 中将 memory_limit 设置为 -1)。
使用 phpdbg 运行
此扩展现在支持 phpdbg,在使用较新版本的 PHP 时可提高执行速度。通过 phpdbg 运行 phpspec
$ phpdbg -qrr phpspec run
注意! PHP 7+ 是使用 phpdbg 进行代码生成所必需的。
配置
下面是一个完整的 phpspec.yml 示例文件,可以作为进一步自定义扩展默认值的起点。下面的配置文件包含所有的 配置选项。
# phpspec.yml # ... extensions: # ... other extensions ... # leanphp/phpspec-code-coverage LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension: # Specify a list of formats in which code coverage report should be # generated. # Default: [html] format: - text - html #- clover #- php #- xml # # Specify output file/directory where code coverage report will be # generated. You can configure different output file/directory per # enabled format. # Default: coverage output: html: coverage #clover: coverage.xml #php: coverage.php #xml: coverage # # Should uncovered files be included in the reports? # Default: true #show_uncovered_files: true # # Set lower upper bound for code coverage # Default: 35 #lower_upper_bound: 35 # # Set high lower bound for code coverage # Default: 70 #high_lower_bound: 70 # # Whilelist directories for which code generation should be done # Default: [src, lib] # whitelist: - src - lib # # Whiltelist files for which code generation should be done # Default: empty #whilelist_files: #- app/bootstrap.php #- web/index.php # # Blacklist directories for which code generation should NOT be done #blacklist: #- src/legacy # # Blacklist files for which code generation should NOT be done #blacklist_files: #- lib/bootstrap.php
选项
format(可选)生成代码覆盖率时使用的格式列表。可以是以下之一或多个:clover、php、text、html、xml(默认html)注意:当使用clover格式选项时,您必须为clover格式配置特定的output文件(见下文)。output(可选)设置特定代码覆盖率格式将生成的输出文件/目录。如果您配置了多个格式,则使用format:output的哈希(例如clover:coverage.xml)(默认coverage)show_uncovered_files(可选)用于在覆盖率报告中包含未覆盖的文件(默认true)lower_upper_bound(可选)设置代码覆盖率的上限(默认35)。high_lower_bound(可选)设置代码覆盖率的下限(默认70)whitelist接受一个目录数组以白名单形式(默认:lib、src)。whitelist_files接受一个文件数组以白名单形式(默认:无)。blacklist接受一个目录数组以黑名单形式(默认:test、vendor、spec)blacklist_files接受一个文件数组以黑名单形式
作者
版权所有(c)2017-2018 ek9 dev@ek9.co (https://ek9.co).
版权所有(c)2013-2016 Henrik Bjornskov,部分代码来自 henrikbjorn/phpspec-code-coverage 项目。
许可证
许可协议为 MIT 许可证。