From 78f885affcbf2d1a99392b3ae6855f9ef8d6b8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Nork=C5=ABnas?= Date: Fri, 22 Aug 2025 15:14:28 +0300 Subject: [PATCH] [LiveComponent] Fix BC Break --- .../Metadata/LiveComponentMetadataFactory.php | 9 +++++++-- .../tests/Fixtures/Dto/DummyUsingPhpDoc.php | 15 +++++++++++++++ .../tests/Fixtures/Enum/ColorEnum.php | 9 +++++++++ .../Integration/LiveComponentHydratorTest.php | 18 ++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/LiveComponent/tests/Fixtures/Dto/DummyUsingPhpDoc.php create mode 100644 src/LiveComponent/tests/Fixtures/Enum/ColorEnum.php diff --git a/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php b/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php index 1e76ca4c7cc..916963f924f 100644 --- a/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php +++ b/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php @@ -13,6 +13,7 @@ use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; use Symfony\Component\PropertyInfo\Type as LegacyType; +use Symfony\Component\TypeInfo\Exception\UnsupportedException; use Symfony\Component\TypeInfo\Type; use Symfony\Component\TypeInfo\Type\CollectionType; use Symfony\Component\TypeInfo\TypeResolver\TypeResolver; @@ -130,8 +131,12 @@ public function createLivePropMetadata(string $className, string $propertyName, // Otherwise, we can use the TypeResolver to convert the ReflectionType to a Type $type = $this->typeResolver->resolve($reflectionType); } else { - // If no type is available, we default to mixed - $type = Type::mixed(); + try { + $type = $this->typeResolver->resolve($property); + } catch (UnsupportedException) { + // If no type is available, we default to mixed + $type = Type::mixed(); + } } return new LivePropMetadata($property->getName(), $liveProp, $type); diff --git a/src/LiveComponent/tests/Fixtures/Dto/DummyUsingPhpDoc.php b/src/LiveComponent/tests/Fixtures/Dto/DummyUsingPhpDoc.php new file mode 100644 index 00000000000..5c910cb5b03 --- /dev/null +++ b/src/LiveComponent/tests/Fixtures/Dto/DummyUsingPhpDoc.php @@ -0,0 +1,15 @@ + [function () { + $input = new DummyUsingPhpDoc(); + $input->color = ColorEnum::Green; + + return HydrationTest::create(new class { + #[LiveProp] + public DummyUsingPhpDoc $input; + }) + ->mountWith(['input' => $input]) + ->assertDehydratesTo(['input' => ['color' => 'green']]) + ->assertObjectAfterHydration(function (object $object) { + self::assertEquals(ColorEnum::Green, $object->input->color); + }) + ; + }]; } public function testHydrationWithInvalidDate()