Skip to content

Commit 0fc140f

Browse files
committed
Add support for phpunit/php-code-coverage 9
1 parent c5a507b commit 0fc140f

File tree

7 files changed

+62
-186
lines changed

7 files changed

+62
-186
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
17-
php-versions: ['7.2', '7.3', '7.4', '8.0']
17+
php-versions: ['7.3', '7.4', '8.0']
18+
composer-versions: ['composer:v1', 'composer:v2']
1819

1920
steps:
2021
- name: Set git to use LF
@@ -31,7 +32,8 @@ jobs:
3132
uses: shivammathur/setup-php@v2
3233
with:
3334
php-version: ${{ matrix.php-versions }}
34-
extensions: mbstring,xdebug,pcov
35+
tools: ${{ matrix.composer-versions }}
36+
extensions: mbstring, xdebug, pcov
3537

3638
- name: Get Composer Cache Directory
3739
id: composer-cache
@@ -45,16 +47,20 @@ jobs:
4547
restore-keys: ${{ runner.os }}-composer-
4648

4749
- name: Install dependencies
50+
if: ${{ matrix.php-versions != '8.0' }} # Remove this as soon as `drupol/php-conventions` supports PHP 8
4851
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
4952

5053
- name: Run Grumphp
54+
if: ${{ matrix.php-versions != '8.0' }} # Remove this as soon as `drupol/php-conventions` supports PHP 8
5155
run: vendor/bin/grumphp run --no-ansi -n
5256

5357
- name: Send PSALM data
58+
if: ${{ matrix.php-versions != '8.0' }} # Remove this as soon as `drupol/php-conventions` supports PHP 8
5459
run: vendor/bin/psalm --shepherd --stats
5560
continue-on-error: true
5661

5762
- name: Send Scrutinizer data
63+
if: ${{ matrix.php-versions != '8.0' }} # Remove this as soon as `drupol/php-conventions` supports PHP 8
5864
run: |
5965
wget https://scrutinizer-ci.com/ocular.phar
6066
php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ 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+
## [6.0.0] - 2020-11-28
10+
11+
- Support PHP 8
12+
- Extension requires PHP7.3+ (due to `phpunit/php-code-coverage` v9 depending on it) #36
13+
Version 5.x will still be maintained
14+
915
## [5.0.0] - 2020-11-16
1016

1117
- Extension requires PHP7.2+ (due to PhpSpec v7 depending on it) #37, #35

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ used as a single metric defining how good your tests are.
2222
- PHP 7+ (for [PhpSpec][2] v4+) or PHP 5.6+ (for [PhpSpec][2] v3)
2323
- [Xdebug][3], [phpdbg][4] or [pcov][6] extension enabled (PHP 7+ is required for code
2424
generation to work with [phpdbg][4]).
25+
26+
## Compatibility
27+
28+
| phpspec-code-coverage | PHP | phpspec | phpunit |
29+
|-----------------------|----------|----------------------------|----------------------------|
30+
| 4.x | `^7.1` | `^4.2 \|\| ^5.0 \|\| ^6.0` | `^5.0 \|\| ^6.0 \|\| ^7.0` |
31+
| 5.x | `>= 7.2` | `^5.0 \|\| ^6.0 \|\| ^7.0` | `^6.0 \|\| ^7.0 \|\| ^8.0` |
32+
| 6.x | `>= 7.3` | `^6.0 \|\| ^7.0` | `^9.0` |
2533

2634
## Change Log
2735

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
}
3939
],
4040
"require": {
41-
"php": "^7.2 || ^8.0",
42-
"phpspec/phpspec": "^5.0 || ^6.0 || ^7.0",
43-
"phpunit/php-code-coverage": "^6.0 || ^7.0 || ^8.0"
41+
"php": ">= 7.3",
42+
"phpspec/phpspec": "^6.0 || ^7.0",
43+
"phpunit/php-code-coverage": "^9.0"
4444
},
4545
"conflict": {
4646
"sebastian/comparator": "< 2.0"
@@ -54,7 +54,7 @@
5454
},
5555
"extra": {
5656
"branch-alias": {
57-
"dev-master": "4.x-dev"
57+
"dev-master": "6.x-dev"
5858
}
5959
},
6060
"autoload": {

spec/Listener/CodeCoverageListenerSpec.php

Lines changed: 27 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66

77
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\Listener\CodeCoverageListener;
88
use PhpSpec\Console\ConsoleIO;
9-
use PhpSpec\Event\SuiteEvent;
109
use PhpSpec\ObjectBehavior;
11-
use Prophecy\Argument;
1210
use SebastianBergmann\CodeCoverage\CodeCoverage;
11+
use SebastianBergmann\CodeCoverage\Driver\Driver;
1312
use SebastianBergmann\CodeCoverage\Filter;
14-
use SebastianBergmann\CodeCoverage\Report;
13+
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
1514

1615
/**
16+
* Disabled due to tests breaking as php-code-coverage marked their classes
17+
* final and we cannot mock them. The tests should be converted into proper
18+
* functional (integration) tests instead. This file is left for reference.
19+
*
20+
* @see https://github.com/leanphp/phpspec-code-coverage/issues/19
21+
*
1722
* @author Henrik Bjornskov
1823
*/
1924
class CodeCoverageListenerSpec extends ObjectBehavior
@@ -25,174 +30,25 @@ public function it_is_initializable()
2530

2631
public function let(ConsoleIO $io)
2732
{
28-
$this->beConstructedWith($io, new CodeCoverage(), []);
33+
$codeCoverage = new CodeCoverage(new DriverStub(), new Filter());
34+
35+
$this->beConstructedWith($io, $codeCoverage, []);
36+
}
37+
}
38+
39+
class DriverStub extends Driver
40+
{
41+
public function nameAndVersion(): string
42+
{
43+
return 'DriverStub';
2944
}
3045

31-
/**
32-
* Disabled due to tests breaking as php-code-coverage marked their classes
33-
* final and we cannot mock them. The tests should be converted into proper
34-
* functional (integration) tests instead. This file is left for reference.
35-
*
36-
* @see https://github.com/leanphp/phpspec-code-coverage/issues/19
37-
*
38-
* function let(ConsoleIO $io, CodeCoverage $coverage)
39-
* {
40-
* $this->beConstructedWith($io, $coverage, array());
41-
* }
42-
*
43-
* function it_is_initializable()
44-
* {
45-
* $this->shouldHaveType('LeanPHP\PhpSpec\CodeCoverage\Listener\CodeCoverageListener');
46-
* }
47-
*
48-
* function it_should_run_all_reports(
49-
* CodeCoverage $coverage,
50-
* Report\Clover $clover,
51-
* Report\PHP $php,
52-
* SuiteEvent $event,
53-
* ConsoleIO $io
54-
* ) {
55-
* $reports = array(
56-
* 'clover' => $clover,
57-
* 'php' => $php
58-
* );
59-
*
60-
* $io->isVerbose()->willReturn(false);
61-
*
62-
* $this->beConstructedWith($io, $coverage, $reports);
63-
* $this->setOptions(array(
64-
* 'format' => array('clover', 'php'),
65-
* 'output' => array(
66-
* 'clover' => 'coverage.xml',
67-
* 'php' => 'coverage.php'
68-
* )
69-
* ));
70-
*
71-
* $clover->process($coverage, 'coverage.xml')->shouldBeCalled();
72-
* $php->process($coverage, 'coverage.php')->shouldBeCalled();
73-
*
74-
* $this->afterSuite($event);
75-
* }
76-
*
77-
* function it_should_color_output_text_report_by_default(
78-
* CodeCoverage $coverage,
79-
* Report\Text $text,
80-
* SuiteEvent $event,
81-
* ConsoleIO $io
82-
* ) {
83-
* $reports = array(
84-
* 'text' => $text
85-
* );
86-
*
87-
* $this->beConstructedWith($io, $coverage, $reports);
88-
* $this->setOptions(array(
89-
* 'format' => 'text'
90-
* ));
91-
*
92-
* $io->isVerbose()->willReturn(false);
93-
* $io->isDecorated()->willReturn(true);
94-
*
95-
* $text->process($coverage, true)->willReturn('report');
96-
* $io->writeln('report')->shouldBeCalled();
97-
*
98-
* $this->afterSuite($event);
99-
* }
100-
*
101-
* function it_should_not_color_output_text_report_unless_specified(
102-
* CodeCoverage $coverage,
103-
* Report\Text $text,
104-
* SuiteEvent $event,
105-
* ConsoleIO $io
106-
* ) {
107-
* $reports = array(
108-
* 'text' => $text
109-
* );
110-
*
111-
* $this->beConstructedWith($io, $coverage, $reports);
112-
* $this->setOptions(array(
113-
* 'format' => 'text'
114-
* ));
115-
*
116-
* $io->isVerbose()->willReturn(false);
117-
* $io->isDecorated()->willReturn(false);
118-
*
119-
* $text->process($coverage, false)->willReturn('report');
120-
* $io->writeln('report')->shouldBeCalled();
121-
*
122-
* $this->afterSuite($event);
123-
* }
124-
*
125-
* function it_should_output_html_report(
126-
* CodeCoverage $coverage,
127-
* Report\Html\Facade $html,
128-
* SuiteEvent $event,
129-
* ConsoleIO $io
130-
* ) {
131-
* $reports = array(
132-
* 'html' => $html
133-
* );
134-
*
135-
* $this->beConstructedWith($io, $coverage, $reports);
136-
* $this->setOptions(array(
137-
* 'format' => 'html',
138-
* 'output' => array('html' => 'coverage'),
139-
* ));
140-
*
141-
* $io->isVerbose()->willReturn(false);
142-
* $io->writeln(Argument::any())->shouldNotBeCalled();
143-
*
144-
* $html->process($coverage, 'coverage')->willReturn('report');
145-
*
146-
* $this->afterSuite($event);
147-
* }
148-
*
149-
* function it_should_provide_extra_output_in_verbose_mode(
150-
* CodeCoverage $coverage,
151-
* Report\Html\Facade $html,
152-
* SuiteEvent $event,
153-
* ConsoleIO $io
154-
* ) {
155-
* $reports = array(
156-
* 'html' => $html,
157-
* );
158-
*
159-
* $this->beConstructedWith($io, $coverage, $reports);
160-
* $this->setOptions(array(
161-
* 'format' => 'html',
162-
* 'output' => array('html' => 'coverage'),
163-
* ));
164-
*
165-
* $io->isVerbose()->willReturn(true);
166-
* $io->writeln('')->shouldBeCalled();
167-
* $io->writeln('Generating code coverage report in html format ...')->shouldBeCalled();
168-
*
169-
* $this->afterSuite($event);
170-
* }
171-
*
172-
* function it_should_correctly_handle_black_listed_files_and_directories(
173-
* CodeCoverage $coverage,
174-
* SuiteEvent $event,
175-
* Filter $filter,
176-
* ConsoleIO $io
177-
* )
178-
* {
179-
* $this->beConstructedWith($io, $coverage, array());
180-
*
181-
* $coverage->filter()->willReturn($filter);
182-
*
183-
* $this->setOptions(array(
184-
* 'whitelist' => array('src'),
185-
* 'blacklist' => array('src/filter'),
186-
* 'whitelist_files' => array('src/filter/whilelisted_file'),
187-
* 'blacklist_files' => array('src/filtered_file')
188-
* ));
189-
*
190-
* $filter->addDirectoryToWhitelist('src')->shouldBeCalled();
191-
* $filter->removeDirectoryFromWhitelist('src/filter')->shouldBeCalled();
192-
* $filter->addFileToWhitelist('src/filter/whilelisted_file')->shouldBeCalled();
193-
* $filter->removeFileFromWhitelist('src/filtered_file')->shouldBeCalled();
194-
*
195-
* $this->beforeSuite($event);
196-
* }
197-
*/
46+
public function start(bool $determineUnusedAndDead = true): void
47+
{
48+
}
49+
50+
public function stop(): RawCodeCoverageData
51+
{
52+
return RawCodeCoverageData::fromXdebugWithoutPathCoverage([]);
53+
}
19854
}

src/CodeCoverageExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PhpSpec\ServiceContainer;
2121
use RuntimeException;
2222
use SebastianBergmann\CodeCoverage\CodeCoverage;
23+
use SebastianBergmann\CodeCoverage\Driver\Selector;
2324
use SebastianBergmann\CodeCoverage\Filter;
2425
use SebastianBergmann\CodeCoverage\Report;
2526
use SebastianBergmann\CodeCoverage\Version;
@@ -50,17 +51,18 @@ public function load(ServiceContainer $container, array $params = []): void
5051
});
5152

5253
$container->define('code_coverage', static function ($container) {
54+
/** @var Filter $filter */
55+
$filter = $container->get('code_coverage.filter');
56+
5357
try {
54-
$coverage = new CodeCoverage(null, $container->get('code_coverage.filter'));
58+
return new CodeCoverage((new Selector())->forLineCoverage($filter), $filter);
5559
} catch (RuntimeException $error) {
5660
throw new NoCoverageDriverAvailableException(
5761
'There is no available coverage driver to be used.',
5862
0,
5963
$error
6064
);
6165
}
62-
63-
return $coverage;
6466
});
6567

6668
$container->define('code_coverage.options', static function ($container) use ($params) {

src/Listener/CodeCoverageListener.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,17 @@ public function beforeSuite(SuiteEvent $event): void
146146
$filter = $this->coverage->filter();
147147

148148
foreach ($this->options['whitelist'] as $option) {
149-
$filter->addDirectoryToWhitelist($option);
149+
$filter->includeDirectory($option);
150150
}
151151

152152
foreach ($this->options['blacklist'] as $option) {
153-
$filter->removeDirectoryFromWhitelist($option);
153+
$filter->excludeDirectory($option);
154154
}
155155

156-
foreach ($this->options['whitelist_files'] as $option) {
157-
$filter->addFilesToWhitelist($option);
158-
}
156+
$filter->includeFiles($this->options['whitelist_files']);
159157

160158
foreach ($this->options['blacklist_files'] as $option) {
161-
$filter->removeFileFromWhitelist($option);
159+
$filter->excludeFile($option);
162160
}
163161
}
164162

0 commit comments

Comments
 (0)