Skip to content

PHPUnit or Clover

Scott Dutton edited this page Dec 2, 2017 · 4 revisions

Basic usage

./vendor/bin/diffFilter --phpunit /tmp/diff.txt report/coverage.xml  90

Will fail (exit status 2) if less than 90% of the code committed is covered by a test. The input report needs to be in clover format (generated with --coverage-clover=report/coverage.xml)

Note: This works for all clover output! so any project using clover can use this regardless of the language it was written for

Speeding up builds with PHPUnit

Adding the following code to your phpunit.xml, and adding a diff and the PHPUnit coverage output in php format (--coverage-php) will run only the tests necessary for the change

<listeners>
    <listener class="exussum12\CoverageChecker\DiffFilter" >
      <arguments>
          <string>php-coverage.php</string>
          <string>diff.txt</string>
      </arguments>
  </listener>
</listeners>

A basic web server for storing the coverage file between runs is https://gist.github.com/exussum12/5af41e6de404c9ab293093c24ca8ce81

This should allow you to save output from a completed run and get it back in the future, There is no clean up process in the script so that should be implemented separately.

Note: This is really designed for local use, a smart version of "--filter" but could be ran on a CI server. There are some errors which can slip though this, so its highly recommended to run this with a static analysis tool such as phpstan or phan

Clone this wiki locally