Skip to content

Commit

Permalink
Merge pull request #225 from range-of-motion/71-split-model-factories
Browse files Browse the repository at this point in the history
Split factories up into multiple files
  • Loading branch information
range-of-motion authored Jul 28, 2020
2 parents 77546bf + 576ee27 commit d174593
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 92 deletions.
13 changes: 13 additions & 0 deletions database/factories/BudgetFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use App\Models\Budget;
use Faker\Generator as Faker;

$factory->define(Budget::class, function (Faker $faker) {
return [
'period' => 'monthly',
'amount' => $faker->randomNumber(3)
];
});
12 changes: 12 additions & 0 deletions database/factories/ConversionRateFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

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

use App\Models\ConversionRate;
use Faker\Generator as Faker;

$factory->define(ConversionRate::class, function (Faker $faker) {
return [
'rate' => $faker->randomFloat(2, .5, 2)
];
});
13 changes: 13 additions & 0 deletions database/factories/CurrencyFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use App\Models\Currency;
use Faker\Generator as Faker;

$factory->define(Currency::class, function (Faker $faker) {
return [
'name' => $faker->word(),
'symbol' => $faker->word()
];
});
14 changes: 14 additions & 0 deletions database/factories/EarningFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

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

use App\Models\Earning;
use Faker\Generator as Faker;

$factory->define(Earning::class, function (Faker $faker) {
return [
'happened_on' => $faker->dateTimeBetween('-50 days', 'now')->format('Y-m-d'),
'description' => implode(' ', array_map('ucfirst', $faker->words(3))),
'amount' => $faker->randomNumber(3)
];
});
92 changes: 0 additions & 92 deletions database/factories/ModelFactory.php

This file was deleted.

17 changes: 17 additions & 0 deletions database/factories/RecurringFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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

use App\Models\Recurring;
use Faker\Generator as Faker;

$factory->define(Recurring::class, function (Faker $faker) {
return [
'type' => 'earning',
'interval' => 'monthly',
'day' => $faker->numberBetween(1, 28),
'starts_on' => $faker->dateTimeBetween('-50 days', 'now')->format('Y-m-d'),
'description' => implode(' ', array_map('ucfirst', $faker->words(3))),
'amount' => $faker->randomNumber(3)
];
});
13 changes: 13 additions & 0 deletions database/factories/SpaceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use App\Models\Space;
use Faker\Generator as Faker;

$factory->define(Space::class, function (Faker $faker) {
return [
'currency_id' => $faker->numberBetween(1, 3),
'name' => $faker->firstName . '\'s Space'
];
});
17 changes: 17 additions & 0 deletions database/factories/SpaceInviteFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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

use App\Models\Space;
use App\Models\SpaceInvite;
use App\Models\User;
use Faker\Generator as Faker;

$factory->define(SpaceInvite::class, function (Faker $faker) {
return [
'space_id' => Space::all()->random()->id,
'invitee_user_id' => User::all()->random()->id,
'inviter_user_id' => User::all()->random()->id,
'role' => 'regular'
];
});
14 changes: 14 additions & 0 deletions database/factories/SpendingFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

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

use App\Models\Spending;
use Faker\Generator as Faker;

$factory->define(Spending::class, function (Faker $faker) {
return [
'happened_on' => $faker->dateTimeBetween('-50 days', 'now')->format('Y-m-d'),
'description' => implode(' ', array_map('ucfirst', $faker->words(3))),
'amount' => $faker->randomNumber(3)
];
});
12 changes: 12 additions & 0 deletions database/factories/TagFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

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

use App\Models\Tag;
use Faker\Generator as Faker;

$factory->define(Tag::class, function (Faker $faker) {
return [
'name' => ucfirst($faker->word)
];
});
16 changes: 16 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

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

use App\Models\User;
use Faker\Generator as Faker;
use Illuminate\Support\Str;

$factory->define(User::class, function (Faker $faker) {
return [
'name' => $faker->firstName,
'email' => $faker->unique()->safeEmail,
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => Str::random(10)
];
});

0 comments on commit d174593

Please sign in to comment.