Skip to content

Commit

Permalink
fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Nov 27, 2024
1 parent c53edc3 commit 7d3edb7
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Spanner/src/SpannerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Google\Cloud\Core\Exception\GoogleException;
use Google\Cloud\Core\Int64;
use Google\Cloud\Core\Iterator\ItemIterator;
use Google\Cloud\Core\LongRunning\LongRunningGapicConnection;
use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient;
use Google\Cloud\Spanner\Admin\Instance\V1\Client\InstanceAdminClient;
use Google\Cloud\Spanner\Admin\Instance\V1\ListInstanceConfigOperationsRequest;
Expand Down Expand Up @@ -514,6 +515,70 @@ function (Operation $operation) {
);
}

/**
* Resume a Long Running Operation
*
* Example:
* ```
* $operation = $spanner->resumeOperation($operationName);
* ```
*
* @param string $operationName The Long Running Operation name.
* @return LongRunningOperation
*/
public function resumeOperation($operationName, array $info = [])
{
return new LongRunningOperation(
new LongRunningGapicConnection($this->databaseAdminClient, $this->serializer),
$operationName,
[
[
'typeUrl' => 'type.googleapis.com/google.spanner.admin.instance.v1.UpdateInstanceMetadata',
'callable' => function ($instance) {
$name = InstanceAdminClient::parseName($instance['name'])['instance'];
return $this->instance($name, $instance);
}
], [
'typeUrl' => 'type.googleapis.com/google.spanner.admin.database.v1.CreateDatabaseMetadata',
'callable' => function ($database) {
$databaseNameComponents = DatabaseAdminClient::parseName($database['name']);
$instanceName = $databaseNameComponents['instance'];
$databaseName = $databaseNameComponents['database'];

$instance = $this->instance($instanceName);
return $instance->database($databaseName);
}
], [
'typeUrl' => 'type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata',
'callable' => function ($database) {
$databaseNameComponents = DatabaseAdminClient::parseName($database['name']);
$instanceName = $databaseNameComponents['instance'];
$databaseName = $databaseNameComponents['database'];

$instance = $this->instance($instanceName);
return $instance->database($databaseName);
}
],[
'typeUrl' => 'type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceMetadata',
'callable' => function ($instance) {
$name = InstanceAdminClient::parseName($instance['name'])['instance'];
return $this->instance($name, $instance);
}
], [
'typeUrl' => 'type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata',
'callable' => function ($backup) {
$backupNameComponents = DatabaseAdminClient::parseName($backup['name']);
$instanceName = $backupNameComponents['instance'];

$instance = $this->instance($instanceName);
return $instance->backup($backup['name'], $backup);
}
]
],
$info
);
}

/**
* Create a new instance.
*
Expand Down
13 changes: 13 additions & 0 deletions Spanner/tests/Snippet/SpannerClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ public function factoriesProvider()
];
}

public function testResumeOperation()
{
$opName = 'operations/foo';
$snippet = $this->snippetFromMagicMethod(SpannerClient::class, 'resumeOperation');
$snippet->addLocal('spanner', $this->client);
$snippet->addLocal('operationName', $opName);

$res = $snippet->invoke('operation');
$op = $res->returnVal();
$this->assertInstanceOf(LongRunningOperation::class, $op);
$this->assertEquals($op->name(), $opName);
}

public function testEmulator()
{
$snippet = $this->snippetFromClass(SpannerClient::class, 1);
Expand Down
12 changes: 12 additions & 0 deletions Spanner/tests/Unit/SpannerClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ public function testInstances()
$this->assertEquals('bar', InstanceAdminClient::parseName($instances[1]->name())['instance']);
}

/**
* @group spanner-admin
*/
public function testResumeOperation()
{
$opName = 'operations/foo';

$op = $this->spannerClient->resumeOperation($opName);
$this->assertInstanceOf(LongRunningOperation::class, $op);
$this->assertEquals($op->name(), $opName);
}

public function testConnect()
{
$database = $this->spannerClient->connect(self::INSTANCE, self::DATABASE);
Expand Down

0 comments on commit 7d3edb7

Please sign in to comment.