#6961·phpunit

Reconsider inheriting `#[Group]` from parent test classes

Author: ruudkCreated Sep 5, 2026Updated Sep 9, 2026
Labelstype/enhancementfeature/test-runnerfeature/metadata/attributes

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.

  1. 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, and Reflection::sourceFilesOf() walks getParentClass() up to TestCase. Reading #[Group] from parent classes would be consistent with that.

  2. The workaround (repeat the attribute on every concrete class, or split tests by directory) does not fit every project. We have an abstract FunctionalTestCase and our tests/ directory mirrors src/, 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.

Source: sebastianbergmann/phpunit