diff --git a/src/Firestore/Connection/Grpc.php b/src/Firestore/Connection/Grpc.php index 933adfc931a4..f3a8a07aaa84 100644 --- a/src/Firestore/Connection/Grpc.php +++ b/src/Firestore/Connection/Grpc.php @@ -112,7 +112,10 @@ public function batchGetDocuments(array $args) public function beginTransaction(array $args) { $rw = new TransactionOptions_ReadWrite; - $rw->setRetryTransaction($this->pluck('retryTransaction', $args, false)); + $retry = $this->pluck('retryTransaction', $args, false); + if ($retry) { + $rw->setRetryTransaction($retry); + } $args['options'] = new TransactionOptions; $args['options']->setReadWrite($rw); diff --git a/tests/unit/Firestore/Connection/GrpcTest.php b/tests/unit/Firestore/Connection/GrpcTest.php index ef3f427a6432..4d6fda5a4154 100644 --- a/tests/unit/Firestore/Connection/GrpcTest.php +++ b/tests/unit/Firestore/Connection/GrpcTest.php @@ -73,6 +73,25 @@ public function testBatchGetDocuments() } public function testBeginTransaction() + { + $args = [ + 'database' => sprintf('projects/%s/databases/%s', self::PROJECT, self::DATABASE), + ]; + + $rw = new TransactionOptions_ReadWrite; + + $options = new TransactionOptions; + $options->setReadWrite($rw); + + $expected = [ + $args['database'], + ['options' => $options] + $this->header() + ]; + + $this->sendAndAssert('beginTransaction', $args, $expected); + } + + public function testBeginTransactionWithPreviousTransactionId() { $args = [ 'retryTransaction' => 'foo',