Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace SebastianBergmann\CodeCoverage\Report\Xml; Chris@14: Chris@14: use SebastianBergmann\Environment\Runtime; Chris@14: Chris@14: class BuildInformation Chris@14: { Chris@14: /** Chris@14: * @var \DOMElement Chris@14: */ Chris@14: private $contextNode; Chris@14: Chris@14: /** Chris@14: * @param \DOMElement $contextNode Chris@14: */ Chris@14: public function __construct(\DOMElement $contextNode) Chris@14: { Chris@14: $this->contextNode = $contextNode; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @param Runtime $runtime Chris@14: */ Chris@14: public function setRuntimeInformation(Runtime $runtime) Chris@14: { Chris@14: $runtimeNode = $this->getNodeByName('runtime'); Chris@14: Chris@14: $runtimeNode->setAttribute('name', $runtime->getName()); Chris@14: $runtimeNode->setAttribute('version', $runtime->getVersion()); Chris@14: $runtimeNode->setAttribute('url', $runtime->getVendorUrl()); Chris@14: Chris@14: $driverNode = $this->getNodeByName('driver'); Chris@14: if ($runtime->isHHVM()) { Chris@14: $driverNode->setAttribute('name', 'hhvm'); Chris@14: $driverNode->setAttribute('version', \constant('HHVM_VERSION')); Chris@14: Chris@14: return; Chris@14: } Chris@14: Chris@14: if ($runtime->hasPHPDBGCodeCoverage()) { Chris@14: $driverNode->setAttribute('name', 'phpdbg'); Chris@14: $driverNode->setAttribute('version', \constant('PHPDBG_VERSION')); Chris@14: } Chris@14: Chris@14: if ($runtime->hasXdebug()) { Chris@14: $driverNode->setAttribute('name', 'xdebug'); Chris@14: $driverNode->setAttribute('version', \phpversion('xdebug')); Chris@14: } Chris@14: } Chris@14: Chris@14: /** Chris@14: * @param $name Chris@14: * Chris@14: * @return \DOMElement Chris@14: */ Chris@14: private function getNodeByName($name) Chris@14: { Chris@14: $node = $this->contextNode->getElementsByTagNameNS( Chris@14: 'http://schema.phpunit.de/coverage/1.0', Chris@14: $name Chris@14: )->item(0); Chris@14: Chris@14: if (!$node) { Chris@14: $node = $this->contextNode->appendChild( Chris@14: $this->contextNode->ownerDocument->createElementNS( Chris@14: 'http://schema.phpunit.de/coverage/1.0', Chris@14: $name Chris@14: ) Chris@14: ); Chris@14: } Chris@14: Chris@14: return $node; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @param \DateTime $date Chris@14: */ Chris@14: public function setBuildTime(\DateTime $date) Chris@14: { Chris@14: $this->contextNode->setAttribute('time', $date->format('D M j G:i:s T Y')); Chris@14: } Chris@14: Chris@14: /** Chris@14: * @param string $phpUnitVersion Chris@14: * @param string $coverageVersion Chris@14: */ Chris@14: public function setGeneratorVersions($phpUnitVersion, $coverageVersion) Chris@14: { Chris@14: $this->contextNode->setAttribute('phpunit', $phpUnitVersion); Chris@14: $this->contextNode->setAttribute('coverage', $coverageVersion); Chris@14: } Chris@14: }