Skip to content

Properly handle null query response #425

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

Merged
merged 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 4 additions & 5 deletions src/Parse/ParseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,11 @@ public function find($useMasterKey = false, $decodeObjects = true)
null,
$useMasterKey
);
if (!isset($result['results'])) {
return [];
}
if (!$decodeObjects) {
if (array_key_exists('results', $result)) {
return $result['results'];
} else {
return [];
}
return $result['results'];
}
$output = [];
foreach ($result['results'] as $row) {
Expand Down
5 changes: 1 addition & 4 deletions tests/Parse/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function setUp()
self::setHttpClient();
}

public static function setHttpClient($httpClient = null)
public static function setHttpClient()
{
//
// Set a curl http client to run primary tests under
Expand All @@ -61,9 +61,6 @@ public static function setHttpClient($httpClient = null)
// ParseCurlHttpClient
// ParseStreamHttpClient
//
if ($httpClient) {
return ParseClient::setHttpClient($httpClient);
}

global $USE_CLIENT_STREAM;

Expand Down
16 changes: 13 additions & 3 deletions tests/Parse/ParseQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseUser;
use Parse\ParseClient;

class ParseQueryTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -2402,19 +2403,28 @@ public function testQueryFindEncoded()
$this->assertEquals('John', $results[2]['name']);
}

public function testQueryFindEncodedInvalidResponse()
public function testQueryNullResponse()
{
$obj = new ParseObject('TestObject');
$obj->set('name', 'John');
$obj->set('country', 'US');
$obj->save();

ParseClient::initialize(
Helper::$appId,
Helper::$restKey,
Helper::$masterKey,
false,
Helper::$accountKey
);
ParseClient::setServerURL('http://localhost:1337', 'parse');

$httpClient = new HttpClientMock();
$httpClient->setResponse('{}');
Helper::setHttpClient($httpClient);
ParseClient::setHttpClient($httpClient);

$query = new ParseQuery('TestObject');
$results = $query->find(false, false);
$results = $query->find(false);

$this->assertEquals(0, count($results));

Expand Down