Skip to content

Commit

Permalink
#23 create fake variation value when not given
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhoelzel committed Apr 19, 2024
1 parent 2488b65 commit 320fe21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Component/ComponentItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Functional/Service/ComponentItemFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit 320fe21

Please sign in to comment.