pdo-document/tests/unit/DocumentExceptionTest.php
Daniel J. Summers 294b608ac8 Implement In/InArray
- WIP on testdox name changes
2024-09-22 17:44:07 -04:00

57 lines
2.0 KiB
PHP

<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Unit;
use BitBadger\PDODocument\DocumentException;
use Exception;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the DocumentException class
*/
#[TestDox('Document Exception (Unit tests)')]
class DocumentExceptionTest extends TestCase
{
public function testConstructorSucceedsWithCodeAndPriorException(): void
{
$priorEx = new Exception('Uh oh');
$ex = new DocumentException('Test Exception', 17, $priorEx);
$this->assertNotNull($ex, 'The exception should not have been null');
$this->assertEquals('Test Exception', $ex->getMessage(), 'Message not filled properly');
$this->assertEquals(17, $ex->getCode(), 'Code not filled properly');
$this->assertSame($priorEx, $ex->getPrevious(), 'Prior exception not filled properly');
}
public function testConstructorSucceedsWithoutCodeAndPriorException(): void
{
$ex = new DocumentException('Oops');
$this->assertNotNull($ex, 'The exception should not have been null');
$this->assertEquals('Oops', $ex->getMessage(), 'Message not filled properly');
$this->assertEquals(0, $ex->getCode(), 'Code not filled properly');
$this->assertNull($ex->getPrevious(), 'Prior exception should have been null');
}
#[TestDox('toString() succeeds without code')]
public function testToStringSucceedsWithoutCode(): void
{
$ex = new DocumentException('Test failure');
$this->assertEquals("BitBadger\PDODocument\DocumentException: Test failure\n", "$ex",
'toString not generated correctly');
}
#[TestDox('toString() succeeds with code')]
public function testToStringSucceedsWithCode(): void
{
$ex = new DocumentException('Oof', -6);
$this->assertEquals("BitBadger\PDODocument\DocumentException: [-6] Oof\n", "$ex",
'toString not generated correctly');
}
}