Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix json_decode problem #1005

Merged
merged 2 commits into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test would also pass without the setJonBigintVersion(true), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this test would also pass without L215, but L215 makes the difference :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the test. But I assume this test would also have passed without the code changes you made? It is more for me to understand if we test if the bug was actually fixed or if we test that we can use the function without any side affects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it wouldn't since the return value of https://github.com/ruflin/Elastica/pull/1005/files#diff-b364251d02e70310f3c6e443372397d3L208 would be \stdClass and not an array and there is not conversion or casting happening till the end of method.

}

/**
* @group functional
*/
Expand Down