Skip to content

Commit

Permalink
Add missing Response infos to Bulk/ResponseSet (ruflin#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinzlj committed Apr 30, 2020
1 parent 19e8615 commit 5f7ed5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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
30 changes: 29 additions & 1 deletion test/Elastica/Bulk/ResponseSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,28 @@
use Elastica\Response;
use Elastica\Test\Base as BaseTest;

/**
* @internal
*/
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 +148,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 5f7ed5d

Please sign in to comment.