sebastianbergmann / sebastianbergmann/phpunit

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

Open
#6,961 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature/metadata/attributes feature/test-runner type/enhancement
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.

  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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.