63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Database;
|
|
|
|
use App\Auth\PasswordHasher;
|
|
use App\Set\SetRepository;
|
|
use App\Shared\ValueObject\EmailAddress;
|
|
use App\User\UserRepository;
|
|
use Database\Seeders\UserSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class DatabaseSeederTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_it_seeds_the_development_user_idempotently(): void
|
|
{
|
|
$this->seed();
|
|
$this->seed();
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
'email' => 'user@example.com',
|
|
]);
|
|
$this->assertDatabaseMissing('users', [
|
|
'email' => 'user@example.com',
|
|
'passwordHash' => 'password',
|
|
]);
|
|
$this->assertDatabaseCount('users', 1);
|
|
|
|
$user = app(UserRepository::class)->findByEmail(
|
|
new EmailAddress('user@example.com'),
|
|
);
|
|
|
|
$this->assertNotNull($user);
|
|
$this->assertTrue(app(PasswordHasher::class)->verify(
|
|
'password',
|
|
$user->getPasswordHash(),
|
|
));
|
|
}
|
|
|
|
public function test_it_seeds_the_available_sets_idempotently(): void
|
|
{
|
|
$this->seed();
|
|
$this->seed();
|
|
|
|
$sets = app(SetRepository::class)->all();
|
|
|
|
$this->assertDatabaseCount('sets', 3);
|
|
$this->assertSame(
|
|
['Bible', 'Course', 'Fitness Program'],
|
|
array_map(function ($set): string {
|
|
return $set->getName();
|
|
}, $sets),
|
|
);
|
|
foreach ($sets as $set) {
|
|
$this->assertSame(
|
|
UserSeeder::EMAIL,
|
|
$set->getCreator()->getEmail()->value(),
|
|
);
|
|
}
|
|
}
|
|
}
|