| 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 DOMElement;
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
|
|
16 |
*/
|
|
|
17 |
final class Tests
|
|
|
18 |
{
|
|
|
19 |
private $contextNode;
|
|
|
20 |
|
|
|
21 |
private $codeMap = [
|
|
|
22 |
-1 => 'UNKNOWN', // PHPUnit_Runner_BaseTestRunner::STATUS_UNKNOWN
|
|
|
23 |
|
|
|
24 |
1 => 'SKIPPED', // PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED
|
|
|
25 |
2 => 'INCOMPLETE', // PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE
|
|
|
26 |
3 => 'FAILURE', // PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE
|
|
|
27 |
4 => 'ERROR', // PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
|
|
|
28 |
5 => 'RISKY', // PHPUnit_Runner_BaseTestRunner::STATUS_RISKY
|
|
|
29 |
6 => 'WARNING', // PHPUnit_Runner_BaseTestRunner::STATUS_WARNING
|
|
|
30 |
];
|
|
|
31 |
|
|
|
32 |
public function __construct(DOMElement $context)
|
|
|
33 |
{
|
|
|
34 |
$this->contextNode = $context;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public function addTest(string $test, array $result): void
|
|
|
38 |
{
|
|
|
39 |
$node = $this->contextNode->appendChild(
|
|
|
40 |
$this->contextNode->ownerDocument->createElementNS(
|
|
|
41 |
'https://schema.phpunit.de/coverage/1.0',
|
|
|
42 |
'test'
|
|
|
43 |
)
|
|
|
44 |
);
|
|
|
45 |
|
|
|
46 |
$node->setAttribute('name', $test);
|
|
|
47 |
$node->setAttribute('size', $result['size']);
|
|
|
48 |
$node->setAttribute('result', (string) $result['status']);
|
|
|
49 |
$node->setAttribute('status', $this->codeMap[(int) $result['status']]);
|
|
|
50 |
}
|
|
|
51 |
}
|