Modern code coverage analysis library


Build Status Stories in Ready Scrutinizer Code Quality Coverage Status Dependency Status

Cloak is a library that takes a code coverage.
This library works with PHP5.5 or more.


  • xdebug >= 2.2.2


  1. Install the composer.

  2. Install the cloak.

     composer require cloak/cloak --dev

How to use

Setup for the report of code coverage

Setup is required to take a code coverage.
You can use the ConfigurationBuilder, and to apply the settings to the analyzer.


use cloak\CoverageAnalyzer;
use cloak\configuration\ConfigurationBuilder;

$builder = new ConfigurationBuilder();

$analyzer = new CoverageAnalyzer( $builder->build() );

Take the code coverage

Run the start / stop at the place where want to take the code coverage.
After you can get the report, you need to run the getResult method.


//I write code here want to take code coverage


$files = $analyzer->getResult()->getFiles();

foreach ($files as $file) {
    $result = sprintf("%s > %6.2f%% (%d/%d)",
    echo $result . "\n";

Support multiple reporter

You can use at the same time more than one reporter.
Reporter that are supported by default are as follows.

  • TextReporter
  • ProcessingTimeReporter
  • LcovReporter
  • MarkdownReporter
  • TreeReporter

Usage is as follows.

$reporter = new CompositeReporter([
	new TextReporter(),
	new ProcessingTimeReporter()

$builder = new ConfigurationBuilder();

$analyzer = new CoverageAnalyzer( $builder->build() );

Result of the output

Code Coverage Started: 1 July 2014 at 12:00

100.00% (19/19) src/Analyzer.php
100.00% (27/27) src/Reporter/TextReporter.php
 85.71% ( 6/ 7) src/Reporter/Reportable.php
 81.25% (13/16) src/Configuration.php
 58.33% (14/24) src/ConfigurationBuilder.php

Code Coverage: 96.70%
Code Coverage Finished in 1.44294 seconds

Configuration file

If you use the configuration file, you can code simple.

use cloak\CoverageAnalyzer;
use cloak\configuration\ConfigurationLoader;

$loader = new ConfigurationLoader();
$configuration = $loader->loadConfiguration('cloak.toml');

$analyzer = new CoverageAnalyzer($configuration);


Other documents

  1. Using the reporter

How to run the test

Run only unit test

composer test

Run the code coverage display and unit test

composer coverage

How to run the example

composer example