Skip to content

Commit

Permalink
Implemented a formal interface for code coverage reporters.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Sep 18, 2017
1 parent 2c92bfd commit 8eeaa57
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 10 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
code-coverage-report/
vendor/
.idea/
composer.lock
/composer.lock
/coverage/
/vendor/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- **[BC BREAK]** Dropped support for [php-code-coverage] < 4.x.
- **[BC BREAK]** Added support for [php-code-coverage] 4.x and 5.x.
- **[BC BREAK]** By default, coverage reports are now placed under `coverage`
instead of `code-coverage-report`.
- **[NEW]** Introduced the `CodeCoverageReporter` interface for use in
configuration files.

[php-code-coverage]: https://github.com/sebastianbergmann/php-code-coverage

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test:

coverage:
phpdbg --version
phpdbg -qrr -d memory_limit=512M vendor/bin/peridot --reporter html-code-coverage specs
phpdbg -qrr -d memory_limit=512M vendor/bin/peridot --reporter spec --reporter html-code-coverage specs

open-coverage:
open code-coverage-report/index.html
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Then register the reporters in your `peridot.php` configuration:

```php
use Evenement\EventEmitterInterface;
use Peridot\Reporter\CodeCoverage\CodeCoverageReporter;
use Peridot\Reporter\CodeCoverageReporters;
use Peridot\Reporter\ReporterInterface;

return function (EventEmitterInterface $emitter) {
$coverage = new CodeCoverageReporters($emitter);
$coverage->register();

$emitter->on('code-coverage.start', function (ReporterInterface $reporter) {
$emitter->on('code-coverage.start', function (CodeCoverageReporter $reporter) {
$reporter->addDirectoryToWhitelist(__DIR__ . '/src');
});
};
Expand Down
4 changes: 2 additions & 2 deletions peridot.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Evenement\EventEmitterInterface;
use Peridot\Reporter\CodeCoverage\AbstractCodeCoverageReporter;
use Peridot\Reporter\CodeCoverage\CodeCoverageReporter;
use Peridot\Reporter\CodeCoverageReporters;

/**
Expand All @@ -16,7 +16,7 @@
$environment->getDefinition()->getArgument('path')->setDefault('specs');
});

$eventEmitter->on('code-coverage.start', function (AbstractCodeCoverageReporter $reporter) {
$eventEmitter->on('code-coverage.start', function (CodeCoverageReporter $reporter) {
$reporter->addDirectoryToWhitelist(__DIR__ . '/src');
});
};
2 changes: 1 addition & 1 deletion src/CodeCoverage/AbstractCodeCoverageReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Class AbstractCodeCoverageReporter
* @package Peridot\Reporter\CodeCoverage
*/
abstract class AbstractCodeCoverageReporter extends AbstractBaseReporter
abstract class AbstractCodeCoverageReporter extends AbstractBaseReporter implements CodeCoverageReporter
{
/**
* @var CodeCoverage
Expand Down
82 changes: 82 additions & 0 deletions src/CodeCoverage/CodeCoverageReporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Peridot\Reporter\CodeCoverage;

use Peridot\Reporter\ReporterInterface;

interface CodeCoverageReporter extends ReporterInterface
{
/**
* Add a directory to the blacklist (recursively).
*
* @param string $directory
* @param string $suffix
* @param string $prefix
*
* @return $this
*/
public function addDirectoryToBlacklist($directory, $suffix = '.php', $prefix = '');

/**
* Add a directory to the whitelist (recursively).
*
* @param string $directory
* @param string $suffix
* @param string $prefix
*
* @return $this
*/
public function addDirectoryToWhitelist($directory, $suffix = '.php', $prefix = '');

/**
* Add a file to the blacklist.
*
* @param string $filename
*
* @return $this
*/
public function addFileToBlacklist($filename);

/**
* Add a file to the whitelist.
*
* @param string $filename
*
* @return $this
*/
public function addFileToWhitelist($filename);

/**
* Add files to the blacklist.
*
* @param array $files
*
* @return $this
*/
public function addFilesToBlacklist(array $files);

/**
* Add files to the whitelist.
*
* @param array $files
*
* @return $this
*/
public function addFilesToWhitelist(array $files);

/**
* Get the report path.
*
* @return string
*/
public function getReportPath();

/**
* Set the report path.
*
* @param string $reportPath
*
* @return $this
*/
public function setReportPath($reportPath);
}

0 comments on commit 8eeaa57

Please sign in to comment.