Skip to content

Commit

Permalink
#27 fix NULL generator implementation
Browse files Browse the repository at this point in the history
- returns NULL when context is NULL or ''
  • Loading branch information
davidhoelzel committed Apr 23, 2024
1 parent d6e9fdf commit be31c1e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Component/Data/Faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Component/Data/Generator/NullGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Service/ComponentItemFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public function testCreateForArrayParameter(): void
'variation1' => [
'arrayParam' => [
'param1' => 'Some cool hipster text',
'param2' => false,
],
],
],
Expand All @@ -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
Expand Down

0 comments on commit be31c1e

Please sign in to comment.