From e16dc8c3bb805e32fd3ab74cfd50b32d4edbbd1b Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 18 Jul 2025 18:50:06 +0900 Subject: [PATCH] Fix file attribute in ListTestsAsXml for abstract class inheritance Use ReflectionClass to get actual class file path instead of method file path. Fixes #6097 --- ChangeLog-10.5.md | 6 +++++ .../Commands/ListTestsAsXmlCommand.php | 6 +++++ .../list-tests-xml-abstract-inheritance.phpt | 22 +++++++++++++++++++ .../list-tests-xml-dataprovider.phpt | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/end-to-end/cli/list-tests/list-tests-xml-abstract-inheritance.phpt diff --git a/ChangeLog-10.5.md b/ChangeLog-10.5.md index b3532a21423..7a20695ff27 100644 --- a/ChangeLog-10.5.md +++ b/ChangeLog-10.5.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 10.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [Unreleased] + +### Fixed + +* [#6097](https://github.com/sebastianbergmann/phpunit/issues/6097): `--list-tests-xml` file attribute shows incorrect path for tests inheriting from abstract classes + ## [10.5.48] - 2025-07-11 ### Fixed diff --git a/src/TextUI/Command/Commands/ListTestsAsXmlCommand.php b/src/TextUI/Command/Commands/ListTestsAsXmlCommand.php index 5a1085f1713..d934891bc97 100644 --- a/src/TextUI/Command/Commands/ListTestsAsXmlCommand.php +++ b/src/TextUI/Command/Commands/ListTestsAsXmlCommand.php @@ -10,6 +10,7 @@ namespace PHPUnit\TextUI\Command; use const PHP_EOL; +use function assert; use function file_put_contents; use function implode; use function sprintf; @@ -19,6 +20,7 @@ use PHPUnit\Runner\PhptTestCase; use PHPUnit\TextUI\Configuration\Registry; use RecursiveIteratorIterator; +use ReflectionClass; use XMLWriter; /** @@ -59,6 +61,10 @@ public function execute(): Result $writer->startElement('testCaseClass'); $writer->writeAttribute('name', $test::class); + $classFile = (new ReflectionClass($test))->getFileName(); + assert($classFile !== false); + $writer->writeAttribute('file', $classFile); + $currentTestCase = $test::class; } diff --git a/tests/end-to-end/cli/list-tests/list-tests-xml-abstract-inheritance.phpt b/tests/end-to-end/cli/list-tests/list-tests-xml-abstract-inheritance.phpt new file mode 100644 index 00000000000..4032dea0b98 --- /dev/null +++ b/tests/end-to-end/cli/list-tests/list-tests-xml-abstract-inheritance.phpt @@ -0,0 +1,22 @@ +--TEST-- +phpunit --list-tests-xml abstract inheritance +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + + + + + + +%A \ No newline at end of file diff --git a/tests/end-to-end/cli/list-tests/list-tests-xml-dataprovider.phpt b/tests/end-to-end/cli/list-tests/list-tests-xml-dataprovider.phpt index f71393a3e23..bcf1cab0bf4 100644 --- a/tests/end-to-end/cli/list-tests/list-tests-xml-dataprovider.phpt +++ b/tests/end-to-end/cli/list-tests/list-tests-xml-dataprovider.phpt @@ -16,7 +16,7 @@ PHPUnit %s by Sebastian Bergmann and contributors. - +