sebastianbergmann / sebastianbergmann/phpunit
Reconsider inheriting `#[Group]` from parent test classes
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 20.1k
- Forks
- 2.2k
- Avg merge
- 7h
- Merged PRs (30d)
- 61
Description
This is a follow-up to #3935, which asked for #[Group] on a parent test class to apply to its subclasses. It was closed. I want to ask to reconsider it for two reasons.
-
Attributes are now the only metadata mechanism. PHPUnit already treats the test class hierarchy as one unit in other places: hook methods (
#[Before],#[After], etc.) declared in a parent class are honored, andReflection::sourceFilesOf()walksgetParentClass()up toTestCase. Reading#[Group]from parent classes would be consistent with that. -
The workaround (repeat the attribute on every concrete class, or split tests by directory) does not fit every project. We have an abstract
FunctionalTestCaseand ourtests/directory mirrorssrc/, so unit and functional tests live side by side. A<testsuite>per directory cannot select only functional tests, and repeating#[Group('functional')]on each class is easy to forget.
Today AttributeParser::forClass() reads attributes from the concrete class only, and TestCase::groups() is final, so there is no user-land option.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with AttributeParser::forClass() and the final TestCase::groups() method, then trace how parent test classes are handled for hooks and Reflection::sourceFilesOf(). Define and verify the expected behavior for #[Group] declared on an abstract or parent test class and inherited by concrete subclasses, including coverage for the existing workaround cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100