Skip to content

Commit a40abae

Browse files
committed
Add LiveComponentMetadataFactory union type test
1 parent 1c92999 commit a40abae

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\LiveComponent\Tests\Fixtures\Component;
13+
14+
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
15+
use Symfony\UX\LiveComponent\Attribute\LiveProp;
16+
use Symfony\UX\LiveComponent\DefaultActionTrait;
17+
18+
#[AsLiveComponent('with_union_type')]
19+
final class WithUnionType
20+
{
21+
use DefaultActionTrait;
22+
23+
#[LiveProp]
24+
public int|float|null $unionProp = null;
25+
}

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

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

1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
15+
use Symfony\Component\TypeInfo\Type;
1516
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadataFactory;
1617
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
1718
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\ComponentWithUrlBoundProps;
19+
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\WithUnionType;
1820

1921
class LiveComponentMetadataFactoryTest extends KernelTestCase
2022
{
@@ -42,4 +44,20 @@ public function testQueryStringMapping()
4244
$this->assertEquals(new UrlMapping(as: 'q'), $propsMetadataByName['boundPropWithAlias']->urlMapping());
4345
$this->assertNotNull($propsMetadataByName['boundPropWithCustomAlias']);
4446
}
47+
48+
public function testLivePropUnionType()
49+
{
50+
/** @var LiveComponentMetadataFactory $metadataFactory */
51+
$metadataFactory = self::getContainer()->get('ux.live_component.metadata_factory');
52+
53+
$class = new \ReflectionClass(WithUnionType::class);
54+
$propsMetadata = $metadataFactory->createPropMetadatas($class);
55+
56+
$propsMetadataByName = [];
57+
foreach ($propsMetadata as $propMetadata) {
58+
$propsMetadataByName[$propMetadata->getName()] = $propMetadata;
59+
}
60+
61+
$this->assertEquals(Type::mixed(), $propsMetadataByName['unionProp']->getType());
62+
}
4563
}

0 commit comments

Comments
 (0)