Skip to content

Commit 78f885a

Browse files
committed
[LiveComponent] Fix BC Break
1 parent fc2b792 commit 78f885a

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
1515
use Symfony\Component\PropertyInfo\Type as LegacyType;
16+
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
1617
use Symfony\Component\TypeInfo\Type;
1718
use Symfony\Component\TypeInfo\Type\CollectionType;
1819
use Symfony\Component\TypeInfo\TypeResolver\TypeResolver;
@@ -130,8 +131,12 @@ public function createLivePropMetadata(string $className, string $propertyName,
130131
// Otherwise, we can use the TypeResolver to convert the ReflectionType to a Type
131132
$type = $this->typeResolver->resolve($reflectionType);
132133
} else {
133-
// If no type is available, we default to mixed
134-
$type = Type::mixed();
134+
try {
135+
$type = $this->typeResolver->resolve($property);
136+
} catch (UnsupportedException) {
137+
// If no type is available, we default to mixed
138+
$type = Type::mixed();
139+
}
135140
}
136141

137142
return new LivePropMetadata($property->getName(), $liveProp, $type);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Symfony\UX\LiveComponent\Tests\Fixtures\Dto;
4+
5+
use Symfony\UX\LiveComponent\Attribute\LiveProp;
6+
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\ColorEnum;
7+
8+
class DummyUsingPhpDoc
9+
{
10+
/**
11+
* @var ColorEnum|null
12+
*/
13+
#[LiveProp]
14+
public $color;
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\UX\LiveComponent\Tests\Fixtures\Enum;
4+
5+
enum ColorEnum: string
6+
{
7+
case Green = 'green';
8+
case Red = 'red';
9+
}

src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Address;
2626
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\BlogPostWithSerializationContext;
2727
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\CustomerDetails;
28+
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\DummyUsingPhpDoc;
2829
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Embeddable2;
2930
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\HoldsArrayOfDtos;
3031
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Money;
@@ -38,6 +39,7 @@
3839
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\Entity2;
3940
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ProductFixtureEntity;
4041
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\User;
42+
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\ColorEnum;
4143
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\EmptyStringEnum;
4244
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\IntEnum;
4345
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\StringEnum;
@@ -1521,6 +1523,22 @@ public function modifyDateProp(LiveProp $prop): LiveProp
15211523
})
15221524
;
15231525
}];
1526+
1527+
yield 'Dehydrates correctly with phpdoc typehint' => [function () {
1528+
$input = new DummyUsingPhpDoc();
1529+
$input->color = ColorEnum::Green;
1530+
1531+
return HydrationTest::create(new class {
1532+
#[LiveProp]
1533+
public DummyUsingPhpDoc $input;
1534+
})
1535+
->mountWith(['input' => $input])
1536+
->assertDehydratesTo(['input' => ['color' => 'green']])
1537+
->assertObjectAfterHydration(function (object $object) {
1538+
self::assertEquals(ColorEnum::Green, $object->input->color);
1539+
})
1540+
;
1541+
}];
15241542
}
15251543

15261544
public function testHydrationWithInvalidDate()

0 commit comments

Comments
 (0)