dragonrun1/phpspec-code-coverage

此软件包已被废弃,不再维护。作者建议使用friends-of-phpspec/phpspec-code-coverage软件包。

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

4.2.3 2019-02-22 05:38 UTC

This package is auto-updated.

Last update: 2020-02-18 17:33:56 UTC


README

License Latest Stable Version Total Downloads Scrutinizer Code Quality Travis AppVeyor

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

生成代码覆盖率报告可以让你分析哪些代码部分被测试以及测试效果如何。然而,单独使用代码覆盖率不应作为衡量测试好坏的唯一标准。

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

composer require --dev dragonrun1/phpspec-code-coverage

phpspec-code-coverage console report phpspec-code-coverage HTML report

要求

  • PHP 7+(对于PhpSpec v4+)或PHP 5.6+(对于PhpSpec v3)
  • Xdebugphpdbg扩展已启用(PHP 7+是使用phpdbg生成代码所必需的)。

变更日志

请参阅CHANGELOG.md以获取最近更改的信息。

安装

将此软件包作为开发依赖项安装到您的项目中

$ composer require --dev dragonrun1/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(可选)指定代码覆盖率生成的格式列表。可以是以下之一或多个:cloverphptexthtmlxml(默认 html注意:当使用 clover 格式选项时,您必须为 clover 格式配置特定的 output 文件(见下文)。
  • output(可选)设置特定代码覆盖率格式生成的输出文件/目录。如果您配置了多个格式,则使用 format:output 的哈希(例如,clover:coverage.xml)(默认 coverage
  • show_uncovered_files(可选)用于在覆盖率报告中包含未覆盖的文件(默认 true
  • lower_upper_bound(可选)设置代码覆盖率下限(默认 35)。
  • high_lower_bound(可选)设置代码覆盖率上限(默认 70
  • whitelist 接收要白名单化的目录数组(默认:libsrc)。
  • whitelist_files 接收要白名单化的文件数组(默认:无)。
  • blacklist 接收要黑名单化的目录数组(默认:testvendorspec
  • blacklist_files 接收要黑名单化的文件数组

作者

版权所有(c)2017-2018 ek9 dev@ek9.co (https://ek9.co)。

版权所有(c)2013-2016 Henrik Bjornskov,部分代码来自 henrikbjorn/phpspec-code-coverage 项目。

许可证

根据 MIT 许可证 许可。