Skip to content

Commit

Permalink
Add missing Response infos to Bulk/ResponseSet (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinzlj committed May 6, 2020
1 parent ea3502b commit e288b7a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
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

0 comments on commit e288b7a

Please sign in to comment.