51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||
|
* @license MIT
|
||
|
*/
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
use BitBadger\PDODocument\{Count, Delete, DocumentException, Field};
|
||
|
use Test\Integration\SQLite\ThrowawayDb;
|
||
|
|
||
|
pest()->group('integration', 'sqlite');
|
||
|
|
||
|
describe('::byId()', function () {
|
||
|
test('deletes a document when one exists', function () {
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(5);
|
||
|
Delete::byId(ThrowawayDb::TABLE, 'four');
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(4);
|
||
|
});
|
||
|
test('does nothing when the document does not exist', function () {
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(5);
|
||
|
Delete::byId(ThrowawayDb::TABLE, 'negative four');
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(5);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('::byFields()', function () {
|
||
|
test('deletes matching documents', function () {
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(5);
|
||
|
Delete::byFields(ThrowawayDb::TABLE, [Field::notEqual('value', 'purple')]);
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(2);
|
||
|
});
|
||
|
test('does nothing when no documents match', function () {
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(5);
|
||
|
Delete::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'crimson')]);
|
||
|
expect(Count::all(ThrowawayDb::TABLE))->toBe(5);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('::byContains()', function () {
|
||
|
test('throws an exception', function () {
|
||
|
expect(fn () => Delete::byContains('', []))->toThrow(DocumentException::class);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('::byJsonPath()', function () {
|
||
|
test('throws an exception', function () {
|
||
|
expect(fn () => Delete::byJsonPath('', ''))->toThrow(DocumentException::class);
|
||
|
});
|
||
|
});
|