Skip to content

test: keep the test suite clean under PHPStan 2.3 - #283

Merged
lisachenko merged 1 commit into
8.4from
fix/phpstan-2.3-test-findings
Oct 10, 2026
Merged

lisachenko merged 1 commit into
8.4from
fix/phpstan-2.3-test-findings

Conversation

@lisachenko

Copy link
Copy Markdown
Owner

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, so

  • in tests/Memory/scenarios/get-iterator-hook.php the 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 with count($iterable->items);
  • in ReflectionClassResolutionHandlersTest::testGetPropertiesHandlerReflectsCurrentObjectState() the (array) snapshot of the proxy read as the constant assigned just before, so the guard ending the loop with fail() looked always taken: the loop asserts with assertSame() instead;
  • in ErrorCallbackHookTest an ArrayObject built 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 phpstan green, cs:check green, the touched tests pass).

The same commit is cherry-picked into #282 (8.5) and feature/redefine-preserve-alias-8.4, where the red check surfaced.

Environment it was verified on

  • PHP version (full first line of php -v): PHP 8.4.19 (cli) (built: Oct 10 2026) (NTS)
  • Thread safety: NTS
  • OS / architecture: Linux x86_64
  • Debug build (--enable-debug)? no

Checklist

  • Targets the minimum affected version branch (master = newest
    supported minor, 8.4 = PHP 8.4, …) — fixes cascade upward, never
    downward
  • composer test passes on the matching PHP minor (the touched tests; ExecutionDataTest::testGetThis aborts 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) and composer cs:check are green
  • Tests added or updated; structs the code dereferences are listed in
    layout_structs in tools/generator/symbols.php (no struct access changed)
  • If tools/generator/symbols.php changed: regenerated with
    composer gen-headers and committed the result — nothing under
    include/, stubs/ or .phpstorm.meta.php was hand-edited (unchanged)
  • Conventional Commits used for the commit messages

🤖 Generated with Claude Code

https://claude.ai/code/session_01VLQcsvgdQUzwBFsoKUAcG2


Generated by Claude Code

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
@lisachenko
lisachenko marked this pull request as ready for review October 10, 2026 16:11
@lisachenko
lisachenko merged commit 37a7d83 into 8.4 Oct 10, 2026
21 checks passed
@lisachenko
lisachenko deleted the fix/phpstan-2.3-test-findings branch October 10, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant