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 11namespace SebastianBergmann\CodeCoverage\Report\Xml; 12 13class Tests 14{ 15 private $contextNode; 16 17 private $codeMap = [ 18 0 => 'PASSED', // PHPUnit_Runner_BaseTestRunner::STATUS_PASSED 19 1 => 'SKIPPED', // PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED 20 2 => 'INCOMPLETE', // PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE 21 3 => 'FAILURE', // PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE 22 4 => 'ERROR', // PHPUnit_Runner_BaseTestRunner::STATUS_ERROR 23 5 => 'RISKY', // PHPUnit_Runner_BaseTestRunner::STATUS_RISKY 24 6 => 'WARNING' // PHPUnit_Runner_BaseTestRunner::STATUS_WARNING 25 ]; 26 27 public function __construct(\DOMElement $context) 28 { 29 $this->contextNode = $context; 30 } 31 32 public function addTest($test, array $result) 33 { 34 $node = $this->contextNode->appendChild( 35 $this->contextNode->ownerDocument->createElementNS( 36 'http://schema.phpunit.de/coverage/1.0', 37 'test' 38 ) 39 ); 40 41 $node->setAttribute('name', $test); 42 $node->setAttribute('size', $result['size']); 43 $node->setAttribute('result', (int) $result['status']); 44 $node->setAttribute('status', $this->codeMap[(int) $result['status']]); 45 } 46} 47