From 6c1f1a18c499195de1b113145fe7b2c86de3f275 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 21 Jan 2025 16:46:58 +0100 Subject: [PATCH] Add tests to count requests called by AbstractApi::retrieveData() --- tests/Unit/Api/AbstractApiTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Unit/Api/AbstractApiTest.php b/tests/Unit/Api/AbstractApiTest.php index cc0fc68c..a74be6ca 100644 --- a/tests/Unit/Api/AbstractApiTest.php +++ b/tests/Unit/Api/AbstractApiTest.php @@ -398,6 +398,31 @@ public static function retrieveDataData(): array ]; } + public function testRetrieveDataWith250ResultsMakes3Requests(): void + { + $response1 = $this->createStub(Response::class); + $response1->method('getContentType')->willReturn('application/json'); + $response1->method('getContent')->willReturn('{"total_count":250,"offset":0,"limit":100,"data":[]}'); + + $response2 = $this->createStub(Response::class); + $response2->method('getContentType')->willReturn('application/json'); + $response2->method('getContent')->willReturn('{"total_count":250,"offset":100,"limit":100,"data":[]}'); + + $response3 = $this->createStub(Response::class); + $response3->method('getContentType')->willReturn('application/json'); + $response3->method('getContent')->willReturn('{"total_count":250,"offset":200,"limit":100,"data":[]}'); + + $client = $this->createMock(HttpClient::class); + $client->expects($this->exactly(3))->method('request')->willReturnOnConsecutiveCalls($response1, $response2, $response3); + + $api = new class ($client) extends AbstractApi {}; + + $method = new ReflectionMethod($api, 'retrieveData'); + $method->setAccessible(true); + + $method->invoke($api, '/data.json', ['limit' => 300]); + } + /** * @dataProvider getRetrieveDataToExceptionData */