Skip to content

Commit 8eeaa57

Browse files
committed
Implemented a formal interface for code coverage reporters.
1 parent 2c92bfd commit 8eeaa57

File tree

7 files changed

+95
-10
lines changed

7 files changed

+95
-10
lines changed

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
code-coverage-report/
2-
vendor/
3-
.idea/
4-
composer.lock
1+
/composer.lock
2+
/coverage/
3+
/vendor/

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

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

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

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test:
44

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

99
open-coverage:
1010
open code-coverage-report/index.html

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Then register the reporters in your `peridot.php` configuration:
1616

1717
```php
1818
use Evenement\EventEmitterInterface;
19+
use Peridot\Reporter\CodeCoverage\CodeCoverageReporter;
1920
use Peridot\Reporter\CodeCoverageReporters;
20-
use Peridot\Reporter\ReporterInterface;
2121

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

26-
$emitter->on('code-coverage.start', function (ReporterInterface $reporter) {
26+
$emitter->on('code-coverage.start', function (CodeCoverageReporter $reporter) {
2727
$reporter->addDirectoryToWhitelist(__DIR__ . '/src');
2828
});
2929
};

peridot.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Evenement\EventEmitterInterface;
4-
use Peridot\Reporter\CodeCoverage\AbstractCodeCoverageReporter;
4+
use Peridot\Reporter\CodeCoverage\CodeCoverageReporter;
55
use Peridot\Reporter\CodeCoverageReporters;
66

77
/**
@@ -16,7 +16,7 @@
1616
$environment->getDefinition()->getArgument('path')->setDefault('specs');
1717
});
1818

19-
$eventEmitter->on('code-coverage.start', function (AbstractCodeCoverageReporter $reporter) {
19+
$eventEmitter->on('code-coverage.start', function (CodeCoverageReporter $reporter) {
2020
$reporter->addDirectoryToWhitelist(__DIR__ . '/src');
2121
});
2222
};

src/CodeCoverage/AbstractCodeCoverageReporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Class AbstractCodeCoverageReporter
1212
* @package Peridot\Reporter\CodeCoverage
1313
*/
14-
abstract class AbstractCodeCoverageReporter extends AbstractBaseReporter
14+
abstract class AbstractCodeCoverageReporter extends AbstractBaseReporter implements CodeCoverageReporter
1515
{
1616
/**
1717
* @var CodeCoverage
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Peridot\Reporter\CodeCoverage;
4+
5+
use Peridot\Reporter\ReporterInterface;
6+
7+
interface CodeCoverageReporter extends ReporterInterface
8+
{
9+
/**
10+
* Add a directory to the blacklist (recursively).
11+
*
12+
* @param string $directory
13+
* @param string $suffix
14+
* @param string $prefix
15+
*
16+
* @return $this
17+
*/
18+
public function addDirectoryToBlacklist($directory, $suffix = '.php', $prefix = '');
19+
20+
/**
21+
* Add a directory to the whitelist (recursively).
22+
*
23+
* @param string $directory
24+
* @param string $suffix
25+
* @param string $prefix
26+
*
27+
* @return $this
28+
*/
29+
public function addDirectoryToWhitelist($directory, $suffix = '.php', $prefix = '');
30+
31+
/**
32+
* Add a file to the blacklist.
33+
*
34+
* @param string $filename
35+
*
36+
* @return $this
37+
*/
38+
public function addFileToBlacklist($filename);
39+
40+
/**
41+
* Add a file to the whitelist.
42+
*
43+
* @param string $filename
44+
*
45+
* @return $this
46+
*/
47+
public function addFileToWhitelist($filename);
48+
49+
/**
50+
* Add files to the blacklist.
51+
*
52+
* @param array $files
53+
*
54+
* @return $this
55+
*/
56+
public function addFilesToBlacklist(array $files);
57+
58+
/**
59+
* Add files to the whitelist.
60+
*
61+
* @param array $files
62+
*
63+
* @return $this
64+
*/
65+
public function addFilesToWhitelist(array $files);
66+
67+
/**
68+
* Get the report path.
69+
*
70+
* @return string
71+
*/
72+
public function getReportPath();
73+
74+
/**
75+
* Set the report path.
76+
*
77+
* @param string $reportPath
78+
*
79+
* @return $this
80+
*/
81+
public function setReportPath($reportPath);
82+
}

0 commit comments

Comments
 (0)