Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The file attribute of <testClass> node of XML test list can be wrong #6097

Open
mondrake opened this issue Jan 9, 2025 · 2 comments
Open
Labels
feature/test-runner CLI test runner type/bug Something is broken

Comments

@mondrake
Copy link
Contributor

mondrake commented Jan 9, 2025

Q A
PHPUnit version 10.5.38
PHP version 8.3
Installation Method Composer

Summary

ListTestsAsXmlCommand builds the file attribute of each <testClass> node by getting the file path of the first test case method found in a class, and using the file path returned by calling $test->valueObjectForEvents()->file().

This is not accurate as this returns the file path of the file where the method is defined, not the file path of the class. The method could be defined in a parent base class, or in a trait, and then the file returned would not be the one where the TestCase class is contained.

Current behavior

See above.

How to reproduce

Make an abstract base TestCase class with test case methods in it, a separate concrete class with no methods extending the abstract, and run phpunit with the --list-tests-xml option. The file attribute of the concrete <testClass> will point to the abstract class file and not to the concrete one.

Expected behavior

The file path should match the class, as the autoloader will map.

@mondrake mondrake added the type/bug Something is broken label Jan 9, 2025
@mondrake mondrake changed the title Thefile attribute of <testClass> node of XML test list can be wrong The file attribute of <testClass> node of XML test list can be wrong Jan 9, 2025
@sebastianbergmann sebastianbergmann added feature/test-runner CLI test runner status/waiting-for-feedback Waiting for feedback from original reporter labels Jan 10, 2025
@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

mondrake added a commit to mondrake/phpunit that referenced this issue Jan 10, 2025
mondrake added a commit to mondrake/phpunit that referenced this issue Jan 10, 2025
@mondrake
Copy link
Contributor Author

mondrake commented Jan 10, 2025

#6101 contains test changes to prove the bug. It targets 11.5, where this is visible in the XML output file. However, the underlying bug, that IMHO is the lack of a method to retrieve the file where the TestCase class is defined, goes down to 10.5 at least.

@sebastianbergmann sebastianbergmann removed the status/waiting-for-feedback Waiting for feedback from original reporter label Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants