using factories in tests

This commit is contained in:
denisdulici
2019-11-22 17:35:46 +03:00
parent a4135ec902
commit 7ba71d17c5
5 changed files with 31 additions and 49 deletions

View File

@ -0,0 +1,21 @@
<?php
use App\Models\Auth\User;
use App\Models\Common\Item;
use Faker\Generator as Faker;
$factory->define(Item::class, function (Faker $faker) {
$user = User::first();
$company = $user->companies()->first();
return [
'company_id' => $company->id,
'name' => $faker->text(15),
'description' => $faker->text(100),
'purchase_price' => $faker->randomFloat(2, 10, 20),
'sale_price' => $faker->randomFloat(2, 10, 20),
'category_id' => $company->categories()->type('item')->pluck('id')->first(),
'tax_id' => 0,
'enabled' => $faker->boolean ? 1 : 0
];
});