<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\Security;

use Ferienpass\AdminBundle\Security\AccessDeniedHandler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

final class AccessDeniedHandlerTest extends TestCase
{
    public function testHandleReturnsResponse(): void
    {
        $request = Request::create('/admin/test');

        $requestStack = new RequestStack();
        $requestStack->push($request);

        $expectedResponse = new Response('Forbidden', 403);

        $httpKernel = $this->createMock(HttpKernelInterface::class);
        $httpKernel->method('handle')->willReturn($expectedResponse);

        $handler = new AccessDeniedHandler($requestStack, $httpKernel);
        $result = $handler->handle($request, new AccessDeniedException());

        self::assertSame($expectedResponse, $result);
    }
}
