Skip to content

Commit 46fcb8c

Browse files
committed
Merge pull request #1005 from theDisco/master
Fix json_decode problem
2 parents d4f8556 + cdf32e5 commit 46fcb8c

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file based on the
88

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

1214
### Added
1315
- Elastica\Query\MultiMatch::setFuzziness now supports being set to `AUTO` with the const `MultiMatch::FUZZINESS_AUTO`

lib/Elastica/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function _prepareConnectionParams(array $config)
123123
$params = array();
124124
$params['config'] = array();
125125
foreach ($config as $key => $value) {
126-
if (in_array($key, array('curl', 'headers', 'url'))) {
126+
if (in_array($key, array('bigintConversion', 'curl', 'headers', 'url'))) {
127127
$params['config'][$key] = $value;
128128
} else {
129129
$params[$key] = $value;

lib/Elastica/Response.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function getData()
205205
} else {
206206
try {
207207
if ($this->getJsonBigintConversion()) {
208-
$response = JSON::parse($response, false, 512, JSON_BIGINT_AS_STRING);
208+
$response = JSON::parse($response, true, 512, JSON_BIGINT_AS_STRING);
209209
} else {
210210
$response = JSON::parse($response);
211211
}

test/lib/Elastica/Test/ClientTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Elastica\Test;
33

4+
use Elastica\Client;
45
use Elastica\Connection;
56
use Elastica\Document;
67
use Elastica\Exception\Connection\HttpException;
@@ -1160,4 +1161,14 @@ public function testRemoveHeader()
11601161
} catch (InvalidException $ex) {
11611162
}
11621163
}
1164+
1165+
/**
1166+
* @group unit
1167+
*/
1168+
public function testPassBigIntSettingsToConnectionConfig()
1169+
{
1170+
$client = new Client(['bigintConversion' => true]);
1171+
1172+
$this->assertTrue($client->getConnection()->getConfig('bigintConversion'));
1173+
}
11631174
}

test/lib/Elastica/Test/ResponseTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ public function testIsNotOkBulkItemsWithStatusField()
200200
$this->assertFalse($response->isOk());
201201
}
202202

203+
/**
204+
* @group unit
205+
*/
206+
public function testDecodeResponseWithBigIntSetToTrue()
207+
{
208+
$response = new Response(json_encode(array(
209+
'took' => 213,
210+
'items' => array(
211+
array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'status' => 200)),
212+
array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'status' => 200)),
213+
),
214+
)));
215+
$response->setJsonBigintConversion(true);
216+
217+
$this->assertTrue(is_array($response->getData()));
218+
}
219+
203220
/**
204221
* @group functional
205222
*/

0 commit comments

Comments
 (0)