using factories in tests
This commit is contained in:
@ -15,7 +15,7 @@ $factory->define(Item::class, function (Faker $faker) {
|
||||
'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' => '',
|
||||
'tax_id' => 0,
|
||||
'enabled' => $faker->boolean ? 1 : 0
|
||||
];
|
||||
});
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Model Factories
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of your model factories. Model factories give
|
||||
| you a convenient way to create models for testing and seeding your
|
||||
| database. Just tell the factory how a default model should look.
|
||||
|
|
||||
*/
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
$factory->define(\App\Models\Auth\User::class, function (Faker\Generator $faker) {
|
||||
static $password;
|
||||
|
||||
return [
|
||||
'name' => $faker->name,
|
||||
'email' => $faker->unique()->safeEmail,
|
||||
'password' => $password ?: $password = bcrypt('secret'),
|
||||
'remember_token' => \Str::random(10),
|
||||
];
|
||||
});
|
@ -9,6 +9,8 @@ $factory->define(Transaction::class, function (Faker $faker) {
|
||||
$user = User::first();
|
||||
$company = $user->companies()->first();
|
||||
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
|
||||
$attachment = UploadedFile::fake()->create('image.jpg');
|
||||
|
||||
return [
|
||||
@ -16,13 +18,13 @@ $factory->define(Transaction::class, function (Faker $faker) {
|
||||
'type' => 'income',
|
||||
'account_id' => setting('default.account'),
|
||||
'paid_at' => $faker->date(),
|
||||
'amount' => $faker->randomFloat(2, 2),
|
||||
'amount' => $faker->randomFloat(2, 2, 1000),
|
||||
'currency_code' => setting('default.currency'),
|
||||
'currency_rate' => '1',
|
||||
'description' => $faker->text(5),
|
||||
'category_id' => $company->categories()->type('income')->first()->id,
|
||||
'reference' => $faker->text(5),
|
||||
'payment_method' => setting('default.payment_method'),
|
||||
'attachment' => $attachment,
|
||||
//'attachment' => $attachment,
|
||||
];
|
||||
});
|
21
database/factories/User.php
Normal file
21
database/factories/User.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Auth\User;
|
||||
use Faker\Generator as Faker;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
$factory->define(User::class, function (Faker $faker) {
|
||||
$password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; // password
|
||||
|
||||
return [
|
||||
'name' => $faker->name,
|
||||
'email' => $faker->unique()->safeEmail,
|
||||
'password' => $password,
|
||||
'password_confirmation' => $password,
|
||||
'remember_token' => Str::random(10),
|
||||
'locale' => 'en-GB',
|
||||
'companies' => ['1'],
|
||||
'roles' => ['1'],
|
||||
'enabled' => $this->faker->boolean ? 1 : 0,
|
||||
];
|
||||
});
|
Reference in New Issue
Block a user