Skip to content

Commit

Permalink
ruflin#1003 set json_decode assoc parameter to false, correctly pass…
Browse files Browse the repository at this point in the history
… bigintConversion config parameter to the connection, provide tests for both
  • Loading branch information
theDisco authored and michalbrauner committed Dec 4, 2017
1 parent e3dbb09 commit 23371dd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Elastica/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function _prepareConnectionParams(array $config)
$params = array();
$params['config'] = array();
foreach ($config as $key => $value) {
if (in_array($key, array('curl', 'headers', 'url'))) {
if (in_array($key, array('bigintConversion', 'curl', 'headers', 'url'))) {
$params['config'][$key] = $value;
} else {
$params[$key] = $value;
Expand Down
6 changes: 5 additions & 1 deletion lib/Elastica/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ public function getData()
$this->_error = true;
} else {
try {
$response = JSON::parse($response);
if ($this->getJsonBigintConversion()) {
$response = JSON::parse($response, true, 512, JSON_BIGINT_AS_STRING);
} else {
$response = JSON::parse($response);
}
} catch (JSONParseException $e) {
// leave response as is if parse fails
}
Expand Down
11 changes: 11 additions & 0 deletions test/lib/Elastica/Test/ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Elastica\Test;

use Elastica\Client;
use Elastica\Connection;
use Elastica\Document;
use Elastica\Exception\Connection\HttpException;
Expand Down Expand Up @@ -1160,4 +1161,14 @@ public function testRemoveHeader()
} catch (InvalidException $ex) {
}
}

/**
* @group unit
*/
public function testPassBigIntSettingsToConnectionConfig()
{
$client = new Client(['bigintConversion' => true]);

$this->assertTrue($client->getConnection()->getConfig('bigintConversion'));
}
}
17 changes: 17 additions & 0 deletions test/lib/Elastica/Test/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ public function testIsNotOkBulkItemsWithStatusField()
$this->assertFalse($response->isOk());
}

/**
* @group unit
*/
public function testDecodeResponseWithBigIntSetToTrue()
{
$response = new Response(json_encode(array(
'took' => 213,
'items' => array(
array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'status' => 200)),
array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'status' => 200)),
),
)));
$response->setJsonBigintConversion(true);

$this->assertTrue(is_array($response->getData()));
}

/**
* @group functional
*/
Expand Down

0 comments on commit 23371dd

Please sign in to comment.