Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
75 lines
2.3 KiB
PHP
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->get_response();
|
|
$this->assertInstanceOf(Response::class, $response);
|
|
$this->assertSame(404, $response->status());
|
|
}
|
|
|
|
public function testGetResponseReturns403Response(): void
|
|
{
|
|
$e = HTTPException::factory(403);
|
|
$response = $e->get_response();
|
|
$this->assertInstanceOf(Response::class, $response);
|
|
$this->assertSame(403, $response->status());
|
|
}
|
|
|
|
public function testGetResponseBodyContainsHtml(): void
|
|
{
|
|
$e = HTTPException::factory(404);
|
|
$body = $e->get_response()->body();
|
|
$this->assertStringContainsString('404', $body);
|
|
}
|
|
|
|
public function testExtendsMyException(): void
|
|
{
|
|
$e = HTTPException::factory(404);
|
|
$this->assertInstanceOf(\System\Classes\MyException::class, $e);
|
|
}
|
|
}
|