Skip to content

Commit

Permalink
Strengthen factory generator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary committed Jan 29, 2020
1 parent 1e30d38 commit eb24b88
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Generators/FactoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ protected function buildDefinition(Model $model)
protected function fakerData(string $name)
{
static $fakeableNames = [
'address1' => 'streetAddress',
'address2' => 'secondaryAddress',
'city' => 'city',
'company' => 'company',
'content' => 'paragraphs(3, true)',
Expand All @@ -111,12 +113,11 @@ protected function fakerData(string $name)
'password' => 'password',
'phone' => 'phoneNumber',
'phone_number' => 'phoneNumber',
'postcode' => 'postcode',
'postal_code' => 'postcode',
'postcode' => 'postcode',
'slug' => 'slug',
'ssn' => 'ssn',
'street' => 'streetName',
'address1' => 'streetAddress',
'address2' => 'secondaryAddress',
'summary' => 'text',
'title' => 'sentence(4)',
'url' => 'url',
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Generator/FactoryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public function modelTreeDataProvider()
['definitions/post.bp', 'database/factories/PostFactory.php', 'factories/post.php'],
['definitions/team.bp', 'database/factories/TeamFactory.php', 'factories/team.php'],
['definitions/unconventional.bp', 'database/factories/TeamFactory.php', 'factories/unconventional.php'],
['definitions/nested-components.bp', 'database/factories/Admin/UserFactory.php', 'factories/nested-components.php']
['definitions/nested-components.bp', 'database/factories/Admin/UserFactory.php', 'factories/nested-components.php'],
['definitions/model-modifiers.bp', 'database/factories/ModifierFactory.php', 'factories/model-modifiers.php']
];
}
}
17 changes: 17 additions & 0 deletions tests/fixtures/factories/model-modifiers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\Modifier;
use Faker\Generator as Faker;

$factory->define(Modifier::class, function (Faker $faker) {
return [
'title' => $faker->sentence(4),
'name' => $faker->name,
'content' => $faker->paragraphs(3, true),
'total' => $faker->randomFloat(),
'ssn' => $faker->ssn,
'role' => $faker->randomElement(["user","admin","owner"]),
];
});

0 comments on commit eb24b88

Please sign in to comment.