Skip to content

Commit c9a346b

Browse files
committed
Drop DOM dependency
1 parent c1a9f74 commit c9a346b

File tree

13 files changed

+298
-438
lines changed

13 files changed

+298
-438
lines changed

composer.json

Lines changed: 69 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,73 @@
11
{
2-
"name": "phpunit/php-code-coverage",
3-
"description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
4-
"type": "library",
5-
"keywords": [
6-
"coverage",
7-
"testing",
8-
"xunit"
9-
],
10-
"homepage": "https://github.com/sebastianbergmann/php-code-coverage",
11-
"license": "BSD-3-Clause",
12-
"authors": [
13-
{
14-
"name": "Sebastian Bergmann",
15-
"email": "[email protected]",
16-
"role": "lead"
17-
}
18-
],
19-
"support": {
20-
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
21-
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy"
22-
},
23-
"config": {
24-
"platform": {
25-
"php": "8.3.0"
26-
},
27-
"optimize-autoloader": true,
28-
"sort-packages": true
29-
},
30-
"prefer-stable": true,
31-
"require": {
32-
"php": ">=8.3",
33-
"ext-dom": "*",
34-
"ext-libxml": "*",
35-
"ext-xmlwriter": "*",
36-
"nikic/php-parser": "^5.6.1",
37-
"phpunit/php-file-iterator": "^6.0",
38-
"phpunit/php-text-template": "^5.0",
39-
"sebastian/complexity": "^5.0",
40-
"sebastian/environment": "^8.0.3",
41-
"sebastian/lines-of-code": "^4.0",
42-
"sebastian/version": "^6.0",
43-
"theseer/tokenizer": "^1.2.3"
44-
},
45-
"require-dev": {
46-
"phpunit/phpunit": "^12.3.7"
47-
},
48-
"suggest": {
49-
"ext-pcov": "PHP extension that provides line coverage",
50-
"ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage"
51-
},
52-
"autoload": {
53-
"classmap": [
54-
"src/"
55-
]
56-
},
57-
"autoload-dev": {
58-
"classmap": [
59-
"tests/"
60-
]
2+
"name": "phpunit/php-code-coverage",
3+
"description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
4+
"type": "library",
5+
"keywords": [
6+
"coverage",
7+
"testing",
8+
"xunit"
9+
],
10+
"homepage": "https://github.com/sebastianbergmann/php-code-coverage",
11+
"license": "BSD-3-Clause",
12+
"authors": [
13+
{
14+
"name": "Sebastian Bergmann",
15+
"email": "[email protected]",
16+
"role": "lead"
17+
}
18+
],
19+
"support": {
20+
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
21+
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy"
22+
},
23+
"config": {
24+
"platform": {
25+
"php": "8.3.0"
6126
},
62-
"extra": {
63-
"branch-alias": {
64-
"dev-main": "12.4.x-dev"
65-
}
27+
"optimize-autoloader": true,
28+
"sort-packages": true
29+
},
30+
"prefer-stable": true,
31+
"require": {
32+
"php": ">=8.3",
33+
"ext-dom": "*",
34+
"ext-libxml": "*",
35+
"ext-xmlwriter": "*",
36+
"nikic/php-parser": "^5.6.1",
37+
"phpunit/php-file-iterator": "^6.0",
38+
"phpunit/php-text-template": "^5.0",
39+
"sebastian/complexity": "^5.0",
40+
"sebastian/environment": "^8.0.3",
41+
"sebastian/lines-of-code": "^4.0",
42+
"sebastian/version": "^6.0",
43+
"theseer/tokenizer": "dev-writer as 1.3-dev"
44+
},
45+
"require-dev": {
46+
"phpunit/phpunit": "^12.3.7"
47+
},
48+
"suggest": {
49+
"ext-pcov": "PHP extension that provides line coverage",
50+
"ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage"
51+
},
52+
"autoload": {
53+
"classmap": [
54+
"src/"
55+
]
56+
},
57+
"autoload-dev": {
58+
"classmap": [
59+
"tests/"
60+
]
61+
},
62+
"extra": {
63+
"branch-alias": {
64+
"dev-main": "12.4.x-dev"
65+
}
66+
},
67+
"repositories": [
68+
{
69+
"type": "vcs",
70+
"url": "https://github.com/staabm/tokenizer"
6671
}
72+
]
6773
}

src/Report/Xml/BuildInformation.php

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,47 @@
99
*/
1010
namespace SebastianBergmann\CodeCoverage\Report\Xml;
1111

12-
use function assert;
1312
use function phpversion;
1413
use DateTimeImmutable;
15-
use DOMElement;
1614
use SebastianBergmann\Environment\Runtime;
15+
use XMLWriter;
1716

1817
/**
1918
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
2019
*/
2120
final readonly class BuildInformation
2221
{
23-
private DOMElement $contextNode;
24-
2522
public function __construct(
26-
DOMElement $contextNode,
23+
XMLWriter $xmlWriter,
2724
Runtime $runtime,
2825
DateTimeImmutable $buildDate,
2926
string $phpUnitVersion,
3027
string $coverageVersion
3128
) {
32-
$this->contextNode = $contextNode;
33-
34-
$runtimeNode = $this->nodeByName('runtime');
29+
$xmlWriter->startElement('build');
30+
$xmlWriter->writeAttribute('time', $buildDate->format('D M j G:i:s T Y'));
31+
$xmlWriter->writeAttribute('phpunit', $phpUnitVersion);
32+
$xmlWriter->writeAttribute('coverage', $coverageVersion);
3533

36-
$runtimeNode->setAttribute('name', $runtime->getName());
37-
$runtimeNode->setAttribute('version', $runtime->getVersion());
38-
$runtimeNode->setAttribute('url', $runtime->getVendorUrl());
34+
$xmlWriter->startElement('runtime');
35+
$xmlWriter->writeAttribute('name', $runtime->getName());
36+
$xmlWriter->writeAttribute('version', $runtime->getVersion());
37+
$xmlWriter->writeAttribute('url', $runtime->getVendorUrl());
38+
$xmlWriter->endElement();
3939

40-
$driverNode = $this->nodeByName('driver');
40+
$xmlWriter->startElement('driver');
4141

4242
if ($runtime->hasXdebug()) {
43-
$driverNode->setAttribute('name', 'xdebug');
44-
$driverNode->setAttribute('version', phpversion('xdebug'));
43+
$xmlWriter->writeAttribute('name', 'xdebug');
44+
$xmlWriter->writeAttribute('version', phpversion('xdebug'));
4545
}
4646

4747
if ($runtime->hasPCOV()) {
48-
$driverNode->setAttribute('name', 'pcov');
49-
$driverNode->setAttribute('version', phpversion('pcov'));
48+
$xmlWriter->writeAttribute('name', 'pcov');
49+
$xmlWriter->writeAttribute('version', phpversion('pcov'));
5050
}
51+
$xmlWriter->endElement();
5152

52-
$this->contextNode->setAttribute('time', $buildDate->format('D M j G:i:s T Y'));
53-
54-
$this->contextNode->setAttribute('phpunit', $phpUnitVersion);
55-
$this->contextNode->setAttribute('coverage', $coverageVersion);
56-
}
57-
58-
private function nodeByName(string $name): DOMElement
59-
{
60-
$node = $this->contextNode->appendChild(
61-
$this->contextNode->ownerDocument->createElementNS(
62-
Facade::XML_NAMESPACE,
63-
$name,
64-
),
65-
);
66-
67-
assert($node instanceof DOMElement);
68-
69-
return $node;
53+
$xmlWriter->endElement();
7054
}
7155
}

src/Report/Xml/Coverage.php

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

12-
use DOMElement;
1312
use XMLWriter;
1413

1514
/**
1615
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
1716
*/
1817
final class Coverage
1918
{
20-
private readonly DOMElement $contextNode;
19+
private readonly XMLWriter $xmlWriter;
2120
private readonly string $line;
2221

23-
public function __construct(DOMElement $context, string $line)
24-
{
25-
$this->contextNode = $context;
26-
$this->line = $line;
22+
public function __construct(
23+
XMLWriter $xmlWriter,
24+
string $line
25+
) {
26+
$this->xmlWriter = $xmlWriter;
27+
$this->line = $line;
2728
}
2829

2930
public function finalize(array $tests): void
3031
{
31-
$writer = new XMLWriter;
32-
$writer->openMemory();
33-
$writer->startElementNs(null, $this->contextNode->nodeName, Facade::XML_NAMESPACE);
32+
$writer = $this->xmlWriter;
33+
$writer->startElement('line');
3434
$writer->writeAttribute('nr', $this->line);
3535

3636
foreach ($tests as $test) {
@@ -39,13 +39,5 @@ public function finalize(array $tests): void
3939
$writer->endElement();
4040
}
4141
$writer->endElement();
42-
43-
$fragment = $this->contextNode->ownerDocument->createDocumentFragment();
44-
$fragment->appendXML($writer->outputMemory());
45-
46-
$this->contextNode->parentNode->replaceChild(
47-
$fragment,
48-
$this->contextNode,
49-
);
5042
}
5143
}

0 commit comments

Comments
 (0)