-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e5e90a
commit 7b4d964
Showing
23 changed files
with
402 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* Playground | ||
*/ | ||
namespace Database\Factories\Playground\Test\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Str; | ||
use Playground\Test\Models\DefaultUser; | ||
|
||
/** | ||
* \Database\Factories\Playground\Test\Models\DefaultUserFactory | ||
*/ | ||
class DefaultUserFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var class-string<DefaultUser> | ||
*/ | ||
protected $model = DefaultUser::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
if (empty(static::$password)) { | ||
$password = config('auth.testing.password'); | ||
$test_password_hashed = config('auth.testing.hashed'); | ||
|
||
if (empty($password) || ! is_string($password)) { | ||
$password = md5(Carbon::now()->format('c')); | ||
$test_password_hashed = false; | ||
} | ||
|
||
if (! $test_password_hashed) { | ||
$password = Hash::make($password); | ||
} | ||
|
||
static::$password = $password; | ||
} | ||
|
||
return [ | ||
'name' => fake()->name(), | ||
'email' => fake()->unique()->safeEmail(), | ||
'email_verified_at' => Carbon::now()->format('Y-m-d H:i:s'), | ||
'password' => static::$password, | ||
'remember_token' => Str::random(10), | ||
]; | ||
} | ||
|
||
/** | ||
* The current password being used by the factory. | ||
*/ | ||
protected static ?string $password = null; | ||
|
||
/** | ||
* Indicate that the model's email address should be unverified. | ||
*/ | ||
public function unverified(): static | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email_verified_at' => null, | ||
]); | ||
} | ||
|
||
/** | ||
* Set the user up as an admin user. | ||
*/ | ||
public function admin(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
|
||
/** | ||
* Set the user up as a guest user. | ||
*/ | ||
public function guest(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
|
||
/** | ||
* Set the user up as a manager user. | ||
*/ | ||
public function manager(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
|
||
/** | ||
* Indicate that the user has the root role. | ||
*/ | ||
public function root(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
|
||
/** | ||
* Indicate that the user has the wheel role. | ||
*/ | ||
public function wheel(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,68 +6,17 @@ | |
*/ | ||
namespace Database\Factories\Playground\Test\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Playground\Test\Models\User; | ||
|
||
/** | ||
* \Database\Factories\Playground\Test\Models\UserFactory | ||
*/ | ||
class UserFactory extends AbstractUserFactory | ||
class UserFactory extends DefaultUserFactory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var class-string<User> | ||
*/ | ||
protected $model = User::class; | ||
|
||
/** | ||
* Set the user up as an admin user. | ||
*/ | ||
public function admin(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
|
||
/** | ||
* Set the user up as a guest user. | ||
*/ | ||
public function guest(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
|
||
/** | ||
* Set the user up as a manager user. | ||
*/ | ||
public function manager(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
|
||
/** | ||
* Indicate that the user has the root role. | ||
*/ | ||
public function root(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
|
||
/** | ||
* Indicate that the user has the wheel role. | ||
*/ | ||
public function wheel(): Factory | ||
{ | ||
return $this->state(fn (array $attributes) => [ | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.