Skip to content

Commit 3ac5d91

Browse files
authored
#23 create fake variation value when not given (#24)
* #23 create fake variation value when not given
1 parent 2488b65 commit 3ac5d91

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Component/ComponentItemFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function createVariationParameters(array $parameters, array $variation):
129129
if (\is_array($type)) {
130130
$paramValue = $this->createVariationParameters($type, $variation[$name] ?? []);
131131
} else {
132-
$paramValue = $this->faker->getFakeData([$name => $type], $variation[$name]);
132+
$paramValue = $this->faker->getFakeData([$name => $type], $variation[$name] ?? []);
133133
}
134134
$params += $paramValue;
135135
}

tests/Functional/Service/ComponentItemFactoryTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,38 @@ public function testCreateForObjectParameter(): void
207207
static::assertEquals('Mitsubishi', $car->getManufacturer()->getName());
208208
}
209209

210+
public function testCreateForParamWithOptionalVariationValue(): void
211+
{
212+
$data = [
213+
'name' => 'component',
214+
'title' => 'title',
215+
'description' => 'description',
216+
'category' => 'MainCategory',
217+
'path' => 'path',
218+
'renderPath' => 'renderPath',
219+
'parameters' => [
220+
'stringParam' => 'String',
221+
'secondParam' => 'String',
222+
],
223+
'variations' => [
224+
'variation1' => [
225+
'stringParam' => 'Some cool hipster text',
226+
],
227+
],
228+
];
229+
230+
/** @var ComponentItemFactory $factory */
231+
$factory = self::getContainer()->get('twig_doc.service.component_factory');
232+
233+
$item = $factory->create($data);
234+
$variations = $item->getVariations();
235+
236+
self::assertIsArray($variations);
237+
self::assertArrayHasKey('variation1', $variations);
238+
self::assertArrayHasKey('secondParam', $variations['variation1']);
239+
self::assertIsString($variations['variation1']['secondParam']);
240+
}
241+
210242
public static function getInvalidComponentConfigurationTestCases(): iterable
211243
{
212244
yield [

0 commit comments

Comments
 (0)