Skip to content

Commit

Permalink
fix: use orm limit length in factory (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYamous authored Nov 15, 2022
1 parent b1d7ce3 commit cd1e394
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/Bundle/Maker/MakeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class MakeFactory extends AbstractMaker
{
private const DEFAULTS = [
'ARRAY' => '[],',
'ASCII_STRING' => 'self::faker()->text(),',
'ASCII_STRING' => 'self::faker()->text({length}),',
'BIGINT' => 'self::faker()->randomNumber(),',
'BLOB' => 'self::faker()->text(),',
'BOOLEAN' => 'self::faker()->boolean(),',
Expand All @@ -44,10 +44,10 @@ final class MakeFactory extends AbstractMaker
'JSON_ARRAY' => '[],',
'SIMPLE_ARRAY' => '[],',
'SMALLINT' => 'self::faker()->numberBetween(1, 32767),',
'STRING' => 'self::faker()->text(),',
'TEXT' => 'self::faker()->text(),',
'TIME_MUTABLE' => 'self::faker()->dateTime(),',
'TIME_IMMUTABLE' => '\DateTimeImmutable::createFromMutable(self::faker()->dateTime()),',
'STRING' => 'self::faker()->text({length}),',
'TEXT' => 'self::faker()->text({length}),',
'TIME_MUTABLE' => 'self::faker()->datetime(),',
'TIME_IMMUTABLE' => '\DateTimeImmutable::createFromMutable(self::faker()->datetime()),',
];

/** @var string[] */
Expand Down Expand Up @@ -232,12 +232,13 @@ private function defaultPropertiesFor(string $class, bool $allFields): iterable

$type = \mb_strtoupper($property['type']);
$value = "null, // TODO add {$type} {$dbType} type manually";
$length = $property['length'] ?? '';

if (\array_key_exists($type, self::DEFAULTS)) {
$value = self::DEFAULTS[$type];
}

yield $property['fieldName'] => $value;
yield $property['fieldName'] => \str_replace('{length}', (string) $length, $value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'name' => self::faker()->text(),
'name' => self::faker()->text(255),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'name' => self::faker()->text(),
'name' => self::faker()->text(255),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'name' => self::faker()->text(),
'name' => self::faker()->text(255),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'name' => self::faker()->text(),
'name' => self::faker()->text(255),
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Maker/expected/can-create-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function getDefaults(): array
{
return [
// TODO add your default values here (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories)
'name' => self::faker()->text(),
'name' => self::faker()->text(255),
];
}

Expand Down

0 comments on commit cd1e394

Please sign in to comment.