From d2d1f189541e7db43dcd97fc0bf7ec3c08b6e53a Mon Sep 17 00:00:00 2001 From: Roman Korchnev Date: Sun, 27 Oct 2024 13:22:23 +0300 Subject: [PATCH] factory changes --- .env.example | 3 +++ database/factories/ChallengeFactory.php | 4 ++-- database/factories/TeamFactory.php | 10 +--------- database/factories/UserFactory.php | 21 ++++++--------------- database/seeders/UsersSeeder.php | 4 +++- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/.env.example b/.env.example index 13b4aec..187f708 100644 --- a/.env.example +++ b/.env.example @@ -68,3 +68,6 @@ TELEGRAM_BOT_TOKEN= TELEGRAM_SECRET_KEY= FRONTEND_URL=https://localhost:3000 + +ADMIN_LOGIN= +ADMIN_PASSWORD= diff --git a/database/factories/ChallengeFactory.php b/database/factories/ChallengeFactory.php index 5c09569..3ba48dc 100644 --- a/database/factories/ChallengeFactory.php +++ b/database/factories/ChallengeFactory.php @@ -16,8 +16,8 @@ public function definition(): array $now = Carbon::now(); return [ - 'name' => fake()->text(20), - 'description' => fake()->text(), + 'name' => $this->faker->realText(20), + 'description' => $this->faker->realText(), 'start_date' => $now, 'end_date' => $now->addDays(rand(1, 30)), 'achievement_id' => Achievement::query()->inRandomOrder()->first(), diff --git a/database/factories/TeamFactory.php b/database/factories/TeamFactory.php index 556db5b..148070a 100644 --- a/database/factories/TeamFactory.php +++ b/database/factories/TeamFactory.php @@ -8,16 +8,8 @@ use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; -/** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Team> - */ class TeamFactory extends Factory { - /** - * Define the model's default state. - * - * @return array - */ protected $model = Team::class; public function definition(): array @@ -25,7 +17,7 @@ public function definition(): array return [ 'name' => $this->faker->company, 'description' => $this->faker->sentence, - 'captain_id' => User::query()->first()->id, + 'captain_id' => User::query()->inRandomOrder()->first()->id, ]; } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 6976f54..d7eaa9d 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -13,33 +13,24 @@ */ class UserFactory extends Factory { - /** - * The current password being used by the factory. - */ protected static ?string $password; - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { + $gender = $this->faker->randomElement(['male', 'female']); + return [ - 'name' => fake()->name(), - 'surname' => fake()->lastName(), - 'about' => fake()->text(), + 'name' => $this->faker->firstName($gender), + 'surname' => $this->faker->lastName($gender), + 'about' => $this->faker->realText(), 'is_confirmed' => true, - 'email' => fake()->unique()->safeEmail(), + 'email' => $this->faker->unique()->safeEmail(), 'email_verified_at' => now(), 'password' => Hash::make('password'), 'remember_token' => Str::random(10), ]; } - /** - * Indicate that the model's email address should be unverified. - */ public function unverified(): static { return $this->state(fn (array $attributes) => [ diff --git a/database/seeders/UsersSeeder.php b/database/seeders/UsersSeeder.php index 10c815e..720daac 100644 --- a/database/seeders/UsersSeeder.php +++ b/database/seeders/UsersSeeder.php @@ -6,6 +6,7 @@ use App\Models\User; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Hash; class UsersSeeder extends Seeder { @@ -15,7 +16,8 @@ public function run(): void User::factory()->create([ 'name' => 'Admin', - 'email' => 'admin@admin.com', + 'email' => env('ADMIN_LOGIN'), + 'password' => Hash::make(env('ADMIN_PASSWORD')), 'is_admin' => true, ]); }