[Serializer] Fix unitialized properties (from PHP 7.4.2) when serializing context for the cache key
This commit is contained in:
parent
5da141b8d0
commit
1fafff7c10
@ -400,6 +400,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
*/
|
||||
private function getCacheKey($format, array $context)
|
||||
{
|
||||
unset($context[self::OBJECT_TO_POPULATE]);
|
||||
unset($context['cache_key']); // avoid artificially different keys
|
||||
try {
|
||||
return md5($format.serialize([
|
||||
|
@ -163,6 +163,14 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
$this->assertEquals('bar', $stringCollection->children[1]);
|
||||
}
|
||||
|
||||
public function testDenormalizeNotSerializableObjectToPopulate()
|
||||
{
|
||||
$normalizer = new AbstractObjectNormalizerDummy();
|
||||
$normalizedData = $normalizer->denormalize(['foo' => 'foo'], Dummy::class, null, [AbstractObjectNormalizer::OBJECT_TO_POPULATE => new NotSerializable()]);
|
||||
|
||||
$this->assertSame('foo', $normalizedData->foo);
|
||||
}
|
||||
|
||||
private function getDenormalizerForStringCollection()
|
||||
{
|
||||
$extractor = $this->getMockBuilder(PhpDocExtractor::class)->getMock();
|
||||
@ -379,3 +387,15 @@ class ArrayDenormalizerDummy implements DenormalizerInterface, SerializerAwareIn
|
||||
$this->serializer = $serializer;
|
||||
}
|
||||
}
|
||||
|
||||
class NotSerializable
|
||||
{
|
||||
public function __sleep()
|
||||
{
|
||||
if (class_exists(\Error::class)) {
|
||||
throw new \Error('not serializable');
|
||||
}
|
||||
|
||||
throw new \Exception('not serializable');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user