Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [Serializer] Remove TranslatableNormalizer service when the Translator is disabled
  Fix support to denormalize plain object types
  [Routing] Restore aliases removal in RouteCollection::remove()
  [Workflow] Add `getEnabledTransition()` to TraceableWorkflow
  [DependencyInjection] Fix parsing named autowiring aliases that contain underscores
  [Console] Add Les-Tilleuls.coop as sponsor of version 6.4/7.0
  remove duplicated service definition
  • Loading branch information
nicolas-grekas committed Dec 1, 2023
2 parents 73f72b1 + 7ead272 commit 9c8f67c
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 @@ -520,7 +520,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 @@ -121,6 +121,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 @@ -1109,6 +1120,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 9c8f67c

Please sign in to comment.