Repository navigation
[PHPUnit60] Follow parent::test() calls in AddDoesNotPerformAssertionToNonAssertingTestRector - #826
Merged
TomasVotruba merged 1 commit intoNov 14, 2026
Conversation
…ToNonAssertingTestRector (rectorphp/rector#9965) "parent::test()" was not resolved, as "parent" is a union of all ancestors in the type resolver. Resolve it to the direct parent class of the current class instead. The containsAssertCall() cache key now includes the name of the class owning the method. Identical bodies ("parent::test()" or "$this->helper()") can mean different things per class, so sibling classes sharing a cache entry could get a wrong result. This also fixes a false positive that already happens without the parent:: change, see the sibling_classes_with_same_helper_body fixture. PHPUnit\Framework\TestCase itself is never resolved as a parent, it has no asserting test methods and is slow to parse.
Member
|
Lets ship it, 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.
Part of rectorphp/rector#9965, split from #822 as requested. The
expectUserDeprecationMessage()part is already in #825.AddDoesNotPerformAssertionToNonAssertingTestRectoradds#[DoesNotPerformAssertions]to tests that only call the parent test:With
failOnRiskythat test then fails with "This test is not expected to perform assertions but performed 1 assertion".Change
parent::test()is resolved to the direct parent class of the current class. The type resolver gives a union of all ancestors forparent, so the call was never followed.PHPUnit\Framework\TestCaseis never resolved as a parent: it has no asserting test methods and is slow to parse.containsAssertCall()cache key now includes the name of the class owning the method. Identical bodies (parent::test(), but also$this->helper()) can mean different things per class. This also fixes a false positive that already happens onmain: two sibling classes with the same$this->helper();body but different helpers shared a cache entry (sibling_classes_with_same_helper_bodyfixture).Bench
bench/does_not_perform_assertion_lifecycle_bench.php(#824), CPU, 3 runs, local ddev PHP 8.5:mainThe extra time is real work: on
maintheparent::calls in the bench were never followed. The class name in the cache key costs part of it too; it is needed for correctness.Tests
New fixtures:
parent_test_call_without_assert,skip_parent_test_call_with_assert,sibling_classes_with_same_helper_body. Full suite, ECS, Rector, class-leak and finalize-classes pass. PHPStan reports the same 6offsetAccess.invalidOffseterrors asmain, in files this PR doesn't touch.Lifecycle hooks (
setUp(),assertPostConditions(),#[Before]...) follow in a separate PR stacked on this one.