diff --git a/src/Runner/Baseline/Reader.php b/src/Runner/Baseline/Reader.php index 5f2d6e8725f..aeb640ae1ce 100644 --- a/src/Runner/Baseline/Reader.php +++ b/src/Runner/Baseline/Reader.php @@ -50,7 +50,8 @@ public function read(string $baselineFile): Baseline } catch (XmlException $e) { throw new CannotLoadBaselineException( sprintf( - 'Cannot read baseline: %s', + 'Cannot read baseline %s: %s', + $baselineFile, trim($e->getMessage()), ), ); diff --git a/src/Util/Xml/Loader.php b/src/Util/Xml/Loader.php index 1e65ec3ade3..1289c253fc6 100644 --- a/src/Util/Xml/Loader.php +++ b/src/Util/Xml/Loader.php @@ -14,6 +14,7 @@ use function libxml_get_errors; use function libxml_use_internal_errors; use function sprintf; +use function trim; use DOMDocument; /** @@ -42,25 +43,25 @@ public function loadFile(string $filename): DOMDocument ); } - return $this->load($contents, $filename); + if (trim($contents) === '') { + throw new XmlException( + sprintf( + 'Could not parse XML from empty file "%s"', + $filename, + ), + ); + } + + return $this->load($contents); } /** * @throws XmlException */ - public function load(string $actual, ?string $filename = null): DOMDocument + public function load(string $actual): DOMDocument { if ($actual === '') { - if ($filename === null) { - throw new XmlException('Could not parse XML from empty string'); - } - - throw new XmlException( - sprintf( - 'Could not parse XML from empty file "%s"', - $filename, - ), - ); + throw new XmlException('Could not parse XML from empty string'); } $document = new DOMDocument; @@ -78,17 +79,7 @@ public function load(string $actual, ?string $filename = null): DOMDocument libxml_use_internal_errors($internal); error_reporting($reporting); - if ($loaded === false || $message !== '') { - if ($filename !== null) { - throw new XmlException( - sprintf( - 'Could not load "%s"%s', - $filename, - $message !== '' ? ":\n" . $message : '', - ), - ); - } - + if ($loaded === false) { if ($message === '') { $message = 'Could not load XML for unknown reason'; } diff --git a/tests/end-to-end/baseline/baseline-invalid-xml.phpt b/tests/end-to-end/baseline/baseline-invalid-xml.phpt index ef0ab6c91aa..4600a47f375 100644 --- a/tests/end-to-end/baseline/baseline-invalid-xml.phpt +++ b/tests/end-to-end/baseline/baseline-invalid-xml.phpt @@ -21,9 +21,7 @@ Time: %s, Memory: %s There was 1 PHPUnit test runner warning: -1) Cannot read baseline: Could not load "%sbaseline.xml": - -%snd%sag%s +1) Cannot read baseline %sbaseline.xml: %s WARNINGS! Tests: 1, Assertions: 1, Warnings: 1.