定制 friends-of-phpspec/phpspec-code-coverage 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

friends-of-phpspec/phpspec-code-coverage

Composer 安装命令:

composer require friends-of-phpspec/phpspec-code-coverage

包简介

Generate Code Coverage reports for PhpSpec tests

README 文档

README

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Scrutinizer code quality License

phpspec-code-coverage

phpspec-code-coverage is a PhpSpec extension that generates Code Coverage reports for PhpSpec tests.

Generating Code Coverage reports allows you to to analyze which parts of your codebase are tested and how well. However, Code Coverage alone should NOT be used as a single metric defining how good your tests are.

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

Requirements

Compatibility

phpspec-code-coverage PHP phpspec phpunit
4.x ^7.1 ^4.2 || ^5.0 || ^6.0 ^5.0 || ^6.0 || ^7.0
5.x >= 7.2 ^5.0 || ^6.0 || ^7.0 ^6.0 || ^7.0 || ^8.0
6.x >= 7.3 ^6.0 || ^7.0 ^9.2 || ^10.0 || ^11.0
7.x >= 8.1 ^7.0 || ^8.0 ^9.2 || ^10.0 || ^11.0

Change Log

Please see CHANGELOG.md for information on recent changes.

Install

Install this package as a development dependency in your project:

$ composer require --dev friends-of-phpspec/phpspec-code-coverage

Enable extension by editing phpspec.yml of your project:

extensions:
  FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension: ~

This will sufficient to enable Code Coverage generation by using defaults provided by the extension. This extension supports various configuration options. For a fully annotated example configuration file check configuration section.

Usage

If you execute phpspec run command, you will see code coverage generated in coverage directory (in html format):

$ bin/phpspec run

Note! When generating Code Coverage reports make sure PHP processes run via CLI are not memory limited (i.e. memory_limit set to -1 in /etc/php/cli/php.ini).

Running with phpdbg

This extension now supports phpdbg, which results in faster execution when using more recent versions of PHP. Run phpspec via phpdbg:

$ phpdbg -qrr phpspec run

Note! PHP 7+ is required for code generation to work with phpdbg.

Configuration

You can see fully annotated phpspec.yml example file below, which can be used as a starting point to further customize the defaults of the extension. The configuration file below has all of the Configuration Options.

# phpspec.yml
# ...
extensions:
  # ... other extensions ...
  # friends-of-phpspec/phpspec-code-coverage
  FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension:
    # Specify a list of formats in which code coverage report should be
    # generated.
    # Default: [html]
    format:
      - text
      - html
      #- clover
      #- php
      #- xml
      #- cobertura
    #
    # 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
      #cobertura: cobertura.xml
    #
    # 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]
    #
    # Should text output show only summary?
    # Default: false
    #show_only_summary: true
    #
    whitelist:
      - src
      - lib
      # or to apply filtering on files names
      #- directory: src
      #  suffix: "Controller.php"
      #  prefix: "Get"
    #
    # 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
      # or to apply filtering on files names
      #- directory: src/legacy
      #  suffix: "Spec.php"
      #  prefix: "Test"
    #
    # Blacklist files for which code generation should NOT be done
    #blacklist_files:
      #- lib/bootstrap.php

Options

  • format (optional) a list of formats in which code coverage should be generated. Can be one or many of: clover, cobertura, crap4j, php, text, html, xml (default html) Note: When using clover format option, you have to configure specific output file for the clover format (see below).
  • output (optional) sets an output file/directory where specific code coverage format will be generated. If you configure multiple formats, takes a hash of format:output (e.g. clover:coverage.xml) (default coverage)
  • show_only_summary (optional) for showing only summary in text report (default false)
  • show_uncovered_files (optional) for including uncovered files in coverage reports (default true)
  • lower_upper_bound (optional) sets lower upper bound for code coverage (default 35).
  • high_lower_bound (optional) sets high lower bound for code coverage (default 70)
  • whitelist takes an array of directories to whitelist (default: lib, src). The array can be made more specific if an associative array is given with the following keys (directory, prefix, suffix)
  • whitelist_files takes an array of files to whitelist (default: none).
  • blacklist takes an array of directories to blacklist (default: test, vendor, spec). The array can be made more specific if an associative array is given with the following keys (directory, prefix, suffix)
  • blacklist_files takes an array of files to blacklist

Authors

Copyright (c) 2017-2018 ek9 dev@ek9.co (https://ek9.co).

Copyright (c) 2013-2016 Henrik Bjornskov, for portions of code from henrikbjorn/phpspec-code-coverage project.

License

Licensed under MIT License.

friends-of-phpspec/phpspec-code-coverage 适用场景与选型建议

friends-of-phpspec/phpspec-code-coverage 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.65M 次下载、GitHub Stars 达 20, 最近一次更新时间为 2019 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「test」 「spec」 「tests」 「report」 「phpspec」 「coverage」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 friends-of-phpspec/phpspec-code-coverage 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 friends-of-phpspec/phpspec-code-coverage 我们能提供哪些服务?
定制开发 / 二次开发

基于 friends-of-phpspec/phpspec-code-coverage 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.65M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 25
  • 依赖项目数: 139
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 2
  • Forks: 37
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-01