[Serializer] Fix configuration of the cache key
This commit is contained in:
parent
df3ab767dd
commit
3b034cb343
@ -115,7 +115,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
throw new InvalidArgumentException(sprintf('The "%s" given in the default context is not callable.', self::MAX_DEPTH_HANDLER));
|
||||
}
|
||||
|
||||
$this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] = [self::CIRCULAR_REFERENCE_LIMIT_COUNTERS];
|
||||
$this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] = array_merge($this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] ?? [], [self::CIRCULAR_REFERENCE_LIMIT_COUNTERS]);
|
||||
|
||||
$this->propertyTypeExtractor = $propertyTypeExtractor;
|
||||
|
||||
@ -360,7 +360,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
try {
|
||||
$this->setAttributeValue($object, $attribute, $value, $format, $context);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": ', $attribute, $type).$e->getMessage(), $e->getCode(), $e);
|
||||
throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": '.$e->getMessage(), $attribute, $type), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -741,6 +741,17 @@ class ObjectNormalizerTest extends TestCase
|
||||
}]));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]);
|
||||
}
|
||||
};
|
||||
$normalizer->normalize(new ObjectDummy());
|
||||
}
|
||||
|
||||
public function testThrowUnexpectedValueException()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException');
|
||||
|
Reference in New Issue
Block a user