|
10 | 10 | namespace PHPUnit\TextUI\XmlConfiguration;
|
11 | 11 |
|
12 | 12 | use const DIRECTORY_SEPARATOR;
|
| 13 | +use const PHP_EOL; |
13 | 14 | use const PHP_VERSION;
|
14 | 15 | use function assert;
|
15 | 16 | use function defined;
|
|
18 | 19 | use function is_numeric;
|
19 | 20 | use function preg_match;
|
20 | 21 | use function realpath;
|
| 22 | +use function sprintf; |
21 | 23 | use function str_contains;
|
22 | 24 | use function str_starts_with;
|
23 | 25 | use function strlen;
|
|
74 | 76 | use PHPUnit\Util\Xml\XmlException;
|
75 | 77 | use SebastianBergmann\CodeCoverage\Report\Html\Colors;
|
76 | 78 | use SebastianBergmann\CodeCoverage\Report\Thresholds;
|
| 79 | +use Throwable; |
77 | 80 |
|
78 | 81 | /**
|
79 | 82 | * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
|
@@ -113,18 +116,33 @@ public function load(string $filename): LoadedFromFileConfiguration
|
113 | 116 |
|
114 | 117 | assert($configurationFileRealpath !== false && $configurationFileRealpath !== '');
|
115 | 118 |
|
116 |
| - return new LoadedFromFileConfiguration( |
117 |
| - $configurationFileRealpath, |
118 |
| - (new Validator)->validate($document, $xsdFilename), |
119 |
| - $this->extensions($xpath), |
120 |
| - $this->source($configurationFileRealpath, $xpath), |
121 |
| - $this->codeCoverage($configurationFileRealpath, $xpath), |
122 |
| - $this->groups($xpath), |
123 |
| - $this->logging($configurationFileRealpath, $xpath), |
124 |
| - $this->php($configurationFileRealpath, $xpath), |
125 |
| - $this->phpunit($configurationFileRealpath, $document), |
126 |
| - $this->testSuite($configurationFileRealpath, $xpath), |
127 |
| - ); |
| 119 | + $validationResult = (new Validator)->validate($document, $xsdFilename); |
| 120 | + |
| 121 | + try { |
| 122 | + return new LoadedFromFileConfiguration( |
| 123 | + $configurationFileRealpath, |
| 124 | + $validationResult, |
| 125 | + $this->extensions($xpath), |
| 126 | + $this->source($configurationFileRealpath, $xpath), |
| 127 | + $this->codeCoverage($configurationFileRealpath, $xpath), |
| 128 | + $this->groups($xpath), |
| 129 | + $this->logging($configurationFileRealpath, $xpath), |
| 130 | + $this->php($configurationFileRealpath, $xpath), |
| 131 | + $this->phpunit($configurationFileRealpath, $document), |
| 132 | + $this->testSuite($configurationFileRealpath, $xpath), |
| 133 | + ); |
| 134 | + } catch (Throwable $t) { |
| 135 | + $message = sprintf( |
| 136 | + 'Cannot load XML configuration file %s', |
| 137 | + $configurationFileRealpath, |
| 138 | + ); |
| 139 | + |
| 140 | + if ($validationResult->hasValidationErrors()) { |
| 141 | + $message .= ' because it has validation errors:' . PHP_EOL . $validationResult->asString(); |
| 142 | + } |
| 143 | + |
| 144 | + throw new Exception($message, previous: $t); |
| 145 | + } |
128 | 146 | }
|
129 | 147 |
|
130 | 148 | private function logging(string $filename, DOMXPath $xpath): Logging
|
|
0 commit comments