*/ class UserFactory extends Factory { /** * Default state mirrors what the OAuth callback produces: an identity * copied from the server, with no local password. * * @return array */ public function definition(): array { return [ 'oauth_id' => fake()->unique()->numberBetween(1000, 999999), 'name' => fake()->name(), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), 'password' => null, 'locale' => fake()->randomElement(array_keys(config('locales.supported'))), 'is_active' => true, 'remote_roles' => ['user'], 'last_login_at' => now(), 'remember_token' => Str::random(10), ]; } public function inactive(): static { return $this->state(fn () => ['is_active' => false]); } /** * A user who has never signed in through the identity server, used to * check that the callback adopts pre-existing local rows by email. */ public function unlinked(): static { return $this->state(fn () => [ 'oauth_id' => null, 'last_login_at' => null, ]); } public function withRole(string $role): static { return $this->afterCreating(fn (User $user) => $user->assignRole($role)); } }