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.'); + } ); }