Skip to content

Commit

Permalink
Fix firestore queries (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpedrie authored and dwsupplee committed Jul 12, 2018
1 parent aa17757 commit 8f3de64
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Firestore/src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ public function __construct(
*/
public function documents(array $options = [])
{
$maxRetries = $this->pluck('maxRetries', $options, false) ?: FirestoreClient::MAX_RETRIES;
$maxRetries = $this->pluck('maxRetries', $options, false);
$maxRetries = $maxRetries === null
? FirestoreClient::MAX_RETRIES
: $maxRetries;

$rows = (new ExponentialBackoff($maxRetries))->execute(function () use ($options) {
$generator = $this->connection->runQuery([
Expand Down Expand Up @@ -212,6 +215,8 @@ public function documents(array $options = [])
* list of field paths to return, or use an empty list to only return the
* references of matching documents.
*
* Subsequent calls to this method will override previous values.
*
* Example:
* ```
* $query = $query->select(['firstName']);
Expand Down Expand Up @@ -241,7 +246,7 @@ public function select(array $fieldPaths)
'select' => [
'fields' => $fields
]
]);
], true);
}

/**
Expand Down
26 changes: 24 additions & 2 deletions Firestore/tests/Unit/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testDocuments()

$this->query->___setProperty('connection', $this->connection->reveal());

$res = $this->query->documents();
$res = $this->query->documents(['maxRetries' => 0]);
$this->assertContainsOnlyInstancesOf(DocumentSnapshot::class, $res);
$this->assertCount(1, $res->rows());

Expand Down Expand Up @@ -145,7 +145,6 @@ public function testSelect()

$this->runAndAssert(function (Query $q) use ($paths) {
$res = $q->select($paths);
$res = $res->select(['users.dan']);

return $res;
}, [
Expand All @@ -156,6 +155,29 @@ public function testSelect()
'fields' => [
[ 'fieldPath' => 'users.john' ],
[ 'fieldPath' => 'users.dave' ],
]
]
]
]);
}

public function testSelectOverride()
{
$paths = [
'users.john',
'users.dave'
];

$this->runAndAssert(function (Query $q) use ($paths) {
$res = $q->select($paths);
$res = $res->select(['users.dan']);
return $res;
}, [
'parent' => self::PARENT,
'structuredQuery' => [
'from' => $this->queryFrom(),
'select' => [
'fields' => [
[ 'fieldPath' => 'users.dan' ],
]
]
Expand Down

0 comments on commit 8f3de64

Please sign in to comment.