|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace OpenSearch\Tests; |
| 6 | + |
| 7 | +use GuzzleHttp\Ring\Future\FutureArray; |
| 8 | +use OpenSearch\ConnectionPool\AbstractConnectionPool; |
| 9 | +use OpenSearch\Connections\Connection; |
| 10 | +use OpenSearch\LegacyTransportWrapper; |
| 11 | +use OpenSearch\Transport; |
| 12 | +use PHPUnit\Framework\MockObject\MockObject; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | +use Psr\Log\LoggerInterface; |
| 15 | +use React\Promise\Deferred; |
| 16 | + |
| 17 | +/** |
| 18 | + * Tests for the LegacyTransportWrapper class. |
| 19 | + * |
| 20 | + * @coversDefaultClass \OpenSearch\LegacyTransportWrapper |
| 21 | + * @group legacy |
| 22 | + * @deprecated in 2.4.2 and will be removed in 3.0.0. |
| 23 | + */ |
| 24 | +class LegacyTransportWrapperTest extends TestCase |
| 25 | +{ |
| 26 | + private Connection&MockObject $connection; |
| 27 | + |
| 28 | + private AbstractConnectionPool&MockObject $connectionPool; |
| 29 | + |
| 30 | + private MockObject&LoggerInterface $logger; |
| 31 | + |
| 32 | + public function setUp(): void |
| 33 | + { |
| 34 | + $this->logger = $this->createMock(LoggerInterface::class); |
| 35 | + $this->connectionPool = $this->createMock(AbstractConnectionPool::class); |
| 36 | + $this->connection = $this->createMock(Connection::class); |
| 37 | + } |
| 38 | + |
| 39 | + public function testSuccess(): void |
| 40 | + { |
| 41 | + $deferred = new Deferred(); |
| 42 | + $deferred->resolve(['foo' => 'bar']); |
| 43 | + $future = new FutureArray($deferred->promise()); |
| 44 | + |
| 45 | + $this->connection->method('performRequest') |
| 46 | + ->willReturn($future); |
| 47 | + |
| 48 | + $this->connectionPool->method('nextConnection') |
| 49 | + ->willReturn($this->connection); |
| 50 | + |
| 51 | + $transport = new Transport(1, $this->connectionPool, $this->logger); |
| 52 | + |
| 53 | + $wrapper = new LegacyTransportWrapper($transport); |
| 54 | + |
| 55 | + $response = $wrapper->sendRequest('GET', 'http://localhost:9200', [], null, []); |
| 56 | + |
| 57 | + $this->assertIsIterable($response); |
| 58 | + |
| 59 | + $this->assertEquals(['foo' => 'bar'], $response); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments