You've already forked Php-Template
feat: implement NotFoundResponse and ServerErrorResponse classes with corresponding tests
Some checks failed
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 4m16s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 4m17s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 4m27s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 4m32s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 4m15s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 3m1s
Some checks failed
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 4m16s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 4m17s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 4m27s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 4m32s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 4m15s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 3m1s
This commit is contained in:
22
tests/Http/Responses/NotFoundResponseTest.php
Normal file
22
tests/Http/Responses/NotFoundResponseTest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Siteworxpro\Tests\Http\Responses;
|
||||
|
||||
use Siteworxpro\App\Http\Responses\NotFoundResponse;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
class NotFoundResponseTest extends Unit
|
||||
{
|
||||
public function testToArray(): void
|
||||
{
|
||||
$response = new NotFoundResponse('/api/resource', ['key' => 'value']);
|
||||
|
||||
$expected = [
|
||||
'status_code' => 404,
|
||||
'message' => 'The requested resource /api/resource was not found.',
|
||||
'context' => ['key' => 'value'],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $response->toArray());
|
||||
}
|
||||
}
|
||||
89
tests/Http/Responses/ServerErrorResponseTest.php
Normal file
89
tests/Http/Responses/ServerErrorResponseTest.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Siteworxpro\Tests\Http\Responses;
|
||||
|
||||
use Siteworxpro\App\Http\Responses\ServerErrorResponse;
|
||||
use Siteworxpro\App\Services\Facades\Config;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
class ServerErrorResponseTest extends Unit
|
||||
{
|
||||
public function testToArrayInDevMode(): void
|
||||
{
|
||||
Config::set('app.dev_mode', true);
|
||||
|
||||
try {
|
||||
// Simulate an exception to generate a server error response
|
||||
throw new \Exception('A Test Error occurred.');
|
||||
} catch (\Exception $e) {
|
||||
$response = new ServerErrorResponse($e, ['operation' => 'data_processing']);
|
||||
|
||||
$expected = [
|
||||
'status_code' => 500,
|
||||
'message' => 'A Test Error occurred.',
|
||||
'context' => [
|
||||
'operation' => 'data_processing'
|
||||
],
|
||||
'file' => '/app/tests/Http/Responses/ServerErrorResponseTest.php',
|
||||
'line' => $e->getLine(),
|
||||
'trace' => $e->getTrace(),
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $response->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function testToArrayNotInDevMode(): void
|
||||
{
|
||||
try {
|
||||
throw new \Exception('A Test Error occurred.');
|
||||
} catch (\Exception $exception) {
|
||||
$response = new ServerErrorResponse($exception);
|
||||
|
||||
$expected = [
|
||||
'status_code' => 500,
|
||||
'message' => 'An internal server error occurred.',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $response->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function testToArrayIfCodeIsSet(): void
|
||||
{
|
||||
try {
|
||||
throw new \Exception('A Test Error occurred.', 1234);
|
||||
} catch (\Exception $exception) {
|
||||
$response = new ServerErrorResponse($exception);
|
||||
|
||||
$expected = [
|
||||
'status_code' => 1234,
|
||||
'message' => 'An internal server error occurred.',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $response->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
public function testToArrayIfCodeIsSetDevMode(): void
|
||||
{
|
||||
Config::set('app.dev_mode', true);
|
||||
|
||||
try {
|
||||
throw new \Exception('A Test Error occurred.', 1234);
|
||||
} catch (\Exception $exception) {
|
||||
$response = new ServerErrorResponse($exception);
|
||||
|
||||
$expected = [
|
||||
'status_code' => 1234,
|
||||
'message' => 'A Test Error occurred.',
|
||||
'file' => '/app/tests/Http/Responses/ServerErrorResponseTest.php',
|
||||
'line' => $exception->getLine(),
|
||||
'trace' => $exception->getTrace(),
|
||||
'context' => [],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $response->toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user