1818use Qossmic \TwigDocBundle \Exception \InvalidComponentConfigurationException ;
1919use Qossmic \TwigDocBundle \Service \CategoryService ;
2020use Qossmic \TwigDocBundle \Tests \TestApp \Entity \Car ;
21+ use Qossmic \TwigDocBundle \Tests \TestApp \Test \ConfigurableContainerTrait ;
2122use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
2223
2324#[CoversClass(ComponentItemFactory::class)]
2930#[UsesClass(NullGenerator::class)]
3031class ComponentItemFactoryTest extends KernelTestCase
3132{
33+ use ConfigurableContainerTrait;
34+
3235 #[DataProvider('getValidComponents ' )]
3336 public function testValidComponent (array $ componentData ): void
3437 {
@@ -115,8 +118,10 @@ public function testFactoryCreatesDefaultVariationWithParameterTypes(): void
115118 ],
116119 ];
117120
121+ $ container = $ this ->createContainer (['twig_doc ' => ['use_fake_parameter ' => true ]]);
122+
118123 /** @var ComponentItemFactory $factory */
119- $ factory = self :: getContainer () ->get ('twig_doc.service.component_factory ' );
124+ $ factory = $ container ->get ('twig_doc.service.component_factory ' );
120125
121126 $ component = $ factory ->create ($ data );
122127
@@ -135,6 +140,40 @@ public function testFactoryCreatesDefaultVariationWithParameterTypes(): void
135140 self ::assertIsFloat ($ component ->getVariations ()['default ' ]['complex ' ]['amount ' ]);
136141 }
137142
143+ public function testCreateObjectParameter (): void
144+ {
145+ $ data = [
146+ 'name ' => 'component ' ,
147+ 'title ' => 'title ' ,
148+ 'description ' => 'description ' ,
149+ 'category ' => 'MainCategory ' ,
150+ 'path ' => 'path ' ,
151+ 'renderPath ' => 'renderPath ' ,
152+ 'parameters ' => [
153+ 'car ' => Car::class,
154+ ],
155+ 'variations ' => [
156+ 'variation1 ' => [
157+ 'car ' => [
158+ 'color ' => 'blue ' ,
159+ ],
160+ ],
161+ 'variation2 ' => [
162+ 'car ' => null ,
163+ ],
164+ ],
165+ ];
166+
167+ $ container = $ this ->createContainer (['twig_doc ' => ['use_fake_parameter ' => true ]]);
168+
169+ /** @var ComponentItemFactory $factory */
170+ $ factory = $ container ->get ('twig_doc.service.component_factory ' );
171+
172+ $ component = $ factory ->create ($ data );
173+
174+ self ::assertInstanceOf (ComponentItem::class, $ component );
175+ }
176+
138177 public function testCreateKeepsParamValueFromVariation (): void
139178 {
140179 $ data = [
@@ -200,11 +239,14 @@ public function testCreateForObjectParameter(): void
200239 static ::assertIsArray ($ variations ['fuchsia ' ]);
201240 static ::assertArrayHasKey ('car ' , $ variations ['fuchsia ' ]);
202241
203- $ car = $ variations ['fuchsia ' ]['car ' ];
242+ $ carData = $ variations ['fuchsia ' ]['car ' ];
204243
205- static ::assertInstanceOf (Car::class, $ car );
206- static ::assertEquals ('fuchsia ' , $ car ->getColor ());
207- static ::assertEquals ('Mitsubishi ' , $ car ->getManufacturer ()->getName ());
244+ static ::assertEquals ([
245+ 'color ' => 'fuchsia ' ,
246+ 'manufacturer ' => [
247+ 'name ' => 'Mitsubishi ' ,
248+ ],
249+ ], $ carData );
208250 }
209251
210252 public function testCreateForParamWithOptionalVariationValue (): void
@@ -224,7 +266,7 @@ public function testCreateForParamWithOptionalVariationValue(): void
224266 'variations ' => [
225267 'variation1 ' => [
226268 'stringParam ' => 'Some cool hipster text ' ,
227- 'optionalEmpty ' => '' ,
269+ 'optionalEmpty ' => null ,
228270 ],
229271 ],
230272 ];
@@ -238,7 +280,7 @@ public function testCreateForParamWithOptionalVariationValue(): void
238280 self ::assertIsArray ($ variations );
239281 self ::assertArrayHasKey ('variation1 ' , $ variations );
240282 self ::assertArrayHasKey ('secondParam ' , $ variations ['variation1 ' ]);
241- self ::assertIsString ($ variations ['variation1 ' ]['secondParam ' ]);
283+ self ::assertNull ($ variations ['variation1 ' ]['secondParam ' ]);
242284 self ::assertNull ($ variations ['variation1 ' ]['optionalEmpty ' ]);
243285 }
244286
0 commit comments