From 4c0316eb3f9f71845df40c8bbbcbb3ce5f1c8af2 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Sat, 10 Oct 2026 01:42:07 +0000 Subject: [PATCH] test: keep the test suite clean under PHPStan 2.3 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 Claude-Session: https://claude.ai/code/session_01VLQcsvgdQUzwBFsoKUAcG2 --- tests/Memory/scenarios/get-iterator-hook.php | 2 +- tests/Reflection/ReflectionClassResolutionHandlersTest.php | 4 +--- tests/System/Hook/ErrorCallbackHookTest.php | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Memory/scenarios/get-iterator-hook.php b/tests/Memory/scenarios/get-iterator-hook.php index 1d88383f..bd7dbc4e 100644 --- a/tests/Memory/scenarios/get-iterator-hook.php +++ b/tests/Memory/scenarios/get-iterator-hook.php @@ -57,7 +57,7 @@ } break; // and break out of the outer loop with the inner one completed } - if ($count !== 3) { + if ($count !== count($iterable->items)) { throw new RuntimeException('Unexpected nested iteration count'); } diff --git a/tests/Reflection/ReflectionClassResolutionHandlersTest.php b/tests/Reflection/ReflectionClassResolutionHandlersTest.php index 4748a007..778272d8 100644 --- a/tests/Reflection/ReflectionClassResolutionHandlersTest.php +++ b/tests/Reflection/ReflectionClassResolutionHandlersTest.php @@ -211,9 +211,7 @@ public function testGetPropertiesHandlerReflectsCurrentObjectState(): void // Stress the rebuild path: every iteration replaces the anchored table for ($index = 0; $index < 1000; $index++) { $proxy->subject = "value{$index}"; - if (self::propertySnapshot($proxy)['subject'] !== "value{$index}") { - self::fail('Unexpected property table snapshot'); - } + $this->assertSame("value{$index}", self::propertySnapshot($proxy)['subject'], 'Unexpected property table snapshot'); } } diff --git a/tests/System/Hook/ErrorCallbackHookTest.php b/tests/System/Hook/ErrorCallbackHookTest.php index 5ff81013..5abed7a5 100644 --- a/tests/System/Hook/ErrorCallbackHookTest.php +++ b/tests/System/Hook/ErrorCallbackHookTest.php @@ -27,6 +27,7 @@ final class ErrorCallbackHookTest extends TestCase { public function testHandlerObservesDiagnosticAndProceedsToEngineDefault(): void { + /** @var ArrayObject $log */ $log = new ArrayObject(); $hook = Core::setErrorCallbackHandler(function (ErrorCallbackHook $hook) use ($log): void { $log->append([ @@ -48,8 +49,8 @@ public function testHandlerObservesDiagnosticAndProceedsToEngineDefault(): void @trigger_error('observable diagnostic', E_USER_WARNING); $this->assertCount(1, $log); - /** @var array{type: int, file: string, line: int, message: string} $entry */ $entry = $log[0]; + $this->assertNotNull($entry); $this->assertSame(E_USER_WARNING, $entry['type']); $this->assertSame(__FILE__, $entry['file']); $this->assertSame($expectedLine, $entry['line']);