Repository navigation
Do not require parent setUp/tearDown when method is always terminating - #360
Merged
Merged
Conversation
staabm
approved these changes
Nov 24, 2026
Contributor
|
needs rebase |
VincentLanglet
approved these changes
Nov 24, 2026
When setUp() or tearDown() always terminates early (e.g. via markTestSkipped(), markTestIncomplete(), fail(), or an unconditional exception), a call to the parent method is not required. Switch ShouldCallParentMethodsRule to inspect MethodReturnStatementsNode and check whether the method's statement result is always terminating.
lyn1dev
force-pushed
the
fix-292-terminating-setup
branch
from
November 26, 2026 01:01
fb9723e to
a9076e5
Compare
Contributor
Author
|
@staabm Rebased onto 2.1.x (head �9076e5), integrating the RuleErrorBuilder::fixNode() changes from #356 and guarding the always-terminating check on getReturnStatements()/getReturnStatementsAfterFinally() so |
Contributor
|
thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
setUp()ortearDown()always terminates early (for example, by callingmarkTestSkipped(),markTestIncomplete(),fail(), or by unconditionally throwing an exception), PHPStan'sShouldCallParentMethodsRulepreviously reported a missing call toparent::setUp()orparent::tearDown(). Requiring parent setup when the test is unconditionally skipped or fails early causes unnecessary work before termination, or dead-code errors if placed after.Reproducer
Previously reported:
Solution
ShouldCallParentMethodsRuleto inspectMethodReturnStatementsNodeinstead ofInClassMethodNode.$node->getStatementResult()->isAlwaysTerminating()and return early if the method unconditionally terminates.ifblock).Test Plan
self::markTestSkipped(),$this->markTestSkipped(),markTestIncomplete(),fail(),throw, and conditional skipping.vendor/bin/phpunit tests/Rules/PHPUnit/ShouldCallParentMethodsRuleTest.phppasses.vendor/bin/phpstan analyse -c phpstan.neonpasses with 0 errors.phpcs) and parallel-lint pass.Closes #292
AI was used to write this code.