Skip to content

Commit eb24b88

Browse files
committed
Strengthen factory generator tests
1 parent 1e30d38 commit eb24b88

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/Generators/FactoryGenerator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected function buildDefinition(Model $model)
9292
protected function fakerData(string $name)
9393
{
9494
static $fakeableNames = [
95+
'address1' => 'streetAddress',
96+
'address2' => 'secondaryAddress',
9597
'city' => 'city',
9698
'company' => 'company',
9799
'content' => 'paragraphs(3, true)',
@@ -111,12 +113,11 @@ protected function fakerData(string $name)
111113
'password' => 'password',
112114
'phone' => 'phoneNumber',
113115
'phone_number' => 'phoneNumber',
114-
'postcode' => 'postcode',
115116
'postal_code' => 'postcode',
117+
'postcode' => 'postcode',
116118
'slug' => 'slug',
119+
'ssn' => 'ssn',
117120
'street' => 'streetName',
118-
'address1' => 'streetAddress',
119-
'address2' => 'secondaryAddress',
120121
'summary' => 'text',
121122
'title' => 'sentence(4)',
122123
'url' => 'url',

tests/Feature/Generator/FactoryGeneratorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public function modelTreeDataProvider()
9191
['definitions/post.bp', 'database/factories/PostFactory.php', 'factories/post.php'],
9292
['definitions/team.bp', 'database/factories/TeamFactory.php', 'factories/team.php'],
9393
['definitions/unconventional.bp', 'database/factories/TeamFactory.php', 'factories/unconventional.php'],
94-
['definitions/nested-components.bp', 'database/factories/Admin/UserFactory.php', 'factories/nested-components.php']
94+
['definitions/nested-components.bp', 'database/factories/Admin/UserFactory.php', 'factories/nested-components.php'],
95+
['definitions/model-modifiers.bp', 'database/factories/ModifierFactory.php', 'factories/model-modifiers.php']
9596
];
9697
}
9798
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use App\Modifier;
6+
use Faker\Generator as Faker;
7+
8+
$factory->define(Modifier::class, function (Faker $faker) {
9+
return [
10+
'title' => $faker->sentence(4),
11+
'name' => $faker->name,
12+
'content' => $faker->paragraphs(3, true),
13+
'total' => $faker->randomFloat(),
14+
'ssn' => $faker->ssn,
15+
'role' => $faker->randomElement(["user","admin","owner"]),
16+
];
17+
});

0 commit comments

Comments
 (0)