diff --git a/LongRunning/.OwlBot.yaml b/LongRunning/.OwlBot.yaml index 50fa62ef7164..bf7df4e13d0a 100644 --- a/LongRunning/.OwlBot.yaml +++ b/LongRunning/.OwlBot.yaml @@ -5,4 +5,6 @@ deep-copy-regex: dest: /owl-bot-staging/LongRunning/tests/$1 - source: /google/longrunning/.*-php/proto/src/(.*) dest: /owl-bot-staging/LongRunning/proto/src/$1 + - source: /google/longrunning/.*-php/samples/(.*) + dest: /owl-bot-staging/LongRunning/samples/$1 api-name: LongRunning diff --git a/LongRunning/composer.json b/LongRunning/composer.json index 59c6f651b0c3..10070691187a 100644 --- a/LongRunning/composer.json +++ b/LongRunning/composer.json @@ -3,10 +3,9 @@ "description": "Google LongRunning Client for PHP", "license": "Apache-2.0", "minimum-stability": "stable", - "version": "0.7.0", + "version": "1.0.0", "autoload": { "psr-4": { - "Google\\ApiCore\\LongRunning\\": "src/ApiCore/LongRunning", "Google\\LongRunning\\": "src/LongRunning", "GPBMetadata\\Google\\Longrunning\\": "metadata/Longrunning" } @@ -20,7 +19,7 @@ } }, "require-dev": { - "google/gax": "^1.38.0", + "google/gax": "2.x-dev", "phpunit/phpunit": "^9.0" } } diff --git a/LongRunning/metadata/README.md b/LongRunning/metadata/README.md deleted file mode 100644 index 1bd41550eeaf..000000000000 --- a/LongRunning/metadata/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Google Protobuf Metadata Classes - -## WARNING! - -These classes are not intended for direct use - they exist only to support -the generated protobuf classes in src/ diff --git a/LongRunning/owlbot.py b/LongRunning/owlbot.py index 667af78fe386..5cb6893c7270 100644 --- a/LongRunning/owlbot.py +++ b/LongRunning/owlbot.py @@ -41,37 +41,6 @@ version_string="longrunning", ) -# Add an alias for the previous namespace -s.replace( - "src/LongRunning/OperationsClient.php", - r"^}$\n", - r"}\n\nclass_alias('Google\\LongRunning\\OperationsClient', 'Google\\ApiCore\\LongRunning\\OperationsClient');\n") - -### [START] protoc backwards compatibility fixes - -# roll back to private properties. -s.replace( - "src/**/**/*.php", - r"Generated from protobuf field ([^\n]{0,})\n\s{5}\*/\n\s{4}protected \$", - r"""Generated from protobuf field \1 - */ - private $""") - -# prevent proto messages from being marked final -s.replace( - "src/**/**/*.php", - r"final class", - r"class") - -### [END] protoc backwards compatibility fixes - -# fix relative cloud.google.com links -s.replace( - "src/**/**/*.php", - r"(.{0,})\]\((/.{0,})\)", - r"\1](https://cloud.google.com\2)" -) - # format generated clients subprocess.run([ 'npm', diff --git a/LongRunning/samples/OperationsClient/cancel_operation.php b/LongRunning/samples/OperationsClient/cancel_operation.php new file mode 100644 index 000000000000..dbe18151d101 --- /dev/null +++ b/LongRunning/samples/OperationsClient/cancel_operation.php @@ -0,0 +1,78 @@ +setName($name); + + // Call the API and handle any network failures. + try { + $operationsClient->cancelOperation($request); + printf('Call completed successfully.' . PHP_EOL); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $name = '[NAME]'; + + cancel_operation_sample($name); +} +// [END longrunning_generated_Operations_CancelOperation_sync] diff --git a/LongRunning/samples/OperationsClient/delete_operation.php b/LongRunning/samples/OperationsClient/delete_operation.php new file mode 100644 index 000000000000..df9f1b786bf9 --- /dev/null +++ b/LongRunning/samples/OperationsClient/delete_operation.php @@ -0,0 +1,71 @@ +setName($name); + + // Call the API and handle any network failures. + try { + $operationsClient->deleteOperation($request); + printf('Call completed successfully.' . PHP_EOL); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $name = '[NAME]'; + + delete_operation_sample($name); +} +// [END longrunning_generated_Operations_DeleteOperation_sync] diff --git a/LongRunning/samples/OperationsClient/get_operation.php b/LongRunning/samples/OperationsClient/get_operation.php new file mode 100644 index 000000000000..94bf19cab621 --- /dev/null +++ b/LongRunning/samples/OperationsClient/get_operation.php @@ -0,0 +1,72 @@ +setName($name); + + // Call the API and handle any network failures. + try { + /** @var Operation $response */ + $response = $operationsClient->getOperation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $name = '[NAME]'; + + get_operation_sample($name); +} +// [END longrunning_generated_Operations_GetOperation_sync] diff --git a/LongRunning/samples/OperationsClient/list_operations.php b/LongRunning/samples/OperationsClient/list_operations.php new file mode 100644 index 000000000000..9d28b39c1ece --- /dev/null +++ b/LongRunning/samples/OperationsClient/list_operations.php @@ -0,0 +1,79 @@ +setName($name) + ->setFilter($filter); + + // Call the API and handle any network failures. + try { + /** @var PagedListResponse $response */ + $response = $operationsClient->listOperations($request); + + /** @var Operation $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $name = '[NAME]'; + $filter = '[FILTER]'; + + list_operations_sample($name, $filter); +} +// [END longrunning_generated_Operations_ListOperations_sync] diff --git a/LongRunning/samples/OperationsClient/wait_operation.php b/LongRunning/samples/OperationsClient/wait_operation.php new file mode 100644 index 000000000000..7fb5a906c208 --- /dev/null +++ b/LongRunning/samples/OperationsClient/wait_operation.php @@ -0,0 +1,65 @@ +waitOperation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END longrunning_generated_Operations_WaitOperation_sync] diff --git a/LongRunning/src/ApiCore/LongRunning/Gapic/OperationsGapicClient.php b/LongRunning/src/ApiCore/LongRunning/Gapic/OperationsGapicClient.php deleted file mode 100644 index 617c15470267..000000000000 --- a/LongRunning/src/ApiCore/LongRunning/Gapic/OperationsGapicClient.php +++ /dev/null @@ -1,16 +0,0 @@ -string name = 1; */ - private $name = ''; + protected $name = ''; /** * @param string $name The name of the operation resource to be cancelled. diff --git a/LongRunning/src/LongRunning/Client/OperationsClient.php b/LongRunning/src/LongRunning/Client/OperationsClient.php index ea86623506a4..787a39443797 100644 --- a/LongRunning/src/LongRunning/Client/OperationsClient.php +++ b/LongRunning/src/LongRunning/Client/OperationsClient.php @@ -1,6 +1,6 @@ listOperationsAsync(ListOperationsRequest $request, array $optionalArgs = []) * @method PromiseInterface waitOperationAsync(WaitOperationRequest $request, array $optionalArgs = []) */ -class OperationsClient +final class OperationsClient { use GapicClientTrait; diff --git a/LongRunning/src/LongRunning/DeleteOperationRequest.php b/LongRunning/src/LongRunning/DeleteOperationRequest.php index 4688e9f6ecad..59dd77e6b61f 100644 --- a/LongRunning/src/LongRunning/DeleteOperationRequest.php +++ b/LongRunning/src/LongRunning/DeleteOperationRequest.php @@ -21,7 +21,7 @@ class DeleteOperationRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * @param string $name The name of the operation resource to be deleted. diff --git a/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php b/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php deleted file mode 100644 index 4185fb84dc13..000000000000 --- a/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php +++ /dev/null @@ -1,493 +0,0 @@ -cancelOperation($name); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @deprecated Please use the new service client {@see \Google\LongRunning\Client\OperationsClient}. - */ -class OperationsGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.longrunning.Operations'; - - /** - * The default address of the service. - * - * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. - */ - const SERVICE_ADDRESS = 'longrunning.googleapis.com'; - - /** The address template of the service. */ - private const SERVICE_ADDRESS_TEMPLATE = 'longrunning.UNIVERSE_DOMAIN'; - - /** The default port of the service. */ - const DEFAULT_SERVICE_PORT = 443; - - /** The name of the code generator, to be included in the agent header. */ - const CODEGEN_NAME = 'gapic'; - - /** The default scopes required by the service. */ - public static $serviceScopes = []; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => - self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => - __DIR__ . '/../resources/operations_client_config.json', - 'descriptorsConfigPath' => - __DIR__ . '/../resources/operations_descriptor_config.php', - 'gcpApiConfigPath' => - __DIR__ . '/../resources/operations_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => - __DIR__ . - '/../resources/operations_rest_client_config.php', - ], - ], - ]; - } - - /** - * Constructor. - * - * @param array $options { - * Optional. Options for configuring the service API wrapper. - * - * @type string $apiEndpoint - * The address of the API remote host. May optionally include the port, formatted - * as ":". Default 'longrunning.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 $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::build()} . - * @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. By - * default this settings points to the default client config file, which is - * provided in the resources folder. - * @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 $transportConfig, and any - * $apiEndpoint 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 the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and - * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the - * supported options. - * @type callable $clientCertSource - * A callable which returns the client cert as a string. This can be used to - * provide a certificate and private key to the transport layer for mTLS. - * } - * - * @throws ValidationException - */ - public function __construct(array $options = []) - { - $clientOptions = $this->buildClientOptions($options); - $this->setClientOptions($clientOptions); - } - - /** - * Starts asynchronous cancellation on a long-running operation. The server - * makes a best effort to cancel the operation, but success is not - * guaranteed. If the server doesn't support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. Clients can use - * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or - * other methods to check whether the cancellation succeeded or whether the - * operation completed despite cancellation. On successful cancellation, - * the operation is not deleted; instead, it becomes an operation with - * an [Operation.error][google.longrunning.Operation.error] value with a - * [google.rpc.Status.code][google.rpc.Status.code] of `1`, corresponding to - * `Code.CANCELLED`. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $name = 'name'; - * $operationsClient->cancelOperation($name); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param string $name The name of the operation resource to be cancelled. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - */ - public function cancelOperation($name, array $optionalArgs = []) - { - $request = new CancelOperationRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'CancelOperation', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Deletes a long-running operation. This method indicates that the client is - * no longer interested in the operation result. It does not cancel the - * operation. If the server doesn't support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $name = 'name'; - * $operationsClient->deleteOperation($name); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param string $name The name of the operation resource to be deleted. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - */ - public function deleteOperation($name, array $optionalArgs = []) - { - $request = new DeleteOperationRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'DeleteOperation', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Gets the latest state of a long-running operation. Clients can use this - * method to poll the operation result at intervals as recommended by the API - * service. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $name = 'name'; - * $response = $operationsClient->getOperation($name); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param string $name The name of the operation resource. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\LongRunning\Operation - * - * @throws ApiException if the remote call fails - */ - public function getOperation($name, array $optionalArgs = []) - { - $request = new GetOperationRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'GetOperation', - Operation::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Lists operations that match the specified filter in the request. If the - * server doesn't support this method, it returns `UNIMPLEMENTED`. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $name = 'name'; - * $filter = 'filter'; - * // Iterate over pages of elements - * $pagedResponse = $operationsClient->listOperations($name, $filter); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $operationsClient->listOperations($name, $filter); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param string $name The name of the operation's parent resource. - * @param string $filter The standard list filter. - * @param array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type bool $returnPartialSuccess - * When set to `true`, operations that are reachable are returned as normal, - * and those that are unreachable are returned in the - * [ListOperationsResponse.unreachable] field. - * - * This can only be `true` when reading across collections e.g. when `parent` - * is set to `"projects/example/locations/-"`. - * - * This field is not by default supported and will result in an - * `UNIMPLEMENTED` error if set unless explicitly documented otherwise in - * service or product specific documentation. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listOperations($name, $filter, array $optionalArgs = []) - { - $request = new ListOperationsRequest(); - $requestParamHeaders = []; - $request->setName($name); - $request->setFilter($filter); - $requestParamHeaders['name'] = $name; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - if (isset($optionalArgs['returnPartialSuccess'])) { - $request->setReturnPartialSuccess( - $optionalArgs['returnPartialSuccess'] - ); - } - - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->getPagedListResponse( - 'ListOperations', - $optionalArgs, - ListOperationsResponse::class, - $request - ); - } - - /** - * Waits until the specified long-running operation is done or reaches at most - * a specified timeout, returning the latest state. If the operation is - * already done, the latest state is immediately returned. If the timeout - * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC - * timeout is used. If the server does not support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. - * Note that this method is on a best-effort basis. It may return the latest - * state before the specified timeout (including immediately), meaning even an - * immediate response is no guarantee that the operation is done. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $response = $operationsClient->waitOperation(); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * - * @type string $name - * The name of the operation resource to wait on. - * @type Duration $timeout - * The maximum duration to wait before timing out. If left blank, the wait - * will be at most the time permitted by the underlying HTTP/RPC protocol. - * If RPC context deadline is also specified, the shorter one will be used. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\LongRunning\Operation - * - * @throws ApiException if the remote call fails - */ - public function waitOperation(array $optionalArgs = []) - { - $request = new WaitOperationRequest(); - if (isset($optionalArgs['name'])) { - $request->setName($optionalArgs['name']); - } - - if (isset($optionalArgs['timeout'])) { - $request->setTimeout($optionalArgs['timeout']); - } - - return $this->startCall( - 'WaitOperation', - Operation::class, - $optionalArgs, - $request - )->wait(); - } -} diff --git a/LongRunning/src/LongRunning/GetOperationRequest.php b/LongRunning/src/LongRunning/GetOperationRequest.php index 3114feae4bf7..53dfb8b5e851 100644 --- a/LongRunning/src/LongRunning/GetOperationRequest.php +++ b/LongRunning/src/LongRunning/GetOperationRequest.php @@ -21,7 +21,7 @@ class GetOperationRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * @param string $name The name of the operation resource. diff --git a/LongRunning/src/LongRunning/ListOperationsRequest.php b/LongRunning/src/LongRunning/ListOperationsRequest.php index f91f63fd5333..6abe7bd540ca 100644 --- a/LongRunning/src/LongRunning/ListOperationsRequest.php +++ b/LongRunning/src/LongRunning/ListOperationsRequest.php @@ -21,25 +21,25 @@ class ListOperationsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 4; */ - private $name = ''; + protected $name = ''; /** * The standard list filter. * * Generated from protobuf field string filter = 1; */ - private $filter = ''; + protected $filter = ''; /** * The standard list page size. * * Generated from protobuf field int32 page_size = 2; */ - private $page_size = 0; + protected $page_size = 0; /** * The standard list page token. * * Generated from protobuf field string page_token = 3; */ - private $page_token = ''; + protected $page_token = ''; /** * When set to `true`, operations that are reachable are returned as normal, * and those that are unreachable are returned in the @@ -52,7 +52,7 @@ class ListOperationsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool return_partial_success = 5; */ - private $return_partial_success = false; + protected $return_partial_success = false; /** * @param string $name The name of the operation's parent resource. diff --git a/LongRunning/src/LongRunning/ListOperationsResponse.php b/LongRunning/src/LongRunning/ListOperationsResponse.php index 73cd6bb0ff5c..7aa1348e9916 100644 --- a/LongRunning/src/LongRunning/ListOperationsResponse.php +++ b/LongRunning/src/LongRunning/ListOperationsResponse.php @@ -27,7 +27,7 @@ class ListOperationsResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Unordered list. Unreachable resources. Populated when the request sets * `ListOperationsRequest.return_partial_success` and reads across diff --git a/LongRunning/src/LongRunning/Operation.php b/LongRunning/src/LongRunning/Operation.php index 2bc97a275e0a..4bb21f0edac0 100644 --- a/LongRunning/src/LongRunning/Operation.php +++ b/LongRunning/src/LongRunning/Operation.php @@ -23,7 +23,7 @@ class Operation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * Service-specific metadata associated with the operation. It typically * contains progress information and common metadata such as create time. @@ -32,7 +32,7 @@ class Operation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Any metadata = 2; */ - private $metadata = null; + protected $metadata = null; /** * If the value is `false`, it means the operation is still in progress. * If `true`, the operation is completed, and either `error` or `response` is @@ -40,7 +40,7 @@ class Operation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool done = 3; */ - private $done = false; + protected $done = false; protected $result; /** diff --git a/LongRunning/src/LongRunning/OperationInfo.php b/LongRunning/src/LongRunning/OperationInfo.php index f3dc932e5d71..e8d2bb3398a3 100644 --- a/LongRunning/src/LongRunning/OperationInfo.php +++ b/LongRunning/src/LongRunning/OperationInfo.php @@ -32,7 +32,7 @@ class OperationInfo extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string response_type = 1; */ - private $response_type = ''; + protected $response_type = ''; /** * Required. The message name of the metadata type for this long-running * operation. @@ -42,7 +42,7 @@ class OperationInfo extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string metadata_type = 2; */ - private $metadata_type = ''; + protected $metadata_type = ''; /** * Constructor. diff --git a/LongRunning/src/LongRunning/OperationsClient.php b/LongRunning/src/LongRunning/OperationsClient.php deleted file mode 100644 index 04e271747a37..000000000000 --- a/LongRunning/src/LongRunning/OperationsClient.php +++ /dev/null @@ -1,36 +0,0 @@ -_simpleRequest('/google.longrunning.Operations/ListOperations', - $argument, - ['\Google\LongRunning\ListOperationsResponse', 'decode'], - $metadata, $options); - } - - /** - * Gets the latest state of a long-running operation. Clients can use this - * method to poll the operation result at intervals as recommended by the API - * service. - * @param \Google\LongRunning\GetOperationRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function GetOperation(\Google\LongRunning\GetOperationRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.longrunning.Operations/GetOperation', - $argument, - ['\Google\LongRunning\Operation', 'decode'], - $metadata, $options); - } - - /** - * Deletes a long-running operation. This method indicates that the client is - * no longer interested in the operation result. It does not cancel the - * operation. If the server doesn't support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. - * @param \Google\LongRunning\DeleteOperationRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function DeleteOperation(\Google\LongRunning\DeleteOperationRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.longrunning.Operations/DeleteOperation', - $argument, - ['\Google\Protobuf\GPBEmpty', 'decode'], - $metadata, $options); - } - - /** - * Starts asynchronous cancellation on a long-running operation. The server - * makes a best effort to cancel the operation, but success is not - * guaranteed. If the server doesn't support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. Clients can use - * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or - * other methods to check whether the cancellation succeeded or whether the - * operation completed despite cancellation. On successful cancellation, - * the operation is not deleted; instead, it becomes an operation with - * an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, - * corresponding to `Code.CANCELLED`. - * @param \Google\LongRunning\CancelOperationRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function CancelOperation(\Google\LongRunning\CancelOperationRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.longrunning.Operations/CancelOperation', - $argument, - ['\Google\Protobuf\GPBEmpty', 'decode'], - $metadata, $options); - } - - /** - * Waits until the specified long-running operation is done or reaches at most - * a specified timeout, returning the latest state. If the operation is - * already done, the latest state is immediately returned. If the timeout - * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC - * timeout is used. If the server does not support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. - * Note that this method is on a best-effort basis. It may return the latest - * state before the specified timeout (including immediately), meaning even an - * immediate response is no guarantee that the operation is done. - * @param \Google\LongRunning\WaitOperationRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function WaitOperation(\Google\LongRunning\WaitOperationRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.longrunning.Operations/WaitOperation', - $argument, - ['\Google\LongRunning\Operation', 'decode'], - $metadata, $options); - } - -} diff --git a/LongRunning/src/LongRunning/WaitOperationRequest.php b/LongRunning/src/LongRunning/WaitOperationRequest.php index 9baf626e3412..957fff8419e3 100644 --- a/LongRunning/src/LongRunning/WaitOperationRequest.php +++ b/LongRunning/src/LongRunning/WaitOperationRequest.php @@ -21,7 +21,7 @@ class WaitOperationRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * The maximum duration to wait before timing out. If left blank, the wait * will be at most the time permitted by the underlying HTTP/RPC protocol. @@ -29,7 +29,7 @@ class WaitOperationRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Duration timeout = 2; */ - private $timeout = null; + protected $timeout = null; /** * Constructor. diff --git a/LongRunning/src/LongRunning/resources/operations_descriptor_config.php b/LongRunning/src/LongRunning/resources/operations_descriptor_config.php index a577192a83e7..8f47a3a01c5f 100644 --- a/LongRunning/src/LongRunning/resources/operations_descriptor_config.php +++ b/LongRunning/src/LongRunning/resources/operations_descriptor_config.php @@ -1,6 +1,6 @@ getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); } - /** @return \Google\LongRunning\Client\OperationsClient */ + /** @return OperationsClient */ private function createClient(array $options = []) { $options += [ 'credentials' => $this->createCredentials(), ]; - return new \Google\LongRunning\Client\OperationsClient($options); + return new OperationsClient($options); } /** @test */ diff --git a/LongRunning/tests/Unit/OperationsClientTest.php b/LongRunning/tests/Unit/OperationsClientTest.php deleted file mode 100644 index 828e560a19c1..000000000000 --- a/LongRunning/tests/Unit/OperationsClientTest.php +++ /dev/null @@ -1,366 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return \Google\LongRunning\OperationsClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new \Google\LongRunning\OperationsClient($options); - } - - /** @test */ - public function cancelOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $gapicClient->cancelOperation($name); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/CancelOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function cancelOperationExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $name = 'name3373707'; - try { - $gapicClient->cancelOperation($name); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $gapicClient->deleteOperation($name); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/DeleteOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteOperationExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $name = 'name3373707'; - try { - $gapicClient->deleteOperation($name); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $done = true; - $expectedResponse = new Operation(); - $expectedResponse->setName($name2); - $expectedResponse->setDone($done); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $response = $gapicClient->getOperation($name); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getOperationExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $name = 'name3373707'; - try { - $gapicClient->getOperation($name); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listOperationsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $operationsElement = new Operation(); - $operations = [ - $operationsElement, - ]; - $expectedResponse = new ListOperationsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setOperations($operations); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $filter = 'filter-1274492040'; - $response = $gapicClient->listOperations($name, $filter); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getOperations()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/ListOperations', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $actualValue = $actualRequestObject->getFilter(); - $this->assertProtobufEquals($filter, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listOperationsExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $name = 'name3373707'; - $filter = 'filter-1274492040'; - try { - $gapicClient->listOperations($name, $filter); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function waitOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $done = true; - $expectedResponse = new Operation(); - $expectedResponse->setName($name2); - $expectedResponse->setDone($done); - $transport->addResponse($expectedResponse); - $response = $gapicClient->waitOperation(); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/WaitOperation', $actualFuncCall); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function waitOperationExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - try { - $gapicClient->waitOperation(); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } -}