<?php

namespace Tests\Unit\Framework;

use Symfony\Component\HttpFoundation\JsonResponse;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

class JsonResponseTest extends TestCase
{
    public function testConstructorSetsDataAndCode(): void
    {
        $data = ['key' => 'value'];
        $code = 201;
        $response = new JsonResponse($data, $code);

        $this->assertEquals('{"key":"value"}', $response->getContent());
        $this->assertEquals($code, $response->getStatusCode());
    }

    public function testDefaultCodeIs200(): void
    {
        $data = ['key' => 'value'];
        $response = new JsonResponse($data);

        $this->assertEquals(SymfonyResponse::HTTP_OK, $response->getStatusCode());
    }

    public function testGetDataReturnsCorrectData(): void
    {
        $data = ['message' => 'success', 'items' => [1, 2, 3]];
        $response = new JsonResponse($data);

        $this->assertEquals('{"message":"success","items":[1,2,3]}', $response->getContent());
    }

    public function testGetCodeReturnsCorrectCode(): void
    {
        $response = new JsonResponse([], 404);

        $this->assertEquals(404, $response->getStatusCode());
    }

    public function testCanUseHttpConstants(): void
    {
        $response = new JsonResponse([], JsonResponse::HTTP_CREATED);

        $this->assertEquals(201, $response->getStatusCode());
    }
}

