2024-06-03 23:46:39 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Test\Unit;
|
|
|
|
|
2024-06-08 03:06:31 +00:00
|
|
|
use BitBadger\PDODocument\{Configuration, DocumentException};
|
2024-06-04 00:13:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
2024-06-03 23:46:39 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the Configuration class
|
|
|
|
*/
|
|
|
|
class ConfigurationTest extends TestCase
|
|
|
|
{
|
2024-06-04 03:10:12 +00:00
|
|
|
#[TestDox('ID field default succeeds')]
|
2024-06-03 23:46:39 +00:00
|
|
|
public function testIdFieldDefaultSucceeds(): void
|
|
|
|
{
|
2024-06-04 00:13:45 +00:00
|
|
|
$this->assertEquals('id', Configuration::$idField, 'Default ID field should be "id"');
|
2024-06-03 23:46:39 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 03:10:12 +00:00
|
|
|
#[TestDox('ID field change succeeds')]
|
2024-06-04 00:13:45 +00:00
|
|
|
public function testIdFieldChangeSucceeds()
|
2024-06-03 23:46:39 +00:00
|
|
|
{
|
|
|
|
try {
|
2024-06-04 00:13:45 +00:00
|
|
|
Configuration::$idField = 'EyeDee';
|
|
|
|
$this->assertEquals('EyeDee', Configuration::$idField, 'ID field should have been updated');
|
2024-06-03 23:46:39 +00:00
|
|
|
} finally {
|
2024-06-04 00:13:45 +00:00
|
|
|
Configuration::$idField = 'id';
|
|
|
|
$this->assertEquals('id', Configuration::$idField, 'Default ID value should have been restored');
|
2024-06-03 23:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-04 00:13:45 +00:00
|
|
|
|
|
|
|
#[TestDox("Db conn fails when no DSN specified")]
|
|
|
|
public function testDbConnFailsWhenNoDSNSpecified(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
2024-06-08 03:06:31 +00:00
|
|
|
Configuration::$pdoDSN = '';
|
2024-06-04 00:13:45 +00:00
|
|
|
Configuration::dbConn();
|
|
|
|
}
|
2024-06-03 23:46:39 +00:00
|
|
|
}
|