diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ad9ab9..1aecd96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## main +## v0.5.2 +- The request all method will now check the response for extract ability of the response + ## v0.5.1 - Added missing address fake builder country iso code type setter diff --git a/src/Services/OnOfficeService.php b/src/Services/OnOfficeService.php index 376e9cc..f962e9b 100644 --- a/src/Services/OnOfficeService.php +++ b/src/Services/OnOfficeService.php @@ -139,8 +139,11 @@ public function requestAll( $countAbsolute = $response->json($countPath, 0); $maxPage = ceil($countAbsolute / $pageSize); } + $responseResult = $response->json($resultPath); - $data->push(...$response->json($resultPath)); + if (is_array($responseResult)) { + $data->push(...$responseResult); + } $offset += $pageSize; $currentPage = $offset / $pageSize; diff --git a/tests/Services/OnOfficeServiceTest.php b/tests/Services/OnOfficeServiceTest.php index 34da144..3c69658 100644 --- a/tests/Services/OnOfficeServiceTest.php +++ b/tests/Services/OnOfficeServiceTest.php @@ -1,5 +1,6 @@ with([300, 301, 400, 401, 500, 501]); + + it('can handle null in result path', function () { + Http::preventStrayRequests(); + Http::fake([ + '*' => Http::response([ + 'status' => [ + 'code' => 200, + ], + 'response' => [ + 'results' => [ + [ + 'data' => [ + 'meta' => [ + 'cntabsolute' => 0, + ], + ], + ], + ], + ] + ]), + ]); + + $onOfficeService = app(OnOfficeService::class); + + $response = $onOfficeService->requestAll(function () { + return app(OnOfficeService::class)->requestApi( + OnOfficeAction::Get, + OnOfficeResourceType::Estate, + ); + }); + + expect($response)->toBeInstanceOf(Collection::class) + ->toBeEmpty(); + }); }); describe('requestAllChunked', function () {