comparison vendor/phpunit/php-code-coverage/src/Report/Xml/BuildInformation.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of the php-code-coverage package.
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
11 namespace SebastianBergmann\CodeCoverage\Report\Xml;
12
13 use SebastianBergmann\Environment\Runtime;
14
15 class BuildInformation
16 {
17 /**
18 * @var \DOMElement
19 */
20 private $contextNode;
21
22 /**
23 * @param \DOMElement $contextNode
24 */
25 public function __construct(\DOMElement $contextNode)
26 {
27 $this->contextNode = $contextNode;
28 }
29
30 /**
31 * @param Runtime $runtime
32 */
33 public function setRuntimeInformation(Runtime $runtime)
34 {
35 $runtimeNode = $this->getNodeByName('runtime');
36
37 $runtimeNode->setAttribute('name', $runtime->getName());
38 $runtimeNode->setAttribute('version', $runtime->getVersion());
39 $runtimeNode->setAttribute('url', $runtime->getVendorUrl());
40
41 $driverNode = $this->getNodeByName('driver');
42 if ($runtime->isHHVM()) {
43 $driverNode->setAttribute('name', 'hhvm');
44 $driverNode->setAttribute('version', \constant('HHVM_VERSION'));
45
46 return;
47 }
48
49 if ($runtime->hasPHPDBGCodeCoverage()) {
50 $driverNode->setAttribute('name', 'phpdbg');
51 $driverNode->setAttribute('version', \constant('PHPDBG_VERSION'));
52 }
53
54 if ($runtime->hasXdebug()) {
55 $driverNode->setAttribute('name', 'xdebug');
56 $driverNode->setAttribute('version', \phpversion('xdebug'));
57 }
58 }
59
60 /**
61 * @param $name
62 *
63 * @return \DOMElement
64 */
65 private function getNodeByName($name)
66 {
67 $node = $this->contextNode->getElementsByTagNameNS(
68 'http://schema.phpunit.de/coverage/1.0',
69 $name
70 )->item(0);
71
72 if (!$node) {
73 $node = $this->contextNode->appendChild(
74 $this->contextNode->ownerDocument->createElementNS(
75 'http://schema.phpunit.de/coverage/1.0',
76 $name
77 )
78 );
79 }
80
81 return $node;
82 }
83
84 /**
85 * @param \DateTime $date
86 */
87 public function setBuildTime(\DateTime $date)
88 {
89 $this->contextNode->setAttribute('time', $date->format('D M j G:i:s T Y'));
90 }
91
92 /**
93 * @param string $phpUnitVersion
94 * @param string $coverageVersion
95 */
96 public function setGeneratorVersions($phpUnitVersion, $coverageVersion)
97 {
98 $this->contextNode->setAttribute('phpunit', $phpUnitVersion);
99 $this->contextNode->setAttribute('coverage', $coverageVersion);
100 }
101 }