diff --git a/Tests/Normalizer/AbstractObjectNormalizerTest.php b/Tests/Normalizer/AbstractObjectNormalizerTest.php index c90ec1185..78046229e 100644 --- a/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -724,6 +724,27 @@ public function testNormalizeUsesContextAttributeForProperties() $this->assertSame(['propertyWithoutNullSkipNullValues' => 'foo'], $data); } + + public function testDefaultExcludeFromCacheKey() + { + $object = new DummyChild(); + $object->bar = 'not called'; + + $normalizer = new class(null, null, null, null, null, [AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY => ['foo']]) extends AbstractObjectNormalizerDummy { + public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool + { + AbstractObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]); + $data->bar = 'called'; + + return true; + } + }; + + $serializer = new Serializer([$normalizer]); + $serializer->normalize($object); + + $this->assertSame('called', $object->bar); + } } class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer diff --git a/Tests/Normalizer/ObjectNormalizerTest.php b/Tests/Normalizer/ObjectNormalizerTest.php index 5eba0707c..d87b7a67a 100644 --- a/Tests/Normalizer/ObjectNormalizerTest.php +++ b/Tests/Normalizer/ObjectNormalizerTest.php @@ -680,19 +680,6 @@ public function testNormalizeNotSerializableContext() }])); } - public function testDefaultExcludeFromCacheKey() - { - $normalizer = new class(null, null, null, null, null, null, [ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY => ['foo']]) extends ObjectNormalizer { - protected function isCircularReference($object, &$context): bool - { - ObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]); - - return false; - } - }; - $normalizer->normalize(new ObjectDummy()); - } - public function testThrowUnexpectedValueException() { $this->expectException(UnexpectedValueException::class);