Skip to content

Commit b7d20a8

Browse files
authored
Add string limit for faker words (#437)
1 parent 78d0cc8 commit b7d20a8

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

src/Generators/FactoryGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ protected function buildDefinition(Model $model)
245245
$faker = 'word';
246246
}
247247

248+
if (($faker === 'word') && (!empty($column->attributes()))) {
249+
$faker = sprintf("regexify('[A-Za-z0-9]{%s}')", current($column->attributes()));
250+
}
251+
248252
if (Blueprint::isLaravel8OrHigher()) {
249253
$definition .= '$this->faker->' . $faker;
250254
} else {

tests/fixtures/drafts/phone.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ models:
66
type: enum:home,cell
77
status: set:archived,deleted
88
foo: morphs
9-
bar: morphs nullable
9+
bar: morphs nullable
10+
tag: string:3

tests/fixtures/factories/phone-laravel8.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function definition()
3131
'status' => $this->faker->randomElement(["archived","deleted"]),
3232
'foo_id' => $this->faker->randomDigitNotNull,
3333
'foo_type' => $this->faker->word,
34+
'tag' => $this->faker->regexify('[A-Za-z0-9]{3}'),
3435
];
3536
}
3637
}

tests/fixtures/factories/phone.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
'status' => $faker->randomElement(["archived","deleted"]),
1515
'foo_id' => $faker->randomDigitNotNull,
1616
'foo_type' => $faker->word,
17+
'tag' => $faker->regexify('[A-Za-z0-9]{3}'),
1718
];
1819
});

0 commit comments

Comments
 (0)