定制 matthiasnoback/live-code-coverage 二次开发

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

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

matthiasnoback/live-code-coverage

Composer 安装命令:

composer require matthiasnoback/live-code-coverage

包简介

Generate code coverage reports on a live server

README 文档

README

Build Status

This library should help you generate code coverage reports on a live server (it doesn't have to be a production server of course).

Install this library using:

composer require matthiasnoback/live-code-coverage

Collecting code coverage data

In your front controller (e.g. index.php), add the following:

<?php

use LiveCodeCoverage\LiveCodeCoverage;

$shutDownCodeCoverage = LiveCodeCoverage::bootstrap(
    (bool)getenv('CODE_COVERAGE_ENABLED'),
    __DIR__ . '/../var/coverage',
    __DIR__ . '/../phpunit.xml.dist'
);

// Run your web application now...

// This will save and store collected coverage data:
$shutDownCodeCoverage();
  • The first argument passed to LiveCodeCoverage::bootstrap() is a boolean that will be used to determine if code coverage is enabled at all. The example shows how you can use an environment variable for that.
  • The second argument is the directory where all the collected coverage data will be stored (*.cov files). If this directory doesn't exist yet, it will be created.
  • The third argument is the path to a PHPUnit configuration file. Its <filter> section will be used to configure the code coverage whitelist. For example, this phpunit.xml.dist file might look something like this:
<?xml version="1.0" encoding="utf-8"?>
<phpunit>
    <filter>
        <whitelist>
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>

Most configuration directives that are available in PHPUnit work for this library too. If you notice that something doesn't work, please submit an issue.

If you don't provide a PHPUnit configuration file, no filters will be applied, so you will get a coverage report for all the code in your project, including vendor and test code if applicable.

If your application is a legacy application which exit()s or die()s before execution reaches the end of your front controller, the bootstrap should be slightly different:

$shutDownCodeCoverage = LiveCodeCoverage::bootstrap(
    // ...
);
register_shutdown_function($shutDownCodeCoverage);

// Run your web application now...

Generating code coverage reports (HTML, Clover, etc.)

To merge all the coverage data and generate a report for it, install Sebastian Bergmann's phpcov tool. Run it like this (or in any other way you like):

phpcov merge --html=./coverage/html ./var/coverage

Downsides

Please note that collecting code coverage data will make your application run much slower. Just see for yourself if that's acceptable.

matthiasnoback/live-code-coverage 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.09M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 117
  • 点击次数: 26
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 117
  • Watchers: 7
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-18