Skip to content

Commit d3d8b78

Browse files
Closes #6249
1 parent f1f7643 commit d3d8b78

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

ChangeLog-11.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 11.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [11.5.25] - 2025-MM-DD
6+
7+
### Fixed
8+
9+
* [#6249](https://github.com/sebastianbergmann/phpunit/issues/6249): No meaningful error when `<testsuite>` element is missing required `name` attribute
10+
511
## [11.5.24] - 2025-06-20
612

713
### Added
@@ -230,6 +236,7 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
230236
* [#6055](https://github.com/sebastianbergmann/phpunit/issues/6055): `assertNotContainsOnly()` (use `assertContainsNotOnlyArray()`, `assertContainsNotOnlyBool()`, `assertContainsNotOnlyCallable()`, `assertContainsNotOnlyFloat()`, `assertContainsNotOnlyInt()`, `assertContainsNotOnlyIterable()`, `assertContainsNotOnlyNumeric()`, `assertContainsNotOnlyObject()`, `assertContainsNotOnlyResource()`, `assertContainsNotOnlyClosedResource()`, `assertContainsNotOnlyScalar()`, or `assertContainsNotOnlyString()` instead)
231237
* [#6059](https://github.com/sebastianbergmann/phpunit/issues/6059): `containsOnly()` (use `containsOnlyArray()`, `containsOnlyBool()`, `containsOnlyCallable()`, `containsOnlyFloat()`, `containsOnlyInt()`, `containsOnlyIterable()`, `containsOnlyNumeric()`, `containsOnlyObject()`, `containsOnlyResource()`, `containsOnlyClosedResource()`, `containsOnlyScalar()`, or `containsOnlyString()` instead)
232238

239+
[11.5.25]: https://github.com/sebastianbergmann/phpunit/compare/11.5.24...11.5
233240
[11.5.24]: https://github.com/sebastianbergmann/phpunit/compare/11.5.23...11.5.24
234241
[11.5.23]: https://github.com/sebastianbergmann/phpunit/compare/11.5.22...11.5.23
235242
[11.5.22]: https://github.com/sebastianbergmann/phpunit/compare/11.5.21...11.5.22

src/TextUI/Configuration/Xml/Loader.php

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PHPUnit\TextUI\XmlConfiguration;
1111

1212
use const DIRECTORY_SEPARATOR;
13+
use const PHP_EOL;
1314
use const PHP_VERSION;
1415
use function assert;
1516
use function defined;
@@ -18,6 +19,7 @@
1819
use function is_numeric;
1920
use function preg_match;
2021
use function realpath;
22+
use function sprintf;
2123
use function str_contains;
2224
use function str_starts_with;
2325
use function strlen;
@@ -74,6 +76,7 @@
7476
use PHPUnit\Util\Xml\XmlException;
7577
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
7678
use SebastianBergmann\CodeCoverage\Report\Thresholds;
79+
use Throwable;
7780

7881
/**
7982
* @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
113116

114117
assert($configurationFileRealpath !== false && $configurationFileRealpath !== '');
115118

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+
}
128146
}
129147

130148
private function logging(string $filename, DOMXPath $xpath): Logging

tests/end-to-end/generic/defaulttestsuite-using-testsuite-without-name.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ phpunit --configuration=__DIR__.'/../../_files/configuration.testsuite_no_name.x
33
--FILE--
44
<?php declare(strict_types=1);
55
$_SERVER['argv'][] = '--do-not-cache-result';
6-
$_SERVER['argv'][] = '--no-progress';
76
$_SERVER['argv'][] = '--configuration';
87
$_SERVER['argv'][] = __DIR__.'/../../_files/configuration.testsuite_no_name.xml';
98

@@ -12,4 +11,7 @@ require_once __DIR__ . '/../../bootstrap.php';
1211
--EXPECTF--
1312
PHPUnit %s by Sebastian Bergmann and contributors.
1413

15-
assert(!empty($name))
14+
Cannot load XML configuration file %sconfiguration.testsuite_no_name.xml because it has validation errors:
15+
16+
Line 3:
17+
- Element 'testsuite': The attribute 'name' is required but missing.

0 commit comments

Comments
 (0)