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

[Breaking Change] Fix firestore queries #1161

Merged
merged 1 commit into from
Jul 12, 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: 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