Skip to content

Commit dfbf89a

Browse files
Merge branch '11.5' into 12.2
2 parents 63f7846 + d3d8b78 commit dfbf89a

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

ChangeLog-12.2.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 12.2 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [12.2.5] - 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
## [12.2.4] - 2025-06-26
612

713
### Changed
@@ -82,6 +88,7 @@ This feature is experimental and the generated XML may change to enhance complia
8288
* A warning is now emitted when more than one of `#[Small]`, `#[Medium]`, or `#[Large]` is used on a test class
8389
* A warning is now emitted when a data provider provides data sets that have more values than the test method consumes using arguments
8490

91+
[12.2.5]: https://github.com/sebastianbergmann/phpunit/compare/12.2.4...12.4
8592
[12.2.4]: https://github.com/sebastianbergmann/phpunit/compare/12.2.3...12.2.4
8693
[12.2.3]: https://github.com/sebastianbergmann/phpunit/compare/12.2.2...12.2.3
8794
[12.2.2]: https://github.com/sebastianbergmann/phpunit/compare/12.2.1...12.2.2

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;
@@ -76,6 +78,7 @@
7678
use PHPUnit\Util\Xml\XmlException;
7779
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
7880
use SebastianBergmann\CodeCoverage\Report\Thresholds;
81+
use Throwable;
7982

8083
/**
8184
* @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
115118

116119
assert($configurationFileRealpath !== false && $configurationFileRealpath !== '');
117120

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+
}
130148
}
131149

132150
private function logging(string $filename, DOMXPath $xpath): Logging
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit>
3+
<testsuite>
4+
<directory>tests</directory>
5+
</testsuite>
6+
</phpunit>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
phpunit --configuration=__DIR__.'/../../_files/configuration.testsuite_no_name.xml'
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--configuration';
7+
$_SERVER['argv'][] = __DIR__.'/../../_files/configuration.testsuite_no_name.xml';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
11+
--EXPECTF--
12+
PHPUnit %s by Sebastian Bergmann and contributors.
13+
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)