test admin command
This commit is contained in:
parent
4ee20396e8
commit
4462879b7d
1 changed files with 70 additions and 0 deletions
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\User\UseCases;
|
||||
|
||||
use App\Console\Commands\EnsureInitialAdminCommand;
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
use App\User\InitialAdminCredentials;
|
||||
use App\User\InitialAdminCredentialsProvider;
|
||||
use App\User\UseCases\EnsureInitialAdmin\EnsureInitialAdmin;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Tests\Fakes\FakeHasher;
|
||||
use Tests\Fakes\FakeUserRepository;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EnsureInitialAdminCommandTest extends TestCase
|
||||
{
|
||||
public function testCommandCreatesInitialAdminFromProvider(): void
|
||||
{
|
||||
$userRepository = new FakeUserRepository();
|
||||
$passwordHasher = new FakeHasher();
|
||||
$command = new EnsureInitialAdminCommand(
|
||||
new EnsureInitialAdmin($userRepository, $passwordHasher),
|
||||
$this->credentialsProvider(
|
||||
'admin@example.com',
|
||||
'secret-password',
|
||||
),
|
||||
);
|
||||
|
||||
$commandTester = new CommandTester($command);
|
||||
$statusCode = $commandTester->execute([]);
|
||||
|
||||
$createdUser = $userRepository->findByEmail(
|
||||
new EmailAddress('admin@example.com')
|
||||
);
|
||||
|
||||
$this->assertSame(0, $statusCode);
|
||||
$this->assertNotNull($createdUser);
|
||||
$this->assertSame(
|
||||
'hashed-secret-password',
|
||||
$createdUser->getPasswordHash(),
|
||||
);
|
||||
$this->assertStringContainsString(
|
||||
'initial admin is ready',
|
||||
$commandTester->getDisplay(),
|
||||
);
|
||||
}
|
||||
|
||||
private function credentialsProvider(
|
||||
string $email,
|
||||
string $password,
|
||||
): InitialAdminCredentialsProvider {
|
||||
return new class ($email, $password) implements
|
||||
InitialAdminCredentialsProvider
|
||||
{
|
||||
public function __construct(
|
||||
private string $email,
|
||||
private string $password,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getCredentials(): InitialAdminCredentials
|
||||
{
|
||||
return new InitialAdminCredentials(
|
||||
email: $this->email,
|
||||
password: $this->password,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue