diff --git a/src/Parse/ParseQuery.php b/src/Parse/ParseQuery.php index 64a50561..be7826b8 100644 --- a/src/Parse/ParseQuery.php +++ b/src/Parse/ParseQuery.php @@ -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, diff --git a/tests/Parse/ParseQueryTest.php b/tests/Parse/ParseQueryTest.php index 536971b1..ae251ab1 100644 --- a/tests/Parse/ParseQueryTest.php +++ b/tests/Parse/ParseQueryTest.php @@ -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); @@ -2695,6 +2695,45 @@ 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' => [ + '$eq' => 'US' + ] + ], + 'limit' => 1, + ], $query->_getOptions()); + } + public function testNotArrayConditions() { $this->expectException( @@ -2770,8 +2809,6 @@ public function testEqualToWithSameKeyDoesNotOverrideOtherConditions() '$eq' => 'bar', ] ], - 'limit' => 0, - 'count' => 1, ], $query->_getOptions()); } }