function ListTestsAsXmlCommand::execute
Overrides Command::execute
File
-
vendor/
phpunit/ phpunit/ src/ TextUI/ Command/ Commands/ ListTestsAsXmlCommand.php, line 40
Class
- ListTestsAsXmlCommand
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\TextUI\CommandCode
public function execute() : Result {
$buffer = $this->warnAboutConflictingOptions();
$writer = new XMLWriter();
$writer->openMemory();
$writer->setIndent(true);
$writer->startDocument();
$writer->startElement('tests');
$currentTestCase = null;
foreach (new RecursiveIteratorIterator($this->suite) as $test) {
if ($test instanceof TestCase) {
if ($test::class !== $currentTestCase) {
if ($currentTestCase !== null) {
$writer->endElement();
}
$writer->startElement('testCaseClass');
$writer->writeAttribute('name', $test::class);
$currentTestCase = $test::class;
}
$writer->startElement('testCaseMethod');
$writer->writeAttribute('id', $test->valueObjectForEvents()
->id());
$writer->writeAttribute('name', $test->name());
$writer->writeAttribute('groups', implode(',', $test->groups()));
/**
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/5481
*/
if (!empty($test->dataSetAsString())) {
$writer->writeAttribute('dataSet', str_replace(' with data set ', '', $test->dataSetAsString()));
}
$writer->endElement();
continue;
}
if ($test instanceof PhptTestCase) {
if ($currentTestCase !== null) {
$writer->endElement();
$currentTestCase = null;
}
$writer->startElement('phptFile');
$writer->writeAttribute('path', $test->getName());
$writer->endElement();
}
}
if ($currentTestCase !== null) {
$writer->endElement();
}
$writer->endElement();
file_put_contents($this->filename, $writer->outputMemory());
$buffer .= sprintf('Wrote list of tests that would have been run to %s' . PHP_EOL, $this->filename);
return Result::from($buffer);
}