From 320fe213412f7b8cf8cd61f68317c812120f5739 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 Apr 2024 11:06:16 +0200 Subject: [PATCH] #23 create fake variation value when not given --- src/Component/ComponentItemFactory.php | 2 +- .../Service/ComponentItemFactoryTest.php | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Component/ComponentItemFactory.php b/src/Component/ComponentItemFactory.php index b3e5c96..dd2afd5 100644 --- a/src/Component/ComponentItemFactory.php +++ b/src/Component/ComponentItemFactory.php @@ -129,7 +129,7 @@ private function createVariationParameters(array $parameters, array $variation): if (\is_array($type)) { $paramValue = $this->createVariationParameters($type, $variation[$name] ?? []); } else { - $paramValue = $this->faker->getFakeData([$name => $type], $variation[$name]); + $paramValue = $this->faker->getFakeData([$name => $type], $variation[$name] ?? []); } $params += $paramValue; } diff --git a/tests/Functional/Service/ComponentItemFactoryTest.php b/tests/Functional/Service/ComponentItemFactoryTest.php index 8ff435d..1bdb19f 100644 --- a/tests/Functional/Service/ComponentItemFactoryTest.php +++ b/tests/Functional/Service/ComponentItemFactoryTest.php @@ -207,6 +207,38 @@ public function testCreateForObjectParameter(): void static::assertEquals('Mitsubishi', $car->getManufacturer()->getName()); } + public function testCreateForParamWithOptionalVariationValue() + { + $data = [ + 'name' => 'component', + 'title' => 'title', + 'description' => 'description', + 'category' => 'MainCategory', + 'path' => 'path', + 'renderPath' => 'renderPath', + 'parameters' => [ + 'stringParam' => 'String', + 'secondParam' => 'String', + ], + 'variations' => [ + 'variation1' => [ + 'stringParam' => 'Some cool hipster text', + ], + ], + ]; + + /** @var ComponentItemFactory $factory */ + $factory = self::getContainer()->get('twig_doc.service.component_factory'); + + $item = $factory->create($data); + $variations = $item->getVariations(); + + self::assertIsArray($variations); + self::assertArrayHasKey('variation1', $variations); + self::assertArrayHasKey('secondParam', $variations['variation1']); + self::assertIsString($variations['variation1']['secondParam']); + } + public static function getInvalidComponentConfigurationTestCases(): iterable { yield [