leanphp/behat-code-coverage

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

v3.4.1 2018-05-09 11:20 UTC

This package is not auto-updated.

Last update: 2024-09-16 22:12:28 UTC


README

License Latest Stable Version Total Downloads Travis AppVeyor Pre Release

behat-code-coverage 是一个 Behat 扩展,用于为 Behat 测试生成代码覆盖率报告。

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

注意! 这是一个维护分支 vipsoft/code-coverage-extension,包括 vipsoft/code-coverage-common 包的代码库,具有兼容的版本号,适用于稳定发布。

要求

变更日志

有关最近更改的信息,请参阅 CHANGELOG.md

安装

将此包作为项目的开发依赖项安装

$ composer require --dev leanphp/behat-code-coverage

通过编辑项目的 behat.yml 启用扩展

default:
  extensions:
    LeanPHP\Behat\CodeCoverage\Extension:
      drivers:
        - local
      filter:
        whitelist:
          include:
            directories:
              'src': ~
      report:
        format:   html
        options:
          target: build/behat-coverage

这将足以在 build/behat-coverage 目录中启用 html 格式的代码覆盖率生成。此扩展支持各种 配置选项。要查看完整注释的示例配置文件,请参阅 配置部分

用法

如果您执行 bin/behat 命令,您将在 target 目录(即 build/behat-coverage)中看到生成的代码覆盖率(以 html 格式)

$ bin/behat

使用 phpdbg 运行

此扩展现在支持 phpdbg,在使用较新版本的 PHP 时可加快执行速度。通过 phpdbg 运行 phpspec

$ phpdbg -qrr bin/behat run

配置

以下是一个完全注释的 behat.yml 示例文件,您可以将其用作扩展默认值的起始点以进一步自定义。下面的配置文件包含所有 [配置选项](#Configuration Options)。

# behat.yml
# ...
default:
  extensions:
    LeanPHP\Behat\CodeCoverage\Extension:
      # http auth (optional)
      auth:        ~
      # select which driver to use when gatherig coverage data
      drivers:
        - local     # local Xdebug driver
      # filter options
      filter:
        forceCoversAnnotation:                false
        mapTestClassNameToCoveredClassName:   false
        whitelist:
          addUncoveredFilesFromWhitelist:     true
          processUncoveredFilesFromWhitelist: false
          include:
            directories:
              'src': ~
              'tests':
                suffix: '.php'
#           files:
#             - script1.php
#             - script2.php
#         exclude:
#           directories:
#             'vendor': ~
#             'path/to/dir':
#               'suffix': '.php'
#               'prefix': 'Test'
#           files:
#             - tests/bootstrap.php
      # report configuration
      report:
        # report format (html, clover, php, text)
        format:    html
        # report options
        options:
          target: build/behat-coverage/html

配置选项

  • auth - HTTP 认证选项(可选)。
  • create (method / path) - 覆盖创建方法的选项
    • method - 指定方法(默认:POST
    • path - 指定路径(默认:/
  • read (method / path) - 覆盖读取方法的选项(方法和路径)。
    • method - 指定方法(默认:GET
    • path - 指定路径(默认:/
  • delete (method / path) - 覆盖删除方法的选项(方法和路径)。
    • method - 指定方法(默认:DELETE
    • path - 指定路径(默认:/
  • drivers - 收集代码覆盖率数据的驱动程序列表
    • local - 本地 Xdebug 驱动程序(默认)。
    • remote - 远程 Xdebug 驱动程序(默认禁用)。
  • filter - 各种筛选选项
    • forceCoversAnnotation - (默认:false
    • mapTestClassNameToCoveredClassName - (默认:false
    • whiltelist - 白名单特定选项
      • addUncoveredFilesFromWhiltelist - (默认:true
      • processUncoveredFilesFromWhitelist - (默认:false)
      • include - 要包含在白名单中的文件或目录列表
        • directories - 包含要包含的白名单目录的键。
          • suffix - 要包含的文件的后缀(默认:' .php '
          • prefix - 要包含的文件的前缀(默认:'')(可选)
        • files - 包含要包含的白名单文件列表。
      • exclude - 要从白名单中排除的文件或目录列表
        • directories - 包含要排除的白名单目录的键。
          • suffix - 要包含的文件的后缀(默认:' .php '
          • prefix - 要包含的文件的前缀(默认:'')(可选)
        • files - 包含要排除的白名单文件的键。
  • report - 报告选项
    • format - 指定报告格式(htmlcloverphptext
    • options - 格式选项
      • target - 目标/输出目录

作者

版权(c)2017 ek9 dev@ek9.co (https://ek9.co)。

版权(c)2013-2016 Anthon Pang,Konstantin Kudryashov everzet 以及 各种贡献者 为从 vipsoft/code-coverage-extensionvipsoft/code-coverage-common 项目中的代码部分。

许可证

根据 BSD-2-Clause License 许可。