Skip to content

Commit 0b9ac2f

Browse files
committed
test: cover drained response bodies without retrying
1 parent 04ef507 commit 0b9ac2f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/Feature/ApiCallRetryTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,4 +500,40 @@ public function testThrowsTypesenseClientErrorWhenSuccessResponseContainsInvalid
500500
$this->assertInstanceOf(JsonException::class, $exception->getPrevious());
501501
}
502502
}
503+
504+
public function testDrainedResponseBodyStillDecodesWithoutRetrying(): void
505+
{
506+
$callCount = 0;
507+
508+
$stream = $this->createMock(StreamInterface::class);
509+
$stream->method('__toString')->willReturn('{"ok": true}');
510+
$stream->method('getContents')->willReturn('');
511+
512+
$response = $this->createMock(ResponseInterface::class);
513+
$response->method('getStatusCode')->willReturn(200);
514+
$response->method('getBody')->willReturn($stream);
515+
516+
$httpClient = $this->createMock(ClientInterface::class);
517+
$httpClient->method('sendRequest')
518+
->willReturnCallback(function() use (&$callCount, $response) {
519+
$callCount++;
520+
521+
return $response;
522+
});
523+
524+
$config = new Configuration([
525+
'api_key' => 'test-key',
526+
'nodes' => [
527+
['host' => 'node1', 'port' => 8108, 'protocol' => 'http']
528+
],
529+
'client' => $httpClient
530+
]);
531+
532+
$apiCall = new ApiCall($config);
533+
534+
$result = $apiCall->get('/health', []);
535+
536+
$this->assertSame(['ok' => true], $result);
537+
$this->assertSame(1, $callCount);
538+
}
503539
}

0 commit comments

Comments
 (0)