Skip to content

Commit

Permalink
Add tests to count requests called by AbstractApi::retrieveData()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jan 21, 2025
1 parent c94d01b commit 6c1f1a1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/Unit/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 6c1f1a1

Please sign in to comment.