Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions src/Parse/ParseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,10 @@ public function count($useMasterKey = false)
if (ParseUser::getCurrentUser()) {
$sessionToken = ParseUser::getCurrentUser()->getSessionToken();
}
$this->limit = 0;
$this->count = 1;
$queryString = $this->buildQueryString($this->_getOptions());
$queryParams = $this->_getOptions();
$queryParams['limit'] = 0;
$queryParams['count'] = 1;
$queryString = $this->buildQueryString($queryParams);
$result = ParseClient::_request(
'GET',
'classes/'.$this->className.'?'.$queryString,
Expand Down
41 changes: 39 additions & 2 deletions tests/Parse/ParseQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2654,8 +2654,8 @@ public function testGetAndSetConditions()
$query->select(['select1','select2']);
$query->skip(24);

// sets count = 1 and limit = 0
$query->count();
// sets count = 1
$query->withCount();
// reset limit up to 42
$query->limit(42);

Expand Down Expand Up @@ -2695,6 +2695,43 @@ public function testGetAndSetConditions()
);
}

/**
* @group query-count-conditions
*/
public function testCountDoesNotOverrideConditions()
{
$obj = new ParseObject('TestObject');
$obj->set('name', 'John');
$obj->set('country', 'US');
$obj->save();

$obj = new ParseObject('TestObject');
$obj->set('name', 'Bob');
$obj->set('country', 'US');
$obj->save();

$obj = new ParseObject('TestObject');
$obj->set('name', 'Mike');
$obj->set('country', 'CA');
$obj->save();

$query = new ParseQuery('TestObject');
$query->equalTo('country', 'US');
$query->limit(1);
$count = $query->count();
$results = $query->find();

$this->assertEquals(1, count($results));
$this->assertEquals(2, $count);

$this->assertSame([
'where' => [
'country' => 'US'
],
'limit' => 1,
], $query->_getOptions());
}

public function testNotArrayConditions()
{
$this->expectException(
Expand Down