2017 © Pedro Peláez
 

library coverage-checker

Allows checking the code coverage of a single pull request

image

exussum12/coverage-checker

Allows checking the code coverage of a single pull request

  • Wednesday, July 11, 2018
  • by exussum
  • Repository
  • 8 Watchers
  • 50 Stars
  • 18,187 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 39 Versions
  • 62 % Grown

The README.md

coverageChecker

Allows old code to use new standards, (*1)

Build Status Coverage Status Scrutinizer Code Quality, (*2)

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

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., (*4)

This is sometimes called "Baselining", (*5)

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

Installing

Composer

With composer simply, (*7)

composer require --dev exussum12/coverage-checker

then call the script you need, (*8)

Using Phar

Phar is a packaged format which should be a single download. The latest Phar can be found Here., (*9)

After downloading run chmod +x diffFilter.phar and then call as ./diffFilter.phar followed by the normal options, (*10)

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, (*11)

Usage

First of all a diff is needed, (*12)

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

See here for a more in depth examples of what diff you should generate, (*13)

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

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

Here the || true ensures that the whole build will not fail if phpcs fails., (*15)

Then call diffFilter, (*16)

 ./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, (*17)

Extended guide

A more in depth guide can be found on the wiki also some tips for speeding up the build., (*18)

Installing as a git hook

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

pre-commit is before the commit happens pre-receive will prevent you pushing, (*20)

Full list of available diff filters

Below is a list of all tools and a brief description, (*21)

--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, (*22)

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, (*23)

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., (*24)

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, (*25)

This saves the coverage information in the first step which the diff then filters to runnable tests., (*26)

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

Check the Wiki for more information on installation and usage, (*28)

The Versions

11/07 2018

dev-master

9999999-dev

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

11/07 2018

0.10.3

0.10.3.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

11/07 2018

dev-versionArgument

dev-versionArgument

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

12/06 2018

0.10.2

0.10.2.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

30/05 2018

0.10.1

0.10.1.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

30/05 2018

dev-addTestForInfection

dev-addTestForInfection

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

08/04 2018

dev-fixSpelling

dev-fixSpelling

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

01/03 2018

0.10.0

0.10.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

01/03 2018

dev-fileNotFound

dev-fileNotFound

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

26/02 2018

dev-addBuddy

dev-addBuddy

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

17/02 2018

0.9.1

0.9.1.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

16/02 2018

0.9.0

0.9.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Requires

 

The Development Requires

by Scott Dutton

08/01 2018

dev-addPhar

dev-addPhar

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

26/11 2017

dev-ImproveCode

dev-ImproveCode

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

03/11 2017

v0.8.0

0.8.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

29/10 2017

dev-fixForWholeFileErrors

dev-fixForWholeFileErrors

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

12/10 2017

v0.7.2

0.7.2.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

07/10 2017

v0.7.1

0.7.1.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

05/10 2017

v0.7

0.7.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

04/10 2017

v0.6.1

0.6.1.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

15/09 2017

v0.6.0

0.6.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

24/08 2017

dev-adjustOutput

dev-adjustOutput

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

18/08 2017

v0.5.5

0.5.5.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

11/08 2017

v0.5.4

0.5.4.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

09/08 2017

v0.5.3

0.5.3.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

25/07 2017

v0.5.2

0.5.2.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

25/07 2017

0.5.1

0.5.1.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

17/07 2017

v0.5.0

0.5.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

26/02 2017

v0.3.1

0.3.1.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

11/02 2017

v0.3.0

0.3.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

10/02 2017

v0.2.0

0.2.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

21/01 2017

0.1.7

0.1.7.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

18/01 2017

v0.1.6

0.1.6.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

18/01 2017

v0.1.5

0.1.5.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

12/01 2017

v0.1.4

0.1.4.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

12/01 2017

v0.1.3

0.1.3.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

12/01 2017

0.1.2

0.1.2.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

06/01 2017

v0.1.1

0.1.1.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton

06/01 2017

v0.1.0

0.1.0.0

Allows checking the code coverage of a single pull request

  Sources   Download

MIT

The Development Requires

by Scott Dutton