Skip to content

Commit

Permalink
#27 fixed missing sub-key in template data for nested arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhoelzel committed Apr 23, 2024
1 parent 251bb0a commit d6e9fdf
Show file tree
Hide file tree
Showing 2 changed files with 37 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 @@ -127,7 +127,7 @@ private function createVariationParameters(array $parameters, array $variation):

foreach ($parameters as $name => $type) {
if (\is_array($type)) {
$paramValue = $this->createVariationParameters($type, $variation[$name] ?? []);
$paramValue[$name] = $this->createVariationParameters($type, $variation[$name] ?? []);
} else {
$paramValue = $this->faker->getFakeData([$name => $type], $variation[$name] ?? null);
}
Expand Down
36 changes: 36 additions & 0 deletions tests/Functional/Service/ComponentItemFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,42 @@ public function testCreateForParamWithOptionalVariationValue(): void
self::assertNull($variations['variation1']['optionalEmpty']);
}

public function testCreateForArrayParameter(): void
{
$data = [
'name' => 'TestComponent',
'title' => 'Test title',
'description' => 'description',
'category' => 'MainCategory',
'path' => 'path/to/component',
'renderPath' => 'path/to/component',
'parameters' => [
'arrayParam' => [
'param1' => 'String',
'param2' => 'Boolean',
],
],
'variations' => [
'variation1' => [
'arrayParam' => [
'param1' => 'Some cool hipster text',
],
],
],
];

/** @var ComponentItemFactory $factory */
$factory = self::getContainer()->get('twig_doc.service.component_factory');

$component = $factory->create($data);
$variations = $component->getVariations();

self::assertIsArray($variations);
self::assertArrayHasKey('variation1', $variations);
self::assertEquals('Some cool hipster text', $variations['variation1']['arrayParam']['param1']);
self::assertIsBool($variations['variation1']['arrayParam']['param2']);
}

public static function getInvalidComponentConfigurationTestCases(): iterable
{
yield [
Expand Down

0 comments on commit d6e9fdf

Please sign in to comment.