From d6e9fdfce2a68ee84167b785b4a279a142ebf4ce Mon Sep 17 00:00:00 2001
From: david <david.hoelzel@gmx.de>
Date: Tue, 23 Apr 2024 11:11:01 +0200
Subject: [PATCH 1/2] #27 fixed missing sub-key in template data for nested
 arrays

---
 src/Component/ComponentItemFactory.php        |  2 +-
 .../Service/ComponentItemFactoryTest.php      | 36 +++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/Component/ComponentItemFactory.php b/src/Component/ComponentItemFactory.php
index d5b1030..026189e 100644
--- a/src/Component/ComponentItemFactory.php
+++ b/src/Component/ComponentItemFactory.php
@@ -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);
             }
diff --git a/tests/Functional/Service/ComponentItemFactoryTest.php b/tests/Functional/Service/ComponentItemFactoryTest.php
index e6b8a4e..1cb145c 100644
--- a/tests/Functional/Service/ComponentItemFactoryTest.php
+++ b/tests/Functional/Service/ComponentItemFactoryTest.php
@@ -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 [

From be31c1ef9d4ac4d61ec10b443caba5d4be42d7b8 Mon Sep 17 00:00:00 2001
From: david <david.hoelzel@gmx.de>
Date: Tue, 23 Apr 2024 13:56:31 +0200
Subject: [PATCH 2/2] #27 fix NULL generator implementation

- returns NULL when context is NULL or ''
---
 src/Component/Data/Faker.php                          | 2 +-
 src/Component/Data/Generator/NullGenerator.php        | 2 +-
 tests/Functional/Service/ComponentItemFactoryTest.php | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/Component/Data/Faker.php b/src/Component/Data/Faker.php
index 482198a..2d2f517 100644
--- a/src/Component/Data/Faker.php
+++ b/src/Component/Data/Faker.php
@@ -46,7 +46,7 @@ private function createFakeData(array $params, mixed $variation): array
 
             if (!\array_key_exists($name, $result)) {
                 // set from variation
-                $result[$name] = $variation;
+                $result[$name] = $variation[$name] ?? $variation;
             }
         }
 
diff --git a/src/Component/Data/Generator/NullGenerator.php b/src/Component/Data/Generator/NullGenerator.php
index a723709..8c9687f 100644
--- a/src/Component/Data/Generator/NullGenerator.php
+++ b/src/Component/Data/Generator/NullGenerator.php
@@ -10,7 +10,7 @@ class NullGenerator implements GeneratorInterface
 {
     public function supports(string $type, mixed $context = null): bool
     {
-        return empty($context);
+        return null === $context || '' === $context;
     }
 
     public function generate(string $type, mixed $context = null): null
diff --git a/tests/Functional/Service/ComponentItemFactoryTest.php b/tests/Functional/Service/ComponentItemFactoryTest.php
index 1cb145c..5fd9834 100644
--- a/tests/Functional/Service/ComponentItemFactoryTest.php
+++ b/tests/Functional/Service/ComponentItemFactoryTest.php
@@ -261,6 +261,7 @@ public function testCreateForArrayParameter(): void
                 'variation1' => [
                     'arrayParam' => [
                         'param1' => 'Some cool hipster text',
+                        'param2' => false,
                     ],
                 ],
             ],
@@ -275,7 +276,7 @@ public function testCreateForArrayParameter(): void
         self::assertIsArray($variations);
         self::assertArrayHasKey('variation1', $variations);
         self::assertEquals('Some cool hipster text', $variations['variation1']['arrayParam']['param1']);
-        self::assertIsBool($variations['variation1']['arrayParam']['param2']);
+        self::assertFalse($variations['variation1']['arrayParam']['param2']);
     }
 
     public static function getInvalidComponentConfigurationTestCases(): iterable