diff --git a/src/OpenSearch/HttpTransport.php b/src/OpenSearch/HttpTransport.php index 676fce4f..0762d648 100644 --- a/src/OpenSearch/HttpTransport.php +++ b/src/OpenSearch/HttpTransport.php @@ -36,7 +36,7 @@ public function sendRequest( array $params = [], mixed $body = null, array $headers = [], - ): array|string|null { + ): iterable|string|null { $request = $this->createRequest($method, $uri, $params, $body, $headers); $response = $this->client->sendRequest($request); $statusCode = $response->getStatusCode(); diff --git a/src/OpenSearch/LegacyTransportWrapper.php b/src/OpenSearch/LegacyTransportWrapper.php index 7335a4d8..ecd14626 100644 --- a/src/OpenSearch/LegacyTransportWrapper.php +++ b/src/OpenSearch/LegacyTransportWrapper.php @@ -1,8 +1,8 @@ transport->performRequest($method, $uri, $params, $body); - $futureArray = $this->transport->resultOrFuture($promise); - if ($futureArray instanceof FutureArrayInterface) { - return $futureArray->wait(); - } - return $futureArray; + // Provide legacy support for options. + $options = $headers; + return $this->transport->resultOrFuture($promise, $options); } } diff --git a/src/OpenSearch/TransportInterface.php b/src/OpenSearch/TransportInterface.php index c2f432d3..91a45da8 100644 --- a/src/OpenSearch/TransportInterface.php +++ b/src/OpenSearch/TransportInterface.php @@ -23,6 +23,6 @@ public function sendRequest( array $params = [], string|array|null $body = null, array $headers = [], - ): array|string|null; + ): iterable|string|null; } diff --git a/tests/LegacyTransportWrapperTest.php b/tests/LegacyTransportWrapperTest.php new file mode 100644 index 00000000..882fb73d --- /dev/null +++ b/tests/LegacyTransportWrapperTest.php @@ -0,0 +1,62 @@ +logger = $this->createMock(LoggerInterface::class); + $this->connectionPool = $this->createMock(AbstractConnectionPool::class); + $this->connection = $this->createMock(Connection::class); + } + + public function testSuccess(): void + { + $deferred = new Deferred(); + $deferred->resolve(['foo' => 'bar']); + $future = new FutureArray($deferred->promise()); + + $this->connection->method('performRequest') + ->willReturn($future); + + $this->connectionPool->method('nextConnection') + ->willReturn($this->connection); + + $transport = new Transport(1, $this->connectionPool, $this->logger); + + $wrapper = new LegacyTransportWrapper($transport); + + $response = $wrapper->sendRequest('GET', 'http://localhost:9200', [], null, []); + + $this->assertIsIterable($response); + + $this->assertEquals(['foo' => 'bar'], $response); + } + +}