Skip to content

Commit

Permalink
Merge branch '11.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 20, 2024
2 parents 9c95792 + c0185b7 commit f149c2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/Runner/Baseline/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
),
);
Expand Down
37 changes: 14 additions & 23 deletions src/Util/Xml/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function libxml_get_errors;
use function libxml_use_internal_errors;
use function sprintf;
use function trim;
use DOMDocument;

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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';
}
Expand Down
4 changes: 1 addition & 3 deletions tests/end-to-end/baseline/baseline-invalid-xml.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit f149c2b

Please sign in to comment.