Skip to content

Commit 6c1f1a1

Browse files
committed
Add tests to count requests called by AbstractApi::retrieveData()
1 parent c94d01b commit 6c1f1a1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/Unit/Api/AbstractApiTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,31 @@ public static function retrieveDataData(): array
398398
];
399399
}
400400

401+
public function testRetrieveDataWith250ResultsMakes3Requests(): void
402+
{
403+
$response1 = $this->createStub(Response::class);
404+
$response1->method('getContentType')->willReturn('application/json');
405+
$response1->method('getContent')->willReturn('{"total_count":250,"offset":0,"limit":100,"data":[]}');
406+
407+
$response2 = $this->createStub(Response::class);
408+
$response2->method('getContentType')->willReturn('application/json');
409+
$response2->method('getContent')->willReturn('{"total_count":250,"offset":100,"limit":100,"data":[]}');
410+
411+
$response3 = $this->createStub(Response::class);
412+
$response3->method('getContentType')->willReturn('application/json');
413+
$response3->method('getContent')->willReturn('{"total_count":250,"offset":200,"limit":100,"data":[]}');
414+
415+
$client = $this->createMock(HttpClient::class);
416+
$client->expects($this->exactly(3))->method('request')->willReturnOnConsecutiveCalls($response1, $response2, $response3);
417+
418+
$api = new class ($client) extends AbstractApi {};
419+
420+
$method = new ReflectionMethod($api, 'retrieveData');
421+
$method->setAccessible(true);
422+
423+
$method->invoke($api, '/data.json', ['limit' => 300]);
424+
}
425+
401426
/**
402427
* @dataProvider getRetrieveDataToExceptionData
403428
*/

0 commit comments

Comments
 (0)