diff --git a/README.md b/README.md index fa9dd682..0cfae9f5 100644 --- a/README.md +++ b/README.md @@ -12,39 +12,6 @@ DocuWare REST API. It is used to query the most common endpoints. [DocuWare REST API](https://developer.docuware.com/rest/index.html). See the documentation if you need further functionality. ⚠️ -## Table of Contents - - - * [Table of Contents](#table-of-contents) - * [💡 What is DocuWare?](#-what-is-docuware) - * [🛠 Requirements](#-requirements) - * [SOmething else](#something-else) - * [> = v4.0 (alpha)](#---v40-alpha) - * [> = v3.0](#---v30) - * [> = v2.0](#---v20) - * [> = v1.2](#---v12) - * [< v1.2](#-v12) - * [⚙️ Installation](#-installation) - * [🏗 Usage](#-usage) - * [Pagination](#pagination) - * [🔍 Search usage](#-search-usage) - * [🖼 Make encrypted URL](#-make-encrypted-url) - * [🏋️ Document Index Fields DTO showcase](#-document-index-fields-dto-showcase) - * [🏋️ DTO showcase](#-dto-showcase) - * [🔐 Authentication](#-authentication) - * [Manual authentication](#manual-authentication) - * [📦 Caching requests](#-caching-requests) - * [💥 Exceptions explained](#-exceptions-explained) - * [✨ Events](#-events) - * [🔧 Configuration file](#-configuration-file) - * [🚧 Testing](#-testing) - * [📝 Changelog](#-changelog) - * [✏️ Contributing](#-contributing) - * [🧑‍💻 Security Vulnerabilities](#-security-vulnerabilities) - * [🙏 Credits](#-credits) - * [🎭 License](#-license) - - ## 💡 What is DocuWare? DocuWare provides cloud document management and workflow automation software @@ -276,61 +243,6 @@ $document = $connector->send(new PostDocumentRequest( $connector->send(new DeleteDocumentRequest($fileCabinetId, $document->id))->dto(); ``` -## Pagination - -Requests that support pagination: - -| Requests | -|-------------------------| -| GetDialogsRequest | -| GetDocumentsRequest | -| GetFieldsRequest | -| GetFileCabinetsRequest | -| GetOrganizationsRequest | -| GetSearchRequest | -| GetSectionsRequest | - - -```php - $paginator = $connector->paginate(new GetDocumentsRequest( - config('laravel-docuware.tests.file_cabinet_id') - )); - - // You can set the per page limit - $paginator->setPerPageLimit(2); - - - - // You can set the start page and how many pages you want to get - - $paginator->setStartPage(3); - $paginator->setMaxPages(3); // Should be equal or more than the start page - - // OR - - $paginator->getSinglePage(3); - - - - // Get the data from the paginator - - $data = collect(); - - foreach ($paginator->collect() as $collection) { - $data->push($collection); - } - - // OR - - foreach ($paginator as $response) { - $data->push($response->dto()); - } - - - - $data->flatten() -``` - ## 🔍 Search usage ```php @@ -688,6 +600,27 @@ CodebarAg\DocuWare\DTO\TableRow { } ``` +```php +CodebarAg\DocuWare\DTO\DocumentPaginator + +total: 39 // integer + +per_page: 10 // integer + +current_page: 9 // integer + +last_page: 15 // integer + +from: 1 // integer + +to: 10 // integer + +documents: Illuminate\Support\Collection { // Collection|Document[] + #items: array:2 [ + 0 => CodebarAg\DocuWare\DTO\Document // Document + 1 => CodebarAg\DocuWare\DTO\Document // Document + ] + } + +error: CodebarAg\DocuWare\DTO\ErrorBag { // ErrorBag|null + +code: 422 // int + +message: "'000' is not valid cabinet id" // string + } +} +``` + ## 🔐 Authentication You only need to provide correct credentials. Everything else is automatically diff --git a/composer.json b/composer.json index 8c742da8..b6f3bdf8 100644 --- a/composer.json +++ b/composer.json @@ -29,9 +29,8 @@ "illuminate/contracts": "^9.0|^10.0", "nesbot/carbon": "^2.64.0", "saloonphp/cache-plugin": "^3.0", - "saloonphp/laravel-plugin": "^3.0", - "saloonphp/pagination-plugin": "^2.1", "saloonphp/saloon": "^3.0", + "saloonphp/laravel-plugin": "^3.0", "spatie/laravel-package-tools": "^1.14.0" }, "require-dev": { diff --git a/src/Connectors/DocuWareDynamicConnector.php b/src/Connectors/DocuWareDynamicConnector.php index bb367a42..f8eca50c 100644 --- a/src/Connectors/DocuWareDynamicConnector.php +++ b/src/Connectors/DocuWareDynamicConnector.php @@ -6,11 +6,8 @@ use CodebarAg\DocuWare\Support\Auth; use GuzzleHttp\Cookie\CookieJar; use Saloon\Http\Connector; -use Saloon\Http\Request; -use Saloon\PaginationPlugin\Contracts\HasPagination; -use Saloon\PaginationPlugin\OffsetPaginator; -class DocuWareDynamicConnector extends Connector implements HasPagination +class DocuWareDynamicConnector extends Connector { public Config $configuration; @@ -58,9 +55,4 @@ public function getConfiguration(): Config { return $this->configuration; } - - public function paginate(Request $request): OffsetPaginator - { - return new DocuWareOffsetPaginator(connector: $this, request: $request); - } } diff --git a/src/Connectors/DocuWareOffsetPaginator.php b/src/Connectors/DocuWareOffsetPaginator.php deleted file mode 100644 index 2eef18e1..00000000 --- a/src/Connectors/DocuWareOffsetPaginator.php +++ /dev/null @@ -1,50 +0,0 @@ -setStartPage($page)->setMaxPages($page); - } - - protected function isLastPage(Response $response): bool - { - $count = Arr::get($response->json(), 'Count'); - - return $this->getOffset() >= (int) Arr::get($count, 'Value'); - } - - protected function getTotalPages(Response $response): int - { - $count = Arr::get($response->json(), 'Count'); - - return (int) ceil((Arr::get($count, 'Value') / $this->perPageLimit)); - } - - protected function getPageItems(Response $response, Request $request): array - { - return [ - $response->dto(), - ]; - } - - protected function applyPagination(Request $request): Request - { - $request->query()->merge([ - 'count' => $this->perPageLimit, - 'start' => $this->getOffset(), - ]); - - return $request; - } -} diff --git a/src/Connectors/DocuWareStaticConnector.php b/src/Connectors/DocuWareStaticConnector.php index 4dde57b7..e18ff25d 100644 --- a/src/Connectors/DocuWareStaticConnector.php +++ b/src/Connectors/DocuWareStaticConnector.php @@ -7,11 +7,8 @@ use CodebarAg\DocuWare\Support\EnsureValidCredentials; use GuzzleHttp\Cookie\CookieJar; use Saloon\Http\Connector; -use Saloon\Http\Request; -use Saloon\PaginationPlugin\Contracts\HasPagination; -use Saloon\PaginationPlugin\OffsetPaginator; -class DocuWareStaticConnector extends Connector implements HasPagination +class DocuWareStaticConnector extends Connector { public CookieJar $cookieJar; @@ -50,9 +47,4 @@ public function getCoookieJar(): CookieJar { return $this->cookieJar; } - - public function paginate(Request $request): OffsetPaginator - { - return new DocuWareOffsetPaginator(connector: $this, request: $request); - } } diff --git a/src/DocuWareSearchRequestBuilder.php b/src/DocuWareSearchRequestBuilder.php index 81d0b49a..a347c1c7 100644 --- a/src/DocuWareSearchRequestBuilder.php +++ b/src/DocuWareSearchRequestBuilder.php @@ -17,6 +17,10 @@ class DocuWareSearchRequestBuilder protected array $additionalFileCabinetIds = []; + protected int $page = 1; + + protected int $perPage = 50; + protected ?string $searchTerm = null; protected string $orderField = 'DWSTOREDATETIME'; @@ -50,6 +54,28 @@ public function dialog(string $dialogId): self return $this; } + public function page(?int $page): self + { + if (is_null($page)) { + $this->page = 1; + } else { + $this->page = $page; + } + + return $this; + } + + public function perPage(?int $perPage): self + { + if (is_null($perPage)) { + $this->perPage = 50; + } else { + $this->perPage = $perPage; + } + + return $this; + } + public function fulltext(?string $searchTerm): self { $this->searchTerm = $searchTerm; @@ -148,6 +174,8 @@ public function get(): GetSearchRequest fileCabinetId: $this->fileCabinetId, dialogId: $this->dialogId, additionalFileCabinetIds: $this->additionalFileCabinetIds, + page: $this->page, + perPage: $this->perPage, searchTerm: $this->searchTerm, orderField: $this->orderField, orderDirection: $this->orderDirection, @@ -161,6 +189,16 @@ protected function guard(): void is_null($this->fileCabinetId), UnableToSearch::cabinetNotSet(), ); + + throw_if( + $this->page <= 0, + UnableToSearch::invalidPageNumber($this->page), + ); + + throw_if( + $this->perPage <= 0, + UnableToSearch::invalidPerPageNumber($this->perPage), + ); } private function checkDateFilterRangeDivergence(): void diff --git a/src/Requests/Dialogs/GetDialogsRequest.php b/src/Requests/Dialogs/GetDialogsRequest.php index fe0c2d6d..e8731fb1 100644 --- a/src/Requests/Dialogs/GetDialogsRequest.php +++ b/src/Requests/Dialogs/GetDialogsRequest.php @@ -10,9 +10,8 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetDialogsRequest extends Request implements Cacheable, Paginatable +class GetDialogsRequest extends Request implements Cacheable { use HasCaching; diff --git a/src/Requests/Document/GetDocumentsRequest.php b/src/Requests/Document/GetDocumentsRequest.php index 30be4cff..2a41c05a 100644 --- a/src/Requests/Document/GetDocumentsRequest.php +++ b/src/Requests/Document/GetDocumentsRequest.php @@ -11,9 +11,8 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetDocumentsRequest extends Request implements Cacheable, Paginatable +class GetDocumentsRequest extends Request implements Cacheable { use HasCaching; diff --git a/src/Requests/Fields/GetFieldsRequest.php b/src/Requests/Fields/GetFieldsRequest.php index 13702d7e..3361f532 100644 --- a/src/Requests/Fields/GetFieldsRequest.php +++ b/src/Requests/Fields/GetFieldsRequest.php @@ -12,9 +12,8 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetFieldsRequest extends Request implements Cacheable, Paginatable +class GetFieldsRequest extends Request implements Cacheable { use HasCaching; diff --git a/src/Requests/FileCabinets/GetFileCabinetsRequest.php b/src/Requests/FileCabinets/GetFileCabinetsRequest.php index a5772781..3fbef5af 100644 --- a/src/Requests/FileCabinets/GetFileCabinetsRequest.php +++ b/src/Requests/FileCabinets/GetFileCabinetsRequest.php @@ -12,9 +12,8 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetFileCabinetsRequest extends Request implements Cacheable, Paginatable +class GetFileCabinetsRequest extends Request implements Cacheable { use HasCaching; diff --git a/src/Requests/Organization/GetOrganizationsRequest.php b/src/Requests/Organization/GetOrganizationsRequest.php index 7d8c81f1..21872337 100644 --- a/src/Requests/Organization/GetOrganizationsRequest.php +++ b/src/Requests/Organization/GetOrganizationsRequest.php @@ -12,9 +12,8 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetOrganizationsRequest extends Request implements Cacheable, Paginatable +class GetOrganizationsRequest extends Request implements Cacheable { use HasCaching; diff --git a/src/Requests/Search/GetSearchRequest.php b/src/Requests/Search/GetSearchRequest.php index 20d9480b..a06800e9 100644 --- a/src/Requests/Search/GetSearchRequest.php +++ b/src/Requests/Search/GetSearchRequest.php @@ -2,9 +2,8 @@ namespace CodebarAg\DocuWare\Requests\Search; -use CodebarAg\DocuWare\DTO\Document; -use Illuminate\Support\Arr; -use Illuminate\Support\Collection; +use CodebarAg\DocuWare\DTO\DocumentPaginator; +use CodebarAg\DocuWare\Responses\Search\GetSearchResponse; use Illuminate\Support\Facades\Cache; use Saloon\CachePlugin\Contracts\Cacheable; use Saloon\CachePlugin\Drivers\LaravelCacheDriver; @@ -13,10 +12,9 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Saloon\PaginationPlugin\Contracts\Paginatable; use Saloon\Traits\Body\HasJsonBody; -class GetSearchRequest extends Request implements Cacheable, HasBody, Paginatable +class GetSearchRequest extends Request implements Cacheable, HasBody { use HasCaching; use HasJsonBody; @@ -27,6 +25,8 @@ public function __construct( protected readonly ?string $fileCabinetId, protected readonly ?string $dialogId = null, protected readonly array $additionalFileCabinetIds = [], + protected readonly int $page = 1, + protected readonly int $perPage = 50, protected readonly ?string $searchTerm = null, protected readonly string $orderField = 'DWSTOREDATETIME', protected readonly string $orderDirection = 'asc', @@ -63,6 +63,8 @@ public function defaultQuery(): array public function defaultBody(): array { return [ + 'Count' => $this->perPage, + 'Start' => ($this->page - 1) * $this->perPage, 'Condition' => $this->condition, 'AdditionalCabinets' => $this->additionalFileCabinetIds, 'SortOrder' => [ @@ -78,10 +80,8 @@ public function defaultBody(): array ]; } - public function createDtoFromResponse(Response $response): Collection + public function createDtoFromResponse(Response $response): DocumentPaginator { - return collect(Arr::get($response->json(), 'Items'))->map(function (array $document) { - return Document::fromJson($document); - }); + return GetSearchResponse::fromResponse($response, $this->page, $this->perPage); } } diff --git a/src/Requests/Sections/GetSectionsRequest.php b/src/Requests/Sections/GetSectionsRequest.php index 257e3ce1..7609933e 100644 --- a/src/Requests/Sections/GetSectionsRequest.php +++ b/src/Requests/Sections/GetSectionsRequest.php @@ -12,9 +12,8 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; -use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetSectionsRequest extends Request implements Cacheable, Paginatable +class GetSectionsRequest extends Request implements Cacheable { use HasCaching; diff --git a/tests/Feature/Requests/Document/GetDocumentsRequestTest.php b/tests/Feature/Requests/Document/GetDocumentsRequestTest.php index dc5cde8c..b68acd95 100644 --- a/tests/Feature/Requests/Document/GetDocumentsRequestTest.php +++ b/tests/Feature/Requests/Document/GetDocumentsRequestTest.php @@ -25,35 +25,3 @@ Event::assertDispatched(DocuWareResponseLog::class); }); - -it('can get all documents paginated', function () { - Event::fake(); - - for ($i = 0; $i < 4; $i++) { - $this->connector->send(new PostDocumentRequest( - config('laravel-docuware.tests.file_cabinet_id'), - '::fake-file-content::', - 'example.txt' - ))->dto(); - } - - $request = new GetDocumentsRequest( - config('laravel-docuware.tests.file_cabinet_id') - ); - - $paginator = $this->connector->paginate($request); - - $paginator->setPerPageLimit(2); - - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(2, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(4, $documents->flatten()); - - Event::assertDispatched(DocuWareResponseLog::class); -}); diff --git a/tests/Feature/Requests/Search/GetSearchRequestTest.php b/tests/Feature/Requests/Search/GetSearchRequestTest.php index f277ae4a..44229edd 100644 --- a/tests/Feature/Requests/Search/GetSearchRequestTest.php +++ b/tests/Feature/Requests/Search/GetSearchRequestTest.php @@ -3,6 +3,7 @@ use Carbon\Carbon; use CodebarAg\DocuWare\DocuWare; use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTextDTO; +use CodebarAg\DocuWare\DTO\DocumentPaginator; use CodebarAg\DocuWare\Events\DocuWareResponseLog; use CodebarAg\DocuWare\Exceptions\UnableToSearch; use CodebarAg\DocuWare\Requests\Document\PostDocumentRequest; @@ -18,6 +19,8 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) + ->page(1) + ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2021)) ->filterDate('DWSTOREDATETIME', '<', now()) @@ -25,21 +28,10 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->paginate($paginatorRequest); + $paginator = $this->connector->send($paginatorRequest)->dto(); - $paginator->setPerPageLimit(5) - ->setStartPage(1) - ->setMaxPages(1); - - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(0, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(0, $documents->flatten()); + $this->assertInstanceOf(DocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); })->group('search'); it('can\'t search documents by more than two dates', function () { @@ -54,6 +46,8 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) + ->page(1) + ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2020)) ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2021)) @@ -62,21 +56,7 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->paginate($request); - - $paginator->setPerPageLimit(5) - ->setStartPage(1) - ->setMaxPages(1); - - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(2, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(4, $documents->flatten()); + $this->connector->send($request)->dto(); })->group('search'); it('can override search documents dates filter by using same operator', function () { @@ -89,6 +69,8 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) + ->page(1) + ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '<=', Carbon::create(2022)) ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2020)) @@ -97,21 +79,10 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->paginate($paginatorRequest); - - $paginator->setPerPageLimit(5) - ->setStartPage(1) - ->setMaxPages(1); - - $documents = collect(); + $paginator = $this->connector->send($paginatorRequest)->dto(); - foreach ($paginator as $response) { - $this->assertCount(0, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(0, $documents->flatten()); + $this->assertInstanceOf(DocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); })->group('search'); it('can override search documents dates filter by using equal operator', function () { @@ -124,6 +95,8 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) + ->page(1) + ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2020)) ->filterDate('DWSTOREDATETIME', '=', Carbon::create(2021)) @@ -131,21 +104,10 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->paginate($paginatorRequest); - - $paginator->setPerPageLimit(5) - ->setStartPage(1) - ->setMaxPages(1); + $paginator = $this->connector->send($paginatorRequest)->dto(); - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(0, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(0, $documents->flatten()); + $this->assertInstanceOf(DocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); })->group('search'); it('can\'t search documents by diverged date range', function () { @@ -160,6 +122,8 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) + ->page(1) + ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '<=', Carbon::create(2020)) ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2021)) @@ -167,21 +131,7 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->paginate($request); - - $paginator->setPerPageLimit(5) - ->setStartPage(1) - ->setMaxPages(1); - - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(2, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(4, $documents->flatten()); + $this->connector->send($request)->dto(); })->group('search'); it('can search documents dates filter in future', function () { @@ -194,27 +144,18 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) + ->page(1) + ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '>', Carbon::create(2018)) ->filter('DOCUMENT_TYPE', 'Abrechnung') ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->paginate($paginatorRequest); - - $paginator->setPerPageLimit(5) - ->setStartPage(1) - ->setMaxPages(1); - - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(0, $response->dto()); + $paginator = $this->connector->send($paginatorRequest)->dto(); - $documents->push($response->dto()); - } - - $this->assertCount(0, $documents->flatten()); + $this->assertInstanceOf(DocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); })->group('search'); it('can search documents dates filter in past', function () { @@ -227,27 +168,18 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) + ->page(1) + ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '<=', Carbon::create(2020)) ->filter('DOCUMENT_TYPE', 'Abrechnung') ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->paginate($paginatorRequest); - - $paginator->setPerPageLimit(5) - ->setStartPage(1) - ->setMaxPages(1); + $paginator = $this->connector->send($paginatorRequest)->dto(); - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(0, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(0, $documents->flatten()); + $this->assertInstanceOf(DocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); })->group('search'); it('can search documents with null values', function () { @@ -260,22 +192,17 @@ $paginatorRequest = (new DocuWare()) ->searchRequestBuilder() ->fileCabinets($fileCabinetIds) + ->page(null) + ->perPage(null) ->fulltext(null) ->filter('DOCUMENT_TYPE', null) ->orderBy('DWSTOREDATETIME', null) ->get(); - $paginator = $this->connector->paginate($paginatorRequest); + $paginator = $this->connector->send($paginatorRequest)->dto(); - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(0, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(0, $documents->flatten()); + $this->assertInstanceOf(DocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); })->group('search'); it('can search documents with multiple values', function () { @@ -319,55 +246,15 @@ $paginatorRequestBothDocuments = (new DocuWare()) ->searchRequestBuilder() ->fileCabinets([$fileCabinetId]) + ->page(null) + ->perPage(null) ->fulltext(null) ->filterIn('DOCUMENT_TYPE', ['Abrechnung', 'Rechnung']) ->get(); - $paginator = $this->connector->paginate($paginatorRequestBothDocuments); - - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(2, $response->dto()); - - $documents->push($response->dto()); - } - - $this->assertCount(2, $documents->flatten()); - Event::assertDispatched(DocuWareResponseLog::class); -})->group('search'); - -it('can search and get paginated results', function () { - Event::fake(); - - $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); - - for ($i = 0; $i < 4; $i++) { - $this->connector->send(new PostDocumentRequest( - config('laravel-docuware.tests.file_cabinet_id'), - '::fake-file-content::', - 'example.txt' - ))->dto(); - } - - $paginatorRequestBothDocuments = (new DocuWare()) - ->searchRequestBuilder() - ->fileCabinets([$fileCabinetId]) - ->fulltext(null) - ->get(); - - $paginator = $this->connector->paginate($paginatorRequestBothDocuments); - - $paginator->setPerPageLimit(2); - - $documents = collect(); - - foreach ($paginator as $response) { - $this->assertCount(2, $response->dto()); - - $documents->push($response->dto()); - } + $paginator = $this->connector->send($paginatorRequestBothDocuments)->dto(); - $this->assertCount(4, $documents->flatten()); + $this->assertInstanceOf(DocumentPaginator::class, $paginator); + $this->assertCount(2, $paginator->documents); Event::assertDispatched(DocuWareResponseLog::class); })->group('search');