test(auth): add UserFactory for testing

This commit is contained in:
peaklabs-dev 2025-12-10 17:24:01 +01:00
parent 60388a832c
commit 5e4eae13ae
No known key found for this signature in database
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
final class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
private static string $password;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => self::$password ??= Hash::make('password'),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes): array => [
'email_verified_at' => null,
]);
}
}