Skip to content

Commit

Permalink
Add missing Response infos to Bulk/ResponseSet (ruflin#1737) (ruflin#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vinzlj authored May 7, 2020
1 parent 19e8615 commit 8c2123c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ All notable changes to this project will be documented in this file based on the

### Improvements

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

### Deprecated

## [Unreleased](https://github.com/ruflin/Elastica/compare/6.1.0...6.1.1)
Expand Down
5 changes: 4 additions & 1 deletion lib/Elastica/Bulk/ResponseSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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
27 changes: 26 additions & 1 deletion test/Elastica/Bulk/ResponseSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@

class ResponseSetTest extends BaseTest
{
/**
* @group unit
*/
public function testConstructor()
{
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 @@ -128,10 +145,18 @@ 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()
->will($this->returnValue(new Response($responseData)));
->willReturn($response)
;

$bulk = new Bulk($client);
$bulk->addActions($actions);
Expand Down

0 comments on commit 8c2123c

Please sign in to comment.