Skip to content

Commit ee49115

Browse files
committed
[LiveComponent] Fix BC break when dealing with entities (implementing an interface) on LiveProp
1 parent bc84475 commit ee49115

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\Entity;
13+
14+
use Doctrine\ORM\Mapping as ORM;
15+
use Symfony\Component\Security\Core\User\UserInterface;
16+
17+
#[ORM\Entity]
18+
class User implements UserInterface
19+
{
20+
#[ORM\Id]
21+
#[ORM\GeneratedValue]
22+
#[ORM\Column(type: 'integer')]
23+
public $id;
24+
25+
26+
public function getRoles(): array
27+
{
28+
return ['ROLE_USER'];
29+
}
30+
31+
public function eraseCredentials(): void
32+
{
33+
// no-op
34+
}
35+
36+
public function getUsername(): string
37+
{
38+
return $this->getUserIdentifier();
39+
}
40+
41+
public function getUserIdentifier(): string
42+
{
43+
return (string) $this->id;
44+
}
45+
46+
public function getPassword(): ?string
47+
{
48+
return null;
49+
}
50+
51+
public function getSalt(): ?string
52+
{
53+
return null;
54+
}
55+
}

src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\Entity1;
3838
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\Entity2;
3939
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ProductFixtureEntity;
40+
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\User;
4041
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\EmptyStringEnum;
4142
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\IntEnum;
4243
use Symfony\UX\LiveComponent\Tests\Fixtures\Enum\StringEnum;
@@ -336,6 +337,25 @@ public function onEntireEntityUpdated($oldValue)
336337
;
337338
}];
338339

340+
yield 'Persisted entity: (de)hydration works correctly to/from id, when the entity implements an interface' => [function () {
341+
$user = persist(User::class);
342+
\assert($user instanceof User);
343+
344+
return HydrationTest::create(new class {
345+
#[LiveProp]
346+
public User $user;
347+
})
348+
->mountWith(['user' => $user])
349+
->assertDehydratesTo(['user' => $user->id])
350+
->assertObjectAfterHydration(function (object $object) use ($user) {
351+
self::assertSame(
352+
$user->id,
353+
$object->user->id
354+
);
355+
})
356+
;
357+
}];
358+
339359
yield 'Persisted entity: writable CAN be changed via id' => [function () {
340360
$entityOriginal = persist(Entity1::class);
341361
$entityNext = persist(Entity1::class);

0 commit comments

Comments
 (0)