Skip to content

Commit 60cf243

Browse files
committed
Add support for OpenClover
1 parent 2f12798 commit 60cf243

9 files changed

Lines changed: 57 additions & 23 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ jobs:
1717
php-version:
1818
- "8.4"
1919
- "8.3"
20-
- "8.2"
21-
- "8.1"
2220

2321
php-code-coverage-version:
24-
- "^12.0"
25-
- "^11.0"
26-
- "^10.1.16"
22+
- "^12.3"
2723

2824
symfony-version:
2925
- "^7.0.3"
@@ -40,16 +36,6 @@ jobs:
4036
- "xdebug"
4137
- "pcov"
4238

43-
exclude:
44-
- php-version: "8.1"
45-
symfony-version: "^7.0.3"
46-
- php-version: "8.1"
47-
php-code-coverage-version: "^11.0"
48-
- php-version: "8.2"
49-
php-code-coverage-version: "^12.0"
50-
- php-version: "8.1"
51-
php-code-coverage-version: "^12.0"
52-
5339
steps:
5440
- uses: actions/checkout@v4
5541
with:
@@ -144,15 +130,15 @@ jobs:
144130
else
145131
php -dmemory_limit=-1 vendor/phpunit/phpunit/phpunit --coverage-clover=build/coverage-phpunit/clover.xml;
146132
fi;
147-
if [ "${{ matrix.php-version }}" = "8.2" ] && [ "${{ matrix.driver }}" != "none" ]; then
133+
if [ "${{ matrix.php-version }}" = "8.3" ] && [ "${{ matrix.driver }}" != "none" ]; then
148134
composer global require scrutinizer/ocular;
149135
~/.composer/vendor/bin/ocular code-coverage:upload --format=php-clover build/coverage-phpunit/clover.xml;
150136
fi;
151137
152138
- name: Behat
153139
run: |
154140
php -dmemory_limit=-1 vendor/behat/behat/bin/behat --strict;
155-
if [ "${{ matrix.php-version }}" = "8.2" ] && [ "${{ matrix.driver }}" != "none" ]; then
141+
if [ "${{ matrix.php-version }}" = "8.3" ] && [ "${{ matrix.driver }}" != "none" ]; then
156142
composer global require scrutinizer/ocular;
157143
~/.composer/vendor/bin/ocular code-coverage:upload --format=php-clover build/coverage-behat/clover.xml;
158144
fi;

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased] - 2025-xx-xx
44

5+
## [5.4.0] - 2025-06-09
6+
### Added
7+
- Added `openclover` report option
8+
59
## [5.3.7] - 2025-02-07
610
### Added
711
- Compatibility with `phpunit/php-code-coverage` v12
@@ -134,8 +138,9 @@
134138
- Support for Symfony components older than `<3.4`
135139
- Support for HHVM
136140

137-
[Unreleased]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.7..master
141+
[Unreleased]: https://github.com/dvdoug/behat-code-coverage/compare/v5.4.0..master
138142

143+
[5.4.0]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.7..v5.4.0
139144
[5.3.7]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.6..v5.3.7
140145
[5.3.6]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.5..v5.3.6
141146
[5.3.5]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.4..v5.3.5

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
behat-code-coverage
22
===================
3-
[![Build Status](https://github.com/dvdoug/behat-code-coverage/workflows/CI/badge.svg?branch=master)](https://github.com/dvdoug/behat-code-coverage/actions?query=workflow%3ACI+branch%3Amaster)
3+
[![Build Status](https://github.com/dvdoug/behat-code-coverage/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/dvdoug/behat-code-coverage/actions/workflows/ci.yml)
44
[![Download count](https://img.shields.io/packagist/dt/dvdoug/behat-code-coverage.svg)](https://packagist.org/packages/dvdoug/behat-code-coverage)
55
[![Current version](https://img.shields.io/packagist/v/dvdoug/behat-code-coverage.svg)](https://packagist.org/packages/dvdoug/behat-code-coverage)
66
[![Documentation](https://readthedocs.org/projects/behat-code-coverage/badge/?version=latest)](https://www.behat.cc)

behat.yml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ default:
2222
target: build/coverage-behat/crap4j.xml
2323
html:
2424
target: build/coverage-behat
25+
openclover:
26+
target: build/coverage-behat/openclover.xml
2527
php:
2628
target: build/coverage-behat/coverage.cov
2729
text:

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^8.1",
15+
"php": "^8.3",
1616
"composer-runtime-api": "^2.0",
1717
"behat/behat": "^3.15",
1818
"composer/semver": "^3.0",
19-
"phpunit/php-code-coverage": "^10.1||^11.0||^12.0",
19+
"phpunit/php-code-coverage": "^12.3",
2020
"symfony/config": "^5.4.35||^6.3.12||^7.0.3",
2121
"symfony/console": "^5.4.35||^6.3.12||^7.0.3",
2222
"symfony/dependency-injection": "^5.3.35||^6.3.12||^7.0.3",

docs/configuration.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,20 @@ basis. It is configured by setting the ``html`` key. The default values are outl
144144
.. note::
145145
The ``colors`` and ``customCSSFile`` settings are only available from php-code-coverage v10
146146

147-
Clover
147+
(Open)Clover
148148
^^^^^^^^^
149149
Originating from the Java world, Clover-format reports are a standard way of exchanging coverage data
150-
between tools. It is configured by setting the ``clover`` key. The default values are outlined below:
150+
between tools. It is configured by setting the ``openclover`` or ``clover`` key. The default values are outlined below:
151151

152152
.. code:: yaml
153153
154154
default:
155155
extensions:
156156
DVDoug\Behat\CodeCoverage\Extension:
157157
reports:
158+
openclover:
159+
target: <file> # no default value, you must specify
160+
name: ''
158161
clover:
159162
target: <file> # no default value, you must specify
160163
name: ''
@@ -163,6 +166,7 @@ between tools. It is configured by setting the ``clover`` key. The default value
163166
an ``.xml`` file extension is suggested.
164167
* Optionally, you can configure the name of your project via the ``name`` key.
165168

169+
166170
Cobertura
167171
^^^^^^^^^
168172
Also originating from the Java world, Cobertura-format reports are becoming a standard way of exchanging coverage data

src/Extension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ public function configure(ArrayNodeDefinition $builder): void
149149
->scalarNode('customCSSFile')->defaultNull()->end()
150150
->end()
151151
->end()
152+
->arrayNode('openclover')
153+
->children()
154+
->scalarNode('name')->defaultNull()->end()
155+
->scalarNode('target')->isRequired()->cannotBeEmpty()->end()
156+
->end()
157+
->end()
152158
->arrayNode('php')
153159
->children()
154160
->scalarNode('target')->isRequired()->cannotBeEmpty()->end()

src/Service/ReportService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
1515
use SebastianBergmann\CodeCoverage\Report\Html\CustomCssFile;
1616
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlFacade;
17+
use SebastianBergmann\CodeCoverage\Report\OpenClover;
1718
use SebastianBergmann\CodeCoverage\Report\PHP;
1819
use SebastianBergmann\CodeCoverage\Report\Text;
1920
use SebastianBergmann\CodeCoverage\Report\Thresholds;
@@ -44,6 +45,10 @@ public function generateReport(CodeCoverage $coverage): void
4445
$report = new PHP();
4546
$report->process($coverage, $config['target']);
4647
break;
48+
case 'openclover':
49+
$report = new OpenClover();
50+
$report->process($coverage, $config['target'], $config['name']);
51+
break;
4752
case 'clover':
4853
$report = new Clover();
4954
$report->process($coverage, $config['target'], $config['name']);

tests/ReportServiceTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ public function testCanGenerateCloverReport(): void
7070
$filesystem->remove($reportFilename);
7171
}
7272

73+
public function testCanGenerateOpenCloverReport(): void
74+
{
75+
$filesystem = new Filesystem();
76+
$reportFilename = sys_get_temp_dir() . '/openclover.xml';
77+
$filesystem->remove($reportFilename);
78+
79+
$driver = $this->createMock(Driver::class);
80+
$coverage = new CodeCoverage($driver, new Filter());
81+
82+
$reportService = new ReportService(
83+
[
84+
'openclover' => [
85+
'target' => $reportFilename,
86+
'name' => 'SomeName',
87+
],
88+
]
89+
);
90+
91+
$reportService->generateReport($coverage);
92+
$report = file_get_contents($reportFilename);
93+
94+
self::assertNotEmpty($report);
95+
96+
$filesystem->remove($reportFilename);
97+
}
98+
7399
public function testCanGenerateCrap4jReport(): void
74100
{
75101
$filesystem = new Filesystem();

0 commit comments

Comments
 (0)