hanken/phpspec-code-coverage

生成 PhpSpec 测试的代码覆盖率报告

v3.2.3 2020-01-17 13:26 UTC

README

License Latest Stable Version Total Downloads Travis AppVeyor Pre Release

phpspec-code-coverage 是一个 PhpSpec 扩展,用于生成 PhpSpec 测试的代码覆盖率报告。

生成代码覆盖率报告允许您分析代码库中哪些部分被测试以及测试效果如何。然而,代码覆盖率本身不应作为衡量测试好坏的唯一指标。

注意! 这是 henrikbjorn/phpspec-code-coverage 包的维护分支,具有兼容的稳定版版本号。

要求

变更日志

有关最近更改的信息,请参阅 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(可选):应生成代码覆盖率格式的列表。可以是以下之一:cloverphptexthtml(默认 html注意:当使用 clover 格式选项时,您必须配置特定的 output 文件用于 clover 格式(见下文)。
  • output(可选):设置特定代码覆盖率格式将生成的输出文件/目录。如果您配置了多个格式,则采用 format:output 的散列(例如,clover:coverage.xml)(默认 coverage
  • show_uncovered_files(可选):在覆盖率报告中包含未覆盖的文件(默认 true
  • lower_upper_bound(可选):设置代码覆盖率下限(默认 35
  • high_lower_bound(可选):设置代码覆盖率上限(默认 70
  • whitelist 采取一个目录数组以白名单(默认:libsrc
  • 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 许可证 下授权。