CodeFehlerAntwortTest.php
Pfad: tests/CodeFehlerAntwortTest.php
Ext: php
Größe: 1238 Bytes
Geändert: 2026-07-16 10:17:43+02
<?php
declare(strict_types=1);
namespace Tests;
use Demo\Infrastructure\Http\CodeFehlerAntwort;
use PDOException;
use PHPUnit\Framework\TestCase;
/**
* Testet die Nutzerfehlermeldung für fehlende Code-DB-Relationen.
*/
final class CodeFehlerAntwortTest extends TestCase
{
/**
* Registriert den Autoloader für die Testklasse.
*/
protected function setUp(): void
{
$root = dirname(__DIR__);
require_once $root . '/src/Autoloader.php';
(new \Demo\Autoloader($root . '/src'))->register();
}
public function testFehlendeCodeTabelleErzeugt500Antwort(): void
{
$antwort = new CodeFehlerAntwort();
$throwable = new PDOException(
'relation "code_datei" does not exist',
1
);
$res = $antwort->fehlendeCodeTabelle($throwable);
self::assertNotNull($res);
self::assertSame(500, $res->status);
self::assertStringContainsString('0009_code_datei.sql', $res->body);
}
public function testAndereFehlerWerdenNichtGehandhabt(): void
{
$antwort = new CodeFehlerAntwort();
$res = $antwort->fehlendeCodeTabelle(new \RuntimeException('oops'));
self::assertNull($res);
}
}