Skip to content

fix(rector): leave custom assertion methods unchanged - #395

Open
ichinya wants to merge 1 commit into
php-testo:1.xfrom
ichinya:feat/390-phpunit-method-ownership
Open

ichinya wants to merge 1 commit into
php-testo:1.xfrom
ichinya:feat/390-phpunit-method-ownership

Conversation

@ichinya

@ichinya ichinya commented Oct 15, 2026 •

Copy link
Copy Markdown

Rector currently recognises PHPUnit assertion methods by call shape and name. A project method such as assertSame() or assertIsString() can therefore be rewritten even when it has its own implementation and return value.

Require the resolved method declaration to belong to PHPUnit's Assert or TestCase. Custom, inherited custom, magic, trait-required and unresolved methods stay unchanged. PHPUnit assertion functions keep their namespace-based recognition.

Only the shared assertion recogniser changes in production. The broad fixture edit adds PHPUnit ancestry to 33 existing method-call fixtures; function-call fixtures retain their existing ancestry. Reflection-only PHPUnit declarations are scanned by PHPStan without loading fake runtime classes into Double or other bridges.

Validation:

  • PHP 8.2.34, 8.3.35 and 8.5.11: all 927 relevant checks pass on each runtime (362 Rector fixtures, 171 harness unit tests and 394 Assert tests). PHP 8.2 was explicitly tested.
  • PHP 8.5 full regular suite: passed, 2926 tests and 5849 assertions; no failures or errors, one flaky and two skipped.
  • Changed-file CS Fixer and git diff checks pass.
  • Combined with fix(rector): preserve string assertion call contracts #396: merges without conflicts and the full regular suite passes (2930 tests, 5853 assertions, no failures or errors).

Part of #390. Named string arguments, weak/strict coercion and evaluation order are handled in #396. Both PRs target 1.x independently; review this ownership change first.

Require a resolved PHPUnit Assert/TestCase declaration before rewriting
assertion methods. Preserve custom, magic, trait-required and unresolved calls.

Give existing method-call fixtures PHPUnit ancestry and scan reflection-only
assertion declarations without loading fake runtime PHPUnit classes.

Refs php-testo#390

Assisted-By: GPT-6 <noreply@anthropic.com>
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.

1 participant