2024-06-08 23:58:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Test\Unit;
|
|
|
|
|
|
|
|
use BitBadger\PDODocument\DocumentException;
|
|
|
|
use Exception;
|
2024-06-21 13:46:41 +00:00
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
2024-06-08 23:58:45 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the DocumentException class
|
|
|
|
*/
|
2024-06-21 13:46:41 +00:00
|
|
|
#[TestDox('Document Exception (Unit tests)')]
|
2024-06-08 23:58:45 +00:00
|
|
|
class DocumentExceptionTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testConstructorSucceedsWithCodeAndPriorException()
|
|
|
|
{
|
|
|
|
$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()
|
|
|
|
{
|
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testToStringSucceedsWithoutCode()
|
|
|
|
{
|
|
|
|
$ex = new DocumentException('Test failure');
|
|
|
|
$this->assertEquals("BitBadger\PDODocument\DocumentException: Test failure\n", "$ex",
|
|
|
|
'toString not generated correctly');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testToStringSucceedsWithCode()
|
|
|
|
{
|
|
|
|
$ex = new DocumentException('Oof', -6);
|
|
|
|
$this->assertEquals("BitBadger\PDODocument\DocumentException: [-6] Oof\n", "$ex",
|
|
|
|
'toString not generated correctly');
|
|
|
|
}
|
|
|
|
}
|