Skip to content

[PHPUnit60] Skip tests in classes with own asserting lifecycle methods in AddDoesNotPerformAssertionToNonAssertingTestRector - #831

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-own-class-lifecycle-asserts
Nov 14, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
tv-own-class-lifecycle-asserts

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Part of rectorphp/rector#9965, split from #827.

PHPUnit counts assertions made in lifecycle methods toward every test of the class. A test whose own body asserts nothing still "performs assertions" when setUp(), tearDown(), assertPreConditions(), assertPostConditions(), a #[Before]/#[After]/#[PreCondition]/#[PostCondition] method or a @before/@after/@preCondition/@postCondition method asserts. With failOnRisky, the added #[DoesNotPerformAssertions] then fails the test.

Change

New LifecycleMethodAssertAnalyzer, which checks only the lifecycle methods of the test's own class:

Bench

New bench/does_not_perform_assertion_own_lifecycle_bench.php: 300 test classes with own setUp() and tearDown(), every other one asserting in setUp(). The existing lifecycle bench now sets the current File on CurrentFileProvider, like AbstractRectorTestCase does, as the rule reads it. CPU, 3 runs, local:

bench main this PR
own lifecycle 0.29-0.35 s 0.29-0.31 s
lifecycle (deep chains) 1.29-1.39 s 1.31-1.32 s

Without the per-class cache the own-lifecycle bench was ~0.44 s.

@TomasVotruba
TomasVotruba merged commit f34c2b2 into main Nov 14, 2026
11 checks passed
@TomasVotruba
TomasVotruba deleted the tv-own-class-lifecycle-asserts branch November 14, 2026 17:11
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