13
13
14
14
use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
15
15
use Symfony \UX \LiveComponent \LiveComponentHydrator ;
16
+ use Symfony \UX \LiveComponent \Tests \ContainerBC ;
16
17
use Symfony \UX \LiveComponent \Tests \Fixture \Component \Component1 ;
17
18
use Symfony \UX \LiveComponent \Tests \Fixture \Component \Component2 ;
18
19
use Symfony \UX \LiveComponent \Tests \Fixture \Component \Component3 ;
27
28
*/
28
29
final class LiveComponentHydratorTest extends KernelTestCase
29
30
{
31
+ use ContainerBC;
30
32
use Factories;
31
33
use ResetDatabase;
32
34
33
35
public function testCanDehydrateAndHydrateLiveComponent (): void
34
36
{
35
- self ::bootKernel ();
36
-
37
37
/** @var LiveComponentHydrator $hydrator */
38
- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
38
+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
39
39
40
40
/** @var ComponentFactory $factory */
41
- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
41
+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
42
42
43
43
/** @var Component1 $component */
44
44
$ component = $ factory ->create ('component1 ' , [
@@ -73,13 +73,11 @@ public function testCanDehydrateAndHydrateLiveComponent(): void
73
73
74
74
public function testCanModifyWritableProps (): void
75
75
{
76
- self ::bootKernel ();
77
-
78
76
/** @var LiveComponentHydrator $hydrator */
79
- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
77
+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
80
78
81
79
/** @var ComponentFactory $factory */
82
- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
80
+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
83
81
84
82
/** @var Component1 $component */
85
83
$ component = $ factory ->create ('component1 ' , [
@@ -100,13 +98,11 @@ public function testCanModifyWritableProps(): void
100
98
101
99
public function testCannotModifyReadonlyProps (): void
102
100
{
103
- self ::bootKernel ();
104
-
105
101
/** @var LiveComponentHydrator $hydrator */
106
- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
102
+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
107
103
108
104
/** @var ComponentFactory $factory */
109
- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
105
+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
110
106
111
107
/** @var Component1 $component */
112
108
$ component = $ factory ->create ('component1 ' , [
@@ -126,41 +122,35 @@ public function testCannotModifyReadonlyProps(): void
126
122
127
123
public function testHydrationFailsIfChecksumMissing (): void
128
124
{
129
- self ::bootKernel ();
130
-
131
125
/** @var LiveComponentHydrator $hydrator */
132
- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
126
+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
133
127
134
128
/** @var ComponentFactory $factory */
135
- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
129
+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
136
130
137
131
$ this ->expectException (\RuntimeException::class);
138
132
$ hydrator ->hydrate ($ factory ->get ('component1 ' ), []);
139
133
}
140
134
141
135
public function testHydrationFailsOnChecksumMismatch (): void
142
136
{
143
- self ::bootKernel ();
144
-
145
137
/** @var LiveComponentHydrator $hydrator */
146
- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
138
+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
147
139
148
140
/** @var ComponentFactory $factory */
149
- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
141
+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
150
142
151
143
$ this ->expectException (\RuntimeException::class);
152
144
$ hydrator ->hydrate ($ factory ->get ('component1 ' ), ['_checksum ' => 'invalid ' ]);
153
145
}
154
146
155
147
public function testPreDehydrateAndPostHydrateHooksCalled (): void
156
148
{
157
- self ::bootKernel ();
158
-
159
149
/** @var LiveComponentHydrator $hydrator */
160
- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
150
+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
161
151
162
152
/** @var ComponentFactory $factory */
163
- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
153
+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
164
154
165
155
/** @var Component2 $component */
166
156
$ component = $ factory ->create ('component2 ' );
@@ -187,13 +177,11 @@ public function testPreDehydrateAndPostHydrateHooksCalled(): void
187
177
188
178
public function testDeletingEntityBetweenDehydrationAndHydrationSetsItToNull (): void
189
179
{
190
- self ::bootKernel ();
191
-
192
180
/** @var LiveComponentHydrator $hydrator */
193
- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
181
+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
194
182
195
183
/** @var ComponentFactory $factory */
196
- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
184
+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
197
185
198
186
$ entity = create (Entity1::class);
199
187
@@ -225,13 +213,11 @@ public function testDeletingEntityBetweenDehydrationAndHydrationSetsItToNull():
225
213
226
214
public function testCorrectlyUsesCustomFrontendNameInDehydrateAndHydrate (): void
227
215
{
228
- self ::bootKernel ();
229
-
230
216
/** @var LiveComponentHydrator $hydrator */
231
- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
217
+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
232
218
233
219
/** @var ComponentFactory $factory */
234
- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
220
+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
235
221
236
222
/** @var Component3 $component */
237
223
$ component = $ factory ->create ('component3 ' , ['prop1 ' => 'value1 ' , 'prop2 ' => 'value2 ' ]);
0 commit comments