File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed
Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -255,9 +255,14 @@ private function getComponentProperties(ComponentMetadata $metadata): array
255255 $ propertyName = $ property ->getName ();
256256
257257 if ($ metadata ->isPublicPropsExposed () && $ property ->isPublic ()) {
258- $ visibility = $ property ->getType ()?->getName();
258+ $ type = $ property ->getType ();
259+ if ($ type instanceof \ReflectionNamedType) {
260+ $ typeName = $ type ->getName ();
261+ } else {
262+ $ typeName = (string ) $ type ;
263+ }
259264 $ value = $ property ->getDefaultValue ();
260- $ propertyDisplay = $ visibility .' $ ' .$ propertyName .(null !== $ value ? ' = ' .json_encode ($ value ) : '' );
265+ $ propertyDisplay = $ typeName .' $ ' .$ propertyName .(null !== $ value ? ' = ' .json_encode ($ value ) : '' );
261266 $ properties [$ property ->name ] = $ propertyDisplay ;
262267 }
263268
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Symfony \UX \TwigComponent \Tests \Fixtures \Component ;
4+
5+ use Symfony \UX \TwigComponent \Attribute \AsTwigComponent ;
6+
7+ #[AsTwigComponent(name: 'union_type_props ' , exposePublicProps: true )]
8+ final class UnionTypeProps
9+ {
10+ public string |bool $ prop1 ;
11+ }
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ public function testWithAnonymousComponent(): void
141141 $ this ->assertStringContainsString ('primary = true ' , $ display );
142142 }
143143
144- public function testWithoutPublicPros (): void
144+ public function testWithoutPublicProps (): void
145145 {
146146 $ commandTester = $ this ->createCommandTester ();
147147 $ commandTester ->execute (['name ' => 'no_public_props ' ]);
@@ -173,6 +173,20 @@ public function testWithExposedVariables(): void
173173 $ this ->assertStringNotContainsString ('prop3 ' , $ display );
174174 }
175175
176+ public function testWithUnionTypeProps (): void
177+ {
178+ $ commandTester = $ this ->createCommandTester ();
179+ $ commandTester ->execute (['name ' => 'union_type_props ' ]);
180+
181+ $ commandTester ->assertCommandIsSuccessful ();
182+
183+ $ display = $ commandTester ->getDisplay ();
184+
185+ $ this ->tableDisplayCheck ($ display );
186+ $ this ->assertStringContainsString ('string|bool ' , $ display );
187+ $ this ->assertStringContainsString ('prop1 ' , $ display );
188+ }
189+
176190 private function createCommandTester (): CommandTester
177191 {
178192 $ kernel = self ::bootKernel ();
You can’t perform that action at this time.
0 commit comments