andrey-tech/phpunit-cobertura-formatter-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

andrey-tech/phpunit-cobertura-formatter-php

Composer 安装命令:

composer require andrey-tech/phpunit-cobertura-formatter-php

包简介

Tool to show code coverage metrics, measured by PHP Unit in Cobertura format, in console and CI/CD pipeline

README 文档

README

PHPUnit Cobertura Formatter logo

Latest Stable Version PHP workflow Total Downloads PHP Version Require License

PHPUnit Cobertura Formatter is a tool to show code coverage metrics, measured by PHP Unit in Cobertura format, in console and CI/CD pipeline.

Installation

The PHPUnit Cobertura Formatter requires:

To install via Composer:

composer require --dev andrey-tech/phpunit-cobertura-formatter-php

Command line options

./vendor/bin/phpunit-cobertura-formatter <path to Cobertura XML file>

The PHPUnit Cobertura Formatter tool command line interface also accepts the following optional arguments:

  • --init — Will generate a default config file phpunit-cobertura-formatter.yml.dist in current working directory.
  • --config-file — The filepath to a custom config YAML file.
  • --filter-class-name — The filter results by class name (regex).
  • --ignore-red-metrics-on-exit — Will exit with a zero code, even "red" metrics exist.
  • --ignore-yellow-metrics-on-exit — Will exit with a zero code, even "yellow" metrics exist.
  • --no-colors — Disable colors in console.

An example command line of PHPUnit Cobertura Formatter tool:

./vendor/bin/phpunit-cobertura-formatter ./var/cobertura.xml --config-file=./phpunit-cobertura-formatter.yml.dist

An example of console output:

CLASS: App\Common\Service\Contract
+---------------------------+--------+--------+-----+------+
| METHOD                    | lcov   | bcov   | ccn | crap |
+---------------------------+--------+--------+-----+------+
| CLASS                     | 31.65  | 50.00  | 74  | 1822 |
| __construct               | 100.00 | 100.00 | 1   | 1    |
| getContractRules          | 0.00   | 0.00   | 5   | 30   |
| compareRules              | 75.00  | 70.00  | 7   | 7    |
| ruleAccept                | 100.00 | 100.00 | 31  | 31   |
| getPriority               | 88.24  | 79.17  | 9   | 9    |
| getContractsByRule        | 0.00   | 0.00   | 3   | 12   |
| getDefaultContracts       | 0.00   | 0.00   | 2   | 6    |
| createRuleDTO             | 0.00   | 0.00   | 7   | 56   |
| hasDefaultRule            | 0.00   | 0.00   | 3   | 12   |
| isDefaultRule             | 0.00   | 0.00   | 6   | 42   |
+---------------------------+--------+--------+-----+------+

Exit code: 2, Time: 17 ms, Memory: 1.85/4.00 MiB.

Software metrics

PHPUnit Cobertura Formatter tool shows metrics, measured by PHP Unit, in green, yellow and red colors in the console, according to boundaries for values, defined in configuration YAML file.

This table shows a list of the software metrics by PHPUnit Cobertura Formatter tool for classes and methods. The table also shows the default values for red/yellow/green boundaries of software metrics.

Metric Description Class Method
lcov Line Coverage, % 0/1/100 0/1/100
bcov Branch Coverage, % 0/1/100 0/1/100
ccn Cyclomatic Complexity Number 11/8/7
crap Change Risk Analysis and Predictions Index (CRAP) 30/-/29

Configuration YAML file

By PHPUnit Cobertura Formatter tool is looking for following configuration YAML files is current working directory:

  • phpunit-cobertura-formatter.yml,
  • phpunit-cobertura-formatter.yml.dist.

Configuration YAML file allows to set color boundaries for values of software metrics.

PHPUnit Cobertura Formatter tool currently defines three color boundaries:

Color Description
green Ok
yellow Warning
red Error

A white value means there are no defined color boundaries for this metric.

You can also add/set custom colors and styles. See How to Color and Style the Console Output in Symfony console.

The default configuration file:

colorizer:
  metrics:

    # Metrics of class
    class:

      lcov:
        green: [ 100, 100 ]
        yellow+bold: [ 1, 99 ]
        red+bold: [ 0, 1 ]

      bcov:
        green: [ 100, 100 ]
        yellow+bold: [ 1, 99 ]
        red+bold: [ 0, 1 ]

    # Metrics of method
    method:

      lcov:
        green: [ 100, 100 ]
        yellow+bold: [ 1, 99 ]
        red+bold: [ 0, 1 ]

      bcov:
        green: [ 100, 100 ]
        yellow+bold: [ 1, 99 ]
        red+bold: [ 0, 1 ]

      ccn:
        green: [ 1, 7 ]
        yellow+bold: [ 8, 10 ]
        red+bold: [ 11 ]

      crap:
        green: [ 0, 29 ]
        red+bold: [ 30 ]

Exit codes

PHPUnit Cobertura Formatter tool defines four different exit codes:

Code Description
0 This exit code indicates that everything worked as expected without "red" or "yellow" metrics
1 This exit code indicates that an error/exception occurred which has interrupted tool during execution
2 This exit code means that tool has processed the Cobertura file with "red" metrics
3 This exit code means that tool has processed the Cobertura file with "yellow" metrics

Authors and Maintainers

The author and maintainer of PHPUnit Cobertura Formatter is andrey-tech.

License

This tool is licensed under the MIT license.

andrey-tech/phpunit-cobertura-formatter-php 适用场景与选型建议

andrey-tech/phpunit-cobertura-formatter-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.75k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 andrey-tech/phpunit-cobertura-formatter-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 andrey-tech/phpunit-cobertura-formatter-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.75k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-07