| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
/*
|
|
|
3 |
* This file is part of PHPUnit.
|
|
|
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 PHPUnit\Util;
|
|
|
11 |
|
|
|
12 |
use function get_class;
|
|
|
13 |
use function implode;
|
|
|
14 |
use function str_replace;
|
|
|
15 |
use PHPUnit\Framework\TestCase;
|
|
|
16 |
use PHPUnit\Framework\TestSuite;
|
|
|
17 |
use PHPUnit\Runner\PhptTestCase;
|
|
|
18 |
use RecursiveIteratorIterator;
|
|
|
19 |
use XMLWriter;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* @internal This class is not covered by the backward compatibility promise for PHPUnit
|
|
|
23 |
*/
|
|
|
24 |
final class XmlTestListRenderer
|
|
|
25 |
{
|
|
|
26 |
/**
|
|
|
27 |
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
|
|
28 |
*/
|
|
|
29 |
public function render(TestSuite $suite): string
|
|
|
30 |
{
|
|
|
31 |
$writer = new XMLWriter;
|
|
|
32 |
|
|
|
33 |
$writer->openMemory();
|
|
|
34 |
$writer->setIndent(true);
|
|
|
35 |
$writer->startDocument('1.0', 'UTF-8');
|
|
|
36 |
$writer->startElement('tests');
|
|
|
37 |
|
|
|
38 |
$currentTestCase = null;
|
|
|
39 |
|
|
|
40 |
foreach (new RecursiveIteratorIterator($suite->getIterator()) as $test) {
|
|
|
41 |
if ($test instanceof TestCase) {
|
|
|
42 |
if (get_class($test) !== $currentTestCase) {
|
|
|
43 |
if ($currentTestCase !== null) {
|
|
|
44 |
$writer->endElement();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
$writer->startElement('testCaseClass');
|
|
|
48 |
$writer->writeAttribute('name', get_class($test));
|
|
|
49 |
|
|
|
50 |
$currentTestCase = get_class($test);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
$writer->startElement('testCaseMethod');
|
|
|
54 |
$writer->writeAttribute('name', $test->getName(false));
|
|
|
55 |
$writer->writeAttribute('groups', implode(',', $test->getGroups()));
|
|
|
56 |
|
|
|
57 |
if (!empty($test->getDataSetAsString(false))) {
|
|
|
58 |
$writer->writeAttribute(
|
|
|
59 |
'dataSet',
|
|
|
60 |
str_replace(
|
|
|
61 |
' with data set ',
|
|
|
62 |
'',
|
|
|
63 |
$test->getDataSetAsString(false)
|
|
|
64 |
)
|
|
|
65 |
);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$writer->endElement();
|
|
|
69 |
} elseif ($test instanceof PhptTestCase) {
|
|
|
70 |
if ($currentTestCase !== null) {
|
|
|
71 |
$writer->endElement();
|
|
|
72 |
|
|
|
73 |
$currentTestCase = null;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
$writer->startElement('phptFile');
|
|
|
77 |
$writer->writeAttribute('path', $test->getName());
|
|
|
78 |
$writer->endElement();
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
if ($currentTestCase !== null) {
|
|
|
83 |
$writer->endElement();
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
$writer->endElement();
|
|
|
87 |
$writer->endDocument();
|
|
|
88 |
|
|
|
89 |
return $writer->outputMemory();
|
|
|
90 |
}
|
|
|
91 |
}
|