Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class UserFactory extends Factory {
*/
public function definition() {
return [
'password' => $this->faker->password(),
'email' => $this->faker->unique()->safeEmail(),
// use the email as the password so that it is easier to log in as these users
'password' => fn (array $attributes) => $attributes['email'],
'verified' => $this->faker->boolean(),
];
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Feature/Models/UserFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Tests\Factories;

use App\User;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;

class UserFactoryTest extends TestCase {
public function testDefaultPasswordMatchesGeneratedEmail(): void {
$user = User::factory()->make();

$this->assertTrue(Hash::check($user->email, $user->password));
}

public function testDefaultPasswordMatchesOverriddenEmail(): void {
$email = 'factory@example.com';
$user = User::factory()->make(['email' => $email]);

$this->assertTrue(Hash::check($email, $user->password));
}

public function testExplicitPasswordOverridesDefault(): void {
$password = 'explicit-password';
$user = User::factory()->make(['password' => $password]);

$this->assertTrue(Hash::check($password, $user->password));
$this->assertFalse(Hash::check($user->email, $user->password));
}
}
Loading