File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments