Skip to content

fix(rector): convert an anonymous class on a project TestCase base - #431

Merged
roxblnfk merged 2 commits into
1.xfrom
fix/rector-anonymous-on-project-base
Nov 21, 2026
Merged

roxblnfk merged 2 commits into
1.xfrom
fix/rector-anonymous-on-project-base

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

🔍 What was changed

  • An anonymous class reaching TestCase through a project base (new class extends BaseTestCase) is now converted like a named subclass: parent:: hook calls are dropped, others become self::/$this-> for the skip and expectation rules, extends stays.
  • PhpunitTestCaseClass resolves ancestry from the extends name, so isTestCase() and the vendor-base check work without a class name. Named classes resolve the same as before.
  • An anonymous class on a vendor PHPUnit base gets no #[\Testo\Skip]: Testo never discovers it, and its parent:: calls stay valid.
  • LifecycleMethodToTestoRector also uses isTestCase(), so such a class now gets lifecycle attributes too, like an anonymous class extending TestCase directly.
  • A subclass of a project base, named or anonymous, loses #[\Override] on a method only PHPUnit declares (a setUp() the base does not override): PHP rejected it on load once the base was detached. It stays where the base or an interface declares the method.

Checklist

Documentation

FEATURE_PARITY.md, the rule docblock and the testo-migrate-from-phpunit skill mention anonymous classes on a project base.

An anonymous class has no name to reflect, so its ancestry is read from the base it extends; it then follows the same path as a named subclass. It gets no `#[Skip]` on a vendor base, since Testo never discovers an anonymous class.

Fixes #428

Assisted-By: Claude Opus 5.5
@roxblnfk
roxblnfk requested a review from a team as a code owner November 18, 2026 11:55
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.37037% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ridge/rector/src/Internal/PhpunitTestCaseClass.php 0.00% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

…only PHPUnit declares

test(rector): cover lifecycle attributes on an anonymous class on a project base

Once the base is detached from `TestCase`, an `#[\Override]` on a hook the base does not declare itself, such as `setUp()`, has no parent method left and PHP rejects the class on load. The attribute stays where the base or an interface declares the method.

Assisted-By: Claude Opus 5.5
@roxblnfk
roxblnfk force-pushed the fix/rector-anonymous-on-project-base branch from 8e7a8a3 to cfb3f21 Compare November 21, 2026 09:41
@roxblnfk
roxblnfk merged commit 8bfa0fe into 1.x Nov 21, 2026
29 of 31 checks passed
@roxblnfk
roxblnfk deleted the fix/rector-anonymous-on-project-base branch November 21, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rector: an anonymous class on a project TestCase base keeps its parent:: calls into PHPUnit

1 participant