<?php
/**
 * @author Daniel J. Summers <daniel@bitbadger.solutions>
 * @license MIT
 */

declare(strict_types=1);

use BitBadger\PDODocument\{Configuration, DocumentException, Mode};
use BitBadger\PDODocument\Mapper\ExistsMapper;

pest()->group('unit');

afterEach(function () { Configuration::overrideMode(null); });

describe('->map()', function () {
    test('returns a boolean value from index 0 [PostgreSQL]', function () {
        Configuration::overrideMode(Mode::PgSQL);
        expect((new ExistsMapper())->map([false, 'nope']))->toBeFalse();
    });
    test('returns a number value as boolean from index 0 [SQLite]', function () {
        Configuration::overrideMode(Mode::SQLite);
        expect((new ExistsMapper())->map([1, 'yep']))->toBeTrue();
    });
    test('throws if mode is not set', function () {
        expect(fn() => (new ExistsMapper())->map(['0']))->toThrow(DocumentException::class);
    });
});