|
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;
|
|
76 | 78 | use PHPUnit\Util\Xml\XmlException;
|
77 | 79 | use SebastianBergmann\CodeCoverage\Report\Html\Colors;
|
78 | 80 | use SebastianBergmann\CodeCoverage\Report\Thresholds;
|
| 81 | +use Throwable; |
79 | 82 |
|
80 | 83 | /**
|
81 | 84 | * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
|
@@ -115,18 +118,33 @@ public function load(string $filename): LoadedFromFileConfiguration
|
115 | 118 |
|
116 | 119 | assert($configurationFileRealpath !== false && $configurationFileRealpath !== '');
|
117 | 120 |
|
118 |
| - return new LoadedFromFileConfiguration( |
119 |
| - $configurationFileRealpath, |
120 |
| - (new Validator)->validate($document, $xsdFilename), |
121 |
| - $this->extensions($xpath), |
122 |
| - $this->source($configurationFileRealpath, $xpath), |
123 |
| - $this->codeCoverage($configurationFileRealpath, $xpath), |
124 |
| - $this->groups($xpath), |
125 |
| - $this->logging($configurationFileRealpath, $xpath), |
126 |
| - $this->php($configurationFileRealpath, $xpath), |
127 |
| - $this->phpunit($configurationFileRealpath, $document), |
128 |
| - $this->testSuite($configurationFileRealpath, $xpath), |
129 |
| - ); |
| 121 | + $validationResult = (new Validator)->validate($document, $xsdFilename); |
| 122 | + |
| 123 | + try { |
| 124 | + return new LoadedFromFileConfiguration( |
| 125 | + $configurationFileRealpath, |
| 126 | + $validationResult, |
| 127 | + $this->extensions($xpath), |
| 128 | + $this->source($configurationFileRealpath, $xpath), |
| 129 | + $this->codeCoverage($configurationFileRealpath, $xpath), |
| 130 | + $this->groups($xpath), |
| 131 | + $this->logging($configurationFileRealpath, $xpath), |
| 132 | + $this->php($configurationFileRealpath, $xpath), |
| 133 | + $this->phpunit($configurationFileRealpath, $document), |
| 134 | + $this->testSuite($configurationFileRealpath, $xpath), |
| 135 | + ); |
| 136 | + } catch (Throwable $t) { |
| 137 | + $message = sprintf( |
| 138 | + 'Cannot load XML configuration file %s', |
| 139 | + $configurationFileRealpath, |
| 140 | + ); |
| 141 | + |
| 142 | + if ($validationResult->hasValidationErrors()) { |
| 143 | + $message .= ' because it has validation errors:' . PHP_EOL . $validationResult->asString(); |
| 144 | + } |
| 145 | + |
| 146 | + throw new Exception($message, previous: $t); |
| 147 | + } |
130 | 148 | }
|
131 | 149 |
|
132 | 150 | private function logging(string $filename, DOMXPath $xpath): Logging
|
|
0 commit comments