hanken / phpspec-code-coverage
生成 PhpSpec 测试的代码覆盖率报告
Requires
- php: ^7.0
- phpspec/phpspec: ^4.0||^5.0||^6.0
- phpunit/php-code-coverage: ~4.0||~5.0||~6.0||~7.0
Requires (Dev)
- bossa/phpspec2-expect: ^3.0
Suggests
- ext-xdebug: Install Xdebug to generate phpspec code coverage if you are not using phpdbg
This package is auto-updated.
Last update: 2024-09-17 23:25:19 UTC
README
phpspec-code-coverage 是一个 PhpSpec 扩展,用于生成 PhpSpec 测试的代码覆盖率报告。
生成代码覆盖率报告允许您分析代码库中哪些部分被测试以及测试效果如何。然而,代码覆盖率本身不应作为衡量测试好坏的唯一指标。
注意! 这是 henrikbjorn/phpspec-code-coverage 包的维护分支,具有兼容的稳定版版本号。
要求
- PHP 5.6+ 或 PHP 7+
- Xdebug 或 phpdbg 扩展已启用(PHP 7+ 是使用 phpdbg 进行代码生成的必要条件)。
- PhpSpec v3 或 v4
变更日志
有关最近更改的信息,请参阅 CHANGELOG.md。
安装
将此包作为项目中的开发依赖项安装
$ composer require --dev leanphp/phpspec-code-coverage
通过编辑您的项目的 phpspec.yml 文件来启用扩展
extensions: LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension: ~
这将为使用扩展提供的默认值启用代码覆盖率生成。此扩展支持各种 [配置选项](#Configuration Options)。要查看带有完全注释的示例配置文件,请参阅 配置部分。
用法
如果您执行 phpspec run 命令,您将在 coverage 目录(以 html 格式)中看到生成的代码覆盖率。
$ bin/phpspec run
使用 phpdbg 运行
此扩展现在支持 phpdbg,当使用较新版本的 PHP 时,这将导致执行速度更快。通过 phpdbg 运行 phpspec。
$ phpdbg -qrr phpspec run
注意! PHP 7+ 是使用 phpdbg 进行代码生成的必要条件。
配置
以下是一个完全注释的 phpspec.yml 示例文件,可以作为进一步自定义扩展默认值的起点。下面的配置文件包含所有 [配置选项](#Configuration Options)。
# 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 # # 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 # # 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(默认html)注意:当使用clover格式选项时,您必须配置特定的output文件用于clover格式(见下文)。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 ek9 dev@ek9.co(《https://ek9.co》)。
版权所有(c)2013-2016 Henrik Bjornskov,部分代码来自 henrikbjorn/phpspec-code-coverage 项目。
许可证
在 MIT 许可证 下授权。