PhpUnitJunit tries to load invalid xml file
Work around outup from phpunit versions before 6.5.7/7.0.2 (before sebastianbergmann/phpunit#2974 was fixed).
This commit is contained in:
parent
30349014b7
commit
4c8398f68f
|
@ -139,8 +139,41 @@ class PhpUnitResultJunit extends PhpUnitResult
|
||||||
return new \SimpleXMLElement('<empty/>'); // new empty element
|
return new \SimpleXMLElement('<empty/>'); // new empty element
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
try {
|
||||||
$suites = simplexml_load_file($this->outputFile);
|
$suites = simplexml_load_file($this->outputFile);
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
$suites = null;
|
||||||
|
} catch (\Throwable $ex) { // since php7
|
||||||
|
$suites = null;
|
||||||
|
}
|
||||||
|
if (!$suites) {
|
||||||
|
// from https://stackoverflow.com/questions/7766455/how-to-handle-invalid-unicode-with-simplexml/8092672#8092672
|
||||||
|
$oldUse = libxml_use_internal_errors(true);
|
||||||
|
libxml_clear_errors();
|
||||||
|
$dom = new \DOMDocument("1.0", "UTF-8");
|
||||||
|
$dom->strictErrorChecking = false;
|
||||||
|
$dom->validateOnParse = false;
|
||||||
|
$dom->recover = true;
|
||||||
|
$dom->loadXML(strtr(
|
||||||
|
file_get_contents($this->outputFile),
|
||||||
|
array('"' => "'") // " in attribute names may mislead the parser
|
||||||
|
));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \LibXMLError
|
||||||
|
*/
|
||||||
|
$xmlError = libxml_get_last_error();
|
||||||
|
if ($xmlError) {
|
||||||
|
$warning = sprintf('L%s C%s: %s', $xmlError->line, $xmlError->column, $xmlError->message);
|
||||||
|
print 'WARNING: ignored errors while reading phpunit result, '.$warning."\n";
|
||||||
|
}
|
||||||
|
if (!$dom->hasChildNodes()) {
|
||||||
|
$this->internalProblem('xml file with no content');
|
||||||
|
}
|
||||||
|
$suites = simplexml_import_dom($dom);
|
||||||
|
|
||||||
|
libxml_clear_errors();
|
||||||
|
libxml_use_internal_errors($oldUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $suites;
|
return $suites;
|
||||||
|
|
Loading…
Reference in a new issue