Skip to content

Commit ad74c88

Browse files
adrienbraultsebastianbergmann
authored andcommitted
Add cobertura support
1 parent b3cbdb1 commit ad74c88

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/cli/Arguments.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ final class Arguments
106106
*/
107107
private $pathPrefix;
108108

109-
public function __construct(?string $command, ?string $script, ?string $directory, ?string $coverage, ?string $patch, ?string $configuration, array $include, bool $pathCoverage, bool $addUncovered, bool $processUncovered, ?string $clover, ?string $crap4j, ?string $html, ?string $php, ?string $text, ?string $xml, ?string $pathPrefix, bool $help, bool $version)
109+
public function __construct(?string $command, ?string $script, ?string $directory, ?string $coverage, ?string $patch, ?string $configuration, array $include, bool $pathCoverage, bool $addUncovered, bool $processUncovered, ?string $clover, ?string $cobertura, ?string $crap4j, ?string $html, ?string $php, ?string $text, ?string $xml, ?string $pathPrefix, bool $help, bool $version)
110110
{
111111
$this->command = $command;
112112
$this->script = $script;
@@ -119,6 +119,7 @@ public function __construct(?string $command, ?string $script, ?string $director
119119
$this->addUncovered = $addUncovered;
120120
$this->processUncovered = $processUncovered;
121121
$this->clover = $clover;
122+
$this->cobertura = $cobertura;
122123
$this->crap4j = $crap4j;
123124
$this->html = $html;
124125
$this->php = $php;
@@ -184,6 +185,11 @@ public function clover(): ?string
184185
return $this->clover;
185186
}
186187

188+
public function cobertura(): ?string
189+
{
190+
return $this->cobertura;
191+
}
192+
187193
public function crap4j(): ?string
188194
{
189195
return $this->crap4j;
@@ -226,6 +232,6 @@ public function version(): bool
226232

227233
public function reportConfigured(): bool
228234
{
229-
return $this->clover() || $this->crap4j() || $this->html() || $this->php() || $this->text() || $this->xml();
235+
return $this->clover() || $this->cobertura() || $this->crap4j() || $this->html() || $this->php() || $this->text() || $this->xml();
230236
}
231237
}

src/cli/ArgumentsBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public function build(array $argv): Arguments
128128
$addUncovered = false;
129129
$processUncovered = false;
130130
$clover = null;
131+
$cobertura = null;
131132
$crap4j = null;
132133
$html = null;
133134
$php = null;
@@ -169,6 +170,11 @@ public function build(array $argv): Arguments
169170

170171
break;
171172

173+
case '--cobertura':
174+
$cobertura = $option[1];
175+
176+
break;
177+
172178
case '--crap4j':
173179
$crap4j = $option[1];
174180

@@ -225,6 +231,7 @@ public function build(array $argv): Arguments
225231
$addUncovered,
226232
$processUncovered,
227233
$clover,
234+
$cobertura,
228235
$crap4j,
229236
$html,
230237
$php,

src/cli/Command.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\TextUI\XmlConfiguration\Loader;
1616
use SebastianBergmann\CodeCoverage\CodeCoverage;
1717
use SebastianBergmann\CodeCoverage\Report\Clover as CloverReport;
18+
use SebastianBergmann\CodeCoverage\Report\Cobertura as CoberturaReport;
1819
use SebastianBergmann\CodeCoverage\Report\Crap4j as Crap4jReport;
1920
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlReport;
2021
use SebastianBergmann\CodeCoverage\Report\PHP as PhpReport;
@@ -89,6 +90,17 @@ protected function handleReports(CodeCoverage $coverage, Arguments $arguments):
8990
print 'done' . PHP_EOL;
9091
}
9192

93+
if ($arguments->cobertura()) {
94+
print 'Generating code coverage report in Cobertura XML format ... ';
95+
96+
$writer = new CoberturaReport;
97+
98+
/* @noinspection UnusedFunctionResultInspection */
99+
$writer->process($coverage, $arguments->cobertura());
100+
101+
print 'done' . PHP_EOL;
102+
}
103+
92104
if ($arguments->crap4j()) {
93105
print 'Generating code coverage report in Crap4J XML format ... ';
94106

src/cli/HelpCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function run(Arguments $arguments): int
3030
Options common for both "phpcov execute" and "phpcov merge":
3131
3232
--clover <file> Generate code coverage report in Clover XML format
33+
--cobertura <file> Generate code coverage report in Cobertura XML format
3334
--crap4j <file> Generate code coverage report in Crap4J XML format
3435
--html <directory> Generate code coverage report in HTML format
3536
--php <file> Export php-code-coverage object

0 commit comments

Comments
 (0)