pdo-document/tests/Integration/SQLite/ExistsTest.php
2024-11-17 21:30:53 +00:00

43 lines
1.3 KiB
PHP

<?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);
});
});