59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Command;
|
|
|
|
use App\Command\CleanupGuestInviteAccountsCommand;
|
|
use App\Repository\UserRepository;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
class CleanupGuestInviteAccountsCommandTest extends TestCase
|
|
{
|
|
public function testCommandReportsWhenNothingWasDeleted(): void
|
|
{
|
|
$repository = $this->createMock(UserRepository::class);
|
|
$repository
|
|
->expects(self::once())
|
|
->method('deleteExpiredDormantGuestInvites')
|
|
->with(self::isInstanceOf(\DateTimeImmutable::class))
|
|
->willReturn(0);
|
|
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
$logger->expects(self::never())->method('info');
|
|
|
|
$tester = new CommandTester(new CleanupGuestInviteAccountsCommand($repository, $logger));
|
|
$exitCode = $tester->execute([]);
|
|
|
|
self::assertSame(0, $exitCode);
|
|
self::assertStringContainsString('No expired dormant guest accounts found.', $tester->getDisplay());
|
|
}
|
|
|
|
public function testCommandLogsAndReportsDeletionCount(): void
|
|
{
|
|
$repository = $this->createMock(UserRepository::class);
|
|
$repository
|
|
->expects(self::once())
|
|
->method('deleteExpiredDormantGuestInvites')
|
|
->with(self::isInstanceOf(\DateTimeImmutable::class))
|
|
->willReturn(3);
|
|
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
$logger
|
|
->expects(self::once())
|
|
->method('info')
|
|
->with(
|
|
'Deleted expired dormant guest accounts',
|
|
self::callback(static fn (array $context): bool => 3 === $context['count'])
|
|
);
|
|
|
|
$tester = new CommandTester(new CleanupGuestInviteAccountsCommand($repository, $logger));
|
|
$exitCode = $tester->execute([]);
|
|
|
|
self::assertSame(0, $exitCode);
|
|
self::assertStringContainsString('Deleted 3 expired dormant guest account(s).', $tester->getDisplay());
|
|
}
|
|
}
|