Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4:
  fix merge
  Require PHPUnit 9.3 on PHP 8
  [Cache] fix catching auth errors
  Fix CS
  [FrameworkBundle] set default session.handler alias if handler_id is not provided
  Fix CS
  Readability update
  Fix checks for phpunit releases on Composer 2 (resolves #37601)
  [Serializer] Support multiple levels of discriminator mapping
  Use hexadecimal numerals instead of hexadecimals in strings to represent error codes.
  [SCA] Minor fixes on tests
  [WebProfilerBundle] modified url generation to use absolute urls
  [Mailer] Fix reply-to functionality in the SendgridApiTransport
  [Mime] Fix compat with HTTP requests
  ticket_36879 - Fix mandrill raw http request setting from email/name
  • Loading branch information
nicolas-grekas committed Jul 23, 2020
2 parents e63119d + 0fe47b7 commit 825b66f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Normalizer/AbstractObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ protected function instantiateObject(array &$data, string $class, array &$contex
throw new RuntimeException(sprintf('The type "%s" has no mapped class for the abstract object "%s".', $type, $class));
}

$class = $mappedClass;
$reflectionClass = new \ReflectionClass($class);
if ($mappedClass !== $class) {
return $this->instantiateObject($data, $mappedClass, $context, new \ReflectionClass($mappedClass), $allowedAttributes, $format);
}
}

return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format);
Expand Down
38 changes: 38 additions & 0 deletions Tests/Normalizer/AbstractObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
Expand Down Expand Up @@ -235,6 +236,43 @@ public function hasMetadataFor($value): bool
$this->assertInstanceOf(DummySecondChildQuux::class, $normalizedData->quux);
}

public function testDenormalizeWithNestedDiscriminatorMap()
{
$classDiscriminatorResolver = new class() implements ClassDiscriminatorResolverInterface {
public function getMappingForClass(string $class): ?ClassDiscriminatorMapping
{
switch ($class) {
case AbstractDummy::class:
return new ClassDiscriminatorMapping('type', [
'foo' => AbstractDummyFirstChild::class,
]);
case AbstractDummyFirstChild::class:
return new ClassDiscriminatorMapping('nested_type', [
'bar' => AbstractDummySecondChild::class,
]);
default:
return null;
}
}

public function getMappingForMappedObject($object): ?ClassDiscriminatorMapping
{
return null;
}

public function getTypeForMappedObject($object): ?string
{
return null;
}
};

$normalizer = new AbstractObjectNormalizerDummy(null, null, null, $classDiscriminatorResolver);

$denormalizedData = $normalizer->denormalize(['type' => 'foo', 'nested_type' => 'bar'], AbstractDummy::class);

$this->assertInstanceOf(AbstractDummySecondChild::class, $denormalizedData);
}

/**
* Test that additional attributes throw an exception if no metadata factory is specified.
*/
Expand Down

0 comments on commit 825b66f

Please sign in to comment.