<?php

declare(strict_types=1);

namespace App\Tests\Unit\Module\Core\Infrastructure\Security;

use App\Module\Core\Domain\Entity\User;
use App\Module\Core\Infrastructure\Security\ArchivedUserChecker;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
use Symfony\Component\Security\Core\User\InMemoryUser;

/**
 * @internal
 */
final class ArchivedUserCheckerTest extends TestCase
{
    public function testArchivedUserIsRejectedPreAuth(): void
    {
        $user = new User()->setArchived(true);

        $this->expectException(CustomUserMessageAccountStatusException::class);

        new ArchivedUserChecker()->checkPreAuth($user);
    }

    public function testActiveUserPassesPreAuth(): void
    {
        $user = new User()->setArchived(false);

        new ArchivedUserChecker()->checkPreAuth($user);

        $this->addToAssertionCount(1);
    }

    public function testNonAppUserIsIgnored(): void
    {
        // A user that is not our entity must not be rejected by this checker.
        new ArchivedUserChecker()->checkPreAuth(new InMemoryUser('someone', null));

        $this->addToAssertionCount(1);
    }
}
