<?php

namespace App\Tests\Controller;

use App\Controller\WebmailController;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;

class WebmailControllerTest extends TestCase
{
    private function buildController(): WebmailController
    {
        $session = new Session(new MockArraySessionStorage());
        $stack = $this->createStub(RequestStack::class);
        $stack->method('getSession')->willReturn($session);

        $twig = $this->createStub(Environment::class);
        $twig->method('render')->willReturn('<html></html>');

        $router = $this->createStub(RouterInterface::class);
        $router->method('generate')->willReturn('/some/path');

        $container = $this->createStub(ContainerInterface::class);
        $container->method('has')->willReturn(true);
        $container->method('get')->willReturnMap([
            ['twig', $twig],
            ['router', $router],
            ['request_stack', $stack],
        ]);

        $controller = new WebmailController();
        $controller->setContainer($container);

        return $controller;
    }

    public function testLoginRendersWebmailLoginTemplate(): void
    {
        $controller = $this->buildController();
        $response = $controller->login();

        $this->assertSame(200, $response->getStatusCode());
    }
}
