From c06d63e3530574ccea832103c0100dc07db469ce Mon Sep 17 00:00:00 2001 From: David Supplee Date: Fri, 2 Nov 2018 07:59:09 -0700 Subject: [PATCH 01/12] rename DataClient to Table and add generic constructor options --- Bigtable/src/BigtableClient.php | 142 +++++++++++++++++++ Bigtable/src/{DataClient.php => Table.php} | 155 +++++++++------------ 2 files changed, 208 insertions(+), 89 deletions(-) create mode 100644 Bigtable/src/BigtableClient.php rename Bigtable/src/{DataClient.php => Table.php} (81%) diff --git a/Bigtable/src/BigtableClient.php b/Bigtable/src/BigtableClient.php new file mode 100644 index 000000000000..c0eaf72c6786 --- /dev/null +++ b/Bigtable/src/BigtableClient.php @@ -0,0 +1,142 @@ +:". + * **Defaults to** 'bigtable.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. + * This option accepts either a path to a credentials file, or a + * decoded credentials file as a PHP array. + * *Advanced usage*: In addition, this option can also accept a + * pre-constructed {@see Google\Auth\FetchAuthTokenInterface} object + * or {@see Google\ApiCore\CredentialsWrapper} object. Note that when + * one of these objects are provided, any settings in + * $config['credentialsConfig'] will be ignored. + * @type array $credentialsConfig Options used to configure credentials, + * including auth token caching, for the client. For a full list of + * supporting configuration options, see + * {@see Google\ApiCore\CredentialsWrapper}. + * @type bool $disableRetries Determines whether or not retries defined by + * the client configuration should be disabled. **Defaults to** + * `false`. + * @type string|array $clientConfig Client method configuration, including + * retry settings. This option can be either a path to a JSON file, or + * a PHP array containing the decoded JSON data. + * @type string|TransportInterface $transport The transport used for + * executing network requests. May be either the string `rest` or + * `grpc`. **Defaults to** `grpc` if gRPC support is detected on + * the system. *Advanced usage*: Additionally, it is possible to + * pass in an already instantiated + * {@see Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in + * $config['transportConfig'] and the $config['serviceAddress'] + * setting will be ignored. + * @type array $transportConfig Configuration options that will be used to + * construct the transport. Options for each supported transport type + * should be passed in a key for that transport. For example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...] + * ]; + * See {@see Google\ApiCore\Transport\GrpcTransport} and + * {@see Google\ApiCore\Transport\RestTransport} for + * the supported options. + * } + * @throws ValidationException + */ + public function __construct(array $config = []) + { + if (!isset($config['transportConfig']['grpc']['stubOpts'])) { + // Workaround for large messages. + $config['transportConfig']['grpc']['stubOpts'] = [ + 'grpc.max_send_message_length' => -1, + 'grpc.max_receive_message_length' => -1 + ]; + } + + $this->projectId = $this->detectProjectId($config); + $this->gapicClient = new GapicClient($config); + } + + /** + * Returns a table instance which can be used to read rows and to perform + * insert, update, and delete operations. + * + * Example: + * ``` + * $table = $bigtable->table('my-instance', 'my-table'); + * ``` + * + * @param string $instanceId The instance ID. + * @param string $tableId The table ID. + * @param array $options [optional] { + * Configuration options. + * + * @type string $appProfileId This value specifies routing for + * replication. **Defaults to** the "default" application profile. + * @type array $headers Headers to be passed with each request. + * } + * @return Table + */ + public function table($instanceId, $tableId, array $options = []) + { + return new Table( + $this->gapicClient, + GapicClient::tableName($this->projectId, $instanceId, $tableId), + $options + ); + } +} diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/Table.php similarity index 81% rename from Bigtable/src/DataClient.php rename to Bigtable/src/Table.php index 3c4112340912..7d1f11bf8e2e 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/Table.php @@ -23,46 +23,34 @@ use Google\Cloud\Bigtable\Filter\FilterInterface; use Google\Cloud\Bigtable\ReadModifyWriteRowRules; use Google\Cloud\Bigtable\Mutations; -use Google\Cloud\Bigtable\V2\BigtableClient as TableClient; +use Google\Cloud\Bigtable\V2\BigtableClient as GapicClient; use Google\Cloud\Bigtable\V2\MutateRowsRequest\Entry; use Google\Cloud\Bigtable\V2\Row; use Google\Cloud\Bigtable\V2\RowRange; use Google\Cloud\Bigtable\V2\RowSet; use Google\Cloud\Core\ArrayTrait; -use Google\Cloud\Core\ClientTrait; use Google\Rpc\Code; /** - * Represents a DataOperation Client to perform data operation on Bigtable table. - * This is used to perform insert,update, delete operation on table in Bigtable. + * A table instance can be used to read rows and to perform insert, update, and + * delete operations. * * Example: * ``` - * use Google\Cloud\Bigtable\DataClient; + * use Google\Cloud\Bigtable\BigtableClient; * - * $dataClient = new DataClient('my-instance', 'my-table'); + * $bigtable = new BigtableClient(); + * $table = $bigtable->table('my-instance', 'my-table'); * ``` - * */ -class DataClient +class Table { use ArrayTrait; - use ClientTrait; - - /** - * @var string - */ - private $instanceId; - - /** - * @var string - */ - private $tableId; /** - * @var TableClient + * @var GapicClient */ - private $bigtableClient; + private $gapicClient; /** * @var array @@ -75,53 +63,33 @@ class DataClient private $tableName; /** - * Create a Bigtable data client. - * - * @param string $instanceId The instance id. - * @param string $tableId The table id on which operation to be performed. - * @param array $config [optional] { - * Configuration Options. - * - * @type string $appProfileId The appProfileId to be used. - * @type array $headers The headers to be passed to request. - * @type TableClient $bigtableClient The GAPIC Bigtable client to use. - * If not provided it will create one. - * @type array $keyFile The contents of the service account credentials - * .json file retrieved from the Google Developer's Console. - * Ex: `json_decode(file_get_contents($path), true)`. - * @type string $keyFilePath The full path to your service account - * credentials .json file retrieved from the Google Developers - * Console. + * @var Serializer + */ + private $serializer; + + /** + * Create a table instance. + * + * @param GapicClient $gapicClient The GAPIC client used to make requests. + * @param string $tableName The full table name. Must match the following + * pattern: projects/{project}/instances/{instance}/tables/{table}. + * @param array $options [optional] { + * Configuration options. + * + * @type string $appProfileId This value specifies routing for + * replication. **Defaults to** the "default" application profile. + * @type array $headers Headers to be passed with each request. * } */ - public function __construct($instanceId, $tableId, array $config = []) - { + public function __construct( + GapicClient $gapicClient, + $tableName, + array $options = [] + ) { + $this->gapicClient = $gapicClient; + $this->tableName = $tableName; + $this->options = $options; $this->serializer = new Serializer(); - $this->instanceId = $instanceId; - $this->tableId = $tableId; - $this->options = []; - if (isset($config['appProfileId'])) { - $this->options['appProfileId'] = $config['appProfileId']; - } - if (isset($config['headers'])) { - $this->options['headers'] = $config['headers']; - } - $config = $this->configureAuthentication($config); - if (isset($config['bigtableClient'])) { - $this->bigtableClient = $config['bigtableClient']; - } else { - // Temp workaround for large messages. - $config['transportConfig'] = [ - 'grpc' => [ - 'stubOpts' => [ - 'grpc.max_send_message_length' => -1, - 'grpc.max_receive_message_length' => -1 - ] - ] - ]; - $this->bigtableClient = new TableClient($config); - } - $this->tableName = TableClient::tableName($this->projectId, $instanceId, $tableId); } /** @@ -129,20 +97,21 @@ public function __construct($instanceId, $tableId, array $config = []) * * Example: * ``` - * use Google\Cloud\Bigtable\DataClient; * use Google\Cloud\Bigtable\Mutations; * * $mutations = (new Mutations) * ->upsert('cf1', 'cq1', 'value1', 1534183334215000); * - * $dataClient->mutateRows(['r1' => $mutations]); + * $table->mutateRows(['r1' => $mutations]); * ``` - * @param array $rowMutations Associative array of rowKey as key and value as - * {@see Google\Cloud\Bigtable\Mutations}. + * + * @param array $rowMutations An associative array with the key being the + * row key and the value being the + * {@see Google\Cloud\Bigtable\Mutations} to perform. * @param array $options [optional] Configuration options. * @return void * @throws ApiException|BigtableDataOperationException If the remote call fails or operation fails. - * @throws InvalidArgumentException If rowMutations is a list instead of associative array indexed by rowkey. + * @throws InvalidArgumentException If rowMutations is a list instead of associative array indexed by row key. */ public function mutateRows(array $rowMutations, array $options = []) { @@ -194,11 +163,19 @@ public function mutateRow($rowKey, Mutations $mutations, array $options = []) * * Example: * ``` - * use Google\Cloud\Bigtable\DataClient; - * - * $dataClient->upsert(['r1' => ['cf1' => ['cq1' => ['value'=>'value1', 'timeStamp' => 1534183334215000]]]]); + * $table->upsert([ + * 'r1' => [ + * 'cf1' => [ + * 'cq1' => [ + * 'value'=>'value1', + * 'timeStamp' => 1534183334215000 + * ] + * ] + * ] + *]); * ``` - * @param array[] $rows array of row. + * + * @param array[] $rows An array of rows. * @param array $options [optional] Configuration options. * @return void * @throws ApiException|BigtableDataOperationException If the remote call fails or operation fails @@ -232,16 +209,16 @@ public function upsert(array $rows, array $options = []) * * Example: * ``` - * $rows = $dataClient->readRows(); + * $rows = $table->readRows(); * * foreach ($rows as $row) { * print_r($row) . PHP_EOL; * } * ``` * - * // Specify a set of row ranges. * ``` - * $rows = $dataClient->readRows([ + * // Specify a set of row ranges. + * $rows = $table->readRows([ * 'rowRanges' => [ * [ * 'startKeyOpen' => 'jefferson', @@ -313,7 +290,7 @@ public function readRows(array $options = []) $options['filter'] = $filter->toProto(); } - $serverStream = $this->bigtableClient->readRows( + $serverStream = $this->gapicClient->readRows( $this->tableName, $options + $this->options ); @@ -325,7 +302,7 @@ public function readRows(array $options = []) * * Example: * ``` - * $row = $dataClient->readRow('jefferson'); + * $row = $table->readRow('jefferson'); * * print_r($row); * ``` @@ -357,7 +334,7 @@ public function readRow($rowKey, array $options = []) * * $rules = (new ReadModifyWriteRowRules) * ->append('cf1', 'cq1', 'value12'); - * $row = $dataClient->readModifyWriteRow('rk1', $rules); + * $row = $table->readModifyWriteRow('rk1', $rules); * * print_r($row); * ``` @@ -371,11 +348,11 @@ public function readRow($rowKey, array $options = []) * $mutations = (new Mutations) * ->upsert('cf1', 'cq1', DataUtil::intToByteString(2)); * - * $dataClient->mutateRows(['rk1' => $mutations]); + * $table->mutateRows(['rk1' => $mutations]); * * $rules = (new ReadModifyWriteRowRules) * ->increment('cf1', 'cq1', 3); - * $row = $dataClient->readModifyWriteRow('rk1', $rules); + * $row = $table->readModifyWriteRow('rk1', $rules); * * print_r($row); * ``` @@ -388,7 +365,7 @@ public function readRow($rowKey, array $options = []) */ public function readModifyWriteRow($rowKey, ReadModifyWriteRowRules $rules, array $options = []) { - $readModifyWriteRowResponse = $this->bigtableClient->readModifyWriteRow( + $readModifyWriteRowResponse = $this->gapicClient->readModifyWriteRow( $this->tableName, $rowKey, $rules->toProto(), @@ -405,7 +382,7 @@ public function readModifyWriteRow($rowKey, ReadModifyWriteRowRules $rules, arra * * Example: * ``` - * $rowKeyStream = $dataClient->sampleRowKeys(); + * $rowKeyStream = $table->sampleRowKeys(); * foreach ($rowKeyStream as $rowKey) { * print_r($rowKey) . PHP_EOL; * } @@ -417,7 +394,7 @@ public function readModifyWriteRow($rowKey, ReadModifyWriteRowRules $rules, arra */ public function sampleRowKeys(array $options = []) { - $stream = $this->bigtableClient->sampleRowKeys( + $stream = $this->gapicClient->sampleRowKeys( $this->tableName, $options + $this->options ); @@ -438,7 +415,7 @@ public function sampleRowKeys(array $options = []) * use Google\Cloud\Bigtable\Mutations; * * $mutations = (new Mutations)->upsert('family', 'qualifier', 'value'); - * $result = $dataClient->checkAndMutateRow('rk1', ['trueMutations' => $mutations]); + * $result = $table->checkAndMutateRow('rk1', ['trueMutations' => $mutations]); * ``` * * ``` @@ -449,7 +426,7 @@ public function sampleRowKeys(array $options = []) * $mutations = (new Mutations)->upsert('family', 'qualifier', 'value'); * $predicateFilter = Filter::qualifier()->exactMatch('cq'); * $options = ['predicateFilter' => $predicateFilter, 'trueMutations' => $mutations]; - * $result = $dataClient->checkAndMutateRow('rk1', $options); + * $result = $table->checkAndMutateRow('rk1', $options); * ``` * * @param string $rowKey The row key to mutate row conditionally. @@ -498,7 +475,7 @@ public function checkAndMutateRow($rowKey, array $options = []) throw new \InvalidArgumentException('checkAndMutateRow must have either trueMutations or falseMutations.'); } - return $this->bigtableClient + return $this->gapicClient ->checkAndMutateRow( $this->tableName, $rowKey, @@ -509,7 +486,7 @@ public function checkAndMutateRow($rowKey, array $options = []) private function mutateRowsWithEntries(array $entries, array $options = []) { - $responseStream = $this->bigtableClient->mutateRows($this->tableName, $entries, $options + $this->options); + $responseStream = $this->gapicClient->mutateRows($this->tableName, $entries, $options + $this->options); $rowMutationsFailedResponse = []; $failureCode = Code::OK; $message = 'partial failure'; From bdfd14570a4dfe0476f29d11efd722206777dae1 Mon Sep 17 00:00:00 2001 From: David Supplee Date: Fri, 2 Nov 2018 08:02:05 -0700 Subject: [PATCH 02/12] update documentation --- Bigtable/src/ChunkFormatter.php | 7 ++++--- Bigtable/src/Filter.php | 11 ++++++----- Bigtable/src/ReadModifyWriteRowRules.php | 9 +++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Bigtable/src/ChunkFormatter.php b/Bigtable/src/ChunkFormatter.php index a1c467301fec..847704823758 100644 --- a/Bigtable/src/ChunkFormatter.php +++ b/Bigtable/src/ChunkFormatter.php @@ -28,10 +28,11 @@ * * Example: * ``` - * use Google\Cloud\Bigtable\DataClient; + * use Google\Cloud\Bigtable\BigtableClient; * - * $dataClient = new DataClient('my-instance', 'my-table'); - * $formatter = $dataClient->readRows(); + * $bigtable = new BigtableClient(); + * $table = $bigtable->table('my-instance', 'my-table'); + * $formatter = $table->readRows(); * ``` */ class ChunkFormatter implements \IteratorAggregate diff --git a/Bigtable/src/Filter.php b/Bigtable/src/Filter.php index 675c745d1d49..161ef8c8231e 100644 --- a/Bigtable/src/Filter.php +++ b/Bigtable/src/Filter.php @@ -34,8 +34,8 @@ /** * This class houses static factory methods which can be used to create a * hierarchy of filters for use with - * {@see Google\Cloud\Bigtable\DataClient::checkAndMutateRow()} or - * {@see Google\Cloud\Bigtable\DataClient::readRows()}. + * {@see Google\Cloud\Bigtable\Table::checkAndMutateRow()} or + * {@see Google\Cloud\Bigtable\Table::readRows()}. * * Filters are used to take an input row and produce an alternate view of the * row based on the specified rules. For example, a filter might trim down a row @@ -68,15 +68,16 @@ * * Example: * ``` - * use Google\Cloud\Bigtable\DataClient; + * use Google\Cloud\Bigtable\BigtableClient; * use Google\Cloud\Bigtable\Filter; * - * $dataClient = new DataClient('my-instance', 'my-table'); + * $bigtable = new BigtableClient(); + * $table = $bigtable->table('my-instance', 'my-table'); * $rowFilter = Filter::chain() * ->addFilter(Filter::qualifier()->regex('prefix.*')) * ->addFilter(Filter::limit()->cellsPerRow(10)); * - * $rows = $dataClient->readRows([ + * $rows = $table->readRows([ * 'filter' => $rowFilter * ]); * diff --git a/Bigtable/src/ReadModifyWriteRowRules.php b/Bigtable/src/ReadModifyWriteRowRules.php index 352b9efbe46e..c9d874d23a21 100644 --- a/Bigtable/src/ReadModifyWriteRowRules.php +++ b/Bigtable/src/ReadModifyWriteRowRules.php @@ -20,10 +20,11 @@ use Google\Cloud\Bigtable\V2\ReadModifyWriteRule; /** - * This is a builder class which builds read/modify/write rules specifying how the specified rows contents - * are to be transformed into writes. Entries are applied in order, meaning that earlier rules will - * affect the results of later ones. This is intended to be used in combination with - * {@see Google\Cloud\Bigtable\DataClient::readModifyWriteRow()}. + * This is a builder class which builds read/modify/write rules specifying how + * the specified rows contents are to be transformed into writes. Entries are + * applied in order, meaning that earlier rules will affect the results of later + * ones. This is intended to be used in combination with + * {@see Google\Cloud\Bigtable\Table::readModifyWriteRow()}. */ class ReadModifyWriteRowRules { From 130650bf1b2193ac80f01cdb53f4fddf47e07bd2 Mon Sep 17 00:00:00 2001 From: David Supplee Date: Fri, 2 Nov 2018 08:02:29 -0700 Subject: [PATCH 03/12] update snippets --- Bigtable/tests/Snippet/BigtableClientTest.php | 48 ++++++++++++ Bigtable/tests/Snippet/ChunkFormatterTest.php | 23 ++---- Bigtable/tests/Snippet/FilterTest.php | 11 +-- .../{DataClientTest.php => TableTest.php} | 73 +++++++++---------- 4 files changed, 97 insertions(+), 58 deletions(-) create mode 100644 Bigtable/tests/Snippet/BigtableClientTest.php rename Bigtable/tests/Snippet/{DataClientTest.php => TableTest.php} (86%) diff --git a/Bigtable/tests/Snippet/BigtableClientTest.php b/Bigtable/tests/Snippet/BigtableClientTest.php new file mode 100644 index 000000000000..4037a2487ac0 --- /dev/null +++ b/Bigtable/tests/Snippet/BigtableClientTest.php @@ -0,0 +1,48 @@ +snippetFromClass(BigtableClient::class); + $res = $snippet->invoke('bigtable'); + + $this->assertInstanceOf(BigtableClient::class, $res->returnVal()); + } + + public function testTable() + { + $client = new BigtableClient(['projectId' => 'my-project']); + $snippet = $this->snippetFromMethod(BigtableClient::class, 'table'); + $snippet->addLocal('bigtable', $client); + $res = $snippet->invoke('table'); + + $this->assertInstanceOf(Table::class, $res->returnVal()); + } +} diff --git a/Bigtable/tests/Snippet/ChunkFormatterTest.php b/Bigtable/tests/Snippet/ChunkFormatterTest.php index 0e4687368fa5..6f5a21948f5c 100644 --- a/Bigtable/tests/Snippet/ChunkFormatterTest.php +++ b/Bigtable/tests/Snippet/ChunkFormatterTest.php @@ -19,7 +19,7 @@ use \Google\ApiCore\ServerStream; use Google\Cloud\Bigtable\ChunkFormatter; -use Google\Cloud\Bigtable\DataClient; +use Google\Cloud\Bigtable\Table; use Google\Cloud\Bigtable\V2\BigtableClient as TableClient; use Google\Cloud\Core\Testing\Snippet\SnippetTestCase; use Google\Cloud\Core\Testing\TestHelpers; @@ -30,28 +30,21 @@ */ class ChunkFormatterTest extends SnippetTestCase { - const PROJECT_ID = 'my-project'; - const INSTANCE_ID = 'my-instance'; - const TABLE_ID = 'my-table'; const TABLE_NAME = 'projects/my-project/instances/my-instance/tables/my-table'; private $bigtableClient; - private $dataClient; + private $table; private $serverStream; public function setUp() { $this->bigtableClient = $this->prophesize(TableClient::class); $this->serverStream = $this->prophesize(ServerStream::class); - $this->dataClient = TestHelpers::stub( - DataClient::class, + $this->table = TestHelpers::stub( + Table::class, [ - self::INSTANCE_ID, - self::TABLE_ID, - [ - 'bigtableClient' => $this->bigtableClient->reveal(), - 'projectId' => self::PROJECT_ID - ] + $this->bigtableClient->reveal(), + self::TABLE_NAME ] ); } @@ -59,13 +52,13 @@ public function setUp() public function testClass() { $snippet = $this->snippetFromClass(ChunkFormatter::class); - $snippet->replace('$dataClient = new DataClient(\'my-instance\', \'my-table\');', ''); + $snippet->replace('$table = $bigtable->table(\'my-instance\', \'my-table\');', ''); $this->bigtableClient->readRows(self::TABLE_NAME, []) ->shouldBeCalled() ->willReturn( $this->serverStream->reveal() ); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('formatter'); $this->assertInstanceOf(ChunkFormatter::class, $res->returnVal()); } diff --git a/Bigtable/tests/Snippet/FilterTest.php b/Bigtable/tests/Snippet/FilterTest.php index 141754dc7662..c3856b312735 100644 --- a/Bigtable/tests/Snippet/FilterTest.php +++ b/Bigtable/tests/Snippet/FilterTest.php @@ -17,8 +17,9 @@ namespace Google\Cloud\Bigtable\Tests\Snippet; -use Google\Cloud\Bigtable\DataClient; +use Google\Cloud\Bigtable\BigtableClient; use Google\Cloud\Bigtable\Filter; +use Google\Cloud\Bigtable\Table; use Google\Cloud\Bigtable\Filter\ChainFilter; use Google\Cloud\Bigtable\Filter\ConditionFilter; use Google\Cloud\Bigtable\Filter\InterleaveFilter; @@ -50,17 +51,17 @@ public function testClass() ]] ] ]; - $dataClient = $this->prophesize(DataClient::class); + $table = $this->prophesize(Table::class); $filter = Filter::chain() ->addFilter(Filter::qualifier()->regex('prefix.*')) ->addFilter(Filter::limit()->cellsPerRow(10)); - $dataClient->readRows(['filter' => $filter]) + $table->readRows(['filter' => $filter]) ->shouldBeCalled() ->willReturn([$expectedRows]); $snippet = $this->snippetFromClass(Filter::class); - $snippet->replace('$dataClient = new DataClient(\'my-instance\', \'my-table\');', ''); - $snippet->addLocal('dataClient', $dataClient->reveal()); + $snippet->replace('$table = $bigtable->table(\'my-instance\', \'my-table\');', ''); + $snippet->addLocal('table', $table->reveal()); $res = $snippet->invoke('rows'); $this->assertEquals( print_r($expectedRows, true), diff --git a/Bigtable/tests/Snippet/DataClientTest.php b/Bigtable/tests/Snippet/TableTest.php similarity index 86% rename from Bigtable/tests/Snippet/DataClientTest.php rename to Bigtable/tests/Snippet/TableTest.php index 95d70d6f5513..75480bac74d6 100644 --- a/Bigtable/tests/Snippet/DataClientTest.php +++ b/Bigtable/tests/Snippet/TableTest.php @@ -18,11 +18,11 @@ namespace Google\Cloud\Bigtable\Tests\Snippet; use Google\ApiCore\ServerStream; -use Google\Cloud\Bigtable\DataClient; use Google\Cloud\Bigtable\DataUtil; -use Google\Cloud\Bigtable\ReadModifyWriteRowRules; use Google\Cloud\Bigtable\Filter; use Google\Cloud\Bigtable\Mutations; +use Google\Cloud\Bigtable\ReadModifyWriteRowRules; +use Google\Cloud\Bigtable\Table; use Google\Cloud\Bigtable\V2\BigtableClient as TableClient; use Google\Cloud\Bigtable\V2\Cell; use Google\Cloud\Bigtable\V2\CheckAndMutateRowResponse; @@ -53,15 +53,12 @@ * @group bigtable * @group bigtabledata */ -class DataClientTest extends SnippetTestCase +class TableTest extends SnippetTestCase { - const PROJECT_ID = 'my-project'; - const INSTANCE_ID = 'my-instance'; - const TABLE_ID = 'my-table'; const TABLE_NAME = 'projects/my-project/instances/my-instance/tables/my-table'; private $bigtableClient; - private $dataClient; + private $table; private $mutateRowsResponses = []; private $serverStream; private $entries = []; @@ -90,25 +87,25 @@ public function setUp() $mutateRowsResponseEntry->setStatus($status); $mutateRowsResponse->setEntries([$mutateRowsResponseEntry]); $this->mutateRowsResponses[] = $mutateRowsResponse; - $this->dataClient = TestHelpers::stub( - DataClient::class, + $this->table = TestHelpers::stub( + Table::class, [ - self::INSTANCE_ID, - self::TABLE_ID, - [ - 'bigtableClient' => $this->bigtableClient->reveal(), - 'projectId' => self::PROJECT_ID - ] + $this->bigtableClient->reveal(), + self::TABLE_NAME ] ); } public function testClass() { - $snippet = $this->snippetFromClass(DataClient::class); - $res = $snippet->invoke('dataClient'); + $snippet = $this->snippetFromClass(Table::class); + $snippet->replace( + '$bigtable = new BigtableClient();', + '$bigtable = new BigtableClient(["projectId" => "my-project"]);' + ); + $res = $snippet->invoke('table'); - $this->assertInstanceOf(DataClient::class, $res->returnVal()); + $this->assertInstanceOf(Table::class, $res->returnVal()); } public function testMutateRows() @@ -123,8 +120,8 @@ public function testMutateRows() ->willReturn( $this->serverStream->reveal() ); - $snippet = $this->snippetFromMethod(DataClient::class, 'mutateRows'); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'mutateRows'); + $snippet->addLocal('table', $this->table); $snippet->invoke(); } @@ -154,8 +151,8 @@ public function testUpsert() ->willReturn( $this->serverStream->reveal() ); - $snippet = $this->snippetFromMethod(DataClient::class, 'upsert'); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'upsert'); + $snippet->addLocal('table', $this->table); $snippet->invoke(); } @@ -171,8 +168,8 @@ public function testReadRows() ->willReturn( $this->serverStream->reveal() ); - $snippet = $this->snippetFromMethod(DataClient::class, 'readRows'); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'readRows'); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('rows'); $expectedRows = [ 'cf1' => [ @@ -205,8 +202,8 @@ public function testReadRowsWithRowRanges() ->shouldBeCalled() ->willReturn($this->serverStream->reveal()); - $snippet = $this->snippetFromMethod(DataClient::class, 'readRows', 1); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'readRows', 1); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('rows'); $expectedRows = [ 'cf1' => [ @@ -235,8 +232,8 @@ public function testReadRow() $this->bigtableClient->readRows(self::TABLE_NAME, ['rows' => $rowSet]) ->shouldBeCalled() ->willReturn($this->serverStream->reveal()); - $snippet = $this->snippetFromMethod(DataClient::class, 'readRow'); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'readRow'); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('row'); $expectedRow = [ 'cf1' => [ @@ -285,8 +282,8 @@ public function testReadModifyWriteRowAppend() ->willReturn( $readModifyWriteRowResponse ); - $snippet = $this->snippetFromMethod(DataClient::class, 'readModifyWriteRow'); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'readModifyWriteRow'); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('row'); $expectedRow = [ 'cf1' => [ @@ -305,7 +302,7 @@ public function testReadModifyWriteRowAppend() public function testReadModifyWriteRowIncrement() { - $snippet = $this->snippetFromMethod(DataClient::class, 'readModifyWriteRow', 1); + $snippet = $this->snippetFromMethod(Table::class, 'readModifyWriteRow', 1); if (!DataUtil::isSupported()) { $this->markTestSkipped('This test only runs on PHP 5.6 or above.'); @@ -352,7 +349,7 @@ public function testReadModifyWriteRowIncrement() ->willReturn( $readModifyWriteRowResponse ); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('row'); $expectedRow = [ 'cf1' => [ @@ -385,8 +382,8 @@ public function testSampleRowKeys() ->willReturn( $this->serverStream->reveal() ); - $snippet = $this->snippetFromMethod(DataClient::class, 'sampleRowKeys'); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'sampleRowKeys'); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('rowKeyStream'); $expectedRowKeys = [ 'rowKey' => 'rk1', @@ -403,8 +400,8 @@ public function testCheckAndMutateRow() $this->bigtableClient->checkAndMutateRow(self::TABLE_NAME, 'rk1', Argument::any()) ->shouldBeCalled() ->willReturn((new CheckAndMutateRowResponse)->setPredicateMatched(true)); - $snippet = $this->snippetFromMethod(DataClient::class, 'checkAndMutateRow'); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'checkAndMutateRow'); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('result'); $this->assertTrue($res->returnVal()); } @@ -419,8 +416,8 @@ public function testCheckAndMutateRowWithFilter() ) ->shouldBeCalled() ->willReturn((new CheckAndMutateRowResponse)->setPredicateMatched(true)); - $snippet = $this->snippetFromMethod(DataClient::class, 'checkAndMutateRow', 1); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'checkAndMutateRow', 1); + $snippet->addLocal('table', $this->table); $res = $snippet->invoke('result'); $this->assertTrue($res->returnVal()); } From 0b297c38a4eb9e6e989437f092a130980c954c11 Mon Sep 17 00:00:00 2001 From: David Supplee Date: Fri, 2 Nov 2018 08:03:00 -0700 Subject: [PATCH 04/12] update and rename system tests --- ...ataClientTest.php => BigtableTestCase.php} | 19 ++++------ ...eRowTest.php => CheckAndMutateRowTest.php} | 16 ++++----- Bigtable/tests/System/FilterTest.php | 9 +++-- ...tMutateRowsTest.php => MutateRowsTest.php} | 35 +++++++++---------- ...RowTest.php => ReadModifyWriteRowTest.php} | 9 +++-- ...lientReadRowsTest.php => ReadRowsTest.php} | 30 ++++++++-------- ...eRowKeysTest.php => SampleRowKeysTest.php} | 8 ++--- 7 files changed, 57 insertions(+), 69 deletions(-) rename Bigtable/tests/System/{DataClientTest.php => BigtableTestCase.php} (92%) rename Bigtable/tests/System/{DataClientCheckAndMutateRowTest.php => CheckAndMutateRowTest.php} (90%) rename Bigtable/tests/System/{DataClientMutateRowsTest.php => MutateRowsTest.php} (83%) rename Bigtable/tests/System/{DataClientReadModifyWriteRowTest.php => ReadModifyWriteRowTest.php} (88%) rename Bigtable/tests/System/{DataClientReadRowsTest.php => ReadRowsTest.php} (95%) rename Bigtable/tests/System/{DataClientSampleRowKeysTest.php => SampleRowKeysTest.php} (91%) diff --git a/Bigtable/tests/System/DataClientTest.php b/Bigtable/tests/System/BigtableTestCase.php similarity index 92% rename from Bigtable/tests/System/DataClientTest.php rename to Bigtable/tests/System/BigtableTestCase.php index 17e9a0cae51e..8056d6e40611 100644 --- a/Bigtable/tests/System/DataClientTest.php +++ b/Bigtable/tests/System/BigtableTestCase.php @@ -23,7 +23,7 @@ use Google\Cloud\Bigtable\Admin\V2\ColumnFamily; use Google\Cloud\Bigtable\Admin\V2\Instance; use Google\Cloud\Bigtable\Admin\V2\Table; -use Google\Cloud\Bigtable\DataClient; +use Google\Cloud\Bigtable\BigtableClient; use Exception; use PHPUnit\Framework\TestCase; @@ -31,7 +31,7 @@ * @group bigtable * @group bigtabledata */ -class DataClientTest extends TestCase +class BigtableTestCase extends TestCase { const INSTANCE_ID_PREFIX = 'php-sys-instance-'; const CLUSTER_ID_PREFIX = 'php-sys-cluster-'; @@ -40,7 +40,7 @@ class DataClientTest extends TestCase protected static $instanceAdminClient; protected static $tableAdminClient; - protected static $dataClient; + protected static $table; protected static $projectId; protected static $instanceId; protected static $clusterId; @@ -49,22 +49,17 @@ public static function setUpBeforeClass() { $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); self::$instanceAdminClient = new InstanceAdminClient([ - 'keyFilePath' => $keyFilePath + 'credentials' => $keyFilePath ]); self::$tableAdminClient = new TableAdminClient([ - 'keyFilePath' => $keyFilePath + 'credentials' => $keyFilePath ]); $keyFileData = json_decode(file_get_contents($keyFilePath), true); self::$projectId = $keyFileData['project_id']; self::$instanceId = uniqid(self::INSTANCE_ID_PREFIX); self::$clusterId = uniqid(self::CLUSTER_ID_PREFIX); - self::$dataClient = new DataClient( - self::$instanceId, - self::TABLE_ID, - [ - 'keyFilePath' => $keyFilePath - ] - ); + self::$table = (new BigtableClient) + ->table(self::$instanceId, self::TABLE_ID); self::createInstance(); self::createTable(); } diff --git a/Bigtable/tests/System/DataClientCheckAndMutateRowTest.php b/Bigtable/tests/System/CheckAndMutateRowTest.php similarity index 90% rename from Bigtable/tests/System/DataClientCheckAndMutateRowTest.php rename to Bigtable/tests/System/CheckAndMutateRowTest.php index fe4e0a3ef797..1ef5bfe04853 100644 --- a/Bigtable/tests/System/DataClientCheckAndMutateRowTest.php +++ b/Bigtable/tests/System/CheckAndMutateRowTest.php @@ -25,7 +25,7 @@ * @group bigtable * @group bigtabledata */ -class DataClientCheckAndMutateRowTest extends DataClientTest +class CheckAndMutateRowTest extends BigtableTestCase { public static function setUpBeforeClass() { @@ -40,18 +40,18 @@ public static function setUpBeforeClass() ] ], ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); } public function testCheckAndMutateRowWithEmptyFilter() { $mutations = (new Mutations)->upsert('cf1', 'cq1', 'value11', 6000); - $result = self::$dataClient->checkAndMutateRow( + $result = self::$table->checkAndMutateRow( 'rk1', ['trueMutations' => $mutations] ); $this->assertTrue($result); - $row = self::$dataClient->readRow('rk1'); + $row = self::$table->readRow('rk1'); $expectedRow = [ 'cf1' => [ 'cq1' => [ @@ -75,7 +75,7 @@ public function testCheckAndMutateRowWithFilterYieldingCell() { $predicateFilter = Filter::family()->exactMatch('cf1'); $mutations = (new Mutations)->upsert('cf1', 'cq1', 'value11', 6000); - $result = self::$dataClient->checkAndMutateRow( + $result = self::$table->checkAndMutateRow( 'rk1', [ 'predicateFilter' => $predicateFilter, @@ -83,7 +83,7 @@ public function testCheckAndMutateRowWithFilterYieldingCell() ] ); $this->assertTrue($result); - $row = self::$dataClient->readRow('rk1'); + $row = self::$table->readRow('rk1'); $expectedRow = [ 'cf1' => [ 'cq1' => [ @@ -108,7 +108,7 @@ public function testCheckAndMutateRowWithFilterNotYieldingCell() $predicateFilter = Filter::qualifier()->exactMatch('cq10'); $trueMutations = (new Mutations)->upsert('cf1', 'cq1', 'value12', 6000); $falseMutations = (new Mutations)->upsert('cf1', 'cq1', 'value11', 6000); - $result = self::$dataClient->checkAndMutateRow( + $result = self::$table->checkAndMutateRow( 'rk1', [ 'predicateFilter' => $predicateFilter, @@ -117,7 +117,7 @@ public function testCheckAndMutateRowWithFilterNotYieldingCell() ] ); $this->assertFalse($result); - $row = self::$dataClient->readRow('rk1'); + $row = self::$table->readRow('rk1'); $expectedRow = [ 'cf1' => [ 'cq1' => [ diff --git a/Bigtable/tests/System/FilterTest.php b/Bigtable/tests/System/FilterTest.php index 51e9d746a314..a44fef76bbd7 100644 --- a/Bigtable/tests/System/FilterTest.php +++ b/Bigtable/tests/System/FilterTest.php @@ -19,20 +19,19 @@ use Google\Cloud\Bigtable\Filter; use Google\Cloud\Bigtable\Mutations; -use Google\Cloud\Bigtable\Tests\System\DataClientTest; /** * @group bigtable * @group bigtabledata */ -class FilterTest extends DataClientTest +class FilterTest extends BigtableTestCase { protected static $rowMutations = []; public static function setUpBeforeClass() { parent::setUpBeforeClass(); - self::$dataClient->mutateRows(self::$rowMutations); + self::$table->mutateRows(self::$rowMutations); } private static function createExpectedRows($insertRows) @@ -55,7 +54,7 @@ private static function createExpectedRows($insertRows) public function testFilter($args, $expectedRows, $message) { $rows = iterator_to_array( - self::$dataClient->readRows($args)->readAll() + self::$table->readRows($args)->readAll() ); $this->assertEquals($expectedRows, $rows, $message); } @@ -437,7 +436,7 @@ public function testSample() { $rowFilter = Filter::key()->sample(.50); $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'filter' => $rowFilter ] diff --git a/Bigtable/tests/System/DataClientMutateRowsTest.php b/Bigtable/tests/System/MutateRowsTest.php similarity index 83% rename from Bigtable/tests/System/DataClientMutateRowsTest.php rename to Bigtable/tests/System/MutateRowsTest.php index 27cc1d9a05d1..319bb39a0e9f 100644 --- a/Bigtable/tests/System/DataClientMutateRowsTest.php +++ b/Bigtable/tests/System/MutateRowsTest.php @@ -17,14 +17,13 @@ namespace Google\Cloud\Bigtable\Tests\System; -use Google\Cloud\Bigtable\Tests\System\DataClientTest; use Google\Cloud\Bigtable\Mutations; /** * @group bigtable * @group bigtabledata */ -class DataClientMutateRowsTest extends DataClientTest +class MutateRowsTest extends BigtableTestCase { public function testBasicWriteAndReadDataOperation() { @@ -38,7 +37,7 @@ public function testBasicWriteAndReadDataOperation() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); $readRows = [ 'rk1' => [ 'cf1' => [ @@ -50,7 +49,7 @@ public function testBasicWriteAndReadDataOperation() ] ] ]; - $rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk1']])->readAll()); + $rows = iterator_to_array(self::$table->readRows(['rowKeys' => ['rk1']])->readAll()); $this->assertEquals($readRows, $rows); } @@ -86,10 +85,10 @@ public function testDeleteRow() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); $mutations = (new Mutations)->deleteRow(); - self::$dataClient->mutateRows(['rk2' => $mutations]); - $rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk2']])->readAll()); + self::$table->mutateRows(['rk2' => $mutations]); + $rows = iterator_to_array(self::$table->readRows(['rowKeys' => ['rk2']])->readAll()); $this->assertEquals([], $rows); } @@ -111,10 +110,10 @@ public function testDeleteFromFamily() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); $mutations = (new Mutations)->deleteFromFamily('cf2'); - self::$dataClient->mutateRows(['rk3' => $mutations]); - $rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk3']])->readAll()); + self::$table->mutateRows(['rk3' => $mutations]); + $rows = iterator_to_array(self::$table->readRows(['rowKeys' => ['rk3']])->readAll()); $expectedRows = [ 'rk3' => [ 'cf1' => [ @@ -145,10 +144,10 @@ public function testDeleteFromColumn() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); $mutations = (new Mutations)->deleteFromColumn('cf1', 'cq2'); - self::$dataClient->mutateRows(['rk4' => $mutations]); - $rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk4']])->readAll()); + self::$table->mutateRows(['rk4' => $mutations]); + $rows = iterator_to_array(self::$table->readRows(['rowKeys' => ['rk4']])->readAll()); $expectedRows = [ 'rk4' => [ 'cf1' => [ @@ -179,7 +178,7 @@ public function testDeleteFromColumnWithRange() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); $insertRows = [ 'rk5' => [ 'cf1' => [ @@ -190,7 +189,7 @@ public function testDeleteFromColumnWithRange() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); $insertRows = [ 'rk5' => [ 'cf1' => [ @@ -201,10 +200,10 @@ public function testDeleteFromColumnWithRange() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); $mutations = (new Mutations)->deleteFromColumn('cf1', 'cq2', ['start' => 21000, 'end' => 40000]); - self::$dataClient->mutateRows(['rk5' => $mutations]); - $rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk5']])->readAll()); + self::$table->mutateRows(['rk5' => $mutations]); + $rows = iterator_to_array(self::$table->readRows(['rowKeys' => ['rk5']])->readAll()); $expectedRows = [ 'rk5' => [ 'cf1' => [ diff --git a/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php b/Bigtable/tests/System/ReadModifyWriteRowTest.php similarity index 88% rename from Bigtable/tests/System/DataClientReadModifyWriteRowTest.php rename to Bigtable/tests/System/ReadModifyWriteRowTest.php index b7d09e2b6337..0942e9788f0c 100644 --- a/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php +++ b/Bigtable/tests/System/ReadModifyWriteRowTest.php @@ -19,13 +19,12 @@ use Google\Cloud\Bigtable\DataUtil; use Google\Cloud\Bigtable\ReadModifyWriteRowRules; -use Google\Cloud\Bigtable\Tests\System\DataClientTest; /** * @group bigtable * @group bigtabledata */ -class DataClientReadModifyWriteRowTest extends DataClientTest +class ReadModifyWriteRowTest extends BigtableTestCase { public static function setUpBeforeClass() { @@ -48,14 +47,14 @@ public static function setUpBeforeClass() ] ], ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); } public function testAppend() { $rules = (new ReadModifyWriteRowRules) ->append('cf1', 'cq1', 'value12'); - $row = self::$dataClient->readModifyWriteRow( + $row = self::$table->readModifyWriteRow( 'rk1', $rules ); @@ -69,7 +68,7 @@ public function testIncrement() { $rules = (new ReadModifyWriteRowRules) ->increment('cf1', 'cq2', 3); - $row = self::$dataClient->readModifyWriteRow( + $row = self::$table->readModifyWriteRow( 'rk2', $rules ); diff --git a/Bigtable/tests/System/DataClientReadRowsTest.php b/Bigtable/tests/System/ReadRowsTest.php similarity index 95% rename from Bigtable/tests/System/DataClientReadRowsTest.php rename to Bigtable/tests/System/ReadRowsTest.php index 47f4c0b50b94..17aecb4fe988 100644 --- a/Bigtable/tests/System/DataClientReadRowsTest.php +++ b/Bigtable/tests/System/ReadRowsTest.php @@ -17,13 +17,11 @@ namespace Google\Cloud\Bigtable\Tests\System; -use Google\Cloud\Bigtable\Tests\System\DataClientTest; - /** * @group bigtable * @group bigtabledata */ -class DataClientReadRowsTest extends DataClientTest +class ReadRowsTest extends BigtableTestCase { public static function setUpBeforeClass() { @@ -70,13 +68,13 @@ public static function setUpBeforeClass() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); } public function testReadRowsRowsLimit() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowsLimit' => 2 ] @@ -112,7 +110,7 @@ public function testReadRowsRowsLimit() public function testReadRowsSingleKey() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowKeys' => ['rk2'] ] @@ -137,7 +135,7 @@ public function testReadRowsSingleKey() public function testReadRowsMultipleRows() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowKeys' => ['rk2', 'rk3'] ] @@ -173,7 +171,7 @@ public function testReadRowsMultipleRows() public function testReadRowsRowRangesStartOpen() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ @@ -213,7 +211,7 @@ public function testReadRowsRowRangesStartOpen() public function testReadRowsRowRangesStartClosed() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ @@ -253,7 +251,7 @@ public function testReadRowsRowRangesStartClosed() public function testReadRowsRowRangesEndOpen() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ @@ -293,7 +291,7 @@ public function testReadRowsRowRangesEndOpen() public function testReadRowsRowRangesEndClosed() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ @@ -322,7 +320,7 @@ public function testReadRowsRowRangesEndClosed() public function testReadRowsRowRangesStartOpenEndClosed() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ @@ -352,7 +350,7 @@ public function testReadRowsRowRangesStartOpenEndClosed() public function testReadRowsRowRangesStartClosedEndClosed() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ @@ -393,7 +391,7 @@ public function testReadRowsRowRangesStartClosedEndClosed() public function testReadRowsRowRangesStartOpenEndOpen() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ @@ -423,7 +421,7 @@ public function testReadRowsRowRangesStartOpenEndOpen() public function testReadRowsRowRangesStartClosedEndOpen() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ @@ -464,7 +462,7 @@ public function testReadRowsRowRangesStartClosedEndOpen() public function testReadRowsMultipleRanges() { $rows = iterator_to_array( - self::$dataClient->readRows( + self::$table->readRows( [ 'rowRanges' => [ [ diff --git a/Bigtable/tests/System/DataClientSampleRowKeysTest.php b/Bigtable/tests/System/SampleRowKeysTest.php similarity index 91% rename from Bigtable/tests/System/DataClientSampleRowKeysTest.php rename to Bigtable/tests/System/SampleRowKeysTest.php index 945da3c12b84..5238b354a84a 100644 --- a/Bigtable/tests/System/DataClientSampleRowKeysTest.php +++ b/Bigtable/tests/System/SampleRowKeysTest.php @@ -17,13 +17,11 @@ namespace Google\Cloud\Bigtable\Tests\System; -use Google\Cloud\Bigtable\Tests\System\DataClientTest; - /** * @group bigtable * @group bigtabledata */ -class DataClientSampleRowKeysTest extends DataClientTest +class SampleRowKeysTest extends BigtableTestCase { public static function setUpBeforeClass() { @@ -70,12 +68,12 @@ public static function setUpBeforeClass() ] ] ]; - self::$dataClient->upsert($insertRows); + self::$table->upsert($insertRows); } public function testSampleRowKeys() { - $rowKeysStream = self::$dataClient->sampleRowKeys(); + $rowKeysStream = self::$table->sampleRowKeys(); $rowKeys = iterator_to_array($rowKeysStream); $expectedRowKeys = [ [ From 0433290f6cea556a43385ef8e1efe011d9cfa33f Mon Sep 17 00:00:00 2001 From: David Supplee Date: Fri, 2 Nov 2018 08:03:55 -0700 Subject: [PATCH 05/12] update unit tests --- Bigtable/tests/Unit/BigtableClientTest.php | 46 +++++++++++ .../{DataClientTest.php => TableTest.php} | 77 +++++++++---------- 2 files changed, 83 insertions(+), 40 deletions(-) create mode 100644 Bigtable/tests/Unit/BigtableClientTest.php rename Bigtable/tests/Unit/{DataClientTest.php => TableTest.php} (91%) diff --git a/Bigtable/tests/Unit/BigtableClientTest.php b/Bigtable/tests/Unit/BigtableClientTest.php new file mode 100644 index 000000000000..37fc7df4a58c --- /dev/null +++ b/Bigtable/tests/Unit/BigtableClientTest.php @@ -0,0 +1,46 @@ +client = TestHelpers::stub(BigtableClient::class, [ + ['projectId' => 'my-project'] + ]); + } + + public function testTable() + { + $table = $this->client->table('my-instance', 'my-table'); + + $this->assertInstanceOf(Table::class, $table); + } +} diff --git a/Bigtable/tests/Unit/DataClientTest.php b/Bigtable/tests/Unit/TableTest.php similarity index 91% rename from Bigtable/tests/Unit/DataClientTest.php rename to Bigtable/tests/Unit/TableTest.php index 7326871d84a4..81e77371fc2e 100644 --- a/Bigtable/tests/Unit/DataClientTest.php +++ b/Bigtable/tests/Unit/TableTest.php @@ -20,12 +20,12 @@ use Google\ApiCore\ApiException; use Google\ApiCore\ServerStream; use Google\Cloud\Bigtable\ChunkFormatter; -use Google\Cloud\Bigtable\DataClient; use Google\Cloud\Bigtable\Exception\BigtableDataOperationException; use Google\Cloud\Bigtable\Filter; use Google\Cloud\Bigtable\Mutations; use Google\Cloud\Bigtable\ReadModifyWriteRowRules; use Google\Cloud\Bigtable\RowMutation; +use Google\Cloud\Bigtable\Table; use Google\Cloud\Bigtable\V2\BigtableClient as TableClient; use Google\Cloud\Bigtable\V2\Cell; use Google\Cloud\Bigtable\V2\CheckAndMutateRowResponse; @@ -48,11 +48,8 @@ * @group bigtable * @group bigtabledata */ -class DataClientTest extends TestCase +class TableTest extends TestCase { - const PROJECT_ID = 'my-project'; - const INSTANCE_ID = 'my-instance'; - const TABLE_ID = 'my-table'; const HEADER = 'my-header'; const HEADER_VALUE = 'my-header-value'; const APP_PROFILE = 'my-app-profile'; @@ -60,7 +57,7 @@ class DataClientTest extends TestCase const TIMESTAMP = 1534183334215000; private $bigtableClient; - private $dataClient; + private $table; private $rowMutations = []; private $entries = []; private $options; @@ -74,11 +71,11 @@ public function setUp() 'appProfileId' => self::APP_PROFILE, 'headers' => [self::HEADER => self::HEADER_VALUE] ]; - $clientOptions = $this->options + [ - 'bigtableClient' => $this->bigtableClient->reveal(), - 'projectId' => self::PROJECT_ID - ]; - $this->dataClient = new DataClient(self::INSTANCE_ID, self::TABLE_ID, $clientOptions); + $this->table = new Table( + $this->bigtableClient->reveal(), + self::TABLE_NAME, + $this->options + ); $mutations = (new Mutations) ->upsert('cf1', 'cq1', 'value1', self::TIMESTAMP); $this->entries[] = (new RequestEntry) @@ -100,7 +97,7 @@ public function setUp() */ public function testMutateRowsThrowsExceptionWhenRowMutationsIsList() { - $this->dataClient->mutateRows([1,2,3,4]); + $this->table->mutateRows([1,2,3,4]); } public function testMutateRows() @@ -122,7 +119,7 @@ public function testMutateRows() ->willReturn( $this->serverStream->reveal() ); - $this->dataClient->mutateRows($this->rowMutations); + $this->table->mutateRows($this->rowMutations); } public function testMutateRowsOptionalConfiguration() @@ -140,7 +137,7 @@ public function testMutateRowsOptionalConfiguration() ->willReturn( $this->serverStream->reveal() ); - $this->dataClient->mutateRows($this->rowMutations, $options); + $this->table->mutateRows($this->rowMutations, $options); } public function testMutateRowsFailure() @@ -166,7 +163,7 @@ public function testMutateRowsFailure() $this->serverStream->reveal() ); try { - $this->dataClient->mutateRows($this->rowMutations); + $this->table->mutateRows($this->rowMutations); $this->fail('Expected exception is not thrown'); } catch (BigtableDataOperationException $e) { $metadata = [ @@ -197,7 +194,7 @@ public function testMutateRowsApiExceptionInMutateRows() ->willThrow( $apiException ); - $this->dataClient->mutateRows($this->rowMutations); + $this->table->mutateRows($this->rowMutations); } /** @@ -217,7 +214,7 @@ public function testMutateRowsApiExceptionInReadAll() ->willReturn( $this->serverStream->reveal() ); - $this->dataClient->mutateRows($this->rowMutations); + $this->table->mutateRows($this->rowMutations); } public function testUpsert() @@ -257,7 +254,7 @@ public function testUpsert() ] ] ]; - $this->dataClient->upsert($rows); + $this->table->upsert($rows); } public function testUpsertOptionalConfiguration() @@ -293,7 +290,7 @@ public function testUpsertOptionalConfiguration() ] ] ]; - $this->dataClient->upsert($rows, $options); + $this->table->upsert($rows, $options); } public function testMutateRow() @@ -317,7 +314,7 @@ public function testReadRowsNoArg() $this->serverStream->reveal() ); $args = []; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -338,7 +335,7 @@ public function testReadRow() ->willReturn( $this->serverStream->reveal() ); - $row = $this->dataClient->readRow('rk1'); + $row = $this->table->readRow('rk1'); $this->assertNull($row); } @@ -357,7 +354,7 @@ public function testReadRowsWithMultipleRowKeys() $args = [ 'rowKeys' => ['rk1', 'rk2'] ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -378,7 +375,7 @@ public function testReadRowsWithRowLimit() 'rowKeys' => ['rk1', 'rk2'], 'rowsLimit' => 10 ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -405,7 +402,7 @@ public function testReadRowsWithRowRangeKeysOpen() ] ] ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -432,7 +429,7 @@ public function testReadRowsWithRowRangeKeysClosed() ] ] ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -459,7 +456,7 @@ public function testReadRowsWithRowRangeKeysOpenClosed() ] ] ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -486,7 +483,7 @@ public function testReadRowsWithRowRangeKeysClosedOpen() ] ] ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -522,7 +519,7 @@ public function testReadRowsWithRowRangeKeysMultipleRowRanges() ] ] ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -551,7 +548,7 @@ public function testReadRowsWithKeyAndRanges() ] ] ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -569,7 +566,7 @@ public function testReadRowsWithFilter() $args = [ 'filter' => $rowFilter ]; - $iterator = $this->dataClient->readRows($args); + $iterator = $this->table->readRows($args); $this->assertInstanceOf(ChunkFormatter::class, $iterator); } @@ -605,7 +602,7 @@ public function testReadModifyWriteRowAppend() ->willReturn( $readModifyWriteRowResponse ); - $row = $this->dataClient->readModifyWriteRow('rk1', $readModifyWriteRowRules); + $row = $this->table->readModifyWriteRow('rk1', $readModifyWriteRowRules); $expectedRow = [ 'cf1' => [ 'cq1' => [[ @@ -653,7 +650,7 @@ public function testReadModifyWriteRowIncrement() ->willReturn( $readModifyWriteRowResponse ); - $row = $this->dataClient->readModifyWriteRow('rk1', $readModifyWriteRowRules); + $row = $this->table->readModifyWriteRow('rk1', $readModifyWriteRowRules); $expectedRow = [ 'cf1' => [ 'cq1' => [[ @@ -685,7 +682,7 @@ public function testSampleRowKeys() ->willReturn( $this->serverStream->reveal() ); - $rowKeyStream = $this->dataClient->sampleRowKeys(); + $rowKeyStream = $this->table->sampleRowKeys(); $rowKeys = iterator_to_array($rowKeyStream); $expectedRowKeys = [ [ @@ -706,7 +703,7 @@ public function testSampleRowKeys() */ public function testCheckAndMutateRowShouldThrowWhenNoTrueOrFalseMutations() { - $this->dataClient->checkAndMutateRow('rk1'); + $this->table->checkAndMutateRow('rk1'); } /** @@ -715,7 +712,7 @@ public function testCheckAndMutateRowShouldThrowWhenNoTrueOrFalseMutations() */ public function testCheckAndMutateRowShouldThrowWhenPredicateFilterIsNotFilter() { - $this->dataClient->checkAndMutateRow('rk1', ['predicateFilter' => new \stdClass()]); + $this->table->checkAndMutateRow('rk1', ['predicateFilter' => new \stdClass()]); } /** @@ -724,7 +721,7 @@ public function testCheckAndMutateRowShouldThrowWhenPredicateFilterIsNotFilter() */ public function testCheckAndMutateRowShouldThrowWhenTrueMutationsNotMutations() { - $this->dataClient->checkAndMutateRow('rk1', ['trueMutations' => new \stdClass()]); + $this->table->checkAndMutateRow('rk1', ['trueMutations' => new \stdClass()]); } /** @@ -733,7 +730,7 @@ public function testCheckAndMutateRowShouldThrowWhenTrueMutationsNotMutations() */ public function testCheckAndMutateRowShouldThrowWhenFalseMutationsNotMutations() { - $this->dataClient->checkAndMutateRow('rk1', ['falseMutations' => new \stdClass()]); + $this->table->checkAndMutateRow('rk1', ['falseMutations' => new \stdClass()]); } public function testCheckAndMutateRowWithTrueMutations() @@ -748,7 +745,7 @@ public function testCheckAndMutateRowWithTrueMutations() ->willReturn( (new CheckAndMutateRowResponse)->setPredicateMatched(true) ); - $result = $this->dataClient->checkAndMutateRow($rowKey, ['trueMutations' => $mutations]); + $result = $this->table->checkAndMutateRow($rowKey, ['trueMutations' => $mutations]); $this->assertTrue($result); } @@ -764,7 +761,7 @@ public function testCheckAndMutateRowWithFalseMutations() ->willReturn( (new CheckAndMutateRowResponse)->setPredicateMatched(false) ); - $result = $this->dataClient->checkAndMutateRow($rowKey, ['falseMutations' => $mutations]); + $result = $this->table->checkAndMutateRow($rowKey, ['falseMutations' => $mutations]); $this->assertFalse($result); } @@ -782,7 +779,7 @@ public function testCheckAndMutateRowWithPredicateFilter() ->willReturn( (new CheckAndMutateRowResponse)->setPredicateMatched(false) ); - $result = $this->dataClient->checkAndMutateRow( + $result = $this->table->checkAndMutateRow( $rowKey, [ 'predicateFilter' => $predicateFilter, From 96a75d609e47b56aee414e53b6fa61bbf3c502bd Mon Sep 17 00:00:00 2001 From: Dave Supplee Date: Fri, 2 Nov 2018 08:37:35 -0700 Subject: [PATCH 06/12] add projectId/credentials to client --- Bigtable/tests/System/BigtableTestCase.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Bigtable/tests/System/BigtableTestCase.php b/Bigtable/tests/System/BigtableTestCase.php index 8056d6e40611..0c7761112df6 100644 --- a/Bigtable/tests/System/BigtableTestCase.php +++ b/Bigtable/tests/System/BigtableTestCase.php @@ -58,8 +58,10 @@ public static function setUpBeforeClass() self::$projectId = $keyFileData['project_id']; self::$instanceId = uniqid(self::INSTANCE_ID_PREFIX); self::$clusterId = uniqid(self::CLUSTER_ID_PREFIX); - self::$table = (new BigtableClient) - ->table(self::$instanceId, self::TABLE_ID); + self::$table = (new BigtableClient([ + 'projectId' => 'my-project', + 'credentials' => $keyFilePath + ]))->table(self::$instanceId, self::TABLE_ID); self::createInstance(); self::createTable(); } From 25047f135b8debaab1f096494680a9073abfd208 Mon Sep 17 00:00:00 2001 From: Dave Supplee Date: Fri, 2 Nov 2018 08:45:56 -0700 Subject: [PATCH 07/12] update mutateRow --- Bigtable/src/BigtableClient.php | 2 +- Bigtable/src/Table.php | 5 ++--- Bigtable/tests/Snippet/TableTest.php | 4 ++-- Bigtable/tests/Unit/TableTest.php | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Bigtable/src/BigtableClient.php b/Bigtable/src/BigtableClient.php index c0eaf72c6786..44aa5c096b8f 100644 --- a/Bigtable/src/BigtableClient.php +++ b/Bigtable/src/BigtableClient.php @@ -123,7 +123,7 @@ public function __construct(array $config = []) * @param string $instanceId The instance ID. * @param string $tableId The table ID. * @param array $options [optional] { - * Configuration options. + * Configuration options. * * @type string $appProfileId This value specifies routing for * replication. **Defaults to** the "default" application profile. diff --git a/Bigtable/src/Table.php b/Bigtable/src/Table.php index 7d1f11bf8e2e..0e77e2dba9e3 100644 --- a/Bigtable/src/Table.php +++ b/Bigtable/src/Table.php @@ -133,13 +133,12 @@ public function mutateRows(array $rowMutations, array $options = []) * * Example: * ``` - * use Google\Cloud\Bigtable\DataClient; * use Google\Cloud\Bigtable\Mutations; * * $mutations = (new Mutations) * ->upsert('cf1', 'cq1', 'value1', 1534183334215000); * - * $dataClient->mutateRow('r1', $mutations); + * $table->mutateRow('r1', $mutations); * ``` * * @param string $rowKey The row key of the row to mutate. @@ -150,7 +149,7 @@ public function mutateRows(array $rowMutations, array $options = []) */ public function mutateRow($rowKey, Mutations $mutations, array $options = []) { - $this->bigtableClient->mutateRow( + $this->gapicClient->mutateRow( $this->tableName, $rowKey, $mutations->toProto(), diff --git a/Bigtable/tests/Snippet/TableTest.php b/Bigtable/tests/Snippet/TableTest.php index 75480bac74d6..896afa4b4a4e 100644 --- a/Bigtable/tests/Snippet/TableTest.php +++ b/Bigtable/tests/Snippet/TableTest.php @@ -134,8 +134,8 @@ public function testMutateRow() ->willReturn( new MutateRowResponse ); - $snippet = $this->snippetFromMethod(DataClient::class, 'mutateRow'); - $snippet->addLocal('dataClient', $this->dataClient); + $snippet = $this->snippetFromMethod(Table::class, 'mutateRow'); + $snippet->addLocal('table', $this->dataClient); $snippet->invoke(); } diff --git a/Bigtable/tests/Unit/TableTest.php b/Bigtable/tests/Unit/TableTest.php index 81e77371fc2e..7fcbbffb364c 100644 --- a/Bigtable/tests/Unit/TableTest.php +++ b/Bigtable/tests/Unit/TableTest.php @@ -302,7 +302,7 @@ public function testMutateRow() ->willReturn( new MutateRowResponse ); - $this->dataClient->mutateRow('r1', $mutations); + $this->table->mutateRow('r1', $mutations); } public function testReadRowsNoArg() From 2b30af8c7348114764ca493203e863f8d9f0cd4f Mon Sep 17 00:00:00 2001 From: Dave Supplee Date: Fri, 2 Nov 2018 08:50:05 -0700 Subject: [PATCH 08/12] update mutateRow system test --- Bigtable/tests/System/MutateRowsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Bigtable/tests/System/MutateRowsTest.php b/Bigtable/tests/System/MutateRowsTest.php index 319bb39a0e9f..5277aec80fcb 100644 --- a/Bigtable/tests/System/MutateRowsTest.php +++ b/Bigtable/tests/System/MutateRowsTest.php @@ -57,7 +57,7 @@ public function testBasicWriteAndReadDataOperationUsingMutateRow() { $mutations = (new Mutations) ->upsert('cf1', 'cq1', 'value1', 5000); - self::$dataClient->mutateRow('rk10', $mutations); + self::$table->mutateRow('rk10', $mutations); $readRows = [ 'rk10' => [ 'cf1' => [ @@ -69,7 +69,7 @@ public function testBasicWriteAndReadDataOperationUsingMutateRow() ] ] ]; - $rows = iterator_to_array(self::$dataClient->readRows(['rowKeys' => ['rk10']])->readAll()); + $rows = iterator_to_array(self::$table->readRows(['rowKeys' => ['rk10']])->readAll()); $this->assertEquals($readRows, $rows); } From d62673d0b4613136695a6d98bd071006f012f099 Mon Sep 17 00:00:00 2001 From: Dave Supplee Date: Fri, 2 Nov 2018 08:52:02 -0700 Subject: [PATCH 09/12] add imports for documentation --- Bigtable/src/BigtableClient.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Bigtable/src/BigtableClient.php b/Bigtable/src/BigtableClient.php index 44aa5c096b8f..125ef61f24d6 100644 --- a/Bigtable/src/BigtableClient.php +++ b/Bigtable/src/BigtableClient.php @@ -17,6 +17,8 @@ namespace Google\Cloud\Bigtable; +use Google\ApiCore\CredentialsWrapper; +use Google\ApiCore\Transport\TransportInterface; use Google\ApiCore\ValidationException; use Google\Auth\FetchAuthTokenInterface; use Google\Cloud\Bigtable\V2\BigtableClient as GapicClient; From fc9d1afb5fd11643dd39f6e436be39cdba4a8656 Mon Sep 17 00:00:00 2001 From: David Supplee Date: Fri, 2 Nov 2018 09:41:52 -0700 Subject: [PATCH 10/12] fix tests --- Bigtable/tests/Snippet/TableTest.php | 2 +- Bigtable/tests/System/CheckAndMutateRowTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Bigtable/tests/Snippet/TableTest.php b/Bigtable/tests/Snippet/TableTest.php index 896afa4b4a4e..142c7484722f 100644 --- a/Bigtable/tests/Snippet/TableTest.php +++ b/Bigtable/tests/Snippet/TableTest.php @@ -135,7 +135,7 @@ public function testMutateRow() new MutateRowResponse ); $snippet = $this->snippetFromMethod(Table::class, 'mutateRow'); - $snippet->addLocal('table', $this->dataClient); + $snippet->addLocal('table', $this->table); $snippet->invoke(); } diff --git a/Bigtable/tests/System/CheckAndMutateRowTest.php b/Bigtable/tests/System/CheckAndMutateRowTest.php index 1ef5bfe04853..83dec33a6716 100644 --- a/Bigtable/tests/System/CheckAndMutateRowTest.php +++ b/Bigtable/tests/System/CheckAndMutateRowTest.php @@ -19,7 +19,6 @@ use Google\Cloud\Bigtable\Filter; use Google\Cloud\Bigtable\Mutations; -use Google\Cloud\Bigtable\Tests\System\DataClientTest; /** * @group bigtable From 7cee78710aef71a82d05490c2f74843d3eea00fa Mon Sep 17 00:00:00 2001 From: David Supplee Date: Fri, 2 Nov 2018 10:14:07 -0700 Subject: [PATCH 11/12] potential fix for hhvm --- Bigtable/tests/Snippet/BigtableClientTest.php | 4 ++++ Bigtable/tests/Snippet/ChunkFormatterTest.php | 4 ++++ Bigtable/tests/Snippet/FilterTest.php | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/Bigtable/tests/Snippet/BigtableClientTest.php b/Bigtable/tests/Snippet/BigtableClientTest.php index 4037a2487ac0..85c3b1908b86 100644 --- a/Bigtable/tests/Snippet/BigtableClientTest.php +++ b/Bigtable/tests/Snippet/BigtableClientTest.php @@ -31,6 +31,10 @@ class BigtableClientTest extends SnippetTestCase public function testClass() { $snippet = $this->snippetFromClass(BigtableClient::class); + $snippet->replace( + '$bigtable = new BigtableClient();', + '$bigtable = new BigtableClient(["projectId" => "my-project"]);' + ); $res = $snippet->invoke('bigtable'); $this->assertInstanceOf(BigtableClient::class, $res->returnVal()); diff --git a/Bigtable/tests/Snippet/ChunkFormatterTest.php b/Bigtable/tests/Snippet/ChunkFormatterTest.php index 6f5a21948f5c..f97bbee71cef 100644 --- a/Bigtable/tests/Snippet/ChunkFormatterTest.php +++ b/Bigtable/tests/Snippet/ChunkFormatterTest.php @@ -52,6 +52,10 @@ public function setUp() public function testClass() { $snippet = $this->snippetFromClass(ChunkFormatter::class); + $snippet->replace( + '$bigtable = new BigtableClient();', + '$bigtable = new BigtableClient(["projectId" => "my-project"]);' + ); $snippet->replace('$table = $bigtable->table(\'my-instance\', \'my-table\');', ''); $this->bigtableClient->readRows(self::TABLE_NAME, []) ->shouldBeCalled() diff --git a/Bigtable/tests/Snippet/FilterTest.php b/Bigtable/tests/Snippet/FilterTest.php index c3856b312735..09efdaed5f31 100644 --- a/Bigtable/tests/Snippet/FilterTest.php +++ b/Bigtable/tests/Snippet/FilterTest.php @@ -60,6 +60,10 @@ public function testClass() ->willReturn([$expectedRows]); $snippet = $this->snippetFromClass(Filter::class); + $snippet->replace( + '$bigtable = new BigtableClient();', + '$bigtable = new BigtableClient(["projectId" => "my-project"]);' + ); $snippet->replace('$table = $bigtable->table(\'my-instance\', \'my-table\');', ''); $snippet->addLocal('table', $table->reveal()); $res = $snippet->invoke('rows'); From 0d735c834390a69854cfa363d7bd3349f73bf7d8 Mon Sep 17 00:00:00 2001 From: David Supplee Date: Fri, 2 Nov 2018 12:55:27 -0700 Subject: [PATCH 12/12] fix projectId --- Bigtable/tests/System/BigtableTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bigtable/tests/System/BigtableTestCase.php b/Bigtable/tests/System/BigtableTestCase.php index 0c7761112df6..370123fafece 100644 --- a/Bigtable/tests/System/BigtableTestCase.php +++ b/Bigtable/tests/System/BigtableTestCase.php @@ -59,7 +59,7 @@ public static function setUpBeforeClass() self::$instanceId = uniqid(self::INSTANCE_ID_PREFIX); self::$clusterId = uniqid(self::CLUSTER_ID_PREFIX); self::$table = (new BigtableClient([ - 'projectId' => 'my-project', + 'projectId' => self::$projectId, 'credentials' => $keyFilePath ]))->table(self::$instanceId, self::TABLE_ID); self::createInstance();