Skip to content

[PHPUnit60] Skip tests in classes with asserting parent lifecycle methods in AddDoesNotPerformAssertionToNonAssertingTestRector - #834

Merged
TomasVotruba merged 2 commits into
mainfrom
does-not-perform-assertion-parent-lifecycle
Nov 14, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
does-not-perform-assertion-parent-lifecycle

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Extracted from #827, follow-up to #831.

PHPUnit counts assertions in parent lifecycle methods (setUp(), tearDown(), #[Before], ...) toward every test. A test extending a base class that asserts in setUp() performs assertions, so it must not get #[DoesNotPerformAssertions].

  • LifecycleMethodAssertAnalyzer walks parent classes up to PHPUnit/Symfony TestCase, max 5 parents
  • a hook overridden without parent::<hook>() hides the parent one
  • parent chains with no assert-like text in their files (incl. traits) are skipped before parsing, as parsing with scope costs ~40 ms per file
  • results are cached per parent class, so sibling test classes share the chain

Bench

New does_not_perform_assertion_parent_lifecycle_bench.php - 300 test classes on 10 chains of 4 parents, every other chain asserts in its top setUp().

local CPU main this PR
does_not_perform_assertion_lifecycle_bench.php ~1.03 s ~1.03 s
does_not_perform_assertion_parent_lifecycle_bench.php ~1.0 s, 100 classes wrongly changed ~1.42 s

@TomasVotruba
TomasVotruba force-pushed the does-not-perform-assertion-parent-lifecycle branch 2 times, most recently from 065f66a to 9b0678e Compare November 14, 2026 21:05
@TomasVotruba
TomasVotruba force-pushed the does-not-perform-assertion-parent-lifecycle branch from 759132c to c87a7fe Compare November 14, 2026 23:48
@TomasVotruba
TomasVotruba merged commit e8fab67 into main Nov 14, 2026
14 checks passed
@TomasVotruba
TomasVotruba deleted the does-not-perform-assertion-parent-lifecycle branch November 14, 2026 23:57
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