make UserFactory username and email unique

This commit is contained in:
lgb
2024-02-26 12:26:38 +08:00
parent 0f551d5091
commit ba1f6e50a9
+7 -2
View File
@@ -11,6 +11,8 @@ class UserFactory extends Factory
{ {
private static string $defaultStyleSheet = ""; private static string $defaultStyleSheet = "";
private static int $sequence = 1;
/** /**
* The name of the factory's corresponding model. * The name of the factory's corresponding model.
@@ -32,9 +34,12 @@ class UserFactory extends Factory
if (self::$defaultStyleSheet == "") { if (self::$defaultStyleSheet == "") {
self::$defaultStyleSheet = get_setting("main.defstylesheet"); self::$defaultStyleSheet = get_setting("main.defstylesheet");
} }
$username = sprintf("%s_%s", microtime(true), self::$sequence);
$email = sprintf("%s@example.net", $username);
self::$sequence++;
return [ return [
'username' => $this->faker->name, 'username' => $username,
'email' => $this->faker->unique()->safeEmail, 'email' => $email,
'secret' => mksecret(), 'secret' => mksecret(),
'editsecret' => "", 'editsecret' => "",
'passhash' => $passhash, 'passhash' => $passhash,