Skip to content

Commit 2a46051

Browse files
committed
v2.1.0 - Final PhpSpec2 Release + phpdbg support + PHP7 support (backported henrikbjorn/phpspec-code-coverage v2.1.0 release)
1 parent fbc1042 commit 2a46051

File tree

6 files changed

+97
-28
lines changed

6 files changed

+97
-28
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ php:
33
- '5.4'
44
- '5.5'
55
- '5.6'
6+
- '7.0'
7+
68
script:
79
- composer validate
810
- composer update

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ documented in this file.
66
The format is based on [Keep a Changelog](http://keepachangelog.com/)
77
and this project adheres to [Semantic Versioning](http://semver.org/).
88

9+
## [2.1.0] - 2017-02-12 (backported v2.1.0, original release on 2016-05-05)
10+
11+
**Note!** v2.1.0 is final release to support PhpSpec2.
12+
13+
- Added PHP 7 support
14+
- Added `phpdbg` extension support (alternative to `xdebug`)
15+
- Updated `blacklist` to include `test` directory by default
16+
- Updated `text` output to use coloring by default.
17+
918
## [1.0.1] - 2017-02-11 (backported v1.0.1, original release on 2014-12-11)
1019

1120
**Note!** This version is a direct backport of `1.0.1` of
1221
[henrikbjorn/phpspec-code-coverage][1] package with updated namespaces to work
1322
as [leanphp/phpspec-code-coverage][0].
1423

15-
This is last release to support PHP `5.3`
16-
1724
- PHP `>=5.3`
1825
- PhpSpec `~2.0`
1926
- Xdebug `>=2.1.4`
@@ -33,7 +40,8 @@ This is last release to support PHP `5.3`
3340
- Support configuring a blacklist of files to be excluded from code coverage
3441
reports (`blaclist_files` option).
3542

36-
[1.0.1]: https://github.com/leanphp/phpspec-code-coverage/releases/tag/1.0.1
43+
[2.1.0]: https://github.com/leanphp/phpspec-code-coverage/releases/tag/v2.1.0
44+
[1.0.1]: https://github.com/leanphp/phpspec-code-coverage/releases/tag/v1.0.1
3745

3846
[0]: https://github.com/leanphp/phpspec-code-coverage
3947
[1]: https://github.com/henrikbjorn/PhpSpecCodeCoverageExtension

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ used as a single metric defining how good your tests are.
1414

1515
**Note!** This is a maintained fork of [henrikbjorn/phpspec-code-coverage][1]
1616
package with compatible version numbers for stable releases. This is
17-
a **backported v1.0.1 release**.
17+
a **backported v2.1.0 release**.
1818

1919
## Requirements
2020

21-
- PHP 5.3
22-
- PHP [Xdebug][3] extension
21+
- PHP 5.3.3+ (**PHP 7** is supported)
22+
- [Xdebug][3] or [phpdbg][4] extension enabled
2323
- [PhpSpec v2][2]
2424

2525
## Install
@@ -36,11 +36,22 @@ extensions:
3636
```
3737
3838
This will sufficient to enable Code Coverage generation by using defaults
39-
provided by the extension. If you execute `phpspec run` command, you will see
40-
code coverage generated in `coverage` directory (in `html` format). This
41-
extension supports various [configuration options](#Configuration Options). For
42-
a fully annotated example configuration file check [Configuration
43-
section](#Configuration).
39+
provided by the extension. This extension supports various [configuration
40+
options](#Configuration Options). For a fully annotated example configuration
41+
file check [Configuration section](#Configuration).
42+
43+
## Usage
44+
45+
If you execute `phpspec run` command, you will see code coverage generated in `coverage` directory (in `html` format):
46+
47+
$ bin/phpspec run
48+
49+
### Running with phpdbg
50+
51+
This extension now supports [phpdbg][4], which results in faster execution when
52+
using more recent versions of PHP. Run `phpspec` via [phpdbg][4]:
53+
54+
$ phpdbg -qrr phpspec run
4455

4556
## Configuration
4657

@@ -152,3 +163,4 @@ Licensed under [MIT License](LICENSE).
152163

153164
[travis-image]: https://travis-ci.org/leanphp/phpspec-code-coverage.svg
154165
[travis-url]: https://travis-ci.org/leanphp/phpspec-code-coverage
166+

composer.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
"source": "https://github.com/leanphp/phpspec-code-coverage",
2424
"docs": "https://github.com/leanphp/phpspec-code-coverage#phpspec-code-coverage"
2525
},
26-
"require" : {
27-
"php": ">=5.3.3",
28-
"phpspec/phpspec": "~2.0",
29-
"phpunit/php-code-coverage": "~2.0"
26+
"require": {
27+
"php": "~5.3,^5.3.3||~7.0",
28+
"phpspec/phpspec": "^2.0",
29+
"phpunit/php-code-coverage": "^2.2.4||^3"
3030
},
3131
"require-dev": {
32-
"ext-xdebug": ">=2.1.4",
33-
"bossa/phpspec2-expect": "~1.0"
32+
"bossa/phpspec2-expect": "^1.0"
33+
},
34+
"suggest": {
35+
"ext-xdebug": "Install Xdebug to generate phpspec code coverage if you are not using phpdbg"
3436
},
3537
"minimum-stability": "stable",
3638
"config": {

spec/Listener/CodeCoverageListenerSpec.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function it_should_run_all_reports(
5151
$this->afterSuite($event);
5252
}
5353

54-
function it_should_output_text_report(
54+
function it_should_color_output_text_report_by_default(
5555
\PHP_CodeCoverage $coverage,
5656
\PHP_CodeCoverage_Report_Text $text,
5757
SuiteEvent $event,
@@ -67,6 +67,7 @@ function it_should_output_text_report(
6767
));
6868

6969
$io->isVerbose()->willReturn(false);
70+
$io->isDecorated()->willReturn(true);
7071
$this->setIO($io);
7172

7273
$text->process($coverage, true)->willReturn('report');
@@ -75,6 +76,31 @@ function it_should_output_text_report(
7576
$this->afterSuite($event);
7677
}
7778

79+
function it_should_not_color_output_text_report_unless_specified(
80+
\PHP_CodeCoverage $coverage,
81+
\PHP_CodeCoverage_Report_Text $text,
82+
SuiteEvent $event,
83+
IO $io
84+
) {
85+
$reports = array(
86+
'text' => $text
87+
);
88+
89+
$this->beConstructedWith($coverage, $reports);
90+
$this->setOptions(array(
91+
'format' => 'text'
92+
));
93+
94+
$io->isVerbose()->willReturn(false);
95+
$io->isDecorated()->willReturn(false);
96+
$this->setIO($io);
97+
98+
$text->process($coverage, false)->willReturn('report');
99+
$io->writeln('report')->shouldBeCalled();
100+
101+
$this->afterSuite($event);
102+
}
103+
78104
function it_should_output_html_report(
79105
\PHP_CodeCoverage $coverage,
80106
\PHP_CodeCoverage_Report_HTML $html,
@@ -144,12 +170,10 @@ function it_should_correctly_handle_black_listed_files_and_directories(
144170
'blacklist_files' => array('src/filtered_file')
145171
));
146172

147-
$filter->addDirectoryToWhitelist('src')->willReturn(null);
148-
$filter->removeDirectoryFromWhitelist('src/filter')->willReturn(null);
149-
$filter->addDirectoryToBlacklist('src/filter')->willReturn(null);
150-
$filter->addFileToWhitelist('src/filter/whilelisted_file')->willReturn(null);
151-
$filter->removeFileFromWhitelist('src/filtered_file')->willReturn(null);
152-
$filter->addFileToBlacklist('src/filtered_file')->willReturn(null);
173+
$filter->addDirectoryToWhitelist('src')->shouldBeCalled();
174+
$filter->removeDirectoryFromWhitelist('src/filter')->shouldBeCalled();
175+
$filter->addFileToWhitelist('src/filter/whilelisted_file')->shouldBeCalled();
176+
$filter->removeFileFromWhitelist('src/filtered_file')->shouldBeCalled();
153177

154178
$this->beforeSuite($event);
155179
}

src/Listener/CodeCoverageListener.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,44 @@ class CodeCoverageListener implements EventSubscriberInterface
1616
private $reports;
1717
private $io;
1818
private $options;
19+
private $enabled;
1920

2021
public function __construct(\PHP_CodeCoverage $coverage, array $reports)
2122
{
2223
$this->coverage = $coverage;
2324
$this->reports = $reports;
2425
$this->options = array(
2526
'whitelist' => array('src', 'lib'),
26-
'blacklist' => array('vendor', 'spec'),
27+
'blacklist' => array('test', 'vendor', 'spec'),
2728
'whitelist_files' => array(),
2829
'blacklist_files' => array(),
2930
'output' => array('html' => 'coverage'),
3031
'format' => array('html'),
3132
);
33+
34+
$this->enabled = extension_loaded('xdebug') || (PHP_SAPI === 'phpdbg');
3235
}
3336

3437
public function beforeSuite(SuiteEvent $event)
3538
{
39+
if (!$this->enabled) {
40+
return;
41+
}
42+
3643
$filter = $this->coverage->filter();
3744

3845
array_map(array($filter, 'addDirectoryToWhitelist'), $this->options['whitelist']);
3946
array_map(array($filter, 'removeDirectoryFromWhitelist'), $this->options['blacklist']);
40-
array_map(array($filter, 'addDirectoryToBlacklist'), $this->options['blacklist']);
4147
array_map(array($filter, 'addFileToWhitelist'), $this->options['whitelist_files']);
4248
array_map(array($filter, 'removeFileFromWhitelist'), $this->options['blacklist_files']);
43-
array_map(array($filter, 'addFileToBlacklist'), $this->options['blacklist_files']);
4449
}
4550

4651
public function beforeExample(ExampleEvent $event)
4752
{
53+
if (!$this->enabled) {
54+
return;
55+
}
56+
4857
$example = $event->getExample();
4958

5059
$name = strtr('%spec%::%example%', array(
@@ -57,11 +66,23 @@ public function beforeExample(ExampleEvent $event)
5766

5867
public function afterExample(ExampleEvent $event)
5968
{
69+
if (!$this->enabled) {
70+
return;
71+
}
72+
6073
$this->coverage->stop();
6174
}
6275

6376
public function afterSuite(SuiteEvent $event)
6477
{
78+
if (!$this->enabled) {
79+
if ($this->io && $this->io->isVerbose()) {
80+
$this->io->writeln('Did not detect Xdebug extension or phpdbg. No code coverage will be generated.');
81+
}
82+
83+
return;
84+
}
85+
6586
if ($this->io && $this->io->isVerbose()) {
6687
$this->io->writeln('');
6788
}
@@ -72,7 +93,7 @@ public function afterSuite(SuiteEvent $event)
7293
}
7394

7495
if ($report instanceof \PHP_CodeCoverage_Report_Text) {
75-
$output = $report->process($this->coverage, /* showColors */ true);
96+
$output = $report->process($this->coverage, /* showColors */ $this->io->isDecorated());
7697
$this->io->writeln($output);
7798
} else {
7899
$report->process($this->coverage, $this->options['output'][$format]);

0 commit comments

Comments
 (0)