Skip to content

[PHPUnit60] Never parse PHPUnit and Symfony base test case methods in AssertCallAnalyzer - #833

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-skip-framework-test-case-parse
Nov 14, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
tv-skip-framework-test-case-parse

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Part of rectorphp/rector#9965.

AssertCallAnalyzer follows calls like parent::setUp() or $this->helper() through AstResolver, which parses and decorates the file that declares the method. Only a direct parent:: call to TestCase was skipped so far. So the file was still parsed in these cases:

  • a test class extends KernelTestCase/WebTestCase and calls parent::setUp()
  • a custom base class does not override setUp(), so the call lands in TestCase or Symfony
  • $this->markTestSkipped() and similar, declared in Assert

Change

Before resolving the method, look up its declaring class. When it is one of PHPUnitClassName::FRAMEWORK_TEST_CASES (PHPUnit TestCase, Assert, Symfony KernelTestCase, WebTestCase, TypeTestCase), the method is not parsed. Their methods do not count as test assertions, and assert*() calls are already matched by name before this step.

This replaces the direct-parent TestCase check.

Tests

New KernelTestCase/WebTestCase stubs. The KernelTestCase::setUp() stub asserts on purpose: the new fixture fails if the file is parsed, and passes with this change.

Bench

New bench/does_not_perform_assertion_framework_test_case_bench.php: 300 test classes extending a base class without setUp(), each with setUp() calling parent::setUp() (lands in PHPUnit's TestCase) and 6 tests calling $this->markTestSkipped() (declared in Assert). CPU, 3 runs, local:

main this PR
CPU 3.30-4.14 s 0.49-0.59 s
changed classes 300 300

On main most of the time goes to parsing and decorating PHPUnit's TestCase.php and Assert.php. The existing benches extend TestCase directly, so they stay the same.

@TomasVotruba
TomasVotruba enabled auto-merge (squash) November 14, 2026 20:51
@TomasVotruba
TomasVotruba merged commit 9545637 into main Nov 14, 2026
12 checks passed
@TomasVotruba
TomasVotruba deleted the tv-skip-framework-test-case-parse branch November 14, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant