<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CmsBundle\Tests\Exception;

use Ferienpass\CmsBundle\Exception\TurboStreamResponseException;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;

final class TurboStreamResponseExceptionTest extends TestCase
{
    public function testSetsContentTypeHeaderWhenMissing(): void
    {
        $response = new Response('body');
        $exception = new TurboStreamResponseException($response);

        self::assertSame('text/vnd.turbo-stream.html', $exception->getResponse()->headers->get('Content-Type'));
    }

    public function testDoesNotOverrideExistingContentTypeHeader(): void
    {
        $response = new Response('body', 200, ['Content-Type' => 'text/html']);
        $exception = new TurboStreamResponseException($response);

        self::assertSame('text/html', $exception->getResponse()->headers->get('Content-Type'));
    }

    public function testExceptionWrapsResponse(): void
    {
        $response = new Response('body');
        $exception = new TurboStreamResponseException($response);

        self::assertSame($response, $exception->getResponse());
    }
}
