Bicycle/tests/Unit/HTTPExceptionTest.php
Egor Isaev b65603b4d0 dev
2026-06-23 10:44:18 +03:00

75 lines
2.3 KiB
PHP

<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use System\Classes\HTTP\Exception\HTTPException_403;
use System\Classes\HTTP\Exception\HTTPException_404;
use System\Classes\HTTP\HTTPException;
use System\Classes\Response;
class HTTPExceptionTest extends TestCase
{
public function testFactory404ReturnsCorrectClass(): void
{
$e = HTTPException::factory(404);
$this->assertInstanceOf(HTTPException_404::class, $e);
$this->assertSame(404, $e->getCode());
}
public function testFactory403ReturnsCorrectClass(): void
{
$e = HTTPException::factory(403);
$this->assertInstanceOf(HTTPException_403::class, $e);
$this->assertSame(403, $e->getCode());
}
public function testFactoryWithMessage(): void
{
$e = HTTPException::factory(404, 'Страница не найдена');
$this->assertSame('Страница не найдена', $e->getMessage());
}
public function testFactoryWithVariables(): void
{
$e = HTTPException::factory(404, 'Файл :name не найден', [':name' => 'test.html']);
$this->assertSame('Файл test.html не найден', $e->getMessage());
}
public function testFactoryUnknownCodeReturnsBaseClass(): void
{
$e = HTTPException::factory(418);
$this->assertInstanceOf(HTTPException::class, $e);
$this->assertSame(418, $e->getCode());
}
public function testGetResponseReturns404Response(): void
{
$e = HTTPException::factory(404);
$response = $e->getResponse();
$this->assertInstanceOf(Response::class, $response);
$this->assertSame(404, $response->status());
}
public function testGetResponseReturns403Response(): void
{
$e = HTTPException::factory(403);
$response = $e->getResponse();
$this->assertInstanceOf(Response::class, $response);
$this->assertSame(403, $response->status());
}
public function testGetResponseBodyContainsHtml(): void
{
$e = HTTPException::factory(404);
$body = $e->getResponse()->body();
$this->assertStringContainsString('404', $body);
}
public function testExtendsMyException(): void
{
$e = HTTPException::factory(404);
$this->assertInstanceOf(\System\Classes\MyException::class, $e);
}
}