2026-07-27 18:08:52 +02:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
/*
|
|
|
|
|
* This file is part of the SplendidBear Websites' projects.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2026 @ www.splendidbear.org
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Tests\Command;
|
|
|
|
|
|
|
|
|
|
use App\Command\PurgeExpiredPendingUsersCommand;
|
|
|
|
|
use App\Entity\User;
|
|
|
|
|
use App\Tests\Factory\UserFactory;
|
|
|
|
|
use App\Tests\WebTestCase;
|
|
|
|
|
use DateTime;
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
|
|
|
|
|
|
#[TestDox('Purge Expired Pending Users Command')]
|
|
|
|
|
class PurgeExpiredPendingUsersCommandTest extends WebTestCase
|
|
|
|
|
{
|
|
|
|
|
#[Test]
|
|
|
|
|
#[TestDox('Deletes expired unverified users only')]
|
|
|
|
|
public function deletesOnlyExpiredUnverifiedUsers(): void
|
|
|
|
|
{
|
|
|
|
|
$expiredUser = UserFactory::createOne([
|
|
|
|
|
'isVerified' => false,
|
|
|
|
|
'verificationToken' => 'expired-token',
|
|
|
|
|
'verificationTokenExpiresAt' => new DateTime('-1 minute'),
|
|
|
|
|
]);
|
|
|
|
|
$pendingUser = UserFactory::createOne([
|
|
|
|
|
'isVerified' => false,
|
|
|
|
|
'verificationToken' => 'valid-token',
|
|
|
|
|
'verificationTokenExpiresAt' => new DateTime('+1 day'),
|
|
|
|
|
]);
|
|
|
|
|
$verifiedUser = UserFactory::createOne([
|
|
|
|
|
'isVerified' => true,
|
|
|
|
|
'verificationToken' => 'verified-token',
|
|
|
|
|
'verificationTokenExpiresAt' => new DateTime('-1 minute'),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$command = static::getContainer()->get(PurgeExpiredPendingUsersCommand::class);
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
$tester->execute([]);
|
|
|
|
|
|
|
|
|
|
$em = static::getContainer()->get(EntityManagerInterface::class);
|
2026-07-27 18:35:42 +02:00
|
|
|
self::assertNull($em->find(User::class, $expiredUser->id));
|
|
|
|
|
self::assertNotNull($em->find(User::class, $pendingUser->id));
|
|
|
|
|
self::assertNotNull($em->find(User::class, $verifiedUser->id));
|
2026-07-27 18:08:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
#[TestDox('Dry run keeps expired unverified users')]
|
|
|
|
|
public function dryRunDoesNotDeleteExpiredUsers(): void
|
|
|
|
|
{
|
|
|
|
|
$expiredUser = UserFactory::createOne([
|
|
|
|
|
'isVerified' => false,
|
|
|
|
|
'verificationToken' => 'expired-token',
|
|
|
|
|
'verificationTokenExpiresAt' => new DateTime('-1 minute'),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$command = static::getContainer()->get(PurgeExpiredPendingUsersCommand::class);
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
$tester->execute(['--dry-run' => true]);
|
|
|
|
|
|
|
|
|
|
$em = static::getContainer()->get(EntityManagerInterface::class);
|
2026-07-27 18:35:42 +02:00
|
|
|
self::assertNotNull($em->find(User::class, $expiredUser->id));
|
2026-07-27 18:08:52 +02:00
|
|
|
}
|
|
|
|
|
}
|