<?php

namespace App\Tests\Security;

use App\Entity\Account;
use App\Security\UserChecker;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
use Symfony\Component\Security\Core\User\UserInterface;

#[AllowMockObjectsWithoutExpectations]
class UserCheckerTest extends TestCase
{
    private $checker;

    protected function setUp(): void
    {
        $this->checker = new UserChecker();
    }

    public function testCheckPreAuthActiveUser()
    {
        $user = $this->createMock(Account::class);
        $user->method('isActif')->willReturn(true);

        $this->checker->checkPreAuth($user);
        $this->assertTrue(true); // No exception thrown
    }

    public function testCheckPreAuthInactiveUserThrowsException()
    {
        $user = $this->createMock(Account::class);
        $user->method('isActif')->willReturn(false);

        $this->expectException(CustomUserMessageAccountStatusException::class);
        $this->expectExceptionMessage('Votre compte a été désactivé.');

        $this->checker->checkPreAuth($user);
    }

    public function testCheckPreAuthNonAccountUserIgnores()
    {
        $user = $this->createMock(UserInterface::class);
        
        $this->checker->checkPreAuth($user);
        $this->assertTrue(true);
    }
}
