improved factories and tests

This commit is contained in:
denisdulici
2020-01-07 01:28:05 +03:00
parent 472a4e00df
commit 751344f11a
13 changed files with 152 additions and 81 deletions

View File

@ -1,4 +1,5 @@
<?php
use App\Models\Auth\User;
use App\Models\Common\Contact;
use Faker\Generator as Faker;
@ -7,22 +8,44 @@ $user = User::first();
$company = $user->companies()->first();
$factory->define(Contact::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns([
'company_id' => $company->id
]);
setting()->setExtraColumns(['company_id' => $company->id]);
return [
'company_id' => $company->id,
'type' => $faker->boolean ? 'customer' : 'vendor',
'name' => $faker->text(15),
'email' => '',
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'user_id' => null,
'tax_number' => null,
'phone' => null,
'address' => null,
'website' => null,
'tax_number' => $faker->randomNumber(9),
'phone' => $faker->phoneNumber,
'address' => $faker->address,
'website' => 'https://akaunting.com',
'currency_code' => setting('default.currency'),
'reference' => null,
'enabled' => $faker->boolean ? 1 : 0
'reference' => $faker->text(5),
'enabled' => $faker->boolean ? 1 : 0,
];
});
$factory->state(Contact::class, 'customer', function (Faker $faker) {
return [
'type' => 'customer',
];
});
$factory->state(Contact::class, 'vendor', function (Faker $faker) {
return [
'type' => 'vendor',
];
});
$factory->state(Contact::class, 'enabled', function (Faker $faker) {
return [
'enabled' => 1,
];
});
$factory->state(Contact::class, 'disabled', function (Faker $faker) {
return [
'enabled' => 0,
];
});