cloak / cloak
Modern code coverage analysis library
Installs: 5 636
Dependents: 4
Suggesters: 0
Security: 0
Stars: 32
Watchers: 1
Forks: 0
Open Issues: 6
Requires
- php: >=5.5.0
- cloak/cloak-analyzer: ~0.1
- eloquent/pathogen: ~0.6
- phpcollection/phpcollection: ~0.4
- phpextra/event-manager: ~4.0.0
- yosymfony/toml: ~0.3
- zendframework/zend-code: ~3.0
- zendframework/zend-config: ~2.6
- zendframework/zend-console: ~2.6
Requires (Dev)
- cloak/robo-coveralls-kit: ~2.1
- codegyre/robo: ~0.7
- expect/peridot-expect-plugin: ~3.0
- holyshared/peridot-temporary-plugin: ~1.0
- holyshared/robo-peridot: ~2.0
- peridot-php/peridot: ~1.18
- peridot-php/peridot-dot-reporter: ~1.0
- phpspec/prophecy: ~1.6
- symfony/yaml: ~3.0
This package is auto-updated.
Last update: 2023-09-15 13:00:41 UTC
README
Cloak is a library that takes a code coverage.
This library works with PHP5.5 or more.
Requirements
- xdebug >= 2.2.2
Installation
-
Install the composer.
-
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.
<?php use cloak\CoverageAnalyzer; use cloak\configuration\ConfigurationBuilder; $builder = new ConfigurationBuilder(); $builder->includeFile('/example/src') ->excludeFile('/spec'); $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.
$analyzer->start(); //I write code here want to take code coverage example\example1(); $analyzer->stop(); $files = $analyzer->getResult()->getFiles(); foreach ($files as $file) { $result = sprintf("%s > %6.2f%% (%d/%d)", $file->getName(), $file->getCodeCoverage()->value(), $file->getExecutedLineCount(), $file->getExecutableLineCount() ); 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(); $builder->includeFile('/example/src') ->excludeFile('/spec') ->reporter($reporter); $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); $analyzer->start(); $analyzer->stop();
Other documents
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