Add in software files and templates

This commit is contained in:
2023-06-21 14:19:40 +01:00
parent f42fdb947c
commit 5228fc5e9f
143 changed files with 23175 additions and 2 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace Liuch\DmarcSrg;
use Liuch\DmarcSrg\Exception\DatabaseExceptionFactory;
class DatabaseExceptionFactoryTest extends \PHPUnit\Framework\TestCase
{
public function testWhenDatabaseAccessDenied(): void
{
$o = new \PDOException('', 1044);
$e = DatabaseExceptionFactory::fromException($o);
$this->checkException($e, 'Database access denied', $o);
$o = new \PDOException('', 1045);
$e = DatabaseExceptionFactory::fromException($o);
$this->checkException($e, 'Database access denied', $o);
}
public function testWhenDatabaseConnectionError(): void
{
$o = new \PDOException('', 2002);
$e = DatabaseExceptionFactory::fromException($o);
$this->checkException($e, 'Database connection error', $o);
$o = new \PDOException('', 2006);
$e = DatabaseExceptionFactory::fromException($o);
$this->checkException($e, 'Database connection error', $o);
}
public function testUnknownException(): void
{
$o = new \Exception('', 1044);
$e = DatabaseExceptionFactory::fromException($o);
$this->checkException($e, 'Database error', $o);
$o = new \Exception('Some error');
$e = DatabaseExceptionFactory::fromException($o);
$this->checkException($e, 'Database error', $o);
}
private function checkException($e, $m, $o): void
{
$this->assertSame('Liuch\DmarcSrg\Exception\DatabaseException', get_class($e));
$this->assertSame(-1, $e->getCode());
$this->assertSame($m, $e->getMessage());
$this->assertSame($o, $e->getPrevious());
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Liuch\DmarcSrg;
use Liuch\DmarcSrg\Exception\RuntimeException;
class RuntimeExceptionTest extends \PHPUnit\Framework\TestCase
{
public function testExceptionCode(): void
{
$this->assertSame(-1, (new RuntimeException())->getCode());
$this->assertSame(0, (new RuntimeException('', 0))->getCode());
$this->assertSame(-1, (new RuntimeException('', -1))->getCode());
$this->assertSame(77, (new RuntimeException('', 77))->getCode());
}
}