File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 37
37
use Symfony \UX \LiveComponent \Tests \Fixtures \Entity \Entity1 ;
38
38
use Symfony \UX \LiveComponent \Tests \Fixtures \Entity \Entity2 ;
39
39
use Symfony \UX \LiveComponent \Tests \Fixtures \Entity \ProductFixtureEntity ;
40
+ use Symfony \UX \LiveComponent \Tests \Fixtures \Entity \User ;
40
41
use Symfony \UX \LiveComponent \Tests \Fixtures \Enum \EmptyStringEnum ;
41
42
use Symfony \UX \LiveComponent \Tests \Fixtures \Enum \IntEnum ;
42
43
use Symfony \UX \LiveComponent \Tests \Fixtures \Enum \StringEnum ;
@@ -336,6 +337,25 @@ public function onEntireEntityUpdated($oldValue)
336
337
;
337
338
}];
338
339
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
+
339
359
yield 'Persisted entity: writable CAN be changed via id ' => [function () {
340
360
$ entityOriginal = persist (Entity1::class);
341
361
$ entityNext = persist (Entity1::class);
You can’t perform that action at this time.
0 commit comments