Skip to content

refactor(autoreview): Extract PHPUnit test analysis into a dedicated helper#3279

Merged
theofidry merged 4 commits into
infection:masterfrom
theofidry:refactor/phpunit-analysis
Jun 9, 2026
Merged

refactor(autoreview): Extract PHPUnit test analysis into a dedicated helper#3279
theofidry merged 4 commits into
infection:masterfrom
theofidry:refactor/phpunit-analysis

Conversation

@theofidry

@theofidry theofidry commented Jun 9, 2026

Copy link
Copy Markdown
Member

Description

Future PHPat rules will need more PHPUnit-related information from PHPStan ClassReflection objects.

This PR takes the first step by extracting existing PHPUnit-specific checks into a reusable helper, PHPUnitTestClassAnalysis. The goal is not to reduce much code immediately, but to make the intent explicit and keep the next behaviour changes small and easier to review.

Changes

Adds PHPUnitTestClassAnalysis, which:

  • Determines whether a PHPStan ClassReflection represents a PHPUnit test case.
  • Moves the #[Group('integration')] attribute parsing out of PHPUnitTestIoRequirements.
  • Gives future PHPat rules a dedicated place for PHPUnit test-class analysis.

The PHPUnit test-case check is intentionally unchanged for now. It remains a small wrapper around the existing logic so that later fixes can be reviewed as behaviour changes, rather than being mixed into this extraction.

Reviewer Notes

This PR is intended as a refactor with no behaviour change.

This is a small step to untangle #3277 which itself is a PR made to untangle things. It's partly about refining the modelisation of our rules with PHPat and partly adjusting AI generated code I previously did not care as much about.

@theofidry

Copy link
Copy Markdown
Member Author

@coderabbitai full reveiw

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

@theofidry Sure, I'll do a full review of all the changes in this PR!

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors PHPUnit test detection in architecture tests by extracting integration-group identification from PHPUnitTestIoRequirements into a new PHPUnitTestClassAnalysis helper class, updating three selectors to use the new class, and updating corresponding test coverage declarations and assertions.

Changes

PHPUnit detection refactoring

Layer / File(s) Summary
New PHPUnitTestClassAnalysis helper class
tests/Architecture/PHPat/Selector/Support/PHPUnitTestClassAnalysis.php
Introduces public APIs isPHPUnitTestCase() and belongsToIntegrationGroup() to detect PHPUnit test cases and integration group membership. Implementation scans class reflection attributes, filters ReflectionAttribute instances, and extracts group names from positional or named arguments.
Refactor PHPUnitTestIoRequirements
tests/Architecture/PHPat/Selector/Support/PHPUnitTestIoRequirements.php
Removes the public hasIntegrationGroup() method, GROUP_NAME constant, and isIntegrationGroup() helper that previously detected integration groups via #[Group] attributes. Updates imports to remove PHPUnit Group dependency and add str_starts_with for attribute-name prefix matching.
Update selectors to use PHPUnitTestClassAnalysis
tests/Architecture/PHPat/Selector/ConcretePHPUnitTestClass.php, tests/Architecture/PHPat/Selector/PHPUnitTestNotRequiringIoWithIntegrationGroup.php, tests/Architecture/PHPat/Selector/PHPUnitTestRequiringIoWithoutIntegrationGroup.php
All three selectors now import PHPUnitTestClassAnalysis and replace direct test-case and integration-group checks with calls to PHPUnitTestClassAnalysis::isPHPUnitTestCase() and PHPUnitTestClassAnalysis::belongsToIntegrationGroup().
Update test coverage and assertions
tests/phpunit/Architecture/PHPat/Selector/ConcretePHPUnitTestClassTest.php, tests/phpunit/Architecture/PHPat/Selector/Support/PHPUnitTestIoRequirementsTest.php
Expands PHPUnit coverage declarations with #[CoversClass(PHPUnitTestClassAnalysis::class)] attributes. Updates the assertion in PHPUnitTestIoRequirementsTest to derive the integration-group value from PHPUnitTestClassAnalysis::belongsToIntegrationGroup() instead of the removed method.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infection/infection#3258: Both PRs update the PHPat selector's I/O/integration-group detection flow—main PR changes PHPUnitTestIoRequirements/selectors to remove #[Group('integration')] handling and delegate test-case/group checks to PHPUnitTestClassAnalysis, whilst retrieved PR refactors PHPUnitTestIoRequirements/analysis to compute I/O via the shared Analyser; they therefore overlap directly in the same PHPat selector classes.

Suggested labels

Internal, TestFramework / PHPUnit

Suggested reviewers

  • sanmai
  • maks-rafalko
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarises the main change: extracting PHPUnit test analysis logic into a dedicated helper class.
Description check ✅ Passed The pull request description clearly explains the refactoring intent: extracting PHPUnit-specific checks into a reusable PHPUnitTestClassAnalysis helper class for future PHPat rules, with no intended behaviour change.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@theofidry theofidry changed the title refactor refactor(autoreview): Extract PHPUnit test analysis into a dedicated helper Jun 9, 2026
@theofidry theofidry marked this pull request as ready for review June 9, 2026 15:36
@theofidry theofidry merged commit e80d931 into infection:master Jun 9, 2026
61 checks passed
@theofidry theofidry deleted the refactor/phpunit-analysis branch June 10, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant