Skip to content

Commit

Permalink
initialize serializer in trait with null
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Apr 5, 2024
1 parent 524c703 commit dae3726
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/SerializerAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
trait SerializerAwareTrait
{
protected SerializerInterface $serializer;
protected ?SerializerInterface $serializer = null;

public function setSerializer(SerializerInterface $serializer): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,16 @@ public function testSamePropertyAsMethodWithMethodSerializedName()

$this->assertSame($expected, $this->normalizer->normalize($object));
}

public function testNormalizeWithoutSerializerSet()
{
$normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()));

$this->expectException(LogicException::class);
$this->expectExceptionMessage('Cannot normalize attribute "foo" because the injected serializer is not a normalizer.');

$normalizer->normalize(new ObjectConstructorDummy([], [], []));
}
}

class ProxyObjectDummy extends ObjectDummy
Expand Down

0 comments on commit dae3726

Please sign in to comment.