Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  Fix support to denormalize plain object types
  [Routing] Restore aliases removal in RouteCollection::remove()
  remove duplicated service definition
  • Loading branch information
nicolas-grekas committed Dec 1, 2023
2 parents 87faafc + d751878 commit 6eee0fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Normalizer/AbstractObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private function validateAndDenormalize(array $types, string $currentClass, stri

$expectedTypes[Type::BUILTIN_TYPE_OBJECT === $builtinType && $class ? $class : $builtinType] = true;

if (Type::BUILTIN_TYPE_OBJECT === $builtinType) {
if (Type::BUILTIN_TYPE_OBJECT === $builtinType && null !== $class) {
if (!$this->serializer instanceof DenormalizerInterface) {
throw new LogicException(sprintf('Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer.', $attribute, $class));
}
Expand Down
17 changes: 17 additions & 0 deletions Tests/Normalizer/AbstractObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory
);
}

public function testDenormalizePlainObject()
{
$extractor = new PhpDocExtractor();
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
$dummy = $normalizer->denormalize(['plainObject' => (object) ['foo' => 'bar']], DummyWithPlainObject::class);

$this->assertInstanceOf(DummyWithPlainObject::class, $dummy);
$this->assertInstanceOf(\stdClass::class, $dummy->plainObject);
$this->assertSame('bar', $dummy->plainObject->foo);
}

public function testDenormalizeWithDuplicateNestedAttributes()
{
$this->expectException(LogicException::class);
Expand Down Expand Up @@ -1145,6 +1156,12 @@ protected function setAttributeValue(object $object, string $attribute, $value,
}
}

class DummyWithPlainObject
{
/** @var object */
public $plainObject;
}

class ObjectWithBasicProperties
{
/** @var bool */
Expand Down

0 comments on commit 6eee0fd

Please sign in to comment.