Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/LiveComponent/tests/Fixtures/Dto/DummyUsingPhpDoc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Symfony\UX\LiveComponent\Tests\Fixtures\Dto;

use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\ColorEnum;

class DummyUsingPhpDoc
{
/**
* @var ColorEnum|null
*/
#[LiveProp]
public $color;
}
9 changes: 9 additions & 0 deletions src/LiveComponent/tests/Fixtures/Enum/ColorEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Symfony\UX\LiveComponent\Tests\Fixtures\Enum;

enum ColorEnum: string
{
case Green = 'green';
case Red = 'red';
}
18 changes: 18 additions & 0 deletions src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Address;
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\BlogPostWithSerializationContext;
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\CustomerDetails;
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\DummyUsingPhpDoc;
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Embeddable2;
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\HoldsArrayOfDtos;
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Money;
Expand All @@ -38,6 +39,7 @@
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\Entity2;
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ProductFixtureEntity;
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\User;
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\ColorEnum;
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\EmptyStringEnum;
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\IntEnum;
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\StringEnum;
Expand Down Expand Up @@ -1521,6 +1523,22 @@ public function modifyDateProp(LiveProp $prop): LiveProp
})
;
}];

yield 'Dehydrates correctly with phpdoc typehint' => [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()
Expand Down
Loading