| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
/*
|
|
|
3 |
* This file is part of phpunit/php-code-coverage.
|
|
|
4 |
*
|
|
|
5 |
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
namespace SebastianBergmann\CodeCoverage\Report\Xml;
|
|
|
11 |
|
|
|
12 |
use function constant;
|
|
|
13 |
use function phpversion;
|
|
|
14 |
use DateTimeImmutable;
|
|
|
15 |
use DOMElement;
|
|
|
16 |
use SebastianBergmann\Environment\Runtime;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
|
|
20 |
*/
|
|
|
21 |
final class BuildInformation
|
|
|
22 |
{
|
|
|
23 |
/**
|
|
|
24 |
* @var DOMElement
|
|
|
25 |
*/
|
|
|
26 |
private $contextNode;
|
|
|
27 |
|
|
|
28 |
public function __construct(DOMElement $contextNode)
|
|
|
29 |
{
|
|
|
30 |
$this->contextNode = $contextNode;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public function setRuntimeInformation(Runtime $runtime): void
|
|
|
34 |
{
|
|
|
35 |
$runtimeNode = $this->nodeByName('runtime');
|
|
|
36 |
|
|
|
37 |
$runtimeNode->setAttribute('name', $runtime->getName());
|
|
|
38 |
$runtimeNode->setAttribute('version', $runtime->getVersion());
|
|
|
39 |
$runtimeNode->setAttribute('url', $runtime->getVendorUrl());
|
|
|
40 |
|
|
|
41 |
$driverNode = $this->nodeByName('driver');
|
|
|
42 |
|
|
|
43 |
if ($runtime->hasPHPDBGCodeCoverage()) {
|
|
|
44 |
$driverNode->setAttribute('name', 'phpdbg');
|
|
|
45 |
$driverNode->setAttribute('version', constant('PHPDBG_VERSION'));
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
if ($runtime->hasXdebug()) {
|
|
|
49 |
$driverNode->setAttribute('name', 'xdebug');
|
|
|
50 |
$driverNode->setAttribute('version', phpversion('xdebug'));
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
if ($runtime->hasPCOV()) {
|
|
|
54 |
$driverNode->setAttribute('name', 'pcov');
|
|
|
55 |
$driverNode->setAttribute('version', phpversion('pcov'));
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public function setBuildTime(DateTimeImmutable $date): void
|
|
|
60 |
{
|
|
|
61 |
$this->contextNode->setAttribute('time', $date->format('D M j G:i:s T Y'));
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
public function setGeneratorVersions(string $phpUnitVersion, string $coverageVersion): void
|
|
|
65 |
{
|
|
|
66 |
$this->contextNode->setAttribute('phpunit', $phpUnitVersion);
|
|
|
67 |
$this->contextNode->setAttribute('coverage', $coverageVersion);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
private function nodeByName(string $name): DOMElement
|
|
|
71 |
{
|
|
|
72 |
$node = $this->contextNode->getElementsByTagNameNS(
|
|
|
73 |
'https://schema.phpunit.de/coverage/1.0',
|
|
|
74 |
$name
|
|
|
75 |
)->item(0);
|
|
|
76 |
|
|
|
77 |
if (!$node) {
|
|
|
78 |
$node = $this->contextNode->appendChild(
|
|
|
79 |
$this->contextNode->ownerDocument->createElementNS(
|
|
|
80 |
'https://schema.phpunit.de/coverage/1.0',
|
|
|
81 |
$name
|
|
|
82 |
)
|
|
|
83 |
);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
return $node;
|
|
|
87 |
}
|
|
|
88 |
}
|