Skip to content

Commit

Permalink
Merge pull request #1005 from theDisco/master
Browse files Browse the repository at this point in the history
Fix json_decode problem
  • Loading branch information
ruflin committed Dec 10, 2015
2 parents d4f8556 + cdf32e5 commit 46fcb8c
Show file tree
Hide file tree
Showing 5 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 @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file based on the

### Bugfixes
- Function score query: corrected the `score_method` `average` to `avg` #975
- Set `json_decode()` assoc parameter to true in `Elastica\Response` #1005
- Add `bigintConversion` to keys passed to connection config in `Elastica\Client` #1005

### Added
- Elastica\Query\MultiMatch::setFuzziness now supports being set to `AUTO` with the const `MultiMatch::FUZZINESS_AUTO`
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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
2 changes: 1 addition & 1 deletion lib/Elastica/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function getData()
} else {
try {
if ($this->getJsonBigintConversion()) {
$response = JSON::parse($response, false, 512, JSON_BIGINT_AS_STRING);
$response = JSON::parse($response, true, 512, JSON_BIGINT_AS_STRING);
} else {
$response = JSON::parse($response);
}
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 @@ -200,6 +200,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 46fcb8c

Please sign in to comment.