Files
Php-Template/tests/Http/JsonResponseFactoryTest.php
Ron Rise 204c6efdec
Some checks failed
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 1m24s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m36s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m15s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m9s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 1m16s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m46s
feat: refactor JWT middleware and update annotations for guards
2025-11-07 11:06:15 -05:00

51 lines
1.5 KiB
PHP

<?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, $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, $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);
}
}