From 6e8b10c61fc2430255856689bf55cfa97702cdce Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 20 Nov 2026 16:44:49 +0100 Subject: [PATCH] Keep the lazy ghost's exceptions alive in the throws fixture Xdebug 3.5.3 caches the stack of each exception by object address and does not clear it when the exception is freed. A later exception allocated at the same address is then reported with the earlier stack. Whether the address is reused depends on the allocator, so local runs credited all four throws of the failing lazy ghost to Lens->get, while CI credits one of them, correctly, to property_is_initialized(). The fixture now keeps every exception it throws, so no two share an address, and the allowlist lists the real call sites. --- tests/Support/Throws/allowed-throws.php | 9 ++++++++- tests/Unit/Encoder/ObjectPropertyPresenceTest.php | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/Support/Throws/allowed-throws.php b/tests/Support/Throws/allowed-throws.php index a62f603..0c34ca8 100644 --- a/tests/Support/Throws/allowed-throws.php +++ b/tests/Support/Throws/allowed-throws.php @@ -11,7 +11,14 @@ 'test' => ObjectPropertyPresenceTest::class.'::optional_property_preserves_absence_null_and_value#lazy object whose initializer throws', 'throw' => RuntimeException::class, 'via' => 'src/Encoder/ObjectEncoder.php -> VeeWee\\Reflecta\\Lens\\Lens->get', - 'throws' => 4, + 'throws' => 3, 'reason' => 'The fixture is a lazy object whose initializer throws on every access the encoder lenses make to it, to prove that the encoder keeps writing xsi:nil for it.', ], + [ + 'test' => ObjectPropertyPresenceTest::class.'::optional_property_preserves_absence_null_and_value#lazy object whose initializer throws', + 'throw' => RuntimeException::class, + 'via' => 'src/Encoder/ObjectEncoder.php -> VeeWee\\Reflecta\\Reflect\\property_is_initialized', + 'throws' => 1, + 'reason' => 'The same lazy object throws again when the encoder checks whether the null note is absent, and property_is_initialized() counts it as present.', + ], ]; diff --git a/tests/Unit/Encoder/ObjectPropertyPresenceTest.php b/tests/Unit/Encoder/ObjectPropertyPresenceTest.php index 7a74ba6..481bb9e 100644 --- a/tests/Unit/Encoder/ObjectPropertyPresenceTest.php +++ b/tests/Unit/Encoder/ObjectPropertyPresenceTest.php @@ -176,8 +176,12 @@ private static function failingLazyObject(): object public ?string $note = null; }; + $thrown = []; + return (new ReflectionClass($class))->newLazyGhost( - static fn (): never => throw new RuntimeException('The initializer fails.') + static function () use (&$thrown): never { + throw $thrown[] = new RuntimeException('The initializer fails.'); + } ); }