1313
1414use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
1515use Symfony \UX \LiveComponent \LiveComponentHydrator ;
16+ use Symfony \UX \LiveComponent \Tests \ContainerBC ;
1617use Symfony \UX \LiveComponent \Tests \Fixture \Component \Component1 ;
1718use Symfony \UX \LiveComponent \Tests \Fixture \Component \Component2 ;
1819use Symfony \UX \LiveComponent \Tests \Fixture \Component \Component3 ;
2728 */
2829final class LiveComponentHydratorTest extends KernelTestCase
2930{
31+ use ContainerBC;
3032 use Factories;
3133 use ResetDatabase;
3234
3335 public function testCanDehydrateAndHydrateLiveComponent (): void
3436 {
35- self ::bootKernel ();
36-
3737 /** @var LiveComponentHydrator $hydrator */
38- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
38+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
3939
4040 /** @var ComponentFactory $factory */
41- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
41+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
4242
4343 /** @var Component1 $component */
4444 $ component = $ factory ->create ('component1 ' , [
@@ -73,13 +73,11 @@ public function testCanDehydrateAndHydrateLiveComponent(): void
7373
7474 public function testCanModifyWritableProps (): void
7575 {
76- self ::bootKernel ();
77-
7876 /** @var LiveComponentHydrator $hydrator */
79- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
77+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
8078
8179 /** @var ComponentFactory $factory */
82- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
80+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
8381
8482 /** @var Component1 $component */
8583 $ component = $ factory ->create ('component1 ' , [
@@ -100,13 +98,11 @@ public function testCanModifyWritableProps(): void
10098
10199 public function testCannotModifyReadonlyProps (): void
102100 {
103- self ::bootKernel ();
104-
105101 /** @var LiveComponentHydrator $hydrator */
106- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
102+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
107103
108104 /** @var ComponentFactory $factory */
109- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
105+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
110106
111107 /** @var Component1 $component */
112108 $ component = $ factory ->create ('component1 ' , [
@@ -126,41 +122,35 @@ public function testCannotModifyReadonlyProps(): void
126122
127123 public function testHydrationFailsIfChecksumMissing (): void
128124 {
129- self ::bootKernel ();
130-
131125 /** @var LiveComponentHydrator $hydrator */
132- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
126+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
133127
134128 /** @var ComponentFactory $factory */
135- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
129+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
136130
137131 $ this ->expectException (\RuntimeException::class);
138132 $ hydrator ->hydrate ($ factory ->get ('component1 ' ), []);
139133 }
140134
141135 public function testHydrationFailsOnChecksumMismatch (): void
142136 {
143- self ::bootKernel ();
144-
145137 /** @var LiveComponentHydrator $hydrator */
146- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
138+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
147139
148140 /** @var ComponentFactory $factory */
149- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
141+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
150142
151143 $ this ->expectException (\RuntimeException::class);
152144 $ hydrator ->hydrate ($ factory ->get ('component1 ' ), ['_checksum ' => 'invalid ' ]);
153145 }
154146
155147 public function testPreDehydrateAndPostHydrateHooksCalled (): void
156148 {
157- self ::bootKernel ();
158-
159149 /** @var LiveComponentHydrator $hydrator */
160- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
150+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
161151
162152 /** @var ComponentFactory $factory */
163- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
153+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
164154
165155 /** @var Component2 $component */
166156 $ component = $ factory ->create ('component2 ' );
@@ -187,13 +177,11 @@ public function testPreDehydrateAndPostHydrateHooksCalled(): void
187177
188178 public function testDeletingEntityBetweenDehydrationAndHydrationSetsItToNull (): void
189179 {
190- self ::bootKernel ();
191-
192180 /** @var LiveComponentHydrator $hydrator */
193- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
181+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
194182
195183 /** @var ComponentFactory $factory */
196- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
184+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
197185
198186 $ entity = create (Entity1::class);
199187
@@ -225,13 +213,11 @@ public function testDeletingEntityBetweenDehydrationAndHydrationSetsItToNull():
225213
226214 public function testCorrectlyUsesCustomFrontendNameInDehydrateAndHydrate (): void
227215 {
228- self ::bootKernel ();
229-
230216 /** @var LiveComponentHydrator $hydrator */
231- $ hydrator = self ::$ container ->get ('ux.live_component.component_hydrator ' );
217+ $ hydrator = self ::getContainer () ->get ('ux.live_component.component_hydrator ' );
232218
233219 /** @var ComponentFactory $factory */
234- $ factory = self ::$ container ->get ('ux.twig_component.component_factory ' );
220+ $ factory = self ::getContainer () ->get ('ux.twig_component.component_factory ' );
235221
236222 /** @var Component3 $component */
237223 $ component = $ factory ->create ('component3 ' , ['prop1 ' => 'value1 ' , 'prop2 ' => 'value2 ' ]);
0 commit comments