<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\Controller\Page;

use Ferienpass\AdminBundle\Controller\Page\Error403Controller;
use Ferienpass\CoreBundle\Settings\MailConfigManager;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Twig\Environment;

final class Error403ControllerTest extends TestCase
{
    public function testInvokeRendersTemplateWithAdminEmail(): void
    {
        $mailConfig = $this->createMock(MailConfigManager::class);
        $mailConfig->method('getAdminEmail')->willReturn('admin@example.com');
        $mailConfig->method('getAdminEmailName')->willReturn('Admin');

        $twig = $this->createMock(Environment::class);
        $twig->expects(self::once())
            ->method('render')
            ->with(
                '@FerienpassAdmin/page/error/403.html.twig',
                self::callback(function (array $params): bool {
                    return 'admin@example.com' === $params['adminEmail']
                        && 'Admin' === $params['adminEmailName'];
                }),
            )
            ->willReturn('Forbidden');

        $container = new Container();
        $container->set('twig', $twig);

        $controller = new Error403Controller($mailConfig);
        $controller->setContainer($container);

        $response = $controller();

        self::assertSame(200, $response->getStatusCode());
        self::assertSame('Forbidden', $response->getContent());
    }
}
