Initial commit

This commit is contained in:
2025-12-29 16:27:01 +00:00
committed by Siteworx Pro Gitea
commit 23f2b6432b
147 changed files with 14731 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace Siteworxpro\Tests\Http;
use PHPUnit\Framework\TestCase;
use Siteworxpro\App\Http\JsonResponseFactory;
use Siteworxpro\HttpStatus\CodesEnum;
class JsonResponseFactoryTest extends TestCase
{
/**
* @throws \JsonException
*/
public function testCreateJsonResponseReturnsValidResponse(): void
{
$data = ['key' => 'value'];
$statusCode = CodesEnum::OK;
$response = JsonResponseFactory::createJsonResponse($data, $statusCode);
$this->assertSame($statusCode->value, $response->getStatusCode());
$this->assertSame('application/json', $response->getHeaderLine('Content-Type'));
$this->assertSame(json_encode($data), (string) $response->getBody());
}
/**
* @throws \JsonException
*/
public function testCreateJsonResponseHandlesEmptyData(): void
{
$data = [];
$statusCode = CodesEnum::NO_CONTENT;
$response = JsonResponseFactory::createJsonResponse($data, $statusCode);
$this->assertSame($statusCode->value, $response->getStatusCode());
$this->assertSame('application/json', $response->getHeaderLine('Content-Type'));
$this->assertSame(json_encode($data), (string) $response->getBody());
}
public function testCreateJsonResponseThrowsExceptionOnInvalidData(): void
{
$this->expectException(\JsonException::class);
$data = ["invalid" => "\xB1\x31"];
JsonResponseFactory::createJsonResponse($data);
}
}