You've already forked Php-Template
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m32s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m47s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m43s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m49s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 2m57s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 1m50s
🏗️✨ Build Workflow / 🖥️ 🔨 Build (push) Successful in 16m55s
🏗️✨ Build Workflow / 🖥️ 🔨 Build Migrations (push) Successful in 1m45s
90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?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' => $e->getFile(),
|
|
'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' => $exception->getFile(),
|
|
'line' => $exception->getLine(),
|
|
'trace' => $exception->getTrace(),
|
|
'context' => [],
|
|
];
|
|
|
|
$this->assertEquals($expected, $response->toArray());
|
|
}
|
|
}
|
|
}
|