Skip to content

Commit

Permalink
Add support for generating Cobertura report
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Oct 11, 2020
1 parent b18ffbc commit 8cd9bd4
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- "7.3"

php-code-coverage-version:
- "^9.1.11"
- "^9.2"

symfony-version:
- "^5.0"
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [5.2.0] - 2020-10-11
### Added
- Added support for the Cobertura report format

### Changed
- Minimum `phpunit/php-code-coverage` version bumped to 9.2

## [5.1.1] - 2020-08-14
### Fixed
- Make the `--no-coverage` option work again
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ default:
# - tests/bootstrap.php
# report configuration. For a report to be generated, include at least 1 configuration option under the relevant key
reports:
cobertura:
target: build/coverage-behat/cobertura.xml
clover:
name: 'Project name'
target: build/coverage-behat/clover.xml
Expand Down Expand Up @@ -140,6 +142,8 @@ default:
(optional)
- `files` - key containing files to exclude.
- `reports` - report options:
- `cobertura`
- `target` - Output filename
- `clover`
- `name` - Project name (optional)
- `target` - Output filename
Expand Down
2 changes: 2 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ default:
includeUncoveredFiles: true
processUncoveredFiles: false
reports:
cobertura:
target: build/coverage-behat/cobertura.xml
clover:
target: build/coverage-behat/clover.xml
crap4j:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"php": "^7.3 || ^8.0",
"composer-runtime-api": "^2.0",
"behat/behat": "^3.5",
"phpunit/php-code-coverage": "^9.1.11",
"phpunit/php-code-coverage": "^9.2",
"symfony/console": "^4.4||^5.0",
"symfony/config": "^4.4||^5.0",
"symfony/dependency-injection": "^4.4||^5.0",
Expand All @@ -37,7 +37,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16.4",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3.4",
"phpunit/phpunit": "^9.4.1",
"symfony/filesystem": "^4.4||^5.0"
},
"suggest": {
Expand Down
6 changes: 6 additions & 0 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public function configure(ArrayNodeDefinition $builder): void
->end()
->arrayNode('reports')
->children()
->arrayNode('cobertura')
->children()
->scalarNode('name')->defaultNull()->end()
->scalarNode('target')->isRequired()->cannotBeEmpty()->end()
->end()
->end()
->arrayNode('clover')
->children()
->scalarNode('name')->defaultNull()->end()
Expand Down
5 changes: 5 additions & 0 deletions src/Service/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Composer\InstalledVersions;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Report\Clover;
use SebastianBergmann\CodeCoverage\Report\Cobertura;
use SebastianBergmann\CodeCoverage\Report\Crap4j;
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlFacade;
use SebastianBergmann\CodeCoverage\Report\PHP;
Expand Down Expand Up @@ -81,6 +82,10 @@ public function generateReport(CodeCoverage $coverage): void
$report = new XmlFacade('');
$report->process($coverage, $config['target']);
break;
case 'cobertura':
$report = new Cobertura();
$report->process($coverage, $config['target']);
break;
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/ReportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,31 @@ public function testCanGenerateXMLReport(): void
$filesystem->remove($reportDirectory);
}

public function testCanGenerateCoberturaReport(): void
{
$filesystem = new Filesystem();
$reportFilename = sys_get_temp_dir() . '/cobertura.xml';
$filesystem->remove($reportFilename);

$driver = $this->createMock(Driver::class);
$coverage = new CodeCoverage($driver, new Filter());

$reportService = new ReportService(
[
'cobertura' => [
'target' => $reportFilename,
],
]
);

$reportService->generateReport($coverage);
$report = file_get_contents($reportFilename);

self::assertNotEmpty($report);

$filesystem->remove($reportFilename);
}

public function testCanGenerateMultipleReport(): void
{
$filesystem = new Filesystem();
Expand Down

0 comments on commit 8cd9bd4

Please sign in to comment.