定制 exussum12/coverage-checker 二次开发

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

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

exussum12/coverage-checker

Composer 安装命令:

composer require exussum12/coverage-checker

包简介

Allows checking the code coverage of a single pull request

README 文档

README

Allows old code to use new standards

Build Status Coverage Status Scrutinizer Code Quality

Coverage checker allows new standards to be implemented incrementally, by only enforcing them on new / edited code.

Tools like phpcs and phpmd are an all or nothing approach, coverage checker allows this to work with the diff i.e. enforce all of the pull request / change request.

This is sometimes called "Baselining"

Also working with PHPunit to allow, for example 90% of new/edited code to be covered. which will increase the overall coverage over time.

Installing

Composer

With composer simply

composer require --dev exussum12/coverage-checker

then call the script you need

Using Phar

Phar is a packaged format which should be a single download. The latest Phar can be found Here.

After downloading run chmod +x diffFilter.phar and then call as ./diffFilter.phar followed by the normal options

Manually

Clone this repository somewhere your your build plan can be accessed, composer install is preferred but there is a non composer class loader which will be used if composer is not installed. If composer is not used some PHP specific features will not work as expected. Then call the script you need

Usage

First of all a diff is needed

git diff origin/master... > diff.txt

See here for a more in depth examples of what diff you should generate

Then the output for the tool you wish to check (such as phpcs, PHPUnit, phpmd etc) for example

 phpcs --standard=psr2 --report=json > phpcs.json || true 

Here the || true ensures that the whole build will not fail if phpcs fails.

Then call diffFilter

 ./vendor/bin/diffFilter --phpcs diff.txt phpcs.json 100

The last argument (100 in this case) is optional, the default is 100. This can be lowered to 90 for example to ensure that at least 90% of the changed code conforms to the standard. diffFilter will exit with a 0 status if the changed code passes the minimum coverage. 2 otherwise

Extended guide

A more in depth guide can be found on the wiki also some tips for speeding up the build.

Installing as a git hook

There are 2 examples hooks in the GitHooks directory, if you symlink to these diffFilter will run locally.

pre-commit is before the commit happens pre-receive will prevent you pushing

Full list of available diff filters

Below is a list of all tools and a brief description

--buddy		Parses buddy (magic number detection) output
--checkstyle	Parses a report in checkstyle format
--clover	Parses text output in clover (xml) format
--codeclimate	Parse codeclimate output
--humbug	Parses the json report format of humbug (mutation testing)
--infecton	Parses the infection text log format
--jacoco	Parses xml coverage report produced by Jacoco
--phan		Parse the default phan(static analysis) output
--phanJson	Parses phan (static analysis) in json format
--phpcpd	Parses the text output from phpcpd (Copy Paste Detect)
--phpcs		Parses the json report format of phpcs, this mode only reports errors as violations
--phpcsStrict	Parses the json report format of phpcs, this mode reports errors and warnings as violations
--phpmd		Parses the xml report format of phpmd, this mode reports multi line violations once per diff, instead of on each line
		the violation occurs
--phpmdStrict	Parses the xml report format of phpmd, this mode reports multi line violations once per line they occur 
--phpmnd	Parses the text output of phpmnd (Magic Number Detection)
--phpstan	Parses the text output of phpstan
--phpunit	Parses text output in clover (xml) format generated with coverage-clover=file.xml
--pylint	Parses PyLint output
--psalm		Parses Psalm output

Running in information mode

Simply pass the 3rd argument in as 0, this will give output showing failed lines but will not fail the build

Why not run the auto fixers

Auto fixers do exist for some of these tools, but on larger code bases there are many instances where these can not be auto fixed. CoverageChecker allows to go to these new standards in the most used parts of the code by enforcing all changes to comply to the new standards

What is a diff filtered test

A diff filtered test is a test where the execution and diffence (diff) is used from a known point. This information can be used to only run the tests which have been changed. Saving in many cases minutes running tests.

A good workflow is to branch, run the tests with --coverage-php=php-coverage.php and then when running your tests run git diff origin/master... > diff.txt && ./composer/bin/phpunit

This saves the coverage information in the first step which the diff then filters to runnable tests.

This one time effort saves running unnecessary tests on each run, tests for which the code has not changed.

Check the Wiki for more information on installation and usage

exussum12/coverage-checker 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.77M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 176
  • 点击次数: 24
  • 依赖项目数: 14
  • 推荐数: 0

GitHub 信息

  • Stars: 176
  • Watchers: 10
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-04