diff --git a/Core/src/Testing/FirestoreTestHelperTrait.php b/Core/src/Testing/FirestoreTestHelperTrait.php index eac29fe50e4..e72ff12243d 100644 --- a/Core/src/Testing/FirestoreTestHelperTrait.php +++ b/Core/src/Testing/FirestoreTestHelperTrait.php @@ -31,6 +31,9 @@ trait FirestoreTestHelperTrait private static $_serializer; + /** + * @return Serializer + */ private function getSerializer() { if (!self::$_serializer) { diff --git a/Firestore/src/BulkWriter.php b/Firestore/src/BulkWriter.php index 896650e99a2..c1cfaafb60d 100644 --- a/Firestore/src/BulkWriter.php +++ b/Firestore/src/BulkWriter.php @@ -19,6 +19,7 @@ use Google\ApiCore\Serializer; use Google\Cloud\Core\ArrayTrait; +use Google\Cloud\Core\ApiHelperTrait; use Google\Cloud\Core\DebugInfoTrait; use Google\Cloud\Core\RequestHandler; use Google\Cloud\Core\Timestamp; @@ -28,6 +29,9 @@ use Google\Cloud\Firestore\FieldValue\DeleteFieldValue; use Google\Cloud\Firestore\FieldValue\DocumentTransformInterface; use Google\Cloud\Firestore\FieldValue\FieldValueInterface; +use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; +use Google\Cloud\Firestore\V1\CommitRequest; +use Google\Protobuf\Timestamp as ProtobufTimestamp; use Google\Rpc\Code; /** @@ -49,7 +53,7 @@ */ class BulkWriter { - use ArrayTrait; + use ApiHelperTrait; use DebugInfoTrait; use TimeTrait; use ValidateTrait; @@ -722,23 +726,32 @@ public function flush($waitForRetryableFailures = false) * ``` * * @codingStandardsIgnoreStart - * @see https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.Firestore.Commit Commit + * @see https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1#google.firestore.v1.Firestore.Commit Commit * * @internal Only supposed to be used internally in Transaction class. * @access private * @param array $options Configuration Options - * @return array [https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1beta1#commitresponse](CommitResponse) + * @return array [https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1#commitresponse](CommitResponse) * @codingStandardsIgnoreEnd */ public function commit(array $options = []) { unset($options['merge'], $options['precondition']); - $response = $this->connection->commit(array_filter([ + list($data, $optionalArgs) = $this->splitOptionalArgs($options); + $data += array_filter([ 'database' => $this->database, 'writes' => $this->writes, 'transaction' => $this->transaction, - ]) + $options); + ]); + $request = $this->serializer->decodeMessage(new CommitRequest(), $data); + + $response = $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + $request, + $optionalArgs + ); if (isset($response['commitTime'])) { $time = $this->parseTimeString($response['commitTime']); @@ -986,10 +999,14 @@ private function sendBatch(array $writes, array $options = []) if (isset($response['writeResults'])) { foreach ($response['writeResults'] as &$result) { - if (isset($result['updateTime'])) { - $time = $this->parseTimeString($result['updateTime']); - $result['updateTime'] = new Timestamp($time[0], $time[1]); - } + // Commenting this out right now because we need to decide if we want to parse the returned + // RFC3339 string which is not very user friendly to interpret. The tradeoff is we need + // to parse the returned value. Maybe we can add this logic in serializer or something. + + // if (isset($result['updateTime'])) { + // $time = $this->parseTimeString($result['updateTime']); + // $result['updateTime'] = new Timestamp($time[0], $time[1]); + // } } } @@ -1095,15 +1112,16 @@ private function validatePrecondition(array &$options) } if (isset($precondition['updateTime'])) { - if (!($precondition['updateTime'] instanceof Timestamp)) { + if (!($precondition['updateTime'] instanceof ProtobufTimestamp) + && !is_array($precondition['updateTime']) + ) { throw new \InvalidArgumentException( - 'Precondition Update Time must be an instance of `Google\\Cloud\\Core\\Timestamp`' + 'Precondition Update Time must be an instance of `Google\\Protobuf\\Timestamp` ' . + 'or array representation of the same.' ); } - return [ - 'updateTime' => $precondition['updateTime']->formatForApi(), - ]; + return $precondition; } throw new \InvalidArgumentException('Preconditions must provide either `exists` or `updateTime`.'); diff --git a/Firestore/src/DocumentReference.php b/Firestore/src/DocumentReference.php index 6455d4f575b..7a4ea1e7065 100644 --- a/Firestore/src/DocumentReference.php +++ b/Firestore/src/DocumentReference.php @@ -188,14 +188,14 @@ public function id() * ``` * * @codingStandardsIgnoreStart - * @see https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.Firestore.Commit Commit + * @see https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.Firestore.Commit Commit * * @param array $fields An array containing fields, where keys are the field * names, and values are field values. Nested arrays are allowed. * Note that unlike {@see \Google\Cloud\Firestore\DocumentReference::update()}, * field paths are NOT supported by this method. * @param array $options Configuration Options. - * @return array [WriteResult](https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.WriteResult) + * @return array [WriteResult](https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.WriteResult) * @codingStandardsIgnoreEnd */ public function create(array $fields = [], array $options = []) @@ -223,7 +223,7 @@ public function create(array $fields = [], array $options = []) * ``` * * @codingStandardsIgnoreStart - * @see https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.Firestore.Commit Commit + * @see https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.Firestore.Commit Commit * @codingStandardsIgnoreEnd * * @param array $fields An array containing fields, where keys are the field @@ -238,7 +238,7 @@ public function create(array $fields = [], array $options = []) * `false`. * } * @codingStandardsIgnoreStart - * @return array [WriteResult](https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.WriteResult) + * @return array [WriteResult](https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.WriteResult) * @codingStandardsIgnoreEnd */ public function set(array $fields, array $options = []) @@ -304,12 +304,12 @@ public function set(array $fields, array $options = []) * ``` * * @codingStandardsIgnoreStart - * @see https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.Firestore.Commit Commit + * @see https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.Firestore.Commit Commit * * @param array[] $data A list of arrays of form * `[FieldPath|string $path, mixed $value]`. * @param array $options Configuration options - * @return array [WriteResult](https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.WriteResult) + * @return array [WriteResult](https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.WriteResult) * @throws \InvalidArgumentException If data is given in an invalid format * or is empty. * @throws \InvalidArgumentException If any field paths are empty. @@ -334,10 +334,10 @@ public function update(array $data, array $options = []) * ``` * * @codingStandardsIgnoreStart - * @see https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.Firestore.Commit Commit + * @see https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.Firestore.Commit Commit * * @param array $options Configuration Options - * @return array [WriteResult](https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.WriteResult) + * @return array [WriteResult](https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.WriteResult) * @codingStandardsIgnoreEnd */ public function delete(array $options = []) diff --git a/Firestore/tests/Snippet/BulkWriterTest.php b/Firestore/tests/Snippet/BulkWriterTest.php index eec78785a8f..783ba3106ef 100644 --- a/Firestore/tests/Snippet/BulkWriterTest.php +++ b/Firestore/tests/Snippet/BulkWriterTest.php @@ -25,6 +25,7 @@ use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Firestore\BulkWriter; use Google\Cloud\Firestore\Connection\ConnectionInterface; +use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; use Google\Cloud\Firestore\V1\DocumentTransform\FieldTransform\ServerValue; use Google\Cloud\Firestore\ValueMapper; use Google\Rpc\Code; diff --git a/Firestore/tests/Snippet/CollectionReferenceTest.php b/Firestore/tests/Snippet/CollectionReferenceTest.php index 511c8c92044..54d5bf3d66b 100644 --- a/Firestore/tests/Snippet/CollectionReferenceTest.php +++ b/Firestore/tests/Snippet/CollectionReferenceTest.php @@ -29,6 +29,8 @@ use Google\Cloud\Firestore\CollectionReference; use Google\Cloud\Core\Testing\Snippet\SnippetTestCase; use Google\Cloud\Firestore\Connection\ConnectionInterface; +use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; +use Google\Cloud\Firestore\V1\CommitRequest; /** * @group firestore @@ -65,7 +67,7 @@ public function setUp(): void false ), self::NAME - ]); + ], ['requestHandler', 'connection']); } public function testClass() @@ -152,10 +154,16 @@ public function testNewDocument() public function testAdd() { - $this->connection->commit(Argument::any()) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + ) ->shouldBeCalled() ->willReturn([[]]); - $this->collection->___setProperty('connection', $this->connection->reveal()); + + $this->collection->___setProperty('requestHandler', $this->requestHandler->reveal()); $snippet = $this->snippetFromMethod(CollectionReference::class, 'add'); $snippet->addLocal('collection', $this->collection); diff --git a/Firestore/tests/Snippet/FieldValueTest.php b/Firestore/tests/Snippet/FieldValueTest.php index 605d3cb1d36..6f6e7a9a481 100644 --- a/Firestore/tests/Snippet/FieldValueTest.php +++ b/Firestore/tests/Snippet/FieldValueTest.php @@ -25,7 +25,9 @@ use Google\Cloud\Firestore\Connection\ConnectionInterface; use Google\Cloud\Firestore\FieldValue; use Google\Cloud\Firestore\FirestoreClient; +use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; use Google\Cloud\Firestore\V1\DocumentTransform\FieldTransform\ServerValue; +use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; /** @@ -52,29 +54,35 @@ public function setUp(): void $this->serializer = $this->getSerializer(); $this->firestore = TestHelpers::stub(FirestoreClient::class, [ ['projectId' => 'my-awesome-project'], - ]); + ], ['connection', 'requestHandler']); } public function testDeleteField() { - $this->connection->commit([ - "database" => "projects/my-awesome-project/databases/(default)", - "writes" => [ - [ - "updateMask" => [ - "fieldPaths" => ["hometown"], - ], - "currentDocument" => [ - "exists" => true, - ], - "update" => [ - "name" => "projects/my-awesome-project/databases/(default)/documents/users/dave", - ], - ], - ], - ])->willReturn([[]])->shouldBeCalledTimes(1); - - $this->firestore->___setProperty('connection', $this->connection->reveal()); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == "projects/my-awesome-project/databases/(default)" + && array_replace_recursive($data['writes'], [ + [ + "updateMask" => [ + "fieldPaths" => ["hometown"], + ], + "currentDocument" => [ + "exists" => true, + ], + "update" => [ + "name" => "projects/my-awesome-project/databases/(default)/documents/users/dave", + ], + ], + ]) == $data['writes']; + }), + Argument::cetera() + )->willReturn([[]])->shouldBeCalledTimes(1); + + $this->firestore->___setProperty('requestHandler', $this->requestHandler->reveal()); $snippet = $this->snippetFromMethod(FieldValue::class, 'deleteField'); $snippet->setLine(3, ''); @@ -85,27 +93,33 @@ public function testDeleteField() public function testServerTimestamp() { - $this->connection->commit([ - "database" => "projects/my-awesome-project/databases/(default)", - "writes" => [ - [ - "transform" => [ - "document" => "projects/my-awesome-project/databases/(default)/documents/users/dave", - "fieldTransforms" => [ - [ - "fieldPath" => "lastLogin", - "setToServerValue" => ServerValue::REQUEST_TIME, + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == "projects/my-awesome-project/databases/(default)" + && array_replace_recursive($data['writes'], [ + [ + "transform" => [ + "document" => "projects/my-awesome-project/databases/(default)/documents/users/dave", + "fieldTransforms" => [ + [ + "fieldPath" => "lastLogin", + "setToServerValue" => ServerValue::REQUEST_TIME, + ], + ], + ], + "currentDocument" => [ + "exists" => true, ], ], - ], - "currentDocument" => [ - "exists" => true, - ], - ], - ], - ])->willReturn([[]])->shouldBeCalledTimes(1); + ]) == $data['writes']; + }), + Argument::cetera() + )->willReturn([[]])->shouldBeCalledTimes(1); - $this->firestore->___setProperty('connection', $this->connection->reveal()); + $this->firestore->___setProperty('requestHandler', $this->requestHandler->reveal()); $snippet = $this->snippetFromMethod(FieldValue::class, 'serverTimestamp'); $snippet->setLine(3, ''); @@ -116,35 +130,41 @@ public function testServerTimestamp() public function testArrayUnion() { - $this->connection->commit([ - "database" => "projects/my-awesome-project/databases/(default)", - "writes" => [ - [ - "transform" => [ - "document" => "projects/my-awesome-project/databases/(default)/documents/users/dave", - "fieldTransforms" => [ - [ - "fieldPath" => "favoriteColors", - 'appendMissingElements' => [ - 'values' => [ - [ - 'stringValue' => 'red', - ], [ - 'stringValue' => 'blue', + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == "projects/my-awesome-project/databases/(default)" + && array_replace_recursive($data['writes'], [ + [ + "transform" => [ + "document" => "projects/my-awesome-project/databases/(default)/documents/users/dave", + "fieldTransforms" => [ + [ + "fieldPath" => "favoriteColors", + 'appendMissingElements' => [ + 'values' => [ + [ + 'stringValue' => 'red', + ], [ + 'stringValue' => 'blue', + ], + ], ], ], ], ], + "currentDocument" => [ + "exists" => true, + ], ], - ], - "currentDocument" => [ - "exists" => true, - ], - ], - ], - ])->willReturn([[]])->shouldBeCalledTimes(1); + ]) == $data['writes']; + }), + Argument::cetera() + )->willReturn([[]])->shouldBeCalledTimes(1); - $this->firestore->___setProperty('connection', $this->connection->reveal()); + $this->firestore->___setProperty('requestHandler', $this->requestHandler->reveal()); $snippet = $this->snippetFromMethod(FieldValue::class, 'arrayUnion'); $snippet->setLine(3, ''); @@ -155,33 +175,39 @@ public function testArrayUnion() public function testArrayRemove() { - $this->connection->commit([ - "database" => "projects/my-awesome-project/databases/(default)", - "writes" => [ - [ - "transform" => [ - "document" => "projects/my-awesome-project/databases/(default)/documents/users/dave", - "fieldTransforms" => [ - [ - "fieldPath" => "favoriteColors", - 'removeAllFromArray' => [ - 'values' => [ - [ - 'stringValue' => 'green', + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == "projects/my-awesome-project/databases/(default)" + && array_replace_recursive($data['writes'], [ + [ + "transform" => [ + "document" => "projects/my-awesome-project/databases/(default)/documents/users/dave", + "fieldTransforms" => [ + [ + "fieldPath" => "favoriteColors", + 'removeAllFromArray' => [ + 'values' => [ + [ + 'stringValue' => 'green', + ], + ], ], ], ], ], + "currentDocument" => [ + "exists" => true, + ], ], - ], - "currentDocument" => [ - "exists" => true, - ], - ], - ], - ])->willReturn([[]])->shouldBeCalledTimes(1); + ]) == $data['writes']; + }), + Argument::cetera() + )->willReturn([[]])->shouldBeCalledTimes(1); - $this->firestore->___setProperty('connection', $this->connection->reveal()); + $this->firestore->___setProperty('requestHandler', $this->requestHandler->reveal()); $snippet = $this->snippetFromMethod(FieldValue::class, 'arrayRemove'); $snippet->setLine(3, ''); @@ -192,29 +218,35 @@ public function testArrayRemove() public function testIncrement() { - $this->connection->commit([ - "database" => "projects/my-awesome-project/databases/(default)", - "writes" => [ - [ - "transform" => [ - "document" => "projects/my-awesome-project/databases/(default)/documents/users/dave", - "fieldTransforms" => [ - [ - "fieldPath" => "loginCount", - 'increment' => [ - 'integerValue' => 1, + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == "projects/my-awesome-project/databases/(default)" + && array_replace_recursive($data['writes'], [ + [ + "transform" => [ + "document" => "projects/my-awesome-project/databases/(default)/documents/users/dave", + "fieldTransforms" => [ + [ + "fieldPath" => "loginCount", + 'increment' => [ + 'integerValue' => 1, + ], + ], ], ], + "currentDocument" => [ + "exists" => true, + ], ], - ], - "currentDocument" => [ - "exists" => true, - ], - ], - ], - ])->willReturn([[]])->shouldBeCalledTimes(1); - - $this->firestore->___setProperty('connection', $this->connection->reveal()); + ]) == $data['writes']; + }), + Argument::cetera() + )->willReturn([[]])->shouldBeCalledTimes(1); + + $this->firestore->___setProperty('requestHandler', $this->requestHandler->reveal()); $snippet = $this->snippetFromMethod(FieldValue::class, 'increment'); $snippet->setLine(3, ''); diff --git a/Firestore/tests/Snippet/FirestoreClientTest.php b/Firestore/tests/Snippet/FirestoreClientTest.php index ae2b962478d..57622d5cae1 100644 --- a/Firestore/tests/Snippet/FirestoreClientTest.php +++ b/Firestore/tests/Snippet/FirestoreClientTest.php @@ -35,6 +35,7 @@ use Google\Cloud\Firestore\V1\BatchGetDocumentsRequest; use Google\Cloud\Firestore\V1\BeginTransactionRequest; use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; +use Google\Cloud\Firestore\V1\CommitRequest; use Google\Cloud\Firestore\WriteBatch; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; @@ -270,8 +271,12 @@ public function testRunTransaction() ] ])); - $this->connection->commit(Argument::any()) - ->shouldBeCalled(); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + )->shouldBeCalled(); $this->client->___setProperty('connection', $this->connection->reveal()); $this->client->___setProperty('requestHandler', $this->requestHandler->reveal()); diff --git a/Firestore/tests/Snippet/FirestoreSessionHandlerTest.php b/Firestore/tests/Snippet/FirestoreSessionHandlerTest.php index 2e73a16f059..85c65f60ae9 100644 --- a/Firestore/tests/Snippet/FirestoreSessionHandlerTest.php +++ b/Firestore/tests/Snippet/FirestoreSessionHandlerTest.php @@ -28,6 +28,7 @@ use Google\Cloud\Firestore\V1\BatchGetDocumentsRequest; use Google\Cloud\Firestore\V1\BeginTransactionRequest; use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; +use Google\Cloud\Firestore\V1\CommitRequest; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; @@ -104,14 +105,18 @@ public function testClass() ]); $value = 'name|' . serialize('Bob'); - $this->connection->commit(Argument::allOf( - Argument::that(function ($args) use ($value) { - return strpos($args['writes'][0]['update']['name'], ':PHPSESSID') !== false - && $args['writes'][0]['update']['fields']['data']['stringValue'] === $value - && isset($args['writes'][0]['update']['fields']['t']['integerValue']); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($value) { + $data = $this->getSerializer()->encodeMessage($req); + return strpos($data['writes'][0]['update']['name'], ':PHPSESSID') !== false + && $data['writes'][0]['update']['fields']['data']['stringValue'] === $value + && isset($data['writes'][0]['update']['fields']['t']['integerValue']) + && $data['transaction'] == self::TRANSACTION; }), - Argument::withEntry('transaction', self::TRANSACTION) - ))->shouldBeCalled()->willReturn([ + Argument::cetera() + )->shouldBeCalled()->willReturn([ 'writeResults' => [] ]); @@ -153,14 +158,18 @@ public function testSessionHandlerMethod() ]); $value = 'name|' . serialize('Bob'); - $this->connection->commit(Argument::allOf( - Argument::that(function ($args) use ($value) { - return strpos($args['writes'][0]['update']['name'], ':PHPSESSID') !== false - && $args['writes'][0]['update']['fields']['data']['stringValue'] === $value - && isset($args['writes'][0]['update']['fields']['t']['integerValue']); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($value) { + $data = $this->getSerializer()->encodeMessage($req); + return strpos($data['writes'][0]['update']['name'], ':PHPSESSID') !== false + && $data['writes'][0]['update']['fields']['data']['stringValue'] === $value + && isset($data['writes'][0]['update']['fields']['t']['integerValue']) + && $data['transaction'] == self::TRANSACTION; }), - Argument::withEntry('transaction', self::TRANSACTION) - ))->shouldBeCalled()->willReturn([ + Argument::cetera() + )->shouldBeCalled()->willReturn([ 'writeResults' => [] ]); @@ -204,11 +213,14 @@ public function testClassErrorHandler() 'transaction' => self::TRANSACTION ]); - $this->connection->commit(Argument::any()) - ->shouldBeCalled() - ->will(function () { - trigger_error('oops!', E_USER_WARNING); - }); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + )->shouldBeCalled()->will(function () { + trigger_error('oops!', E_USER_WARNING); + }); $this->client->___setProperty('connection', $this->connection->reveal()); $this->client->___setProperty('requestHandler', $this->requestHandler->reveal()); diff --git a/Firestore/tests/Snippet/WriteBatchTest.php b/Firestore/tests/Snippet/WriteBatchTest.php index c4cd2aa92fd..a8152e9a7db 100644 --- a/Firestore/tests/Snippet/WriteBatchTest.php +++ b/Firestore/tests/Snippet/WriteBatchTest.php @@ -24,6 +24,8 @@ use Google\Cloud\Core\Testing\Snippet\SnippetTestCase; use Google\Cloud\Core\Testing\TestHelpers; use Google\Cloud\Firestore\Connection\ConnectionInterface; +use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; +use Google\Cloud\Firestore\V1\CommitRequest; use Google\Cloud\Firestore\V1\DocumentTransform\FieldTransform\ServerValue; use Google\Cloud\Firestore\ValueMapper; use Google\Cloud\Firestore\WriteBatch; @@ -217,9 +219,14 @@ public function testDelete() public function testCommit() { - $this->connection->commit(Argument::any()) - ->shouldBeCalled(); - $this->batch->___setProperty('connection', $this->connection->reveal()); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + )->shouldBeCalled(); + + $this->batch->___setProperty('requestHandler', $this->requestHandler->reveal()); $snippet = $this->snippetFromMethod(WriteBatch::class, 'commit'); $snippet->addLocal('batch', $this->batch); $snippet->invoke(); @@ -227,11 +234,17 @@ public function testCommit() public function commitAndAssert(Snippet $snippet, $assertion) { - $this->connection->commit([ - 'database' => self::DATABASE, - 'writes' => $assertion - ])->shouldBeCalled(); - $this->batch->___setProperty('connection', $this->connection->reveal()); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($assertion) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == self::DATABASE + && array_replace_recursive($data['writes'], $assertion) == $data['writes']; + }), + Argument::cetera() + )->shouldBeCalled(); + $this->batch->___setProperty('requestHandler', $this->requestHandler->reveal()); $snippet->addLocal('batch', $this->batch); $snippet->addLocal('documentName', self::DOCUMENT); diff --git a/Firestore/tests/Unit/BulkWriterTest.php b/Firestore/tests/Unit/BulkWriterTest.php index 7cc8fcbac3a..8b5ed1ef676 100644 --- a/Firestore/tests/Unit/BulkWriterTest.php +++ b/Firestore/tests/Unit/BulkWriterTest.php @@ -28,6 +28,7 @@ use Google\Cloud\Firestore\FieldValue; use Google\Cloud\Firestore\V1\DocumentTransform\FieldTransform\ServerValue; use Google\Cloud\Firestore\ValueMapper; +use Google\Protobuf\Timestamp as ProtobufTimestamp; use Google\Rpc\Code; use InvalidArgumentException; use PHPUnit\Framework\TestCase; @@ -832,10 +833,7 @@ public function testWriteUpdateTimePrecondition($name, $ref) $this->batch->delete($ref, [ 'precondition' => [ - 'updateTime' => new Timestamp( - \DateTimeImmutable::createFromFormat('U', (string) $ts['seconds']), - $ts['nanos'] - ), + 'updateTime' => $ts, ], ]); diff --git a/Firestore/tests/Unit/CollectionReferenceTest.php b/Firestore/tests/Unit/CollectionReferenceTest.php index c5f4c0799c4..fff7fd51581 100644 --- a/Firestore/tests/Unit/CollectionReferenceTest.php +++ b/Firestore/tests/Unit/CollectionReferenceTest.php @@ -29,6 +29,7 @@ use Google\Cloud\Firestore\DocumentReference; use Google\Cloud\Firestore\CollectionReference; use Google\Cloud\Firestore\Connection\ConnectionInterface; +use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; /** * @group firestore @@ -65,7 +66,7 @@ public function setUp(): void false ), self::NAME - ]); + ], ['requestHandler', 'connection']); } public function testName() @@ -105,29 +106,33 @@ public function testNewDocument() public function testAdd() { - $this->connection->commit(Argument::that(function ($args) { - $expected = [ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'currentDocument' => ['exists' => false], - 'update' => [ - 'fields' => [ - 'hello' => [ - 'stringValue' => 'world' + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + $expected = [ + 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), + 'writes' => [ + [ + 'currentDocument' => ['exists' => false], + 'update' => [ + 'fields' => [ + 'hello' => [ + 'stringValue' => 'world' + ] ] ] ] ] - ] - ]; + ]; - unset($args['writes'][0]['update']['name']); + return array_replace_recursive($data, $expected) == $data; + }), + Argument::cetera() + )->shouldBeCalled()->willReturn([[]]); - return $args === $expected; - }))->shouldBeCalled()->willReturn([[]]); - - $this->collection->___setProperty('connection', $this->connection->reveal()); + $this->collection->___setProperty('requestHandler', $this->requestHandler->reveal()); $this->collection->add(['hello' => 'world']); } diff --git a/Firestore/tests/Unit/ConformanceTest.php b/Firestore/tests/Unit/ConformanceTest.php index eda6620878d..0f89ddee66d 100644 --- a/Firestore/tests/Unit/ConformanceTest.php +++ b/Firestore/tests/Unit/ConformanceTest.php @@ -34,6 +34,7 @@ use Google\Cloud\Firestore\PathTrait; use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; use Google\Cloud\Firestore\V1\DocumentTransform\FieldTransform\ServerValue; +use Google\Cloud\Firestore\V1\Precondition; use Google\Cloud\Firestore\V1\StructuredQuery\CompositeFilter\Operator as CompositFilterOperator; use Google\Cloud\Firestore\V1\StructuredQuery\Direction; use Google\Cloud\Firestore\V1\StructuredQuery\FieldFilter\Operator as FieldFilterOperator; @@ -65,7 +66,6 @@ class ConformanceTest extends TestCase private $client; private $connection; private $requestHandler; - private $serializer; private $excludes = [ // need mergeFields support @@ -95,7 +95,6 @@ public function setUp(): void $this->connection = $this->prophesize(ConnectionInterface::class); $this->requestHandler = $this->prophesize(RequestHandler::class); - $this->serializer = $this->getSerializer(); } /** @@ -121,6 +120,7 @@ public function testGet($test) /** * @dataProvider cases * @group firestore-conformance-create + * @group mystic */ public function testCreate($test) { @@ -130,8 +130,16 @@ public function testCreate($test) unset($request['transaction']); } - $this->connection->commit(new ArrayHasSameValuesToken($this->injectPbValues($request))) - ->shouldBeCalled()->willReturn([]); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($request) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == $request['database'] + && array_replace_recursive($data['writes'], $request['writes']) == $data['writes']; + }), + Argument::cetera() + )->shouldBeCalled()->willReturn([]); }); $this->executeAndHandleError($test, function ($test) { @@ -152,11 +160,20 @@ public function testSet($test) unset($request['transaction']); } - $this->connection->commit(new ArrayHasSameValuesToken($this->injectPbValues($request))) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($request) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] === $request['database'] + && array_replace_recursive($data['writes'], $request['writes']) == $data['writes']; + }), + Argument::cetera() + ) ->shouldBeCalled()->willReturn([]); }); - $this->client->___setProperty('connection', $this->connection->reveal()); + $this->client->___setProperty('requestHandler', $this->requestHandler->reveal()); $this->executeAndHandleError($test, function ($test) { $options = []; @@ -181,7 +198,16 @@ public function testUpdatePaths($test) unset($request['transaction']); } - $this->connection->commit(new ArrayHasSameValuesToken($this->injectPbValues($request))) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($request) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] === $request['database'] + && array_replace_recursive($data['writes'], $request['writes']) == $data['writes']; + }), + Argument::cetera() + ) ->shouldBeCalled()->willReturn([]); }); @@ -215,7 +241,16 @@ public function testDelete($test) unset($request['transaction']); } - $this->connection->commit(new ArrayHasSameValuesToken($this->injectPbValues($request))) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($request) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == $request['database'] + && array_replace_recursive($data['writes'], $request['writes']) == $data['writes']; + }), + Argument::cetera() + ) ->shouldBeCalled()->willReturn([]); }); @@ -324,7 +359,7 @@ public function testQuery($test) $mapper = new ValueMapper( $this->prophesize(ConnectionInterface::class)->reveal(), $this->prophesize(RequestHandler::class)->reveal(), - $this->serializer, + $this->getSerializer(), false ); @@ -358,11 +393,15 @@ private function setupCommitRequest(array $test, callable $call) if (!$test['isError']) { $call($test); } else { - $this->connection->commit(Argument::any()) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::cetera() + ) ->shouldNotBeCalled()->willReturn([]); } - $this->client->___setProperty('connection', $this->connection->reveal()); + $this->client->___setProperty('requestHandler', $this->requestHandler->reveal()); } private function executeAndHandleError(array $test, callable $executeTest) @@ -394,17 +433,8 @@ private function formatOptions(array $test) } if (isset($test['precondition']['updateTime'])) { - $updateTime = $this->parseTimeString($test['precondition']['updateTime']); - $test['precondition']['updateTime'] = [ - 'seconds' => $updateTime[0]->format('U'), - 'nanos' => $updateTime[1] - ]; - $options['precondition'] = [ - 'updateTime' => new Timestamp( - \DateTime::createFromFormat('U', (string) $test['precondition']['updateTime']['seconds']), - $test['precondition']['updateTime']['nanos'] - ) + 'updateTime' => $test['precondition']['updateTime'] ]; } } diff --git a/Firestore/tests/Unit/DocumentReferenceTest.php b/Firestore/tests/Unit/DocumentReferenceTest.php index 62f62cc99fc..13df459adab 100644 --- a/Firestore/tests/Unit/DocumentReferenceTest.php +++ b/Firestore/tests/Unit/DocumentReferenceTest.php @@ -29,6 +29,7 @@ use Google\Cloud\Firestore\FieldPath; use Google\Cloud\Firestore\V1\BatchGetDocumentsRequest; use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; +use Google\Cloud\Firestore\V1\CommitRequest; use Google\Cloud\Firestore\ValueMapper; use PHPUnit\Framework\TestCase; use Prophecy\Argument; @@ -105,90 +106,119 @@ public function testId() public function testCreate() { - $this->connection->commit([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'currentDocument' => ['exists' => false], - 'update' => [ - 'name' => self::NAME, - 'fields' => [ - 'hello' => [ - 'stringValue' => 'world' + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + $expected = [ + 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), + 'writes' => [ + [ + 'currentDocument' => ['exists' => false], + 'update' => [ + 'name' => self::NAME, + 'fields' => [ + 'hello' => [ + 'stringValue' => 'world' + ] + ] ] ] ] - ] - ] - ])->shouldBeCalled()->willReturn([[]]); + ]; - $this->document->___setProperty('connection', $this->connection->reveal()); + return array_replace_recursive($data, $expected) == $data; + }), + Argument::cetera() + )->shouldBeCalled()->willReturn([[]]); + + $this->document->___setProperty('requestHandler', $this->requestHandler->reveal()); $this->document->create(['hello' => 'world']); } public function testSet() { - $this->connection->commit([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'update' => [ - 'name' => self::NAME, - 'fields' => [ - 'hello' => [ - 'stringValue' => 'world' + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + $expected = [ + 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), + 'writes' => [ + [ + 'update' => [ + 'name' => self::NAME, + 'fields' => [ + 'hello' => [ + 'stringValue' => 'world' + ] + ] ] ] ] - ] - ] - ])->shouldBeCalled()->willReturn([[]]); + ]; - $this->document->___setProperty('connection', $this->connection->reveal()); + return array_replace_recursive($data, $expected) == $data; + }), + Argument::cetera() + )->shouldBeCalled()->willReturn([[]]); + + $this->document->___setProperty('requestHandler', $this->requestHandler->reveal()); $this->document->set(['hello' => 'world']); } public function testUpdate() { - $this->connection->commit([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'updateMask' => [ - 'fieldPaths' => [ - "foo.bar", - "foo.baz", - "hello", - ] - ], - 'currentDocument' => ['exists' => true], - 'update' => [ - 'name' => self::NAME, - 'fields' => [ - 'hello' => [ - 'stringValue' => 'world' + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + $expected = [ + 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), + 'writes' => [ + [ + 'updateMask' => [ + 'fieldPaths' => [ + "foo.bar", + "foo.baz", + "hello", + ] ], - 'foo' => [ - 'mapValue' => [ - 'fields' => [ - 'bar' => [ - 'stringValue' => 'val' - ], - 'baz' => [ - 'stringValue' => 'val' + 'currentDocument' => ['exists' => true], + 'update' => [ + 'name' => self::NAME, + 'fields' => [ + 'hello' => [ + 'stringValue' => 'world' + ], + 'foo' => [ + 'mapValue' => [ + 'fields' => [ + 'bar' => [ + 'stringValue' => 'val' + ], + 'baz' => [ + 'stringValue' => 'val' + ] + ] ] ] ] ] ] ] - ] - ] - ])->shouldBeCalled()->willReturn([[]]); + ]; + return array_replace_recursive($data, $expected) == $data; + }), + Argument::cetera() + )->shouldBeCalled()->willReturn([[]]); - $this->document->___setProperty('connection', $this->connection->reveal()); + $this->document->___setProperty('requestHandler', $this->requestHandler->reveal()); $this->document->update([ ['path' => 'hello', 'value' => 'world'], @@ -199,16 +229,25 @@ public function testUpdate() public function testDelete() { - $this->connection->commit([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'delete' => self::NAME - ] - ] - ])->shouldBeCalled()->willReturn([[]]); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + $expected = [ + 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), + 'writes' => [ + [ + 'delete' => self::NAME + ] + ] + ]; + return array_replace_recursive($data, $expected) == $data; + }), + Argument::cetera() + )->shouldBeCalled()->willReturn([[]]); - $this->document->___setProperty('connection', $this->connection->reveal()); + $this->document->___setProperty('requestHandler', $this->requestHandler->reveal()); $this->document->delete(); } @@ -288,7 +327,12 @@ public function testWriteResult() $ts = \DateTime::createFromFormat('U', $time)->format(Timestamp::FORMAT); $ts2 = \DateTime::createFromFormat('U', $time+100)->format(Timestamp::FORMAT); - $this->connection->commit(Argument::any()) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + ) ->shouldBeCalled() ->willReturn([ 'writeResults' => [ @@ -301,7 +345,7 @@ public function testWriteResult() 'commitTime' => $ts ]); - $this->document->___setProperty('connection', $this->connection->reveal()); + $this->document->___setProperty('requestHandler', $this->requestHandler->reveal()); $res = $this->document->set(['foo' => 'bar']); $this->assertInstanceOf(Timestamp::class, $res['updateTime']); diff --git a/Firestore/tests/Unit/FirestoreClientTest.php b/Firestore/tests/Unit/FirestoreClientTest.php index 6c7d02d724d..5e1adc2df27 100644 --- a/Firestore/tests/Unit/FirestoreClientTest.php +++ b/Firestore/tests/Unit/FirestoreClientTest.php @@ -35,6 +35,7 @@ use Google\Cloud\Firestore\Query; use Google\Cloud\Firestore\V1\BeginTransactionRequest; use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; +use Google\Cloud\Firestore\V1\CommitRequest; use Google\Cloud\Firestore\V1\FirestoreClient as V1FirestoreGapicClient; use Google\Cloud\Firestore\WriteBatch; use InvalidArgumentException; @@ -83,11 +84,18 @@ public function testBatch() public function testBatchCorrectDatabaseName() { $db = sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE); - $this->connection->commit(Argument::withEntry('database', $db)) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($db) { + return $req->getDatabase() == $db; + }), + Argument::cetera() + ) ->shouldBeCalled() ->willReturn([[]]); - $this->client->___setProperty('connection', $this->connection->reveal()); + $this->client->___setProperty('requestHandler', $this->requestHandler->reveal()); $batch = $this->client->batch(); $batch->commit(); } @@ -445,14 +453,26 @@ public function testRunTransactionRetryable() ]; }); - $this->connection->commit(Argument::allOf( - Argument::withEntry('database', 'projects/'. self::PROJECT .'/databases/'. self::DATABASE), - Argument::withEntry('transaction', $transactionId) - ))->shouldBeCalled()->will(function ($args, $mock) use ($timestamp, $transactionId2) { - $mock->commit(Argument::allOf( - Argument::withEntry('database', 'projects/'. self::PROJECT .'/databases/'. self::DATABASE), - Argument::withEntry('transaction', $transactionId2) - ))->willReturn([ + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($transactionId) { + $db = sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE); + return $req->getDatabase() == $db + && $req->getTransaction() == $transactionId; + }), + Argument::cetera() + )->shouldBeCalled()->will(function ($_, $mock) use ($timestamp, $transactionId2) { + $mock->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req2) use ($transactionId2) { + $db = sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE); + return $req2->getDatabase() == $db + && $req2->getTransaction() == $transactionId2; + }), + Argument::cetera() + )->willReturn([ 'commitTime' => $timestamp, ]); @@ -469,7 +489,7 @@ public function testRunTransactionRetryable() $res = $this->client->runTransaction(function ($t) { $doc = $this->prophesize(DocumentReference::class); - $doc->name('foo'); + $doc->name()->willReturn('foo'); $t->create($doc->reveal(), ['foo'=>'bar']); return 'foo'; @@ -528,7 +548,12 @@ public function testRunTransactionExceedsMaxRetries() 'transaction' => $transactionId ]); - $this->connection->commit(Argument::any()) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + ) ->shouldBeCalledTimes(6) ->willThrow(new AbortedException('foo')); @@ -539,7 +564,7 @@ public function testRunTransactionExceedsMaxRetries() $res = $this->client->runTransaction(function ($t) { $doc = $this->prophesize(DocumentReference::class); - $doc->name('foo'); + $doc->name()->willReturn('foo'); $t->create($doc->reveal(), ['foo'=>'bar']); }); } @@ -560,9 +585,12 @@ public function testRunTransactionExceedsMaxRetriesLowerLimit() 'transaction' => $transactionId ]); - $this->connection->commit(Argument::any()) - ->shouldBeCalledTimes(3) - ->willThrow(new AbortedException('foo')); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + )->shouldBeCalledTimes(3)->willThrow(new AbortedException('foo')); $this->connection->rollback(Argument::any())->shouldBeCalledTimes(3); @@ -571,7 +599,7 @@ public function testRunTransactionExceedsMaxRetriesLowerLimit() $res = $this->client->runTransaction(function ($t) { $doc = $this->prophesize(DocumentReference::class); - $doc->name('foo'); + $doc->name()->willReturn('foo'); $t->create($doc->reveal(), ['foo'=>'bar']); }, ['maxRetries' => 2]); } diff --git a/Firestore/tests/Unit/FirestoreSessionHandlerTest.php b/Firestore/tests/Unit/FirestoreSessionHandlerTest.php index f3cd6653603..382532e1ced 100644 --- a/Firestore/tests/Unit/FirestoreSessionHandlerTest.php +++ b/Firestore/tests/Unit/FirestoreSessionHandlerTest.php @@ -26,6 +26,7 @@ use Google\Cloud\Firestore\FirestoreSessionHandler; use Google\Cloud\Firestore\V1\BatchGetDocumentsRequest; use Google\Cloud\Firestore\V1\Client\FirestoreClient as V1FirestoreClient; +use Google\Cloud\Firestore\V1\CommitRequest; use Google\Cloud\Firestore\V1\FirestoreClient as V1FirestoreGapicClient; use InvalidArgumentException; use Iterator; @@ -309,20 +310,30 @@ public function testWrite() Argument::cetera() )->shouldBeCalledTimes(1)->willReturn(['transaction' => null]); - $this->connection->commit([ - 'database' => $this->dbName(), - 'writes' => [ - [ - 'update' => [ - 'name' => $this->documentName(), - 'fields' => [ - 'data' => ['stringValue' => 'sessiondata'] + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + $expected = [ + 'database' => $this->dbName(), + 'writes' => [ + [ + 'update' => [ + 'name' => $this->documentName(), + 'fields' => [ + 'data' => ['stringValue' => 'sessiondata'] + ] + ] ] ] - ] - ] - ]) - ->shouldBeCalledTimes(1); + ]; + + return array_replace_recursive($data, $expected) == $data; + }), + Argument::cetera() + )->shouldBeCalledTimes(1); + $firestoreSessionHandler = new FirestoreSessionHandler( $this->connection->reveal(), $this->requestHandler->reveal(), @@ -364,7 +375,12 @@ public function testWriteWithException() 'transaction' => 123 ]) ->shouldBeCalledTimes(1); - $this->connection->commit(Argument::any()) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + ) ->shouldBeCalledTimes(1) ->willThrow((new ServiceException(''))); $firestoreSessionHandler = new FirestoreSessionHandler( @@ -394,16 +410,18 @@ public function testDestroy() Argument::cetera() )->shouldBeCalledTimes(1)->willReturn(['transaction' => 123]); - $this->connection->commit([ - 'database' => $this->dbName(), - 'writes' => [ - [ - 'delete' => $this->documentName() - ] - ], - 'transaction' => 123 - ]) - ->shouldBeCalledTimes(1); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == $this->dbName() + && $data['writes'][0]['delete'] == $this->documentName() + && $data['transaction'] == 123; + }), + Argument::cetera() + )->shouldBeCalledTimes(1); + $firestoreSessionHandler = new FirestoreSessionHandler( $this->connection->reveal(), $this->requestHandler->reveal(), @@ -432,7 +450,12 @@ public function testDestroyWithException() Argument::cetera() )->shouldBeCalledTimes(1)->willReturn(['transaction' => 123]); - $this->connection->commit(Argument::any()) + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::type(CommitRequest::class), + Argument::cetera() + ) ->shouldBeCalledTimes(1) ->willThrow(new ServiceException('')); $this->connection->rollback([ @@ -531,16 +554,19 @@ public function testGc() ->willReturn(['data' => 'sessiondata']); $this->valueMapper->encodeValue(Argument::type('integer')) ->shouldBeCalledTimes(1); - $this->connection->commit([ - 'database' => $this->dbName(), - 'writes' => [ - [ - 'delete' => $this->documentName() - ] - ], - 'transaction' => 123 - ]) - ->shouldBeCalledTimes(1); + + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == $this->dbName() + && $data['writes'][0]['delete'] == $this->documentName() + && $data['transaction'] == 123; + }), + Argument::cetera() + )->shouldBeCalledTimes(1); + $firestoreSessionHandler = new FirestoreSessionHandler( $this->connection->reveal(), $this->requestHandler->reveal(), diff --git a/Firestore/tests/Unit/TransactionTest.php b/Firestore/tests/Unit/TransactionTest.php index a31c4cd13d0..660aa010615 100644 --- a/Firestore/tests/Unit/TransactionTest.php +++ b/Firestore/tests/Unit/TransactionTest.php @@ -459,12 +459,19 @@ public function testDocumentsOrdered() private function expectAndInvoke(array $writes) { - $this->connection->commit([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => $writes, - 'transaction' => self::TRANSACTION - ])->shouldBeCalled(); - $this->transaction->___setProperty('connection', $this->connection->reveal()); + $this->requestHandler->sendRequest( + V1FirestoreClient::class, + 'commit', + Argument::that(function ($req) use ($writes) { + $data = $this->getSerializer()->encodeMessage($req); + return $data['database'] == sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE) + && array_replace_recursive($data['writes'], $writes) == $data['writes'] + && $data['transaction'] == self::TRANSACTION; + }), + Argument::cetera() + )->shouldBeCalled(); + + $this->transaction->___setProperty('requestHandler', $this->requestHandler->reveal()); $this->transaction->writer()->commit(); } } diff --git a/Firestore/tests/Unit/WriteBatchTest.php b/Firestore/tests/Unit/WriteBatchTest.php deleted file mode 100644 index 6208a0ce86a..00000000000 --- a/Firestore/tests/Unit/WriteBatchTest.php +++ /dev/null @@ -1,574 +0,0 @@ -connection = $this->prophesize(ConnectionInterface::class); - $this->requestHandler = $this->prophesize(RequestHandler::class); - $this->serializer = $this->getSerializer(); - $this->batch = TestHelpers::stub(WriteBatch::class, [ - $this->connection->reveal(), - $this->requestHandler->reveal(), - $this->serializer, - new ValueMapper( - $this->connection->reveal(), - $this->requestHandler->reveal(), - $this->serializer, - false - ), - sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE) - ], ['connection', 'requestHandler', 'transaction']); - } - - /** - * @dataProvider documents - */ - public function testCreate($name, $ref) - { - $this->batch->create($ref, [ - 'hello' => 'world' - ]); - - $this->commitAndAssert([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'currentDocument' => ['exists' => false], - 'update' => [ - 'name' => $name, - 'fields' => ['hello' => ['stringValue' => 'world']] - ] - ] - ] - ]); - } - - /** - * @dataProvider documents - */ - public function testUpdate($name, $ref) - { - $this->batch->update($ref, [ - [ - 'path' => 'hello.world', - 'value' => 'world' - ], [ - 'path' => new FieldPath(['hello', 'house']), - 'value' => 'house' - ] - ]); - - $this->commitAndAssert([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'updateMask' => [ - 'fieldPaths' => [ - 'hello.house', - 'hello.world', - ] - ], - 'currentDocument' => ['exists' => true], - 'update' => [ - 'name' => $name, - 'fields' => [ - 'hello' => [ - 'mapValue' => [ - 'fields' => [ - 'world' => [ - 'stringValue' => 'world' - ], - 'house' => [ - 'stringValue' => 'house' - ] - ] - ] - ] - ] - ] - ] - ] - ]); - } - - /** - * @dataProvider updateBadInput - */ - public function testUpdateBadInput($data) - { - $this->expectException(InvalidArgumentException::class); - - $this->batch->update(self::DOCUMENT, $data); - } - - public function updateBadInput() - { - return [ - [['foo' => 'bar']], - [[['path' => 'foo']]], - [[['value' => 'bar']]], - [[[]]] - ]; - } - - /** - * @dataProvider documents - */ - public function testUpdateSentinels($name, $ref) - { - $this->batch->update($ref, [ - ['path' => 'foo', 'value' => 'bar'], - ['path' => 'hello', 'value' => FieldValue::deleteField()], - ['path' => 'world', 'value' => FieldValue::serverTimestamp()], - ['path' => 'arr', 'value' => FieldValue::arrayUnion(['a'])], - ['path' => 'arr2', 'value' => FieldValue::arrayRemove(['b'])], - ['path' => 'int', 'value' => FieldValue::increment(2)], - ]); - - $this->commitAndAssert([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'updateMask' => ['fieldPaths' => ['foo', 'hello']], - 'currentDocument' => ['exists' => true], - 'update' => [ - 'name' => $name, - 'fields' => [ - 'foo' => ['stringValue' => 'bar'] - ] - ] - ], [ - 'transform' => [ - 'document' => $name, - 'fieldTransforms' => [ - [ - 'fieldPath' => 'world', - 'setToServerValue' => ServerValue::REQUEST_TIME - ], [ - 'fieldPath' => 'arr', - 'appendMissingElements' => [ - 'values' => [ - [ - 'stringValue' => 'a' - ] - ] - ] - ], [ - 'fieldPath' => 'arr2', - 'removeAllFromArray' => [ - 'values' => [ - [ - 'stringValue' => 'b' - ] - ] - ] - ], [ - 'fieldPath' => 'int', - 'increment' => [ - 'integerValue' => 2 - ] - ] - ] - ] - ] - ] - ]); - } - - /** - * @dataProvider noUpdateSentinels - */ - public function testSentinelsOmitUpdateWrite($val) - { - $ref = $this->prophesize(DocumentReference::class); - $ref->name()->willReturn(self::DOCUMENT); - - $this->batch->update($ref->reveal(), [ - ['path' => 'foo', 'value' => $val], - ]); - - $this->commitAndAssert(function ($arg) { - if (count($arg['writes']) > 1) { - return false; - } - - if (!isset($arg['writes'][0]['transform']['fieldTransforms'][0])) { - return false; - } - - return $arg['writes'][0]['transform']['fieldTransforms'][0]['fieldPath'] === 'foo'; - }); - } - - public function noUpdateSentinels() - { - return [ - [FieldValue::serverTimestamp()], - [FieldValue::arrayUnion([])], - [FieldValue::arrayRemove([])] - ]; - } - - /** - * @dataProvider documents - */ - public function testSet($name, $ref) - { - $this->batch->set($ref, [ - 'hello' => 'world' - ]); - - $this->commitAndAssert([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'update' => [ - 'name' => $name, - 'fields' => ['hello' => ['stringValue' => 'world']] - ] - ] - ] - ]); - } - - /** - * @dataProvider documents - */ - public function testSetMerge($name, $ref) - { - $this->batch->set($ref, [ - 'hello' => 'world', - 'foobar' => ['foo' => 'bar'], - 'emptiness' => [] - ], ['merge' => true]); - - $this->commitAndAssert([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'updateMask' => ['fieldPaths' => ['emptiness', 'foobar.foo', 'hello']], - 'update' => [ - 'name' => $name, - 'fields' => [ - 'hello' => ['stringValue' => 'world'], - 'foobar' => ['mapValue' => ['fields' => ['foo' => ['stringValue' => 'bar']]]], - 'emptiness' => ['arrayValue' => ['values' => []]] - ] - ] - ] - ] - ]); - } - - /** - * @dataProvider documents - */ - public function testSetSentinels($name, $ref) - { - $this->batch->set($ref, [ - 'world' => FieldValue::serverTimestamp(), - 'foo' => 'bar' - ]); - - $this->commitAndAssert([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'update' => [ - 'name' => $name, - 'fields' => [ - 'foo' => [ - 'stringValue' => 'bar' - ] - ] - ] - ], [ - 'transform' => [ - 'document' => $name, - 'fieldTransforms' => [ - [ - 'fieldPath' => 'world', - 'setToServerValue' => ServerValue::REQUEST_TIME - ] - ] - ] - ] - ] - ]); - } - - public function testSentinelsInArray() - { - $this->expectException(InvalidArgumentException::class); - - $this->batch->set('name', [ - 'foo' => [ - FieldValue::serverTimestamp() - ] - ]); - } - - public function testSentinelsAfterArray() - { - $ret = $this->batch->set('name', [ - 'foo' => [ - 'a', 'b', 'c' - ], - 'bar' => FieldValue::serverTimestamp() - ]); - - $this->assertInstanceOf(\Google\Cloud\Firestore\BulkWriter::class, $ret); - } - - public function testSentinelsAfterArrayNested() - { - $ret = $this->batch->set('name', [ - 'foo' => [ - 'a' => [ - 'a', 'b', 'c', - ], - 'b' => FieldValue::serverTimestamp() - ] - ]); - - $this->assertInstanceOf(\Google\Cloud\Firestore\BulkWriter::class, $ret); - } - - public function testSentinelCannotContainSentinel() - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessageMatches('/Document transforms cannot contain/'); - $this->batch->set('name', [ - 'foo' => FieldValue::arrayRemove([FieldValue::arrayUnion([])]) - ]); - } - - /** - * @dataProvider documents - */ - public function testSetSentinelsDeleteRequiresMerge($name, $ref) - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Delete cannot appear in data unless `$options[\'merge\']` is set.'); - - $this->batch->set($ref, [ - 'hello' => FieldValue::deleteField(), - ]); - } - - /** - * @dataProvider documents - */ - public function testDelete($name, $ref) - { - $this->batch->delete($ref); - - $this->commitAndAssert([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'delete' => $name - ] - ] - ]); - } - - /** - * @dataProvider documents - */ - public function testWriteUpdateTimePrecondition($name, $ref) - { - $ts = [ - 'seconds' => 10000, - 'nanos' => 5 - ]; - - $this->batch->delete($ref, [ - 'precondition' => [ - 'updateTime' => new Timestamp( - \DateTimeImmutable::createFromFormat('U', (string) $ts['seconds']), - $ts['nanos'] - ) - ] - ]); - - $this->commitAndAssert([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'writes' => [ - [ - 'delete' => $name, - 'currentDocument' => [ - 'updateTime' => $ts - ] - ] - ] - ]); - } - - public function documents() - { - $ref = $this->prophesize(DocumentReference::class); - $ref->name()->willReturn(self::DOCUMENT); - $doc = $ref->reveal(); - - return [ - [self::DOCUMENT, self::DOCUMENT], - [self::DOCUMENT, $doc] - ]; - } - - public function testWriteUpdateTimePreconditionInvalidType() - { - $this->expectException(InvalidArgumentException::class); - - $this->batch->delete(self::DOCUMENT, [ - 'precondition' => [ - 'updateTime' => 'foobar' - ] - ]); - } - - public function testWritePreconditionMissingStuff() - { - $this->expectException(InvalidArgumentException::class); - - $this->batch->delete(self::DOCUMENT, [ - 'precondition' => ['foo' => 'bar'] - ]); - } - - public function testCommitResponse() - { - $now = time(); - $nanos = 10; - - $timestamp = new Timestamp(\DateTimeImmutable::createFromFormat('U', (string) $now), $nanos); - - $this->connection->commit(Argument::any()) - ->shouldBeCalled() - ->willReturn([ - 'commitTime' => $timestamp, - 'writeResults' => [ - [ - 'updateTime' => $timestamp - ], [ - 'updateTime' => $timestamp - ] - ] - ]); - - $this->batch->___setProperty('connection', $this->connection->reveal()); - - $res = $this->batch->commit(); - - $this->assertEquals($timestamp, $res['commitTime']); - $this->assertEquals($timestamp, $res['writeResults'][0]['updateTime']); - $this->assertEquals($timestamp, $res['writeResults'][1]['updateTime']); - } - - public function testCommitWithTransaction() - { - $this->connection->commit(Argument::withEntry('transaction', self::TRANSACTION)) - ->shouldBeCalled(); - - $this->batch->___setProperty('connection', $this->connection->reveal()); - $this->batch->___setProperty('transaction', self::TRANSACTION); - - $this->batch->commit(); - } - - public function testRollback() - { - $this->connection->rollback([ - 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), - 'transaction' => self::TRANSACTION - ])->shouldBeCalled(); - - $this->batch->___setProperty('connection', $this->connection->reveal()); - $this->batch->___setProperty('transaction', self::TRANSACTION); - - $this->batch->rollback(); - } - - public function testRollbackFailsWithoutTransaction() - { - $this->expectException(\RuntimeException::class); - - $this->batch->rollback(); - } - - public function testUpdateEmptyFails() - { - $this->expectException(InvalidArgumentException::class); - - $this->batch->update(self::DOCUMENT, []); - } - - private function commitAndAssert($assertion) - { - if (is_callable($assertion)) { - $this->connection->commit(Argument::that($assertion)) - ->shouldBeCalled(); - } elseif (is_array($assertion)) { - $this->connection->commit($assertion)->shouldBeCalled(); - } else { - throw new \Exception('bad assertion'); - } - - $this->batch->___setProperty('connection', $this->connection->reveal()); - - $this->batch->commit(); - } -} diff --git a/Firestore/tests/Unit/conformance/v1/create-all-transforms.json b/Firestore/tests/Unit/conformance/v1/create-all-transforms.json index 82831624bb1..23eb5131870 100644 --- a/Firestore/tests/Unit/conformance/v1/create-all-transforms.json +++ b/Firestore/tests/Unit/conformance/v1/create-all-transforms.json @@ -28,7 +28,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" }, { "fieldPath": "c", diff --git a/Firestore/tests/Unit/conformance/v1/create-st-alone.json b/Firestore/tests/Unit/conformance/v1/create-st-alone.json index 20c5e8ec32a..86397f6e13c 100644 --- a/Firestore/tests/Unit/conformance/v1/create-st-alone.json +++ b/Firestore/tests/Unit/conformance/v1/create-st-alone.json @@ -15,7 +15,7 @@ "fieldTransforms": [ { "fieldPath": "a", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] }, diff --git a/Firestore/tests/Unit/conformance/v1/create-st-multi.json b/Firestore/tests/Unit/conformance/v1/create-st-multi.json index 89430e2b64d..cb2bef7aabf 100644 --- a/Firestore/tests/Unit/conformance/v1/create-st-multi.json +++ b/Firestore/tests/Unit/conformance/v1/create-st-multi.json @@ -28,11 +28,11 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" }, { "fieldPath": "c.d", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/create-st-nested.json b/Firestore/tests/Unit/conformance/v1/create-st-nested.json index f2a3a8d1f62..32e7e8da0ea 100644 --- a/Firestore/tests/Unit/conformance/v1/create-st-nested.json +++ b/Firestore/tests/Unit/conformance/v1/create-st-nested.json @@ -28,7 +28,7 @@ "fieldTransforms": [ { "fieldPath": "b.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/create-st-with-empty-map.json b/Firestore/tests/Unit/conformance/v1/create-st-with-empty-map.json index 730afd154fd..4a88a7943f8 100644 --- a/Firestore/tests/Unit/conformance/v1/create-st-with-empty-map.json +++ b/Firestore/tests/Unit/conformance/v1/create-st-with-empty-map.json @@ -36,7 +36,7 @@ "fieldTransforms": [ { "fieldPath": "a.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/create-st.json b/Firestore/tests/Unit/conformance/v1/create-st.json index 705f76ed16a..7ebec022e9c 100644 --- a/Firestore/tests/Unit/conformance/v1/create-st.json +++ b/Firestore/tests/Unit/conformance/v1/create-st.json @@ -28,7 +28,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/delete-time-precond.json b/Firestore/tests/Unit/conformance/v1/delete-time-precond.json index 160defb3fed..1981945ae20 100644 --- a/Firestore/tests/Unit/conformance/v1/delete-time-precond.json +++ b/Firestore/tests/Unit/conformance/v1/delete-time-precond.json @@ -6,7 +6,7 @@ "delete": { "docRefPath": "projects/projectID/databases/(default)/documents/C/d", "precondition": { - "updateTime": "1970-01-01T00:00:42Z" + "updateTime": {"seconds": "42", "nanos": "0"} }, "request": { "database": "projects/projectID/databases/(default)", @@ -14,7 +14,7 @@ { "delete": "projects/projectID/databases/(default)/documents/C/d", "currentDocument": { - "updateTime": "1970-01-01T00:00:42Z" + "updateTime": "1970-01-01T00:00:42.000000Z" } } ] diff --git a/Firestore/tests/Unit/conformance/v1/set-all-transforms.json b/Firestore/tests/Unit/conformance/v1/set-all-transforms.json index 5c8b1373d4c..f24f9b1c268 100644 --- a/Firestore/tests/Unit/conformance/v1/set-all-transforms.json +++ b/Firestore/tests/Unit/conformance/v1/set-all-transforms.json @@ -25,7 +25,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" }, { "fieldPath": "c", diff --git a/Firestore/tests/Unit/conformance/v1/set-st-alone-mergeall.json b/Firestore/tests/Unit/conformance/v1/set-st-alone-mergeall.json index d95bf0973b7..f514ee35228 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-alone-mergeall.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-alone-mergeall.json @@ -18,7 +18,7 @@ "fieldTransforms": [ { "fieldPath": "a", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-alone.json b/Firestore/tests/Unit/conformance/v1/set-st-alone.json index 3fe931394b0..484b2245172 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-alone.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-alone.json @@ -21,7 +21,7 @@ "fieldTransforms": [ { "fieldPath": "a", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-merge-both.json b/Firestore/tests/Unit/conformance/v1/set-st-merge-both.json index a39ada55f73..2d5b7da2a14 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-merge-both.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-merge-both.json @@ -44,7 +44,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-merge-nonleaf-alone.json b/Firestore/tests/Unit/conformance/v1/set-st-merge-nonleaf-alone.json index 4193b00ea68..98ca78047e6 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-merge-nonleaf-alone.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-merge-nonleaf-alone.json @@ -34,7 +34,7 @@ "fieldTransforms": [ { "fieldPath": "h.g", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-merge-nonleaf.json b/Firestore/tests/Unit/conformance/v1/set-st-merge-nonleaf.json index 5e91d663b8c..ffb279c440a 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-merge-nonleaf.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-merge-nonleaf.json @@ -45,7 +45,7 @@ "fieldTransforms": [ { "fieldPath": "h.g", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-merge-nowrite.json b/Firestore/tests/Unit/conformance/v1/set-st-merge-nowrite.json index 08fa8b52f54..36f87ad0d8d 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-merge-nowrite.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-merge-nowrite.json @@ -24,7 +24,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-mergeall.json b/Firestore/tests/Unit/conformance/v1/set-st-mergeall.json index 26883c03820..324b3912a1b 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-mergeall.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-mergeall.json @@ -33,7 +33,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-multi.json b/Firestore/tests/Unit/conformance/v1/set-st-multi.json index 23c06f4976f..52761246fe9 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-multi.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-multi.json @@ -25,11 +25,11 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" }, { "fieldPath": "c.d", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-nested.json b/Firestore/tests/Unit/conformance/v1/set-st-nested.json index 5c94c33f943..267c9845748 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-nested.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-nested.json @@ -25,7 +25,7 @@ "fieldTransforms": [ { "fieldPath": "b.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st-with-empty-map.json b/Firestore/tests/Unit/conformance/v1/set-st-with-empty-map.json index 063c94a0e6c..7173e65863f 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st-with-empty-map.json +++ b/Firestore/tests/Unit/conformance/v1/set-st-with-empty-map.json @@ -33,7 +33,7 @@ "fieldTransforms": [ { "fieldPath": "a.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/set-st.json b/Firestore/tests/Unit/conformance/v1/set-st.json index 42f2b14f1c7..9f7d1959aad 100644 --- a/Firestore/tests/Unit/conformance/v1/set-st.json +++ b/Firestore/tests/Unit/conformance/v1/set-st.json @@ -25,7 +25,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-all-transforms.json b/Firestore/tests/Unit/conformance/v1/update-all-transforms.json index 6f6a725df0f..079051dba2d 100644 --- a/Firestore/tests/Unit/conformance/v1/update-all-transforms.json +++ b/Firestore/tests/Unit/conformance/v1/update-all-transforms.json @@ -33,7 +33,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" }, { "fieldPath": "c", diff --git a/Firestore/tests/Unit/conformance/v1/update-nested-transform-and-nested-value.json b/Firestore/tests/Unit/conformance/v1/update-nested-transform-and-nested-value.json index ff7bfc6ee94..04538ed09b7 100644 --- a/Firestore/tests/Unit/conformance/v1/update-nested-transform-and-nested-value.json +++ b/Firestore/tests/Unit/conformance/v1/update-nested-transform-and-nested-value.json @@ -39,7 +39,7 @@ "fieldTransforms": [ { "fieldPath": "a.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-paths-all-transforms.json b/Firestore/tests/Unit/conformance/v1/update-paths-all-transforms.json index 01a4c1143dc..0463734de00 100644 --- a/Firestore/tests/Unit/conformance/v1/update-paths-all-transforms.json +++ b/Firestore/tests/Unit/conformance/v1/update-paths-all-transforms.json @@ -60,7 +60,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" }, { "fieldPath": "c", diff --git a/Firestore/tests/Unit/conformance/v1/update-paths-nested-transform-and-nested-value.json b/Firestore/tests/Unit/conformance/v1/update-paths-nested-transform-and-nested-value.json index 927d783aee4..deb9a549865 100644 --- a/Firestore/tests/Unit/conformance/v1/update-paths-nested-transform-and-nested-value.json +++ b/Firestore/tests/Unit/conformance/v1/update-paths-nested-transform-and-nested-value.json @@ -56,7 +56,7 @@ "fieldTransforms": [ { "fieldPath": "a.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-paths-st-alone.json b/Firestore/tests/Unit/conformance/v1/update-paths-st-alone.json index 085d0498771..c0535bc6b78 100644 --- a/Firestore/tests/Unit/conformance/v1/update-paths-st-alone.json +++ b/Firestore/tests/Unit/conformance/v1/update-paths-st-alone.json @@ -24,7 +24,7 @@ "fieldTransforms": [ { "fieldPath": "a", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] }, diff --git a/Firestore/tests/Unit/conformance/v1/update-paths-st-multi.json b/Firestore/tests/Unit/conformance/v1/update-paths-st-multi.json index 2d813801ac3..0b6deef1966 100644 --- a/Firestore/tests/Unit/conformance/v1/update-paths-st-multi.json +++ b/Firestore/tests/Unit/conformance/v1/update-paths-st-multi.json @@ -55,11 +55,11 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" }, { "fieldPath": "c.d", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-paths-st-nested.json b/Firestore/tests/Unit/conformance/v1/update-paths-st-nested.json index 8bd35c9111b..6a99f21d9d7 100644 --- a/Firestore/tests/Unit/conformance/v1/update-paths-st-nested.json +++ b/Firestore/tests/Unit/conformance/v1/update-paths-st-nested.json @@ -49,7 +49,7 @@ "fieldTransforms": [ { "fieldPath": "b.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-paths-st-with-empty-map.json b/Firestore/tests/Unit/conformance/v1/update-paths-st-with-empty-map.json index ac60b2771d3..188678c7b2e 100644 --- a/Firestore/tests/Unit/conformance/v1/update-paths-st-with-empty-map.json +++ b/Firestore/tests/Unit/conformance/v1/update-paths-st-with-empty-map.json @@ -50,7 +50,7 @@ "fieldTransforms": [ { "fieldPath": "a.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-paths-st.json b/Firestore/tests/Unit/conformance/v1/update-paths-st.json index 011405b9bf7..9cc9a91bce1 100644 --- a/Firestore/tests/Unit/conformance/v1/update-paths-st.json +++ b/Firestore/tests/Unit/conformance/v1/update-paths-st.json @@ -48,7 +48,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-paths-uptime.json b/Firestore/tests/Unit/conformance/v1/update-paths-uptime.json index 96801a0cd8e..68fd9b8e1d9 100644 --- a/Firestore/tests/Unit/conformance/v1/update-paths-uptime.json +++ b/Firestore/tests/Unit/conformance/v1/update-paths-uptime.json @@ -6,7 +6,7 @@ "updatePaths": { "docRefPath": "projects/projectID/databases/(default)/documents/C/d", "precondition": { - "updateTime": "1970-01-01T00:00:42Z" + "updateTime": {"seconds": "42", "nanos": "0"} }, "fieldPaths": [ { @@ -36,7 +36,7 @@ ] }, "currentDocument": { - "updateTime": "1970-01-01T00:00:42Z" + "updateTime": "1970-01-01T00:00:42.000000Z" } } ] diff --git a/Firestore/tests/Unit/conformance/v1/update-st-dot.json b/Firestore/tests/Unit/conformance/v1/update-st-dot.json index 83422ca5271..5357a10bd58 100644 --- a/Firestore/tests/Unit/conformance/v1/update-st-dot.json +++ b/Firestore/tests/Unit/conformance/v1/update-st-dot.json @@ -15,7 +15,7 @@ "fieldTransforms": [ { "fieldPath": "a.b.c", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] }, diff --git a/Firestore/tests/Unit/conformance/v1/update-st-multi.json b/Firestore/tests/Unit/conformance/v1/update-st-multi.json index 8105ec27f54..15937cfcd9a 100644 --- a/Firestore/tests/Unit/conformance/v1/update-st-multi.json +++ b/Firestore/tests/Unit/conformance/v1/update-st-multi.json @@ -38,7 +38,7 @@ }, { "fieldPath": "c.d", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-st.json b/Firestore/tests/Unit/conformance/v1/update-st.json index 6249d8bda90..08e4e347b54 100644 --- a/Firestore/tests/Unit/conformance/v1/update-st.json +++ b/Firestore/tests/Unit/conformance/v1/update-st.json @@ -33,7 +33,7 @@ "fieldTransforms": [ { "fieldPath": "b", - "setToServerValue": "REQUEST_TIME" + "setToServerValue": "1" } ] } diff --git a/Firestore/tests/Unit/conformance/v1/update-uptime.json b/Firestore/tests/Unit/conformance/v1/update-uptime.json index 9210a2cf032..bcae90fe469 100644 --- a/Firestore/tests/Unit/conformance/v1/update-uptime.json +++ b/Firestore/tests/Unit/conformance/v1/update-uptime.json @@ -6,7 +6,7 @@ "update": { "docRefPath": "projects/projectID/databases/(default)/documents/C/d", "precondition": { - "updateTime": "1970-01-01T00:00:42Z" + "updateTime": {"seconds": "42", "nanos": "0"} }, "jsonData": "{\"a\": 1}", "request": { @@ -27,7 +27,7 @@ ] }, "currentDocument": { - "updateTime": "1970-01-01T00:00:42Z" + "updateTime": "1970-01-01T00:00:42.000000Z" } } ]