Skip to content

Commit 48c9c12

Browse files
author
Nathan E
committed
fix: ENUM and SET datatype FactoryGenerator
1 parent 7b6a8e2 commit 48c9c12

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/Generators/FactoryGenerator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ protected function buildDefinition(Model $model)
8080
$definition .= '$faker->' . $faker;
8181
$definition .= ',' . PHP_EOL;
8282

83-
if ($column->dataType() === 'enum' and !empty($column->attributes())) {
84-
$definition = str_replace("/** attributes **/", json_encode($column->attributes()), $definition);
83+
if (in_array($column->dataType(), ['enum', 'set']) and !empty($column->attributes())) {
84+
$definition = str_replace("/** {$column->dataType()}_attributes **/", json_encode($column->attributes()), $definition);
8585
}
8686
}
8787
}
@@ -148,7 +148,8 @@ protected function fakerDataType(string $type)
148148
'float' => 'randomFloat()',
149149
'longtext' => 'text',
150150
'boolean' => 'boolean',
151-
'enum' => 'randomElement(/** attributes **/)',
151+
'set' => 'randomElement(/** set_attributes **/)',
152+
'enum' => 'randomElement(/** enum_attributes **/)',
152153
];
153154

154155
return $fakeableTypes[$type] ?? null;

tests/fixtures/definitions/phone.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ models:
44
user_id: id
55
phone_number: text
66
type: enum:home,cell
7+
status: set:archived,deleted

tests/fixtures/factories/phone.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'label' => $faker->word,
1111
'user_id' => factory(\App\User::class),
1212
'phone_number' => $faker->phoneNumber,
13-
'type' => $faker->randomElement(["home", "cell"]),
13+
'type' => $faker->randomElement(["home","cell"]),
14+
'status' => $faker->randomElement(["archived","deleted"]),
1415
];
1516
});

0 commit comments

Comments
 (0)