2024-07-21 01:47:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Test\Unit;
|
|
|
|
|
|
|
|
use BitBadger\PDODocument\{DocumentException, Mode};
|
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the Mode enumeration
|
|
|
|
*/
|
|
|
|
#[TestDox('Mode (Unit tests)')]
|
|
|
|
class ModeTest extends TestCase
|
|
|
|
{
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('deriveFromDSN() succeeds for PostgreSQL')]
|
2024-07-21 01:47:21 +00:00
|
|
|
public function testDeriveFromDSNSucceedsForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(Mode::PgSQL, Mode::deriveFromDSN('pgsql:Host=localhost'), 'PostgreSQL mode incorrect');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('deriveFromDSN() succeeds for SQLite')]
|
2024-07-21 01:47:21 +00:00
|
|
|
public function testDeriveFromDSNSucceedsForSQLite(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(Mode::SQLite, Mode::deriveFromDSN('sqlite:data.db'), 'SQLite mode incorrect');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('deriveFromDSN() fails for MySQL')]
|
2024-07-21 01:47:21 +00:00
|
|
|
public function testDeriveFromDSNFailsForMySQL(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
|
|
|
Mode::deriveFromDSN('mysql:Host=localhost');
|
|
|
|
}
|
|
|
|
}
|