Skip to content

Commit d6e9fdf

Browse files
committed
#27 fixed missing sub-key in template data for nested arrays
1 parent 251bb0a commit d6e9fdf

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Component/ComponentItemFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function createVariationParameters(array $parameters, array $variation):
127127

128128
foreach ($parameters as $name => $type) {
129129
if (\is_array($type)) {
130-
$paramValue = $this->createVariationParameters($type, $variation[$name] ?? []);
130+
$paramValue[$name] = $this->createVariationParameters($type, $variation[$name] ?? []);
131131
} else {
132132
$paramValue = $this->faker->getFakeData([$name => $type], $variation[$name] ?? null);
133133
}

tests/Functional/Service/ComponentItemFactoryTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,42 @@ public function testCreateForParamWithOptionalVariationValue(): void
242242
self::assertNull($variations['variation1']['optionalEmpty']);
243243
}
244244

245+
public function testCreateForArrayParameter(): void
246+
{
247+
$data = [
248+
'name' => 'TestComponent',
249+
'title' => 'Test title',
250+
'description' => 'description',
251+
'category' => 'MainCategory',
252+
'path' => 'path/to/component',
253+
'renderPath' => 'path/to/component',
254+
'parameters' => [
255+
'arrayParam' => [
256+
'param1' => 'String',
257+
'param2' => 'Boolean',
258+
],
259+
],
260+
'variations' => [
261+
'variation1' => [
262+
'arrayParam' => [
263+
'param1' => 'Some cool hipster text',
264+
],
265+
],
266+
],
267+
];
268+
269+
/** @var ComponentItemFactory $factory */
270+
$factory = self::getContainer()->get('twig_doc.service.component_factory');
271+
272+
$component = $factory->create($data);
273+
$variations = $component->getVariations();
274+
275+
self::assertIsArray($variations);
276+
self::assertArrayHasKey('variation1', $variations);
277+
self::assertEquals('Some cool hipster text', $variations['variation1']['arrayParam']['param1']);
278+
self::assertIsBool($variations['variation1']['arrayParam']['param2']);
279+
}
280+
245281
public static function getInvalidComponentConfigurationTestCases(): iterable
246282
{
247283
yield [

0 commit comments

Comments
 (0)