Skip to content

Commit d85f292

Browse files
committed
Fix LiveComponentMetadataFactoryTest testLivePropUnionType
1 parent a40abae commit d85f292

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ public function createPropMetadatas(\ReflectionClass $class): array
8383
public function createLivePropMetadata(string $className, string $propertyName, \ReflectionProperty $property, LiveProp $liveProp): LivePropMetadata|LegacyLivePropMetadata
8484
{
8585
$reflectionType = $property->getType();
86-
if ($reflectionType instanceof \ReflectionUnionType || $reflectionType instanceof \ReflectionIntersectionType) {
87-
return new LivePropMetadata($property->getName(), $liveProp, Type::mixed());
88-
}
8986

9087
// BC layer when "symfony/type-info" is not available
9188
if (!method_exists($this->propertyTypeExtractor, 'getType')) {
89+
if ($reflectionType instanceof \ReflectionUnionType || $reflectionType instanceof \ReflectionIntersectionType) {
90+
return new LegacyLivePropMetadata($property->getName(), $liveProp, 'mixed', true, $reflectionType->allowsNull(), null);
91+
}
92+
9293
$infoTypes = $this->propertyTypeExtractor->getTypes($className, $propertyName) ?? [];
9394

9495
$collectionValueType = null;
@@ -122,6 +123,10 @@ public function createLivePropMetadata(string $className, string $propertyName,
122123
$collectionValueType
123124
);
124125
} else {
126+
if ($reflectionType instanceof \ReflectionUnionType || $reflectionType instanceof \ReflectionIntersectionType) {
127+
return new LivePropMetadata($property->getName(), $liveProp, Type::mixed());
128+
}
129+
125130
$infoType = $this->propertyTypeExtractor->getType($className, $property->getName());
126131

127132
if ($infoType instanceof CollectionType) {

src/LiveComponent/tests/Fixtures/Component/WithUnionType.php renamed to src/LiveComponent/tests/Fixtures/Component/WithUnionIntersectionType.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
1515
use Symfony\UX\LiveComponent\Attribute\LiveProp;
1616
use Symfony\UX\LiveComponent\DefaultActionTrait;
17+
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\IntEnum;
18+
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\ZeroIntEnum;
1719

18-
#[AsLiveComponent('with_union_type')]
19-
final class WithUnionType
20+
#[AsLiveComponent('with_union_intersection_type')]
21+
final class WithUnionIntersectionType
2022
{
2123
use DefaultActionTrait;
2224

2325
#[LiveProp]
2426
public int|float|null $unionProp = null;
27+
28+
#[LiveProp]
29+
public IntEnum&ZeroIntEnum $intersectionProp;
2530
}

src/LiveComponent/tests/Functional/Metadata/LiveComponentMetadataFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
namespace Symfony\UX\LiveComponent\Tests\Functional\Metadata;
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
15-
use Symfony\Component\TypeInfo\Type;
1615
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadataFactory;
1716
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
1817
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\ComponentWithUrlBoundProps;
19-
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\WithUnionType;
18+
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\WithUnionIntersectionType;
2019

2120
class LiveComponentMetadataFactoryTest extends KernelTestCase
2221
{
@@ -50,14 +49,15 @@ public function testLivePropUnionType()
5049
/** @var LiveComponentMetadataFactory $metadataFactory */
5150
$metadataFactory = self::getContainer()->get('ux.live_component.metadata_factory');
5251

53-
$class = new \ReflectionClass(WithUnionType::class);
52+
$class = new \ReflectionClass(WithUnionIntersectionType::class);
5453
$propsMetadata = $metadataFactory->createPropMetadatas($class);
5554

5655
$propsMetadataByName = [];
5756
foreach ($propsMetadata as $propMetadata) {
5857
$propsMetadataByName[$propMetadata->getName()] = $propMetadata;
5958
}
6059

61-
$this->assertEquals(Type::mixed(), $propsMetadataByName['unionProp']->getType());
60+
$this->assertEquals('mixed', (string)$propsMetadataByName['unionProp']->getType());
61+
$this->assertEquals('mixed', (string)$propsMetadataByName['intersectionProp']->getType());
6262
}
6363
}

0 commit comments

Comments
 (0)