46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||
|
* @license MIT
|
||
|
*/
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
use BitBadger\PDODocument\{Count, Field};
|
||
|
use Test\Integration\PostgreSQL\ThrowawayDb;
|
||
|
|
||
|
pest()->group('integration', 'postgresql');
|
||
|
|
||
|
describe('::all()', function () {
|
||
|
test('counts all documents', function () {
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(5);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('::byFields()', function () {
|
||
|
test('counts for numeric range correctly', function () {
|
||
|
expect(Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]))->toBe(3);
|
||
|
});
|
||
|
test('counts for non-numeric range correctly', function () {
|
||
|
expect(Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]))->toBe(1);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('::byContains()', function () {
|
||
|
test('counts matching documents', function () {
|
||
|
expect(Count::byContains(ThrowawayDb::TABLE, ['value' => 'purple']))->toBe(2);
|
||
|
});
|
||
|
test('returns 0 for no matching documents', function () {
|
||
|
expect(Count::byContains(ThrowawayDb::TABLE, ['value' => 'magenta']))->toBe(0);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('::byJsonPath()', function () {
|
||
|
test('counts matching documents', function () {
|
||
|
expect(Count::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ < 5)'))->toBe(2);
|
||
|
});
|
||
|
test('returns 0 for no matching documents', function () {
|
||
|
expect(Count::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)'))->toBe(0);
|
||
|
});
|
||
|
});
|