diff --git a/Core/tests/Unit/LongRunning/OperationResponseTraitTest.php b/Core/tests/Unit/LongRunning/OperationResponseTraitTest.php index dc61548dc79f..1bfd54709939 100644 --- a/Core/tests/Unit/LongRunning/OperationResponseTraitTest.php +++ b/Core/tests/Unit/LongRunning/OperationResponseTraitTest.php @@ -18,10 +18,14 @@ namespace Google\Cloud\Core\Tests\Unit\LongRunning; use Google\ApiCore\OperationResponse; +use Google\ApiCore\OperationsClientInterface; use Google\ApiCore\Serializer; use Google\Cloud\Core\LongRunning\OperationResponseTrait; use Google\Cloud\Core\LongRunning\LongRunningOperation; use Google\Cloud\Core\LongRunning\LongRunningConnectionInterface; +use Google\LongRunning\Operation; +use Google\Protobuf\Any; +use Google\Rpc\Status; use Prophecy\Argument; use Google\Cloud\Audit\RequestMetadata; use Google\Cloud\Audit\AuthorizationInfo; @@ -43,6 +47,7 @@ class OperationResponseTraitTest extends TestCase const OPERATION_NAME = 'test-operation'; private $serializer; + private $operationsClient; private $lroResponseMappers = [ [ 'typeUrl' => self::METADATA_TYPE, @@ -57,10 +62,31 @@ public function setUp(): void { $serializer = $this->prophesize(Serializer::class); $serializer->encodeMessage(Argument::any())->will(function ($arg) { + if ($arg[0] instanceof Operation) { + $result = [ + 'done' => $arg[0]->getDone(), + 'metadata' => [ + 'typeUrl' => $arg[0]->getMetadata()->getTypeUrl(), + 'value' => $arg[0]->getMetadata()->getValue(), + ], + ]; + if ($arg[0]->hasResponse()) { + $result['response'] = [ + 'typeUrl' => $arg[0]->getResponse()->getTypeUrl(), + 'value' => $arg[0]->getResponse()->getValue(), + ]; + } + if ($arg[0]->hasError()) { + $result['error'] = $arg[0]->getError(); + } + + return $result; + } $json = $arg[0]->serializeToJsonString(); return json_decode($json, true); }); $this->serializer = $serializer->reveal(); + $this->operationsClient = $this->prophesize(OperationsClientInterface::class)->reveal(); } public function testOperationWithResponse() @@ -73,8 +99,12 @@ public function testOperationWithResponse() $meta = new RequestMetadata([ 'caller_ip' => '127.8.9.10', // Sic(!) ]); - $response = new Response(self::METADATA_TYPE, $meta, self::RESULT_TYPE, $result); - $operation = new OperationResponse(self::OPERATION_NAME, null, ['lastProtoResponse' => $response]); + $response = $this->createOperation(self::METADATA_TYPE, $meta, self::RESULT_TYPE, $result); + $operation = new OperationResponse( + self::OPERATION_NAME, + $this->operationsClient, + ['lastProtoResponse' => $response] + ); $got = $this->operationToArray($operation, $this->serializer, $this->lroResponseMappers); $expected = [ @@ -95,17 +125,20 @@ public function testOperationWithResponse() public function testOperationWithError() { - $error = new AuthorizationInfo([ - 'resource' => 'any', - 'permission' => 'all', - 'granted' => true, + $error = new Status([ + 'code' => 1, + 'message' => 'error', ]); $meta = new RequestMetadata([ 'caller_ip' => '127.8.9.10', // Sic(!) ]); - $response = new Response(self::METADATA_TYPE, $meta); - $response->error = $error; - $operation = new OperationResponse(self::OPERATION_NAME, null, ['lastProtoResponse' => $response]); + $response = $this->createOperation(self::METADATA_TYPE, $meta); + $response->setError($error); + $operation = new OperationResponse( + self::OPERATION_NAME, + $this->operationsClient, + ['lastProtoResponse' => $response] + ); $got = $this->operationToArray($operation, $this->serializer, $this->lroResponseMappers); $expected = [ @@ -115,9 +148,8 @@ public function testOperationWithError() 'typeUrl' => self::METADATA_TYPE, ], 'error' => [ - 'resource' => 'any', - 'permission' => 'all', - 'granted' => true, + 'code' => 1, + 'message' => 'error', ], 'response' => null, ]; @@ -126,7 +158,7 @@ public function testOperationWithError() public function testNullProtoResponse() { - $operation = new OperationResponse(self::OPERATION_NAME, null); + $operation = new OperationResponse(self::OPERATION_NAME, $this->operationsClient); $got = $this->operationToArray($operation, $this->serializer, $this->lroResponseMappers); $this->assertNull($got); } @@ -141,8 +173,12 @@ public function testLroCallable() $meta = new RequestMetadata([ 'caller_ip' => '127.8.9.10', ]); - $response = new Response(self::METADATA_TYPE, $meta, self::RESULT_TYPE, $result); - $operation = new OperationResponse(self::OPERATION_NAME, null, ['lastProtoResponse' => $response]); + $response = $this->createOperation(self::METADATA_TYPE, $meta, self::RESULT_TYPE, $result); + $operation = new OperationResponse( + self::OPERATION_NAME, + $this->operationsClient, + ['lastProtoResponse' => $response] + ); $connection = $this->prophesize(LongRunningConnectionInterface::class); $t = $this; @@ -162,81 +198,23 @@ public function testLroCallable() $expected = 'any|all|1'; $this->assertEquals($expected, $got); } -} - -//@codingStandardsIgnoreStart -class Value -{ - public $value; - - public function __construct($value = null) - { - $this->value = $value; - } - - public function getValue() + private function createOperation($metaType, $metadata, $respType = null, $response = null): Operation { - return $this->value; - } -} - -class Response extends \Google\Protobuf\Internal\Message -{ - public $metadataType; - public $metadata; - public $responseType; - public $response = null; - public $error = null; - - public function __construct($metaType, $metadata, $respType = null, $response = null) - { - $this->metadataType = $metaType; - $this->metadata = $metadata->serializeToString(); - $this->responseType = $respType; - if (isset($response)) { - $this->response = $response->serializeToString(); - } - } - - public function getResponse() - { - return new Value($this->response); - } - - public function getMetadata() - { - return new Value($this->metadata); - } - - public function getDone() - { - return (isset($this->response) or isset($this->error)); - } - - public function getError() - { - return $this->error; - } - - public function serializeToJsonString($options = 0) - { - $result = [ + $operation = new Operation([ 'done' => true, - 'metadata' => [ - 'typeUrl' => $this->metadataType, - 'value' => $this->metadata, - ], - ]; - if (isset($this->response)) { - $result['response'] = [ - 'typeUrl' => $this->responseType, - 'value' => $this->response, - ]; + 'metadata' => new Any([ + 'type_url' => $metaType, + 'value' => $metadata->serializeToString(), + ]), + ]); + if (isset($response)) { + $operation->setResponse(new Any([ + 'type_url' => $respType, + 'value' => $response->serializeToString(), + ])); } - return json_encode($result); + return $operation; } } - -//@codingStandardsIgnoreEnd diff --git a/Gax/MIGRATING.md b/Gax/MIGRATING.md index 13bd49d06607..cf5c0cb31bea 100644 --- a/Gax/MIGRATING.md +++ b/Gax/MIGRATING.md @@ -55,3 +55,11 @@ Update your `google/gax` dependency to `^2.0`: - Added `declare(strict_types=1)` across all `Google\ApiCore` files. - Added native parameter, property, and return type declarations across all `Google\ApiCore` classes, interfaces (`TransportInterface`, `MiddlewareInterface`, `ResourceTemplateInterface`, `ServerStreamingCallInterface`, `ResumableUploadTransportInterface`, `HeaderCredentialsInterface`), and traits. - **`PathTemplate::__construct(string $path)`** now requires a non-null `string`. +- **`OperationResponse`**: + - `__construct(string $operationName, object $operationsClient, array $options = [])` now requires non-null `$operationName` (`string`) and `$operationsClient` (`object`). + - `getName()` now returns non-nullable `string`. + - `getError()` now returns `?Google\Rpc\Status`. + - `getLastProtoResponse()` now returns `?Google\Protobuf\Internal\Message` (annotated as `Operation|Message|null`), preserving the raw custom operation message (e.g. `Google\Cloud\Compute\V1\Operation`) for custom operation services such as Compute. + - `getOperationsClient()` now returns non-nullable `object` (annotated as `OperationsClient|OperationsClientInterface|object`), unwrapping `OperationsClientWrapperInterface` adapters so custom operation services still receive their underlying operations client. + - Custom operations clients (e.g., Compute's `ZoneOperationsClient`) and custom operation RPC options are now encapsulated in `Google\ApiCore\CustomOperationsClient` (implementing `Google\ApiCore\OperationsClientWrapperInterface`). + diff --git a/Gax/src/CustomOperationsClient.php b/Gax/src/CustomOperationsClient.php new file mode 100644 index 000000000000..16faa47e58f7 --- /dev/null +++ b/Gax/src/CustomOperationsClient.php @@ -0,0 +1,168 @@ +client = $client; + $options += [ + 'getOperationMethod' => 'getOperation', + 'cancelOperationMethod' => 'cancelOperation', + 'deleteOperationMethod' => 'deleteOperation', + 'getOperationRequest' => GetOperationRequest::class, + 'cancelOperationRequest' => CancelOperationRequest::class, + 'deleteOperationRequest' => DeleteOperationRequest::class, + 'additionalOperationArguments' => [], + ]; + + $this->getOperationMethod = $options['getOperationMethod']; + $this->cancelOperationMethod = $options['cancelOperationMethod']; + $this->deleteOperationMethod = $options['deleteOperationMethod']; + $this->getOperationRequest = $options['getOperationRequest']; + $this->cancelOperationRequest = $options['cancelOperationRequest']; + $this->deleteOperationRequest = $options['deleteOperationRequest']; + $this->additionalArgs = $options['additionalOperationArguments']; + } + + public static function hasCustomOptions(array $options): bool + { + foreach (self::CUSTOM_OPTION_KEYS as $key) { + if (array_key_exists($key, $options)) { + return true; + } + } + + return false; + } + + public function getOperation(GetOperationRequest $request, array $callOptions = []): Message + { + return $this->operationsCall( + $this->getOperationMethod, + $this->getOperationRequest, + $request->getName(), + $callOptions + ); + } + + public function cancelOperation(CancelOperationRequest $request, array $callOptions = []): void + { + if (is_null($this->cancelOperationMethod) || is_null($this->cancelOperationRequest)) { + throw new LogicException('The cancel operation is not supported by this API'); + } + + $this->operationsCall( + $this->cancelOperationMethod, + $this->cancelOperationRequest, + $request->getName(), + $callOptions + ); + } + + public function deleteOperation(DeleteOperationRequest $request, array $callOptions = []): void + { + if (is_null($this->deleteOperationMethod) || is_null($this->deleteOperationRequest)) { + throw new LogicException('The delete operation is not supported by this API'); + } + + $this->operationsCall( + $this->deleteOperationMethod, + $this->deleteOperationRequest, + $request->getName(), + $callOptions + ); + } + + public function getOperationsClient(): object + { + return $this->client; + } + + private function operationsCall( + string $method, + string $requestClass, + string $operationName, + array $callOptions = [] + ): mixed { + if (!method_exists($requestClass, 'build')) { + throw new LogicException('Request class must support the static build method'); + } + + // In Compute, the Request "build" methods contain the operation ID last instead + // of first. Compute is the only API which uses $additionalArgs, so switching the order + // will not break anything. + $request = $requestClass::build(...array_merge( + array_values($this->additionalArgs), + [$operationName] + )); + + if ($callOptions) { + return $this->client->$method($request, $callOptions); + } + + return $this->client->$method($request); + } +} diff --git a/Gax/src/Middleware/OperationsMiddleware.php b/Gax/src/Middleware/OperationsMiddleware.php index 07bbe42cc23c..13de084071e3 100644 --- a/Gax/src/Middleware/OperationsMiddleware.php +++ b/Gax/src/Middleware/OperationsMiddleware.php @@ -71,7 +71,9 @@ public function __invoke(Call $call, array $options): PromiseInterface 'lastProtoResponse' => $response ]; $operationNameMethod = $options['operationNameMethod'] ?? 'getName'; - $operationName = call_user_func([$response, $operationNameMethod]); + $operationName = method_exists($response, $operationNameMethod) + ? (string) $response->$operationNameMethod() + : ''; return new OperationResponse($operationName, $this->operationsClient, $options); }); } diff --git a/Gax/src/OperationResponse.php b/Gax/src/OperationResponse.php index a147a95748cb..c57209742406 100644 --- a/Gax/src/OperationResponse.php +++ b/Gax/src/OperationResponse.php @@ -69,8 +69,8 @@ class OperationResponse const DEFAULT_MAX_POLLING_INTERVAL = 60000; const DEFAULT_MAX_POLLING_DURATION = 0; - private ?string $operationName; - private ?object $operationsClient; + private string $operationName; + private OperationsClient|OperationsClientInterface $operationsClient; private ?string $operationReturnType; private ?string $metadataReturnType; @@ -85,13 +85,6 @@ class OperationResponse private ?Message $lastProtoResponse; private bool $deleted = false; - private array $additionalArgs; - private string $getOperationMethod; - private ?string $cancelOperationMethod; - private ?string $deleteOperationMethod; - private string $getOperationRequest; - private ?string $cancelOperationRequest; - private ?string $deleteOperationRequest; private string $operationStatusMethod; private mixed $operationStatusDoneValue; private ?string $operationErrorCodeMethod; @@ -100,8 +93,8 @@ class OperationResponse /** * OperationResponse constructor. * - * @param string|null $operationName - * @param ServiceInterface|object|null $operationsClient + * @param string $operationName + * @param OperationsClient|OperationsClientInterface|object $operationsClient * @param array $options { * Optional. Options for configuring the operation response object. * @@ -116,46 +109,41 @@ class OperationResponse * @type string $cancelOperationMethod The method on $operationsClient to cancel the operation. * @type string $deleteOperationMethod The method on $operationsClient to delete the operation. * @type string $operationStatusMethod The method on the operation to get the status. - * @type string $operationStatusDoneValue The method on the operation to determine if the status is done. + * @type mixed $operationStatusDoneValue The value on the operation indicating status is done. * @type array $additionalOperationArguments Additional arguments to pass to $operationsClient methods. * @type string $operationErrorCodeMethod The method on the operation to get the error code * @type string $operationErrorMessageMethod The method on the operation to get the error status * } */ - public function __construct(?string $operationName, ?object $operationsClient, array $options = []) - { + public function __construct( + string $operationName, + object $operationsClient, + array $options = [] + ) { $this->operationName = $operationName; + // @TODO: Remove check for OperationsClient once support for google/longrunning:0.4 is dropped + $isStandardClient = $operationsClient instanceof OperationsClient + || $operationsClient instanceof OperationsClientInterface; + if (!$isStandardClient || CustomOperationsClient::hasCustomOptions($options)) { + $operationsClient = new CustomOperationsClient($operationsClient, $options); + } $this->operationsClient = $operationsClient; $options += [ 'operationReturnType' => null, 'metadataReturnType' => null, 'lastProtoResponse' => null, - 'getOperationMethod' => 'getOperation', - 'cancelOperationMethod' => 'cancelOperation', - 'deleteOperationMethod' => 'deleteOperation', 'operationStatusMethod' => 'getDone', 'operationStatusDoneValue' => true, - 'additionalOperationArguments' => [], 'operationErrorCodeMethod' => null, 'operationErrorMessageMethod' => null, - 'getOperationRequest' => GetOperationRequest::class, - 'cancelOperationRequest' => CancelOperationRequest::class, - 'deleteOperationRequest' => DeleteOperationRequest::class, ]; $this->operationReturnType = $options['operationReturnType']; $this->metadataReturnType = $options['metadataReturnType']; $this->lastProtoResponse = $options['lastProtoResponse']; - $this->getOperationMethod = $options['getOperationMethod']; - $this->cancelOperationMethod = $options['cancelOperationMethod']; - $this->deleteOperationMethod = $options['deleteOperationMethod']; - $this->additionalArgs = $options['additionalOperationArguments']; $this->operationStatusMethod = $options['operationStatusMethod']; $this->operationStatusDoneValue = $options['operationStatusDoneValue']; $this->operationErrorCodeMethod = $options['operationErrorCodeMethod']; $this->operationErrorMessageMethod = $options['operationErrorMessageMethod']; - $this->getOperationRequest = $options['getOperationRequest']; - $this->cancelOperationRequest = $options['cancelOperationRequest']; - $this->deleteOperationRequest = $options['deleteOperationRequest']; if (isset($options['initialPollDelayMillis'])) { $this->defaultPollSettings['initialPollDelayMillis'] = $options['initialPollDelayMillis']; @@ -225,9 +213,9 @@ public function operationFailed(): bool /** * Get the formatted name of the operation * - * @return string|null The formatted name of the operation + * @return string The formatted name of the operation */ - public function getName(): ?string + public function getName(): string { return $this->operationName; } @@ -277,10 +265,8 @@ public function reload(): void throw new ValidationException('Cannot call reload() on a deleted operation'); } - $this->lastProtoResponse = $this->operationsCall( - $this->getOperationMethod, - $this->getOperationRequest - ); + $request = GetOperationRequest::build($this->getName()); + $this->lastProtoResponse = $this->operationsClient->getOperation($request); } /** @@ -322,10 +308,10 @@ public function getResult(): mixed /** * If the operation failed, return the status. If operationFailed() is false, return null. * - * @return Status|Message|null The status of the operation in case of failure, or null if + * @return Status|null The status of the operation in case of failure, or null if * operationFailed() is false. */ - public function getError(): ?Message + public function getError(): ?Status { if (!$this->hasProtoResponse() || !$this->isDone()) { return null; @@ -339,8 +325,8 @@ public function getError(): ?Message ? call_user_func([$this->lastProtoResponse, $this->operationErrorMessageMethod]) : null; return (new Status()) - ->setCode(ApiStatus::rpcCodeFromHttpStatusCode($errorCode)) - ->setMessage($errorMessage); + ->setCode(ApiStatus::rpcCodeFromHttpStatusCode((int) $errorCode)) + ->setMessage((string) $errorMessage); } if (method_exists($this->lastProtoResponse, 'getError')) { @@ -375,11 +361,15 @@ public function getLastProtoResponse(): ?Message } /** - * @return ServiceInterface|object|null The OperationsClient object used to make + * @return OperationsClient|OperationsClientInterface|object The OperationsClient object used to make * requests to the operations API. */ - public function getOperationsClient(): ?object + public function getOperationsClient(): object { + if ($this->operationsClient instanceof OperationsClientWrapperInterface) { + return $this->operationsClient->getOperationsClient(); + } + return $this->operationsClient; } @@ -402,11 +392,8 @@ public function getOperationsClient(): ?object */ public function cancel(): void { - if (is_null($this->cancelOperationMethod)) { - throw new LogicException('The cancel operation is not supported by this API'); - } - - $this->operationsCall($this->cancelOperationMethod, $this->cancelOperationRequest); + $request = CancelOperationRequest::build($this->getName()); + $this->operationsClient->cancelOperation($request); } /** @@ -422,11 +409,8 @@ public function cancel(): void */ public function delete(): void { - if (is_null($this->deleteOperationMethod)) { - throw new LogicException('The delete operation is not supported by this API'); - } - - $this->operationsCall($this->deleteOperationMethod, $this->deleteOperationRequest); + $request = DeleteOperationRequest::build($this->getName()); + $this->operationsClient->deleteOperation($request); $this->deleted = true; } @@ -464,28 +448,6 @@ public function getMetadata(): mixed return $metadata; } - /** - * Call the operations client to perform an operation. - * - * @param string $method The method to call on the operations client. - * @param string $requestClass The request class to use for the call. - * Will be null for legacy operations clients. - */ - private function operationsCall(string $method, string $requestClass): mixed - { - if (!method_exists($requestClass, 'build')) { - throw new LogicException('Request class must support the static build method'); - } - // In Compute, the Request "build" methods contain the operation ID last instead - // of first. Compute is the only API which uses $additionalArgs, so switching the order - // will not break anything. - $request = $requestClass::build(...array_merge( - array_values($this->additionalArgs), - [$this->getName()] - )); - return $this->operationsClient->$method($request); - } - private function canHaveResult(): bool { // The call to getResponse is only for OnePlatform LROs, and is not diff --git a/Gax/src/OperationsClientInterface.php b/Gax/src/OperationsClientInterface.php new file mode 100644 index 000000000000..8c418778eac6 --- /dev/null +++ b/Gax/src/OperationsClientInterface.php @@ -0,0 +1,53 @@ +getOperation( \Google\CustomOperation\GetOperationRequest::build('abc', 100, 'test-123') ) - ->shouldBeCalledOnce(); + ->shouldBeCalledOnce() + ->willReturn($expectedOperation); $operationResponse = $client->startOperationsCall( 'method.name', diff --git a/Gax/tests/Unit/OperationResponseTest.php b/Gax/tests/Unit/OperationResponseTest.php index c7bd9be89e4f..eab8c9d27076 100644 --- a/Gax/tests/Unit/OperationResponseTest.php +++ b/Gax/tests/Unit/OperationResponseTest.php @@ -38,7 +38,10 @@ use Google\CustomOperation\CustomOperationWithErrorAnnotations; use Google\CustomOperation\DeleteOperationRequest as CustomDeleteOperationRequest; use Google\CustomOperation\GetOperationRequest as CustomGetOperationRequest; +use Google\ApiCore\CustomOperationsClient; use Google\ApiCore\OperationResponse; +use Google\ApiCore\OperationsClientInterface; +use Google\ApiCore\OperationsClientWrapperInterface; use Google\LongRunning\CancelOperationRequest; use Google\LongRunning\Client\OperationsClient; use Google\LongRunning\DeleteOperationRequest; @@ -401,6 +404,9 @@ public function testEmptyCustomOperationErrorIsSuccessful($operationClient) */ public function testMisconfiguredCustomOperationThrowsException($operationClient) { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Unable to determine operation error status for this service'); + $operationName = 'test-123'; $operation = new CustomOperationWithErrorAnnotations('Yes, it is!'); $options = [ @@ -411,9 +417,6 @@ public function testMisconfiguredCustomOperationThrowsException($operationClient ]; $operationResponse = new OperationResponse($operationName, $operationClient, $options); - $this->expectException(LogicException::class); - $this->expectExceptionMessage('Unable to determine operation error status for this service'); - $operationResponse->operationSucceeded(); } @@ -494,6 +497,60 @@ public function testDeleteWithOperationsClient() $operationResponse->delete(); } + public function testOperationsClientInterface() + { + $operationClient = $this->prophesize(OperationsClientInterface::class); + $getRequest = new GetOperationRequest(['name' => 'test-123']); + $cancelRequest = new CancelOperationRequest(['name' => 'test-123']); + $deleteRequest = new DeleteOperationRequest(['name' => 'test-123']); + $protoOp = new Operation(['name' => 'test-123', 'done' => true]); + + $operationClient->getOperation($getRequest) + ->shouldBeCalledOnce() + ->willReturn($protoOp); + $operationClient->cancelOperation($cancelRequest) + ->shouldBeCalledOnce(); + $operationClient->deleteOperation($deleteRequest) + ->shouldBeCalledOnce(); + + $operationResponse = new OperationResponse('test-123', $operationClient->reveal()); + $this->assertSame($operationClient->reveal(), $operationResponse->getOperationsClient()); + + $operationResponse->reload(); + $this->assertTrue($operationResponse->isDone()); + $this->assertSame($protoOp, $operationResponse->getLastProtoResponse()); + + $operationResponse->cancel(); + $operationResponse->delete(); + } + + public function testCustomOperationsClientDirectly() + { + $operationName = 'test-123'; + $customOp = new CustomOperation('Yes, it is!', null); + + $rawClient = $this->prophesize(CustomOperationClient::class); + $rawClient->getMyOperationPlease(Argument::type(Message::class)) + ->shouldBeCalledOnce() + ->willReturn($customOp); + + $adapter = new CustomOperationsClient($rawClient->reveal(), [ + 'getOperationMethod' => 'getMyOperationPlease', + ]); + $this->assertInstanceOf(OperationsClientWrapperInterface::class, $adapter); + + $operationResponse = new OperationResponse($operationName, $adapter, [ + 'operationStatusMethod' => 'isThisOperationDoneOrWhat', + 'operationStatusDoneValue' => 'Yes, it is!', + ]); + $this->assertSame($rawClient->reveal(), $operationResponse->getOperationsClient()); + + $operationResponse->reload(); + $this->assertTrue($operationResponse->isDone()); + $this->assertTrue($operationResponse->operationSucceeded()); + $this->assertSame($customOp, $operationResponse->getLastProtoResponse()); + } + private function createOperationResponse($options, $reloadCount) { $opName = 'operations/opname'; diff --git a/Spanner/tests/Snippet/BackupTest.php b/Spanner/tests/Snippet/BackupTest.php index f5b065d0f777..b195066fd577 100644 --- a/Spanner/tests/Snippet/BackupTest.php +++ b/Spanner/tests/Snippet/BackupTest.php @@ -74,6 +74,8 @@ public function setUp(): void $this->serializer = new Serializer(); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('my-operation'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); $this->expireTime = new \DateTime('+ 7 hours'); $database = $this->prophesize(Database::class); diff --git a/Spanner/tests/Snippet/DatabaseTest.php b/Spanner/tests/Snippet/DatabaseTest.php index eae38f0c9678..899be42a8e87 100644 --- a/Spanner/tests/Snippet/DatabaseTest.php +++ b/Spanner/tests/Snippet/DatabaseTest.php @@ -100,6 +100,8 @@ public function setUp(): void $this->databaseAdminClient = $this->prophesize(DatabaseAdminClient::class); $this->instanceAdminClient = $this->prophesize(InstanceAdminClient::class); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('my-operation'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); $this->serializer = new Serializer(); $session = $this->prophesize(SessionCache::class); diff --git a/Spanner/tests/Snippet/InstanceConfigurationTest.php b/Spanner/tests/Snippet/InstanceConfigurationTest.php index a38710c935e6..7d7091c1012b 100644 --- a/Spanner/tests/Snippet/InstanceConfigurationTest.php +++ b/Spanner/tests/Snippet/InstanceConfigurationTest.php @@ -56,6 +56,8 @@ public function setUp(): void $this->serializer = new Serializer(); $this->instanceAdminClient = $this->prophesize(InstanceAdminClient::class); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('my-operation'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); $this->config = new InstanceConfiguration( $this->instanceAdminClient->reveal(), diff --git a/Spanner/tests/Snippet/InstanceTest.php b/Spanner/tests/Snippet/InstanceTest.php index 6b04e6c55ade..bfe8d8e47fd0 100644 --- a/Spanner/tests/Snippet/InstanceTest.php +++ b/Spanner/tests/Snippet/InstanceTest.php @@ -88,6 +88,8 @@ public function setUp(): void $this->instanceAdminClient = $this->prophesize(InstanceAdminClient::class); $this->databaseAdminClient = $this->prophesize(DatabaseAdminClient::class); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('my-operation'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); $this->page = $this->prophesize(Page::class); $this->page->getNextPageToken() diff --git a/Spanner/tests/Snippet/SpannerClientTest.php b/Spanner/tests/Snippet/SpannerClientTest.php index 9c643e272940..03f98cf10821 100644 --- a/Spanner/tests/Snippet/SpannerClientTest.php +++ b/Spanner/tests/Snippet/SpannerClientTest.php @@ -82,6 +82,8 @@ public function setUp(): void 'gapicSpannerInstanceAdminClient' => $this->instanceAdminClient->reveal(), ]); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('my-operation'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); } public function testClass() @@ -168,7 +170,7 @@ public function testCreateInstance() Argument::type('array') ) ->shouldBeCalledOnce() - ->willReturn($this->prophesize(OperationResponse::class)->reveal()); + ->willReturn($this->operationResponse->reveal()); $res = $snippet->invoke('operation'); $this->assertInstanceOf(LongRunningOperation::class, $res->returnVal()); diff --git a/Spanner/tests/Unit/BackupTest.php b/Spanner/tests/Unit/BackupTest.php index c35e1a8fc6bf..de3f6f93de32 100644 --- a/Spanner/tests/Unit/BackupTest.php +++ b/Spanner/tests/Unit/BackupTest.php @@ -84,6 +84,8 @@ public function setUp(): void $this->instance->database(Argument::any())->willReturn($this->database); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('operation-name'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); $this->expireTime = new DateTime('+7 hours'); $this->versionTime = new DateTime('-2 hours'); diff --git a/Spanner/tests/Unit/DatabaseTest.php b/Spanner/tests/Unit/DatabaseTest.php index c4e340cd2e90..a3628c9f016e 100644 --- a/Spanner/tests/Unit/DatabaseTest.php +++ b/Spanner/tests/Unit/DatabaseTest.php @@ -185,6 +185,8 @@ public function setUp(): void ); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('operation-name'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); } public function testName() diff --git a/Spanner/tests/Unit/InstanceConfigurationTest.php b/Spanner/tests/Unit/InstanceConfigurationTest.php index 9b5df8c3df95..f8fec13d324a 100644 --- a/Spanner/tests/Unit/InstanceConfigurationTest.php +++ b/Spanner/tests/Unit/InstanceConfigurationTest.php @@ -245,6 +245,9 @@ public function testUpdateWithChanges() 'displayName' => 'New Name', ]; + $operationResponse = $this->prophesize(OperationResponse::class); + $operationResponse->getName()->willReturn('operation-name'); + $operationResponse->getLastProtoResponse()->willReturn(null); $this->instanceAdminClient->updateInstanceConfig( Argument::that(function (UpdateInstanceConfigRequest $request) use ($config) { $instanceConfig = $request->getInstanceConfig()->serializeToJsonString(); @@ -253,7 +256,7 @@ public function testUpdateWithChanges() Argument::type('array') ) ->shouldBeCalledOnce() - ->willReturn($this->prophesize(OperationResponse::class)->reveal()); + ->willReturn($operationResponse->reveal()); $instanceConfig = new InstanceConfiguration( $this->instanceAdminClient->reveal(), diff --git a/Spanner/tests/Unit/InstanceTest.php b/Spanner/tests/Unit/InstanceTest.php index 253f04ffc22e..8afeeae2179f 100644 --- a/Spanner/tests/Unit/InstanceTest.php +++ b/Spanner/tests/Unit/InstanceTest.php @@ -99,6 +99,8 @@ public function setUp(): void $this->instanceAdminClient = $this->prophesize(InstanceAdminClient::class); $this->databaseAdminClient = $this->prophesize(DatabaseAdminClient::class); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('operation-name'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); $this->page = $this->prophesize(Page::class); $this->pagedListResponse = $this->prophesize(PagedListResponse::class); $this->pagedListResponse->getPage()->willReturn($this->page->reveal()); diff --git a/Spanner/tests/Unit/SpannerClientTest.php b/Spanner/tests/Unit/SpannerClientTest.php index 62e231cac99b..7d71d701855e 100644 --- a/Spanner/tests/Unit/SpannerClientTest.php +++ b/Spanner/tests/Unit/SpannerClientTest.php @@ -117,6 +117,8 @@ public function setUp(): void ]); $this->operationResponse = $this->prophesize(OperationResponse::class); + $this->operationResponse->getName()->willReturn('operation-name'); + $this->operationResponse->getLastProtoResponse()->willReturn(null); } public function testBatch()