Skip to content

Commit 6d84e78

Browse files
Merge branch '11.0'
* 11.0: Closes #1131
2 parents 9654885 + 8adf337 commit 6d84e78

File tree

9 files changed

+154
-29
lines changed

9 files changed

+154
-29
lines changed

ChangeLog-12.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [12.5.2] - 2025-MM-DD
6+
7+
### Fixed
8+
9+
* [#1131](https://github.com/sebastianbergmann/php-code-coverage/issues/1131): Invalid XML generated when both PCOV and Xdebug are loaded
10+
511
## [12.5.1] - 2025-12-08
612

713
### Changed
@@ -23,5 +29,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
2329
* [#1126](https://github.com/sebastianbergmann/php-code-coverage/issues/1126): Add test execution time to `<test>` elements under `projects/tests` in the XML reports index file
2430
* [#1127](https://github.com/sebastianbergmann/php-code-coverage/issues/1127): Add SHA-1 hash of content of SUT source file to XML report
2531

32+
[12.5.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.5.1...main
2633
[12.5.1]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.5.0...12.5.1
2734
[12.5.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.4.0...12.5.0

src/CodeCoverage.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,22 @@ public function validate(TargetCollection $targets): ValidationResult
406406
return (new TargetCollectionValidator)->validate($this->targetMapper(), $targets);
407407
}
408408

409+
/**
410+
* @internal
411+
*/
412+
public function driverIsPcov(): bool
413+
{
414+
return $this->driver->isPcov();
415+
}
416+
417+
/**
418+
* @internal
419+
*/
420+
public function driverIsXdebug(): bool
421+
{
422+
return $this->driver->isXdebug();
423+
}
424+
409425
/**
410426
* @param false|TargetedLines $linesToBeCovered
411427
* @param TargetedLines $linesToBeUsed

src/Driver/Driver.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public function disableBranchAndPathCoverage(): void
7676
$this->collectBranchAndPathCoverage = false;
7777
}
7878

79+
public function isPcov(): bool
80+
{
81+
return false;
82+
}
83+
84+
public function isXdebug(): bool
85+
{
86+
return false;
87+
}
88+
7989
abstract public function nameAndVersion(): string;
8090

8191
abstract public function start(): void;

src/Driver/PcovDriver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function nameAndVersion(): string
7373
return 'PCOV ' . phpversion('pcov');
7474
}
7575

76+
public function isPcov(): true
77+
{
78+
return true;
79+
}
80+
7681
/**
7782
* @throws PcovNotAvailableException
7883
*/

src/Driver/XdebugDriver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public function nameAndVersion(): string
113113
return 'Xdebug ' . phpversion('xdebug');
114114
}
115115

116+
public function isXdebug(): true
117+
{
118+
return true;
119+
}
120+
116121
/**
117122
* @throws XdebugNotAvailableException
118123
* @throws XdebugNotEnabledException

src/Report/Xml/BuildInformation.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
namespace SebastianBergmann\CodeCoverage\Report\Xml;
1111

12-
use function phpversion;
1312
use DateTimeImmutable;
1413
use SebastianBergmann\Environment\Runtime;
1514
use XMLWriter;
@@ -24,7 +23,9 @@ public function __construct(
2423
Runtime $runtime,
2524
DateTimeImmutable $buildDate,
2625
string $phpUnitVersion,
27-
string $coverageVersion
26+
string $coverageVersion,
27+
string $driverExtensionName,
28+
string $driverExtensionVersion,
2829
) {
2930
$xmlWriter->startElement('build');
3031
$xmlWriter->writeAttribute('time', $buildDate->format('D M j G:i:s T Y'));
@@ -38,16 +39,8 @@ public function __construct(
3839
$xmlWriter->endElement();
3940

4041
$xmlWriter->startElement('driver');
41-
42-
if ($runtime->hasXdebug()) {
43-
$xmlWriter->writeAttribute('name', 'xdebug');
44-
$xmlWriter->writeAttribute('version', phpversion('xdebug'));
45-
}
46-
47-
if ($runtime->hasPCOV()) {
48-
$xmlWriter->writeAttribute('name', 'pcov');
49-
$xmlWriter->writeAttribute('version', phpversion('pcov'));
50-
}
42+
$xmlWriter->writeAttribute('name', $driverExtensionName);
43+
$xmlWriter->writeAttribute('version', $driverExtensionVersion);
5144
$xmlWriter->endElement();
5245

5346
$xmlWriter->endElement();

src/Report/Xml/Facade.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
namespace SebastianBergmann\CodeCoverage\Report\Xml;
1111

1212
use const DIRECTORY_SEPARATOR;
13+
use function assert;
1314
use function count;
1415
use function dirname;
1516
use function file_get_contents;
1617
use function is_array;
1718
use function is_dir;
1819
use function is_file;
1920
use function is_writable;
21+
use function phpversion;
2022
use function sprintf;
2123
use function strlen;
2224
use function substr;
@@ -76,21 +78,34 @@ public function process(CodeCoverage $coverage, string $target): void
7678
$coverage->getReport()->name(),
7779
);
7880

79-
$this->setBuildInformation();
81+
$this->setBuildInformation($coverage);
8082

8183
$this->project->startProject();
8284
$this->processTests($coverage->getTests());
8385
$this->processDirectory($report, $this->project);
8486
$this->project->finalize();
8587
}
8688

87-
private function setBuildInformation(): void
89+
private function setBuildInformation(CodeCoverage $coverage): void
8890
{
91+
if ($coverage->driverIsPcov()) {
92+
$driverExtensionName = 'pcov';
93+
$driverExtensionVersion = phpversion('pcov');
94+
} elseif ($coverage->driverIsXdebug()) {
95+
$driverExtensionName = 'xdebug';
96+
$driverExtensionVersion = phpversion('xdebug');
97+
}
98+
99+
assert(isset($driverExtensionName));
100+
assert(isset($driverExtensionVersion));
101+
89102
$this->project->buildInformation(
90103
new Runtime,
91104
new DateTimeImmutable,
92105
$this->phpUnitVersion,
93106
Version::id(),
107+
$driverExtensionName,
108+
$driverExtensionVersion,
94109
);
95110
}
96111

src/Report/Xml/Project.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ public function buildInformation(
4141
Runtime $runtime,
4242
DateTimeImmutable $buildDate,
4343
string $phpUnitVersion,
44-
string $coverageVersion
44+
string $coverageVersion,
45+
string $driverExtensionName,
46+
string $driverExtensionVersion,
4547
): void {
4648
new BuildInformation(
4749
$this->xmlWriter,
4850
$runtime,
4951
$buildDate,
5052
$phpUnitVersion,
5153
$coverageVersion,
54+
$driverExtensionName,
55+
$driverExtensionVersion,
5256
);
5357
}
5458

0 commit comments

Comments
 (0)