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

40 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2024-11-17 21:30:53 +00:00
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
use BitBadger\PDODocument\{Count, DocumentException, Field};
use Test\Integration\SQLite\ThrowawayDb;
pest()->group('integration', 'sqlite');
describe('::all()', function () {
test('counts all documents', function () {
expect(Count::all(ThrowawayDb::TABLE))->toBe(5);
});
});
describe('::byFields()', function () {
test('counts by numeric range', function () {
expect(Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]))->toBe(3);
});
test('counts by non-numeric range', function () {
expect(Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]))->toBe(1);
});
});
describe('::byContains()', function () {
test('throws an exception', function () {
expect(fn () => Count::byContains('', []))->toThrow(DocumentException::class);
});
});
describe('::byJsonPath()', function () {
test('throws an exception', function () {
expect(fn () => Count::byJsonPath('', ''))->toThrow(DocumentException::class);
});
});