Migrate tests to Pest (#8)
Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
45
tests/Integration/PostgreSQL/CountTest.php
Normal file
45
tests/Integration/PostgreSQL/CountTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user