|
12 | 12 | namespace Symfony\UX\LiveComponent\Tests\Integration; |
13 | 13 |
|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
| 15 | +use Symfony\UX\LiveComponent\Attribute\LiveProp; |
15 | 16 | use Symfony\UX\LiveComponent\LiveComponentHydrator; |
16 | 17 | use Symfony\UX\LiveComponent\Tests\ContainerBC; |
17 | 18 | use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component1; |
@@ -239,4 +240,29 @@ public function testCorrectlyUsesCustomFrontendNameInDehydrateAndHydrate(): void |
239 | 240 | $this->assertSame('value1', $component->prop1); |
240 | 241 | $this->assertSame('value2', $component->prop2); |
241 | 242 | } |
| 243 | + |
| 244 | + public function testCanDehydrateAndHydrateArrays(): void |
| 245 | + { |
| 246 | + /** @var LiveComponentHydrator $hydrator */ |
| 247 | + $hydrator = self::getContainer()->get('ux.live_component.component_hydrator'); |
| 248 | + |
| 249 | + $component = new class() { |
| 250 | + #[LiveProp] |
| 251 | + public array $prop; |
| 252 | + }; |
| 253 | + |
| 254 | + $instance = clone $component; |
| 255 | + $instance->prop = ['some', 'array']; |
| 256 | + |
| 257 | + $dehydrated = $hydrator->dehydrate($instance); |
| 258 | + |
| 259 | + $this->assertArrayHasKey('prop', $dehydrated); |
| 260 | + $this->assertSame($instance->prop, $dehydrated['prop']); |
| 261 | + |
| 262 | + $this->assertFalse(isset($component->prop)); |
| 263 | + |
| 264 | + $hydrator->hydrate($component, $dehydrated); |
| 265 | + |
| 266 | + $this->assertSame($instance->prop, $component->prop); |
| 267 | + } |
242 | 268 | } |
0 commit comments