Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing Response infos to Bulk/ResponseSet (#1737) #1776

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `Elastica\Aggregation\WeightedAvg` aggregation [#1770](https://github.com/ruflin/Elastica/pull/1770)

### Changed
* Added missing Response information to Bulk/ResponseSet [#1776](https://github.com/ruflin/Elastica/pull/1776)

### Deprecated
### Removed
### Fixed
Expand Down
5 changes: 4 additions & 1 deletion src/Bulk/ResponseSet.php
Expand Up @@ -21,7 +21,10 @@ class ResponseSet extends BaseResponse implements \Iterator, \Countable
*/
public function __construct(BaseResponse $response, array $bulkResponses)
{
parent::__construct($response->getData());
parent::__construct($response->getData(), $response->getStatus());

$this->setQueryTime($response->getQueryTime());
$this->setTransferInfo($response->getTransferInfo());

$this->_bulkResponses = $bulkResponses;
}
Expand Down
26 changes: 25 additions & 1 deletion tests/Bulk/ResponseSetTest.php
Expand Up @@ -16,6 +16,23 @@
*/
class ResponseSetTest extends BaseTest
{
/**
* @group unit
*/
public function testConstructor(): void
{
list($responseData, $actions) = $this->_getFixture();

$responseSet = $this->_createResponseSet($responseData, $actions);

$this->assertEquals(200, $responseSet->getStatus());
$this->assertEquals(12.3, $responseSet->getQueryTime());
$this->assertEquals([
'url' => 'http://127.0.0.1:9200/_bulk',
'http_code' => 200,
], $responseSet->getTransferInfo());
}

/**
* @group unit
* @dataProvider isOkDataProvider
Expand Down Expand Up @@ -129,10 +146,17 @@ protected function _createResponseSet(array $responseData, array $actions): Resp
{
$client = $this->createMock(Client::class);

$response = new Response($responseData, 200);
$response->setQueryTime(12.3);
$response->setTransferInfo([
'url' => 'http://127.0.0.1:9200/_bulk',
'http_code' => 200,
]);

$client->expects($this->once())
->method('request')
->withAnyParameters()
->willReturn(new Response($responseData))
->willReturn($response)
;

$bulk = new Bulk($client);
Expand Down