* @license MIT */ declare(strict_types=1); use BitBadger\PDODocument\{DocumentException, DocumentList, Query}; use BitBadger\PDODocument\Mapper\DocumentMapper; use Test\Integration\PostgreSQL\ThrowawayDb; use Test\Integration\TestDocument; pest()->group('integration', 'postgresql'); describe('::create()', function () { test('creates a document list', function () { $list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class)); expect($list)->not->toBeNull(); $list = null; // free database result }); }); describe('::items()', function () { test('enumerates items in the list', function () { $list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class)); expect($list)->not->toBeNull(); $count = 0; foreach ($list->items() as $item) { expect(['one', 'two', 'three', 'four', 'five'])->toContain($item->id); $count++; } expect($count)->toBe(5); }); test('fails when the list is exhausted', function () { $list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class)); expect($list)->not->toBeNull()->hasItems()->toBeTrue(); $ignored = iterator_to_array($list->items()); expect($list)->hasItems()->toBeFalse() ->and(fn () => iterator_to_array($list->items()))->toThrow(DocumentException::class); }); });