Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use System\Classes\MyException;
|
|
|
|
class MyExceptionTest extends TestCase
|
|
{
|
|
public function testMessageWithoutVariables(): void
|
|
{
|
|
$e = new MyException('Something went wrong');
|
|
$this->assertSame('Something went wrong', $e->getMessage());
|
|
}
|
|
|
|
public function testMessageWithVariables(): void
|
|
{
|
|
$e = new MyException('File :file not found', [':file' => 'test.html']);
|
|
$this->assertSame('File test.html not found', $e->getMessage());
|
|
}
|
|
|
|
public function testMultipleVariables(): void
|
|
{
|
|
$e = new MyException(':a + :b = :c', [':a' => '1', ':b' => '2', ':c' => '3']);
|
|
$this->assertSame('1 + 2 = 3', $e->getMessage());
|
|
}
|
|
|
|
public function testNullVariablesLeavesMessageUntouched(): void
|
|
{
|
|
$e = new MyException('Plain :message', null);
|
|
$this->assertSame('Plain :message', $e->getMessage());
|
|
}
|
|
|
|
public function testCodeIsSet(): void
|
|
{
|
|
$e = new MyException('Error', null, 42);
|
|
$this->assertSame(42, $e->getCode());
|
|
}
|
|
|
|
public function testDefaultCode(): void
|
|
{
|
|
$e = new MyException('Error');
|
|
$this->assertSame(0, $e->getCode());
|
|
}
|
|
|
|
public function testPreviousException(): void
|
|
{
|
|
$prev = new \Exception('original');
|
|
$e = new MyException('Wrapped', null, 0, $prev);
|
|
$this->assertSame($prev, $e->getPrevious());
|
|
}
|
|
|
|
public function testExtendsException(): void
|
|
{
|
|
$e = new MyException('test');
|
|
$this->assertInstanceOf(\Exception::class, $e);
|
|
}
|
|
}
|