Skip to content

Commit

Permalink
[Serializer] Fix unitialized properties (from PHP 7.4.2) when seriali…
Browse files Browse the repository at this point in the history
…zing context for the cache key
  • Loading branch information
alanpoulain authored and fabpot committed Apr 4, 2020
1 parent 5da141b commit 1fafff7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -400,6 +400,7 @@ protected function createChildContext(array $parentContext, $attribute/*, string
*/
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([
Expand Down
Expand Up @@ -163,6 +163,14 @@ public function testDenormalizeStringCollectionDecodedFromXmlWithTwoChildren()
$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();
Expand Down Expand Up @@ -379,3 +387,15 @@ public function setSerializer(SerializerInterface $serializer)
$this->serializer = $serializer;
}
}

class NotSerializable
{
public function __sleep()
{
if (class_exists(\Error::class)) {
throw new \Error('not serializable');
}

throw new \Exception('not serializable');
}
}

0 comments on commit 1fafff7

Please sign in to comment.