diff --git a/CHANGELOG.md b/CHANGELOG.md index 65bf1693bb..8536ee04d2 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Bulk/ResponseSet.php b/src/Bulk/ResponseSet.php index 344d40f2d9..7781550e86 100644 --- a/src/Bulk/ResponseSet.php +++ b/src/Bulk/ResponseSet.php @@ -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; } diff --git a/tests/Bulk/ResponseSetTest.php b/tests/Bulk/ResponseSetTest.php index ab5223c03c..859c028f4b 100644 --- a/tests/Bulk/ResponseSetTest.php +++ b/tests/Bulk/ResponseSetTest.php @@ -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 @@ -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);