micheh/teamcity-clover 问题修复 & 功能扩展

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

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

micheh/teamcity-clover

最新稳定版本:0.7

Composer 安装命令:

composer require micheh/teamcity-clover

包简介

Parse the clover.xml and report the code coverage and CRAP indices to TeamCity

README 文档

README

This small php script integrates the code coverage information from PHPUnit into TeamCity. The script uses service messages to notify TeamCity of the build metrics (since usage of teamcity-info.xml has been deprecated, and support may be removed in future versions of TeamCity).

The metrics will appear in the TeamCity GUI by default (under the Overview tab for a specific build and under the Statistics tab for your build configuration). As of TeamCity 9, you can easily add custom charts if your reporting needs are more sophisticated (see below).

Additionally, these metrics can be used to enforce standards on builds. For example, you can update your build configuration to enforce that code coverage has not dropped below some pre-determined threshold, or has not dropped by some percentage. See the TeamCity documentation for more information.

Installation

Use composer to add teamcity-clover to your project: composer require --dev micheh/teamcity-clover.

Or manually add it to your composer.json file with:

"require-dev": {
    "micheh/teamcity-clover": "~0.6"
}

To use the script without composer, download the current version and extract the files to a location where TeamCity has access.

Usage

Run PHPUnit and make sure to use the --coverage-clover argument to create the clover.xml. Then add another build step to run the teamcity-clover.php script and provide the path to the clover.xml as the only argument, for example: php path/to/teamcity-clover.php %system.teamcity.build.tempDir%/clover.xml. If you are using the PHPUnit Meta-Runner from the JetBrains Meta-Runner Power Pack, the above path is where you'll find the clover.xml.

Mapping

Since TeamCity and PHPUnit do not provide the same code coverage information, the different attributes had to be matched. The code coverage mapping is as follows:

TeamCity PHPUnit Statistic Key Names
Lines Elements CodeCoverageAbsLTotal, CodeCoverageAbsLCovered, CodeCoverageL
Blocks Statements CodeCoverageAbsBTotal, CodeCoverageAbsBCovered, CodeCoverageB
Methods Methods CodeCoverageAbsMTotal, CodeCoverageAbsMCovered, CodeCoverageM
Classes Classes/Traits CodeCoverageAbsCTotal, CodeCoverageAbsCCovered, CodeCoverageC

Custom statistics

In addition to the code coverage, the script will also report custom statistic values to TeamCity. These values do not appear in the web interface by default, but can be used for custom graphs or for build failure conditions.

CRAP Index

PHPUnit calculates a Change Risk Anti-Patterns (CRAP) Index for each method, which depends on the cyclomatic complexity and code coverage (see this question on StackOverflow for more information). The script will report the total, average, and maximum CRAP index to TeamCity, as well as the number and percentage of methods with a CRAP index equal or above a specified threshold (by default 30). You can change the CRAP threshold by providing the --crap-threshold <number> argument to the script. For example, to count all methods with a CRAP index of 20 or more, use php teamcity-clover.php --crap-threshold 20 clover.xml. Set the threshold to 0 to disable the reporting of the CRAP metrics.

Custom Statistic Key Description
CRAPAmount Number of methods with a CRAP index >= threshold (default: 30)
CRAPPercent Percentage of methods with a CRAP index >= threshold (default: 30)
CRAPTotal Total CRAP index (sum of all CRAP indices)
CRAPAverage Average CRAP index over all methods
CRAPMaximum Highest CRAP index reported

Other metrics

In addition, the following various metrics are reported to TeamCity:

Custom Statistic Key Description
Files Amount of files
LinesOfCode Amount of lines of code
NonCommentLinesOfCode Amount of non-comment lines of code

Custom Graphs

Besides the automatically created code coverage graphs, you can create graphs for the custom statistics as well, by updating the <TeamCity Data Directory>/config/main-config.xml. For example:

<graph title="Metrics" defaultFilters="showFailed" seriesTitle="Type">
    <valueType key="Files" title="Files" />
    <valueType key="CodeCoverageAbsCTotal" title="Classes" />
    <valueType key="CodeCoverageAbsMTotal" title="Methods" />
</graph>
<graph title="Lines" defaultFilters="showFailed" seriesTitle="Type">
    <valueType key="LinesOfCode" title="Lines of code" />
    <valueType key="NonCommentLinesOfCode" title="Non-Comment lines of code" />
</graph>

If you use TeamCity 9 or newer, you can also add custom graphs directly via the TeamCity web interface, instead of manually editing project XML's. See the TeamCity documentation for more information.

License

The files in this archive are licensed under the BSD-3-Clause license. You can find a copy of this license in LICENSE.md.

micheh/teamcity-clover 适用场景与选型建议

micheh/teamcity-clover 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 429.83k 次下载、GitHub Stars 达 11, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 micheh/teamcity-clover 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 11
  • Watchers: 3
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 未知