Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions src/Report/Xml/BuildInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
{
private DOMElement $contextNode;

public function __construct(DOMElement $contextNode)
{
public function __construct(
DOMElement $contextNode,
Runtime $runtime,
DateTimeImmutable $buildDate,
string $phpUnitVersion,
string $coverageVersion
) {
$this->contextNode = $contextNode;
}

public function setRuntimeInformation(Runtime $runtime): void
{
$runtimeNode = $this->nodeByName('runtime');

$runtimeNode->setAttribute('name', $runtime->getName());
Expand All @@ -46,34 +48,21 @@ public function setRuntimeInformation(Runtime $runtime): void
$driverNode->setAttribute('name', 'pcov');
$driverNode->setAttribute('version', phpversion('pcov'));
}
}

public function setBuildTime(DateTimeImmutable $date): void
{
$this->contextNode->setAttribute('time', $date->format('D M j G:i:s T Y'));
}
$this->contextNode->setAttribute('time', $buildDate->format('D M j G:i:s T Y'));

public function setGeneratorVersions(string $phpUnitVersion, string $coverageVersion): void
{
$this->contextNode->setAttribute('phpunit', $phpUnitVersion);
$this->contextNode->setAttribute('coverage', $coverageVersion);
}

private function nodeByName(string $name): DOMElement
{
$node = $this->contextNode->getElementsByTagNameNS(
Facade::XML_NAMESPACE,
$name,
)->item(0);

if ($node === null) {
$node = $this->contextNode->appendChild(
$this->contextNode->ownerDocument->createElementNS(
Facade::XML_NAMESPACE,
$name,
),
);
}
$node = $this->contextNode->appendChild(
$this->contextNode->ownerDocument->createElementNS(
Facade::XML_NAMESPACE,
$name,
),
);

assert($node instanceof DOMElement);

Expand Down
10 changes: 6 additions & 4 deletions src/Report/Xml/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ public function process(CodeCoverage $coverage, string $target): void

private function setBuildInformation(): void
{
$buildNode = $this->project->buildInformation();
$buildNode->setRuntimeInformation(new Runtime);
$buildNode->setBuildTime(new DateTimeImmutable);
$buildNode->setGeneratorVersions($this->phpUnitVersion, Version::id());
$this->project->buildInformation(
new Runtime,
new DateTimeImmutable,
$this->phpUnitVersion,
Version::id(),
);
}

/**
Expand Down
18 changes: 15 additions & 3 deletions src/Report/Xml/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
namespace SebastianBergmann\CodeCoverage\Report\Xml;

use function assert;
use DateTimeImmutable;
use DOMDocument;
use DOMElement;
use SebastianBergmann\Environment\Runtime;

/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
Expand Down Expand Up @@ -40,8 +42,12 @@ public function projectSourceDirectory(): string
return $this->directory;
}

public function buildInformation(): BuildInformation
{
public function buildInformation(
Runtime $runtime,
DateTimeImmutable $buildDate,
string $phpUnitVersion,
string $coverageVersion
): void {
$buildNode = $this->dom()->getElementsByTagNameNS(
Facade::XML_NAMESPACE,
'build',
Expand All @@ -58,7 +64,13 @@ public function buildInformation(): BuildInformation

assert($buildNode instanceof DOMElement);

return new BuildInformation($buildNode);
new BuildInformation(
$buildNode,
$runtime,
$buildDate,
$phpUnitVersion,
$coverageVersion,
);
}

public function tests(): Tests
Expand Down