Repository navigation
test: keep the test suite clean under PHPStan 2.3 - #283
Merged
Merged
Conversation
PHPStan 2.3 folds more constants through loops and casts: the nested iteration count of the get-iterator scenario and the property snapshot of the resolution-handlers test read as constant on the first iteration, which made their guards look always-true and the loops look endless, and an ArrayObject built without a type reads as holding nothing. - the scenario compares the nested iteration count with the item count of the iterated instance instead of a literal; - the resolution-handlers test asserts the snapshot with assertSame() instead of a guard ending the loop with fail(); - the error-callback test declares the element type of its log. No behaviour of the tests changes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLQcsvgdQUzwBFsoKUAcG2
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.
What this changes
The
PHPStan (level max)job is red on the version branches since PHPStan 2.3.1 was released (the lock file is not committed, so CI resolves the newest release): five findings in test code that was analysed clean by 2.2. PHPStan 2.3 folds more constants through loops and casts, sotests/Memory/scenarios/get-iterator-hook.phpthe nested iteration count read as a constant other than 3 on the first iteration, which made the guard always true and everything after the loop unreachable: the scenario now compares the count withcount($iterable->items);ReflectionClassResolutionHandlersTest::testGetPropertiesHandlerReflectsCurrentObjectState()the(array)snapshot of the proxy read as the constant assigned just before, so the guard ending the loop withfail()looked always taken: the loop asserts withassertSame()instead;ErrorCallbackHookTestanArrayObjectbuilt without a type read as holding nothing: the log declares its element type and the entry is asserted non-null before its keys are read.No behaviour of the tests changes. Verified with PHPStan 2.3.1 on PHP 8.4.19 (
composer phpstangreen,cs:checkgreen, the touched tests pass).The same commit is cherry-picked into #282 (
8.5) andfeature/redefine-preserve-alias-8.4, where the red check surfaced.Environment it was verified on
php -v): PHP 8.4.19 (cli) (built: Oct 10 2026) (NTS)--enable-debug)? noChecklist
master= newestsupported minor,
8.4= PHP 8.4, …) — fixes cascade upward, neverdownward
composer testpasses on the matching PHP minor (the touched tests;ExecutionDataTest::testGetThisaborts the full run on this PHP 8.4.19 build independently of this change, see feat(reflection): preserve the previous body of redefine() under an alias and accept method donors #282 for the note)composer phpstan(level max) andcomposer cs:checkare greenlayout_structsintools/generator/symbols.php(no struct access changed)tools/generator/symbols.phpchanged: regenerated withcomposer gen-headersand committed the result — nothing underinclude/,stubs/or.phpstorm.meta.phpwas hand-edited (unchanged)🤖 Generated with Claude Code
https://claude.ai/code/session_01VLQcsvgdQUzwBFsoKUAcG2
Generated by Claude Code