PHP code example of esi / phpunit-coverage-check

1. Go to this page and download the library: Download esi/phpunit-coverage-check library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

esi / phpunit-coverage-check example snippets


    /**
     * Processes the coverage data with the given clover file and threshold, and returns the information
     * similar to how the Console application will.
     *
     * This is mainly useful for those that may wish to use this library outside the CLI/Console or PHAR.
     */
    public function nonConsoleCall(string $cloverFile, int $threshold = 100, bool $onlyPercentage = false): string

use Esi\CoverageCheck\CoverageCheck;

$check = new CoverageCheck();
$results = $check->nonConsoleCall(__DIR__ . '/tests/fixtures/clover.xml', 90);

echo $results; // Total code coverage is 90.32%
bash
$ php phpunit-coverage-check.phar /path/to/clover.xml 100
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 --only-percentage
# -O for only-percentage works as well
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 -O
# -F or show-files will display coverage per file, formatted in a table
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 -F
bash
$ php coverage-check build/logs/clover.xml 90 -F

 ------------------------------------------------------------------- -------------------------- ----------
  File                                                                Elements (Covered/Total)   Coverage
 ------------------------------------------------------------------- -------------------------- ----------
  [...]\phpunit-coverage-check\src\Application.php                    12/12                      100.00%
  [...]\phpunit-coverage-check\src\Command\CoverageCheckCommand.php   94/94                      100.00%
  [...]\phpunit-coverage-check\src\CoverageCheck.php                  80/80                      100.00%
  [...]\phpunit-coverage-check\src\Style\CoverageCheckStyle.php       12/12                      100.00%
  [...]\phpunit-coverage-check\src\Utils.php                          39/39                      100.00%
 ------------------------------------------------------------------- -------------------------- ----------
  Overall Totals                                                      237/237                    100.00%
 ------------------------------------------------------------------- -------------------------- ----------
bash
$ php coverage-check tests/fixtures/clover.xml 90 -F

 ----------------------------- -------------------------- ----------
  File                          Elements (Covered/Total)   Coverage
 ----------------------------- -------------------------- ----------
  /tmp/Example/String.php       36/38                      94.74%
  /tmp/Example/StringList.php   20/24                      83.33%
 ----------------------------- -------------------------- ----------
  Overall Totals                56/62                      89.04%
 ----------------------------- -------------------------- ----------