2024-07-21 01:47:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2024-06-08 23:58:45 +00:00
|
|
|
|
|
|
|
namespace Test\Unit;
|
|
|
|
|
2024-06-11 11:07:56 +00:00
|
|
|
use BitBadger\PDODocument\{AutoId, Configuration, DocumentException};
|
2024-06-08 23:58:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the Configuration class
|
|
|
|
*/
|
2024-06-21 13:46:41 +00:00
|
|
|
#[TestDox('Configuration (Unit tests)')]
|
2024-06-08 23:58:45 +00:00
|
|
|
class ConfigurationTest extends TestCase
|
|
|
|
{
|
|
|
|
#[TestDox('ID field default succeeds')]
|
|
|
|
public function testIdFieldDefaultSucceeds(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals('id', Configuration::$idField, 'Default ID field should be "id"');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('ID field change succeeds')]
|
2024-08-30 13:24:25 +00:00
|
|
|
public function testIdFieldChangeSucceeds(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
Configuration::$idField = 'EyeDee';
|
|
|
|
$this->assertEquals('EyeDee', Configuration::$idField, 'ID field should have been updated');
|
|
|
|
} finally {
|
|
|
|
Configuration::$idField = 'id';
|
|
|
|
$this->assertEquals('id', Configuration::$idField, 'Default ID value should have been restored');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-11 11:07:56 +00:00
|
|
|
#[TestDox('Auto ID default succeeds')]
|
|
|
|
public function testAutoIdDefaultSucceeds(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(AutoId::None, Configuration::$autoId, 'Auto ID should default to None');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('ID string length default succeeds')]
|
|
|
|
public function testIdStringLengthDefaultSucceeds(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(16, Configuration::$idStringLength, 'ID string length should default to 16');
|
|
|
|
}
|
|
|
|
|
2024-06-08 23:58:45 +00:00
|
|
|
#[TestDox("Db conn fails when no DSN specified")]
|
|
|
|
public function testDbConnFailsWhenNoDSNSpecified(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::useDSN('');
|
2024-06-08 23:58:45 +00:00
|
|
|
Configuration::dbConn();
|
|
|
|
}
|
|
|
|
}
|