From bec28c82ab4fb69e6076f4bcc9fb00b4c9788d29 Mon Sep 17 00:00:00 2001 From: Mackenzie Starr Date: Fri, 15 Feb 2019 16:49:40 -0500 Subject: [PATCH] add ability to use filters with #readRow() (#1679) --- Bigtable/src/Table.php | 3 +-- Bigtable/tests/Unit/TableTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Bigtable/src/Table.php b/Bigtable/src/Table.php index 2d9ad7f25885..e3bbbf76841e 100644 --- a/Bigtable/src/Table.php +++ b/Bigtable/src/Table.php @@ -325,8 +325,7 @@ public function readRows(array $options = []) public function readRow($rowKey, array $options = []) { return $this->readRows( - ['rowKeys' => [$rowKey]], - $options + $this->options + ['rowKeys' => [$rowKey]] + $options + $this->options ) ->readAll() ->current(); diff --git a/Bigtable/tests/Unit/TableTest.php b/Bigtable/tests/Unit/TableTest.php index 857567263b20..e3dc3df5ebd3 100644 --- a/Bigtable/tests/Unit/TableTest.php +++ b/Bigtable/tests/Unit/TableTest.php @@ -345,6 +345,32 @@ public function testReadRow() $this->assertNull($row); } + public function testReadRowWithFilter() + { + $rowSet = new RowSet(); + $rowSet->setRowKeys(['rk1']); + $rowFilter = Filter::pass(); + $expectedArgs = $this->options + [ + 'rows' => $rowSet, + 'filter' => $rowFilter->toProto() + ]; + $this->serverStream->readAll() + ->shouldBeCalled() + ->willReturn( + $this->arrayAsGenerator([]) + ); + $this->bigtableClient->readRows(self::TABLE_NAME, $expectedArgs) + ->shouldBeCalled() + ->willReturn( + $this->serverStream->reveal() + ); + $args = [ + 'filter' => $rowFilter + ]; + $row = $this->table->readRow('rk1', $args); + $this->assertNull($row); + } + public function testReadRowsWithMultipleRowKeys() { $rowSet = new RowSet();