pdo-document/tests/Integration/SQLite/ExistsTest.php

43 lines
1.3 KiB
PHP
Raw Normal View History

2024-11-16 03:25:14 +00:00
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
use BitBadger\PDODocument\{DocumentException, Exists, Field};
use Test\Integration\SQLite\ThrowawayDb;
pest()->group('integration', 'sqlite');
describe('::byId()', function () {
test('returns true when a document exists', function () {
expect(Exists::byId(ThrowawayDb::TABLE, 'three'))->toBeTrue();
});
test('returns false when no document exists', function () {
expect(Exists::byId(ThrowawayDb::TABLE, 'seven'))->toBeFalse();
});
});
describe('::byFields()', function () {
test('returns true when matching documents exist', function () {
expect(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]))->toBeTrue();
});
test('returns false when no matching documents exist', function () {
expect(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]))->toBeFalse();
});
});
describe('::byContains()', function () {
test('throws an exception', function () {
expect(fn () => Exists::byContains('', []))->toThrow(DocumentException::class);
});
});
describe('::byJsonPath()', function () {
test('throws an exception', function () {
expect(fn () => Exists::byJsonPath('', ''))->toThrow(DocumentException::class);
});
});