-
Notifications
You must be signed in to change notification settings - Fork 973
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transport.php fix backported into 6.8.x (#1109)
* Update Transport.php * Fix 6.8.0 release adding missing class alises (#1114) * Fix for #1112 issue. Adding endpoint aliases + IndicesNamespace::getAliases() * Reverted array alias to class in src/autoload.php + added unit tests for missing class aliases in 6.8 * Fixed indentation in src/ autoload.php * Added TransportTest Co-authored-by: Enrico Zimuel <[email protected]>
- Loading branch information
1 parent
285ed33
commit 7f2525f
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Elasticsearch PHP client | ||
* | ||
* @link https://github.com/elastic/elasticsearch-php/ | ||
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co) | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | ||
* @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1 | ||
* | ||
* Licensed to Elasticsearch B.V under one or more agreements. | ||
* Elasticsearch B.V licenses this file to you under the Apache 2.0 License or | ||
* the GNU Lesser General Public License, Version 2.1, at your option. | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
|
||
declare(strict_types = 1); | ||
|
||
namespace Elasticsearch\Tests; | ||
|
||
use Elasticsearch\Common\Exceptions\ServerErrorResponseException; | ||
use Elasticsearch\ConnectionPool\AbstractConnectionPool; | ||
use Elasticsearch\Connections\Connection; | ||
use Elasticsearch\Serializers\SerializerInterface; | ||
use Elasticsearch\Transport; | ||
use GuzzleHttp\Ring\Future\FutureArray; | ||
use GuzzleHttp\Ring\Future\FutureArrayInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
use React\Promise\Deferred; | ||
|
||
class TransportTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->logger = $this->createMock(LoggerInterface::class); | ||
$this->trace = $this->createMock(LoggerInterface::class); | ||
$this->serializer = $this->createMock(SerializerInterface::class); | ||
$this->connectionPool = $this->createMock(AbstractConnectionPool::class); | ||
$this->connection = $this->createMock(Connection::class); | ||
} | ||
|
||
public function testPerformRequestWithServerErrorResponseException404Result() | ||
{ | ||
$deferred = new Deferred(); | ||
$deferred->reject(new ServerErrorResponseException('foo', 404)); | ||
$future = new FutureArray($deferred->promise()); | ||
|
||
$this->connection->method('performRequest') | ||
->willReturn($future); | ||
|
||
$this->connectionPool->method('nextConnection') | ||
->willReturn($this->connection); | ||
|
||
$this->connectionPool->expects($this->never()) | ||
->method('scheduleCheck'); | ||
|
||
$transport = new Transport(1, $this->connectionPool, $this->logger); | ||
|
||
$result = $transport->performRequest('GET', '/'); | ||
$this->assertInstanceOf(FutureArrayInterface::class, $result); | ||
} | ||
|
||
public function testPerformRequestWithServerErrorResponseException500Result() | ||
{ | ||
$deferred = new Deferred(); | ||
$deferred->reject(new ServerErrorResponseException('foo', 500)); | ||
$future = new FutureArray($deferred->promise()); | ||
|
||
$this->connection->method('performRequest') | ||
->willReturn($future); | ||
|
||
$this->connectionPool->method('nextConnection') | ||
->willReturn($this->connection); | ||
|
||
$this->connectionPool->expects($this->once()) | ||
->method('scheduleCheck'); | ||
|
||
$transport = new Transport(1, $this->connectionPool, $this->logger); | ||
|
||
$result = $transport->performRequest('GET', '/'); | ||
$this->assertInstanceOf(FutureArrayInterface::class, $result); | ||
} | ||
} |