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\Mapper;
|
|
|
|
|
|
|
|
use BitBadger\PDODocument\{Configuration, DocumentException, Mode};
|
|
|
|
use BitBadger\PDODocument\Mapper\ExistsMapper;
|
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the ExistsMapper class
|
|
|
|
*/
|
2024-06-21 13:46:41 +00:00
|
|
|
#[TestDox('Exists Mapper (Unit tests)')]
|
2024-06-08 23:58:45 +00:00
|
|
|
class ExistsMapperTest extends TestCase
|
|
|
|
{
|
2024-09-23 00:18:17 +00:00
|
|
|
#[TestDox('map() succeeds for PostgreSQL')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testMapSucceedsForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
try {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertFalse((new ExistsMapper())->map([false, 'nope']), 'Result should have been false');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-23 00:18:17 +00:00
|
|
|
#[TestDox('map() succeeds for SQLite')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testMapSucceedsForSQLite(): void
|
|
|
|
{
|
|
|
|
try {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertTrue((new ExistsMapper())->map([1, 'yep']), 'Result should have been true');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-23 00:18:17 +00:00
|
|
|
#[TestDox('map() fails when mode not set')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testMapFailsWhenModeNotSet(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
(new ExistsMapper())->map(['0']);
|
|
|
|
}
|
|
|
|
}
|