-
-
Notifications
You must be signed in to change notification settings - Fork 398
[LiveComponent] Support for liveProp union type #3150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.x
Are you sure you want to change the base?
Changes from all commits
49fa189
1c92999
a40abae
d85f292
2da2c11
afef986
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <fabien@symfony.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\UX\LiveComponent\Tests\Fixtures\Component; | ||
|
|
||
| use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; | ||
| use Symfony\UX\LiveComponent\Attribute\LiveProp; | ||
| use Symfony\UX\LiveComponent\DefaultActionTrait; | ||
| use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\IntEnum; | ||
| use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\ZeroIntEnum; | ||
|
|
||
| #[AsLiveComponent('with_union_intersection_type')] | ||
| final class WithUnionIntersectionType | ||
| { | ||
| use DefaultActionTrait; | ||
|
|
||
| #[LiveProp] | ||
| public int|float|null $unionProp = null; | ||
|
|
||
| #[LiveProp] | ||
| public IntEnum&ZeroIntEnum $intersectionProp; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadataFactory; | ||
| use Symfony\UX\LiveComponent\Metadata\UrlMapping; | ||
| use Symfony\UX\LiveComponent\Tests\Fixtures\Component\ComponentWithUrlBoundProps; | ||
| use Symfony\UX\LiveComponent\Tests\Fixtures\Component\WithUnionIntersectionType; | ||
|
|
||
| class LiveComponentMetadataFactoryTest extends KernelTestCase | ||
| { | ||
|
|
@@ -42,4 +43,21 @@ public function testQueryStringMapping() | |
| $this->assertEquals(new UrlMapping(as: 'q'), $propsMetadataByName['boundPropWithAlias']->urlMapping()); | ||
| $this->assertNotNull($propsMetadataByName['boundPropWithCustomAlias']); | ||
| } | ||
|
|
||
| public function testLivePropUnionType() | ||
| { | ||
| /** @var LiveComponentMetadataFactory $metadataFactory */ | ||
| $metadataFactory = self::getContainer()->get('ux.live_component.metadata_factory'); | ||
|
|
||
| $class = new \ReflectionClass(WithUnionIntersectionType::class); | ||
| $propsMetadata = $metadataFactory->createPropMetadatas($class); | ||
|
|
||
| $propsMetadataByName = []; | ||
| foreach ($propsMetadata as $propMetadata) { | ||
| $propsMetadataByName[$propMetadata->getName()] = $propMetadata; | ||
| } | ||
|
|
||
| $this->assertEquals('mixed', (string) $propsMetadataByName['unionProp']->getType()); | ||
| $this->assertEquals('mixed', (string) $propsMetadataByName['intersectionProp']->getType()); | ||
| } | ||
|
Comment on lines
+47
to
+62
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it makes sense to have this test |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1636,6 +1636,23 @@ public function testInterfaceTypedLivePropCannotBeDehydrated() | |
| $this->hydrator()->dehydrate($component, $this->createComponentAttributes(), $this->createLiveMetadata($component)); | ||
| } | ||
|
|
||
| public function testObjectTypedLivePropCannotBeDehydrated() | ||
| { | ||
| $componentClass = new class { | ||
| #[LiveProp(writable: true)] | ||
| public object $object; | ||
| }; | ||
|
|
||
| $component = new $componentClass(); | ||
| $component->object = new class { | ||
| }; | ||
|
|
||
| $this->expectException(\LogicException::class); | ||
| $this->expectExceptionMessageMatches('/The "object" property on component ".*" is missing its property-type. Add the ".*" type so the object can be hydrated later./'); | ||
|
|
||
| $this->hydrator()->dehydrate($component, $this->createComponentAttributes(), $this->createLiveMetadata($component)); | ||
| } | ||
|
Comment on lines
+1639
to
+1654
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To move in |
||
|
|
||
| /** | ||
| * @dataProvider provideInvalidHydrationTests | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we use
Type::mixed()here, instead of$this->typeResolver->resolve($property)below?