From 76fcb6cf5ca836ffe401aa19848f57bd0e3c7a00 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 24 May 2023 20:54:07 -0700 Subject: [PATCH] feat: add push config wrapper fields (#6272) PiperOrigin-RevId: 534994946 Source-Link: https://github.com/googleapis/googleapis/commit/64ecfebceee57a7fd22723d1b11b729270baf9c5 Source-Link: https://github.com/googleapis/googleapis-gen/commit/03534b3dd4c926f706729d979d893458db7e174d Copy-Tag: eyJwIjoiUHViU3ViLy5Pd2xCb3QueWFtbCIsImgiOiIwMzUzNGIzZGQ0YzkyNmY3MDY3MjlkOTc5ZDg5MzQ1OGRiN2UxNzRkIn0= --- PubSub/metadata/V1/Pubsub.php | Bin 14006 -> 14203 bytes PubSub/src/V1/AcknowledgeRequest.php | 19 + .../Client/BaseClient/PublisherBaseClient.php | 631 +++++++ .../BaseClient/SchemaServiceBaseClient.php | 577 +++++++ .../BaseClient/SubscriberBaseClient.php | 864 ++++++++++ PubSub/src/V1/Client/PublisherClient.php | 40 + PubSub/src/V1/Client/SchemaServiceClient.php | 40 + PubSub/src/V1/Client/SubscriberClient.php | 40 + PubSub/src/V1/CommitSchemaRequest.php | 17 + PubSub/src/V1/CreateSchemaRequest.php | 27 + PubSub/src/V1/CreateSnapshotRequest.php | 30 + PubSub/src/V1/DeleteSchemaRequest.php | 15 + PubSub/src/V1/DeleteSchemaRevisionRequest.php | 21 + PubSub/src/V1/DeleteSnapshotRequest.php | 15 + PubSub/src/V1/DeleteSubscriptionRequest.php | 15 + PubSub/src/V1/DeleteTopicRequest.php | 15 + PubSub/src/V1/GetSchemaRequest.php | 15 + PubSub/src/V1/GetSnapshotRequest.php | 15 + PubSub/src/V1/GetSubscriptionRequest.php | 15 + PubSub/src/V1/GetTopicRequest.php | 15 + PubSub/src/V1/ListSchemaRevisionsRequest.php | 14 + PubSub/src/V1/ListSchemasRequest.php | 15 + PubSub/src/V1/ListSnapshotsRequest.php | 15 + PubSub/src/V1/ListSubscriptionsRequest.php | 15 + PubSub/src/V1/ListTopicSnapshotsRequest.php | 15 + .../src/V1/ListTopicSubscriptionsRequest.php | 15 + PubSub/src/V1/ListTopicsRequest.php | 15 + PubSub/src/V1/ModifyAckDeadlineRequest.php | 26 + PubSub/src/V1/ModifyPushConfigRequest.php | 22 + PubSub/src/V1/PublishRequest.php | 17 + PubSub/src/V1/PullRequest.php | 46 + PubSub/src/V1/PushConfig.php | 81 + PubSub/src/V1/PushConfig/NoWrapper.php | 78 + PubSub/src/V1/PushConfig/PubsubWrapper.php | 38 + PubSub/src/V1/RollbackSchemaRequest.php | 19 + PubSub/src/V1/Subscription.php | 47 + PubSub/src/V1/Topic.php | 18 + PubSub/src/V1/UpdateSnapshotRequest.php | 16 + PubSub/src/V1/UpdateSubscriptionRequest.php | 16 + PubSub/src/V1/UpdateTopicRequest.php | 19 + PubSub/src/V1/ValidateSchemaRequest.php | 17 + .../resources/publisher_descriptor_config.php | 141 ++ .../schema_service_descriptor_config.php | 150 ++ .../subscriber_descriptor_config.php | 218 +++ .../Unit/V1/Client/PublisherClientTest.php | 941 +++++++++++ .../V1/Client/SchemaServiceClientTest.php | 1037 ++++++++++++ .../Unit/V1/Client/SubscriberClientTest.php | 1494 +++++++++++++++++ 47 files changed, 6971 insertions(+) create mode 100644 PubSub/src/V1/Client/BaseClient/PublisherBaseClient.php create mode 100644 PubSub/src/V1/Client/BaseClient/SchemaServiceBaseClient.php create mode 100644 PubSub/src/V1/Client/BaseClient/SubscriberBaseClient.php create mode 100644 PubSub/src/V1/Client/PublisherClient.php create mode 100644 PubSub/src/V1/Client/SchemaServiceClient.php create mode 100644 PubSub/src/V1/Client/SubscriberClient.php create mode 100644 PubSub/src/V1/PushConfig/NoWrapper.php create mode 100644 PubSub/src/V1/PushConfig/PubsubWrapper.php create mode 100644 PubSub/tests/Unit/V1/Client/PublisherClientTest.php create mode 100644 PubSub/tests/Unit/V1/Client/SchemaServiceClientTest.php create mode 100644 PubSub/tests/Unit/V1/Client/SubscriberClientTest.php diff --git a/PubSub/metadata/V1/Pubsub.php b/PubSub/metadata/V1/Pubsub.php index e1138e8fdd21ad76ed32aaa77532f394dcbb16b4..5df7ba5d4e3e07228bfbba15034df63c0d9be24d 100644 GIT binary patch delta 181 zcmdm%`#W#LS!Sl2X`9b8@8o0p#5}o6Xt9`(3m0EOX;N`%Qha$)VnIP_kpznZs}U08 q;wvx8EJ=;eO)W`GNi0c}U{qk#;Fz2(?8EKE$;A$J#^&w9|CIpI96cfc delta 39 xcmV+?0NDTgZnkZ(%>x3IWwXx%xefxY0+Wgoqm!`{Ka*t$GLu*o8MAy8{~}$#5E}ph diff --git a/PubSub/src/V1/AcknowledgeRequest.php b/PubSub/src/V1/AcknowledgeRequest.php index 116551825304..273d05cd30e6 100644 --- a/PubSub/src/V1/AcknowledgeRequest.php +++ b/PubSub/src/V1/AcknowledgeRequest.php @@ -31,6 +31,25 @@ class AcknowledgeRequest extends \Google\Protobuf\Internal\Message */ private $ack_ids; + /** + * @param string $subscription Required. The subscription whose message is being acknowledged. + * Format is `projects/{project}/subscriptions/{sub}`. Please see + * {@see SubscriberClient::subscriptionName()} for help formatting this field. + * @param string[] $ackIds Required. The acknowledgment ID for the messages being acknowledged that + * was returned by the Pub/Sub system in the `Pull` response. Must not be + * empty. + * + * @return \Google\Cloud\PubSub\V1\AcknowledgeRequest + * + * @experimental + */ + public static function build(string $subscription, array $ackIds): self + { + return (new self()) + ->setSubscription($subscription) + ->setAckIds($ackIds); + } + /** * Constructor. * diff --git a/PubSub/src/V1/Client/BaseClient/PublisherBaseClient.php b/PubSub/src/V1/Client/BaseClient/PublisherBaseClient.php new file mode 100644 index 000000000000..9b196bca75de --- /dev/null +++ b/PubSub/src/V1/Client/BaseClient/PublisherBaseClient.php @@ -0,0 +1,631 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/publisher_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/publisher_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/publisher_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/publisher_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * _deleted-topic_ resource. + * + * @return string The formatted _deleted-topic_ resource. + */ + public static function deletedTopicName(): string + { + return self::getPathTemplate('deletedTopic')->render([]); + } + + /** + * Formats a string containing the fully-qualified path to represent a project + * resource. + * + * @param string $project + * + * @return string The formatted project resource. + */ + public static function projectName(string $project): string + { + return self::getPathTemplate('project')->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * project_topic resource. + * + * @param string $project + * @param string $topic + * + * @return string The formatted project_topic resource. + */ + public static function projectTopicName(string $project, string $topic): string + { + return self::getPathTemplate('projectTopic')->render([ + 'project' => $project, + 'topic' => $topic, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a schema + * resource. + * + * @param string $project + * @param string $schema + * + * @return string The formatted schema resource. + */ + public static function schemaName(string $project, string $schema): string + { + return self::getPathTemplate('schema')->render([ + 'project' => $project, + 'schema' => $schema, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a subscription + * resource. + * + * @param string $project + * @param string $subscription + * + * @return string The formatted subscription resource. + */ + public static function subscriptionName(string $project, string $subscription): string + { + return self::getPathTemplate('subscription')->render([ + 'project' => $project, + 'subscription' => $subscription, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a topic + * resource. + * + * @param string $project + * @param string $topic + * + * @return string The formatted topic resource. + */ + public static function topicName(string $project, string $topic): string + { + return self::getPathTemplate('topic')->render([ + 'project' => $project, + 'topic' => $topic, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - deletedTopic: _deleted-topic_ + * - project: projects/{project} + * - projectTopic: projects/{project}/topics/{topic} + * - schema: projects/{project}/schemas/{schema} + * - subscription: projects/{project}/subscriptions/{subscription} + * - topic: projects/{project}/topics/{topic} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * 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 'pubsub.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates the given topic with the given name. See the [resource name rules] + * (https://cloud.google.com/pubsub/docs/admin#resource_names). + * + * The async variant is {@see self::createTopicAsync()} . + * + * @param Topic $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Topic + * + * @throws ApiException Thrown if the API call fails. + */ + public function createTopic(Topic $request, array $callOptions = []): Topic + { + return $this->startApiCall('CreateTopic', $request, $callOptions)->wait(); + } + + /** + * Deletes the topic with the given name. Returns `NOT_FOUND` if the topic + * does not exist. After a topic is deleted, a new topic may be created with + * the same name; this is an entirely new topic with none of the old + * configuration or subscriptions. Existing subscriptions to this topic are + * not deleted, but their `topic` field is set to `_deleted-topic_`. + * + * The async variant is {@see self::deleteTopicAsync()} . + * + * @param DeleteTopicRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Thrown if the API call fails. + */ + public function deleteTopic(DeleteTopicRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteTopic', $request, $callOptions)->wait(); + } + + /** + * Detaches a subscription from this topic. All messages retained in the + * subscription are dropped. Subsequent `Pull` and `StreamingPull` requests + * will return FAILED_PRECONDITION. If the subscription is a push + * subscription, pushes to the endpoint will stop. + * + * The async variant is {@see self::detachSubscriptionAsync()} . + * + * @param DetachSubscriptionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 DetachSubscriptionResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function detachSubscription(DetachSubscriptionRequest $request, array $callOptions = []): DetachSubscriptionResponse + { + return $this->startApiCall('DetachSubscription', $request, $callOptions)->wait(); + } + + /** + * Gets the configuration of a topic. + * + * The async variant is {@see self::getTopicAsync()} . + * + * @param GetTopicRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Topic + * + * @throws ApiException Thrown if the API call fails. + */ + public function getTopic(GetTopicRequest $request, array $callOptions = []): Topic + { + return $this->startApiCall('GetTopic', $request, $callOptions)->wait(); + } + + /** + * Lists the names of the snapshots on this topic. Snapshots are used in + * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + * which allow you to manage message acknowledgments in bulk. That is, you can + * set the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * + * The async variant is {@see self::listTopicSnapshotsAsync()} . + * + * @param ListTopicSnapshotsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listTopicSnapshots(ListTopicSnapshotsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTopicSnapshots', $request, $callOptions); + } + + /** + * Lists the names of the attached subscriptions on this topic. + * + * The async variant is {@see self::listTopicSubscriptionsAsync()} . + * + * @param ListTopicSubscriptionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listTopicSubscriptions(ListTopicSubscriptionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTopicSubscriptions', $request, $callOptions); + } + + /** + * Lists matching topics. + * + * The async variant is {@see self::listTopicsAsync()} . + * + * @param ListTopicsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listTopics(ListTopicsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTopics', $request, $callOptions); + } + + /** + * Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic + * does not exist. + * + * The async variant is {@see self::publishAsync()} . + * + * @param PublishRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PublishResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function publish(PublishRequest $request, array $callOptions = []): PublishResponse + { + return $this->startApiCall('Publish', $request, $callOptions)->wait(); + } + + /** + * Updates an existing topic. Note that certain properties of a + * topic are not modifiable. + * + * The async variant is {@see self::updateTopicAsync()} . + * + * @param UpdateTopicRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Topic + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateTopic(UpdateTopicRequest $request, array $callOptions = []): Topic + { + return $this->startApiCall('UpdateTopic', $request, $callOptions)->wait(); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/PubSub/src/V1/Client/BaseClient/SchemaServiceBaseClient.php b/PubSub/src/V1/Client/BaseClient/SchemaServiceBaseClient.php new file mode 100644 index 000000000000..fa8df6e6b1ab --- /dev/null +++ b/PubSub/src/V1/Client/BaseClient/SchemaServiceBaseClient.php @@ -0,0 +1,577 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/schema_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/schema_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/schema_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/schema_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a project + * resource. + * + * @param string $project + * + * @return string The formatted project resource. + */ + public static function projectName(string $project): string + { + return self::getPathTemplate('project')->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a schema + * resource. + * + * @param string $project + * @param string $schema + * + * @return string The formatted schema resource. + */ + public static function schemaName(string $project, string $schema): string + { + return self::getPathTemplate('schema')->render([ + 'project' => $project, + 'schema' => $schema, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - project: projects/{project} + * - schema: projects/{project}/schemas/{schema} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * 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 'pubsub.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Commits a new schema revision to an existing schema. + * + * The async variant is {@see self::commitSchemaAsync()} . + * + * @param CommitSchemaRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Schema + * + * @throws ApiException Thrown if the API call fails. + */ + public function commitSchema(CommitSchemaRequest $request, array $callOptions = []): Schema + { + return $this->startApiCall('CommitSchema', $request, $callOptions)->wait(); + } + + /** + * Creates a schema. + * + * The async variant is {@see self::createSchemaAsync()} . + * + * @param CreateSchemaRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Schema + * + * @throws ApiException Thrown if the API call fails. + */ + public function createSchema(CreateSchemaRequest $request, array $callOptions = []): Schema + { + return $this->startApiCall('CreateSchema', $request, $callOptions)->wait(); + } + + /** + * Deletes a schema. + * + * The async variant is {@see self::deleteSchemaAsync()} . + * + * @param DeleteSchemaRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Thrown if the API call fails. + */ + public function deleteSchema(DeleteSchemaRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteSchema', $request, $callOptions)->wait(); + } + + /** + * Deletes a specific schema revision. + * + * The async variant is {@see self::deleteSchemaRevisionAsync()} . + * + * @param DeleteSchemaRevisionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Schema + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteSchemaRevision(DeleteSchemaRevisionRequest $request, array $callOptions = []): Schema + { + return $this->startApiCall('DeleteSchemaRevision', $request, $callOptions)->wait(); + } + + /** + * Gets a schema. + * + * The async variant is {@see self::getSchemaAsync()} . + * + * @param GetSchemaRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Schema + * + * @throws ApiException Thrown if the API call fails. + */ + public function getSchema(GetSchemaRequest $request, array $callOptions = []): Schema + { + return $this->startApiCall('GetSchema', $request, $callOptions)->wait(); + } + + /** + * Lists all schema revisions for the named schema. + * + * The async variant is {@see self::listSchemaRevisionsAsync()} . + * + * @param ListSchemaRevisionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listSchemaRevisions(ListSchemaRevisionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListSchemaRevisions', $request, $callOptions); + } + + /** + * Lists schemas in a project. + * + * The async variant is {@see self::listSchemasAsync()} . + * + * @param ListSchemasRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listSchemas(ListSchemasRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListSchemas', $request, $callOptions); + } + + /** + * Creates a new schema revision that is a copy of the provided revision_id. + * + * The async variant is {@see self::rollbackSchemaAsync()} . + * + * @param RollbackSchemaRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Schema + * + * @throws ApiException Thrown if the API call fails. + */ + public function rollbackSchema(RollbackSchemaRequest $request, array $callOptions = []): Schema + { + return $this->startApiCall('RollbackSchema', $request, $callOptions)->wait(); + } + + /** + * Validates a message against a schema. + * + * The async variant is {@see self::validateMessageAsync()} . + * + * @param ValidateMessageRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 ValidateMessageResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function validateMessage(ValidateMessageRequest $request, array $callOptions = []): ValidateMessageResponse + { + return $this->startApiCall('ValidateMessage', $request, $callOptions)->wait(); + } + + /** + * Validates a schema. + * + * The async variant is {@see self::validateSchemaAsync()} . + * + * @param ValidateSchemaRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 ValidateSchemaResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function validateSchema(ValidateSchemaRequest $request, array $callOptions = []): ValidateSchemaResponse + { + return $this->startApiCall('ValidateSchema', $request, $callOptions)->wait(); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/PubSub/src/V1/Client/BaseClient/SubscriberBaseClient.php b/PubSub/src/V1/Client/BaseClient/SubscriberBaseClient.php new file mode 100644 index 000000000000..21ff4b451bf0 --- /dev/null +++ b/PubSub/src/V1/Client/BaseClient/SubscriberBaseClient.php @@ -0,0 +1,864 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/subscriber_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/subscriber_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/subscriber_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/subscriber_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * _deleted-topic_ resource. + * + * @return string The formatted _deleted-topic_ resource. + */ + public static function deletedTopicName(): string + { + return self::getPathTemplate('deletedTopic')->render([]); + } + + /** + * Formats a string containing the fully-qualified path to represent a project + * resource. + * + * @param string $project + * + * @return string The formatted project resource. + */ + public static function projectName(string $project): string + { + return self::getPathTemplate('project')->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * project_topic resource. + * + * @param string $project + * @param string $topic + * + * @return string The formatted project_topic resource. + */ + public static function projectTopicName(string $project, string $topic): string + { + return self::getPathTemplate('projectTopic')->render([ + 'project' => $project, + 'topic' => $topic, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a snapshot + * resource. + * + * @param string $project + * @param string $snapshot + * + * @return string The formatted snapshot resource. + */ + public static function snapshotName(string $project, string $snapshot): string + { + return self::getPathTemplate('snapshot')->render([ + 'project' => $project, + 'snapshot' => $snapshot, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a subscription + * resource. + * + * @param string $project + * @param string $subscription + * + * @return string The formatted subscription resource. + */ + public static function subscriptionName(string $project, string $subscription): string + { + return self::getPathTemplate('subscription')->render([ + 'project' => $project, + 'subscription' => $subscription, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a topic + * resource. + * + * @param string $project + * @param string $topic + * + * @return string The formatted topic resource. + */ + public static function topicName(string $project, string $topic): string + { + return self::getPathTemplate('topic')->render([ + 'project' => $project, + 'topic' => $topic, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - deletedTopic: _deleted-topic_ + * - project: projects/{project} + * - projectTopic: projects/{project}/topics/{topic} + * - snapshot: projects/{project}/snapshots/{snapshot} + * - subscription: projects/{project}/subscriptions/{subscription} + * - topic: projects/{project}/topics/{topic} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * 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 'pubsub.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Acknowledges the messages associated with the `ack_ids` in the + * `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages + * from the subscription. + * + * Acknowledging a message whose ack deadline has expired may succeed, + * but such a message may be redelivered later. Acknowledging a message more + * than once will not result in an error. + * + * The async variant is {@see self::acknowledgeAsync()} . + * + * @param AcknowledgeRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Thrown if the API call fails. + */ + public function acknowledge(AcknowledgeRequest $request, array $callOptions = []): void + { + $this->startApiCall('Acknowledge', $request, $callOptions)->wait(); + } + + /** + * Creates a snapshot from the requested subscription. Snapshots are used in + * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + * which allow you to manage message acknowledgments in bulk. That is, you can + * set the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * If the snapshot already exists, returns `ALREADY_EXISTS`. + * If the requested subscription doesn't exist, returns `NOT_FOUND`. + * If the backlog in the subscription is too old -- and the resulting snapshot + * would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned. + * See also the `Snapshot.expire_time` field. If the name is not provided in + * the request, the server will assign a random + * name for this snapshot on the same project as the subscription, conforming + * to the [resource name format] + * (https://cloud.google.com/pubsub/docs/admin#resource_names). The + * generated name is populated in the returned Snapshot object. Note that for + * REST API requests, you must specify a name in the request. + * + * The async variant is {@see self::createSnapshotAsync()} . + * + * @param CreateSnapshotRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Snapshot + * + * @throws ApiException Thrown if the API call fails. + */ + public function createSnapshot(CreateSnapshotRequest $request, array $callOptions = []): Snapshot + { + return $this->startApiCall('CreateSnapshot', $request, $callOptions)->wait(); + } + + /** + * Creates a subscription to a given topic. See the [resource name rules] + * (https://cloud.google.com/pubsub/docs/admin#resource_names). + * If the subscription already exists, returns `ALREADY_EXISTS`. + * If the corresponding topic doesn't exist, returns `NOT_FOUND`. + * + * If the name is not provided in the request, the server will assign a random + * name for this subscription on the same project as the topic, conforming + * to the [resource name format] + * (https://cloud.google.com/pubsub/docs/admin#resource_names). The generated + * name is populated in the returned Subscription object. Note that for REST + * API requests, you must specify a name in the request. + * + * The async variant is {@see self::createSubscriptionAsync()} . + * + * @param Subscription $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Subscription + * + * @throws ApiException Thrown if the API call fails. + */ + public function createSubscription(Subscription $request, array $callOptions = []): Subscription + { + return $this->startApiCall('CreateSubscription', $request, $callOptions)->wait(); + } + + /** + * Removes an existing snapshot. Snapshots are used in [Seek] + * (https://cloud.google.com/pubsub/docs/replay-overview) operations, which + * allow you to manage message acknowledgments in bulk. That is, you can set + * the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * When the snapshot is deleted, all messages retained in the snapshot + * are immediately dropped. After a snapshot is deleted, a new one may be + * created with the same name, but the new one has no association with the old + * snapshot or its subscription, unless the same subscription is specified. + * + * The async variant is {@see self::deleteSnapshotAsync()} . + * + * @param DeleteSnapshotRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Thrown if the API call fails. + */ + public function deleteSnapshot(DeleteSnapshotRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteSnapshot', $request, $callOptions)->wait(); + } + + /** + * Deletes an existing subscription. All messages retained in the subscription + * are immediately dropped. Calls to `Pull` after deletion will return + * `NOT_FOUND`. After a subscription is deleted, a new one may be created with + * the same name, but the new one has no association with the old + * subscription or its topic unless the same topic is specified. + * + * The async variant is {@see self::deleteSubscriptionAsync()} . + * + * @param DeleteSubscriptionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Thrown if the API call fails. + */ + public function deleteSubscription(DeleteSubscriptionRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteSubscription', $request, $callOptions)->wait(); + } + + /** + * Gets the configuration details of a snapshot. Snapshots are used in + * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + * which allow you to manage message acknowledgments in bulk. That is, you can + * set the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * + * The async variant is {@see self::getSnapshotAsync()} . + * + * @param GetSnapshotRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Snapshot + * + * @throws ApiException Thrown if the API call fails. + */ + public function getSnapshot(GetSnapshotRequest $request, array $callOptions = []): Snapshot + { + return $this->startApiCall('GetSnapshot', $request, $callOptions)->wait(); + } + + /** + * Gets the configuration details of a subscription. + * + * The async variant is {@see self::getSubscriptionAsync()} . + * + * @param GetSubscriptionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Subscription + * + * @throws ApiException Thrown if the API call fails. + */ + public function getSubscription(GetSubscriptionRequest $request, array $callOptions = []): Subscription + { + return $this->startApiCall('GetSubscription', $request, $callOptions)->wait(); + } + + /** + * Lists the existing snapshots. Snapshots are used in [Seek]( + * https://cloud.google.com/pubsub/docs/replay-overview) operations, which + * allow you to manage message acknowledgments in bulk. That is, you can set + * the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * + * The async variant is {@see self::listSnapshotsAsync()} . + * + * @param ListSnapshotsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listSnapshots(ListSnapshotsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListSnapshots', $request, $callOptions); + } + + /** + * Lists matching subscriptions. + * + * The async variant is {@see self::listSubscriptionsAsync()} . + * + * @param ListSubscriptionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listSubscriptions(ListSubscriptionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListSubscriptions', $request, $callOptions); + } + + /** + * Modifies the ack deadline for a specific message. This method is useful + * to indicate that more time is needed to process a message by the + * subscriber, or to make the message available for redelivery if the + * processing was interrupted. Note that this does not modify the + * subscription-level `ackDeadlineSeconds` used for subsequent messages. + * + * The async variant is {@see self::modifyAckDeadlineAsync()} . + * + * @param ModifyAckDeadlineRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Thrown if the API call fails. + */ + public function modifyAckDeadline(ModifyAckDeadlineRequest $request, array $callOptions = []): void + { + $this->startApiCall('ModifyAckDeadline', $request, $callOptions)->wait(); + } + + /** + * Modifies the `PushConfig` for a specified subscription. + * + * This may be used to change a push subscription to a pull one (signified by + * an empty `PushConfig`) or vice versa, or change the endpoint URL and other + * attributes of a push subscription. Messages will accumulate for delivery + * continuously through the call regardless of changes to the `PushConfig`. + * + * The async variant is {@see self::modifyPushConfigAsync()} . + * + * @param ModifyPushConfigRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Thrown if the API call fails. + */ + public function modifyPushConfig(ModifyPushConfigRequest $request, array $callOptions = []): void + { + $this->startApiCall('ModifyPushConfig', $request, $callOptions)->wait(); + } + + /** + * Pulls messages from the server. + * + * The async variant is {@see self::pullAsync()} . + * + * @param PullRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PullResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function pull(PullRequest $request, array $callOptions = []): PullResponse + { + return $this->startApiCall('Pull', $request, $callOptions)->wait(); + } + + /** + * Seeks an existing subscription to a point in time or to a given snapshot, + * whichever is provided in the request. Snapshots are used in [Seek] + * (https://cloud.google.com/pubsub/docs/replay-overview) operations, which + * allow you to manage message acknowledgments in bulk. That is, you can set + * the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. Note that both the subscription and the + * snapshot must be on the same topic. + * + * The async variant is {@see self::seekAsync()} . + * + * @param SeekRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 SeekResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function seek(SeekRequest $request, array $callOptions = []): SeekResponse + { + return $this->startApiCall('Seek', $request, $callOptions)->wait(); + } + + /** + * Establishes a stream with the server, which sends messages down to the + * client. The client streams acknowledgements and ack deadline modifications + * back to the server. The server will close the stream and return the status + * on any error. The server may close the stream with status `UNAVAILABLE` to + * reassign server-side resources, in which case, the client should + * re-establish the stream. Flow control can be achieved by configuring the + * underlying RPC channel. + * + * @param array $callOptions { + * Optional. + * + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return BidiStream + * + * @throws ApiException Thrown if the API call fails. + */ + public function streamingPull(array $callOptions = []): BidiStream + { + return $this->startApiCall('StreamingPull', null, $callOptions); + } + + /** + * Updates an existing snapshot. Snapshots are used in + * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + * which allow you to manage message acknowledgments in bulk. That is, you can + * set the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * + * The async variant is {@see self::updateSnapshotAsync()} . + * + * @param UpdateSnapshotRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Snapshot + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateSnapshot(UpdateSnapshotRequest $request, array $callOptions = []): Snapshot + { + return $this->startApiCall('UpdateSnapshot', $request, $callOptions)->wait(); + } + + /** + * Updates an existing subscription. Note that certain properties of a + * subscription, such as its topic, are not modifiable. + * + * The async variant is {@see self::updateSubscriptionAsync()} . + * + * @param UpdateSubscriptionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Subscription + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateSubscription(UpdateSubscriptionRequest $request, array $callOptions = []): Subscription + { + return $this->startApiCall('UpdateSubscription', $request, $callOptions)->wait(); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/PubSub/src/V1/Client/PublisherClient.php b/PubSub/src/V1/Client/PublisherClient.php new file mode 100644 index 000000000000..80f22781de9b --- /dev/null +++ b/PubSub/src/V1/Client/PublisherClient.php @@ -0,0 +1,40 @@ +setName($name) + ->setSchema($schema); + } + /** * Constructor. * diff --git a/PubSub/src/V1/CreateSchemaRequest.php b/PubSub/src/V1/CreateSchemaRequest.php index 62cce2e1828c..1ae4568d1d87 100644 --- a/PubSub/src/V1/CreateSchemaRequest.php +++ b/PubSub/src/V1/CreateSchemaRequest.php @@ -41,6 +41,33 @@ class CreateSchemaRequest extends \Google\Protobuf\Internal\Message */ private $schema_id = ''; + /** + * @param string $parent Required. The name of the project in which to create the schema. + * Format is `projects/{project-id}`. Please see + * {@see SchemaServiceClient::projectName()} for help formatting this field. + * @param \Google\Cloud\PubSub\V1\Schema $schema Required. The schema object to create. + * + * This schema's `name` parameter is ignored. The schema object returned + * by CreateSchema will have a `name` made using the given `parent` and + * `schema_id`. + * @param string $schemaId The ID to use for the schema, which will become the final component of + * the schema's resource name. + * + * See https://cloud.google.com/pubsub/docs/admin#resource_names for resource + * name constraints. + * + * @return \Google\Cloud\PubSub\V1\CreateSchemaRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\PubSub\V1\Schema $schema, string $schemaId): self + { + return (new self()) + ->setParent($parent) + ->setSchema($schema) + ->setSchemaId($schemaId); + } + /** * Constructor. * diff --git a/PubSub/src/V1/CreateSnapshotRequest.php b/PubSub/src/V1/CreateSnapshotRequest.php index f1135b343fb4..acf5a0ded21e 100644 --- a/PubSub/src/V1/CreateSnapshotRequest.php +++ b/PubSub/src/V1/CreateSnapshotRequest.php @@ -48,6 +48,36 @@ class CreateSnapshotRequest extends \Google\Protobuf\Internal\Message */ private $labels; + /** + * @param string $name Required. User-provided name for this snapshot. If the name is not provided + * in the request, the server will assign a random name for this snapshot on + * the same project as the subscription. Note that for REST API requests, you + * must specify a name. See the [resource name + * rules](https://cloud.google.com/pubsub/docs/admin#resource_names). Format + * is `projects/{project}/snapshots/{snap}`. Please see + * {@see SubscriberClient::snapshotName()} for help formatting this field. + * @param string $subscription Required. The subscription whose backlog the snapshot retains. + * Specifically, the created snapshot is guaranteed to retain: + * (a) The existing backlog on the subscription. More precisely, this is + * defined as the messages in the subscription's backlog that are + * unacknowledged upon the successful completion of the + * `CreateSnapshot` request; as well as: + * (b) Any messages published to the subscription's topic following the + * successful completion of the CreateSnapshot request. + * Format is `projects/{project}/subscriptions/{sub}`. Please see + * {@see SubscriberClient::subscriptionName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\CreateSnapshotRequest + * + * @experimental + */ + public static function build(string $name, string $subscription): self + { + return (new self()) + ->setName($name) + ->setSubscription($subscription); + } + /** * Constructor. * diff --git a/PubSub/src/V1/DeleteSchemaRequest.php b/PubSub/src/V1/DeleteSchemaRequest.php index a6d3030e8649..eb4083984436 100644 --- a/PubSub/src/V1/DeleteSchemaRequest.php +++ b/PubSub/src/V1/DeleteSchemaRequest.php @@ -23,6 +23,21 @@ class DeleteSchemaRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of the schema to delete. + * Format is `projects/{project}/schemas/{schema}`. Please see + * {@see SchemaServiceClient::schemaName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\DeleteSchemaRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/PubSub/src/V1/DeleteSchemaRevisionRequest.php b/PubSub/src/V1/DeleteSchemaRevisionRequest.php index baa78eb7bb0f..62a50169cfaf 100644 --- a/PubSub/src/V1/DeleteSchemaRevisionRequest.php +++ b/PubSub/src/V1/DeleteSchemaRevisionRequest.php @@ -33,6 +33,27 @@ class DeleteSchemaRevisionRequest extends \Google\Protobuf\Internal\Message */ protected $revision_id = ''; + /** + * @param string $name Required. The name of the schema revision to be deleted, with a revision ID + * explicitly included. + * + * Example: `projects/123/schemas/my-schema@c7cfa2a8` + * Please see {@see SchemaServiceClient::schemaName()} for help formatting this field. + * @param string $revisionId Optional. This field is deprecated and should not be used for specifying + * the revision ID. The revision ID should be specified via the `name` + * parameter. + * + * @return \Google\Cloud\PubSub\V1\DeleteSchemaRevisionRequest + * + * @experimental + */ + public static function build(string $name, string $revisionId): self + { + return (new self()) + ->setName($name) + ->setRevisionId($revisionId); + } + /** * Constructor. * diff --git a/PubSub/src/V1/DeleteSnapshotRequest.php b/PubSub/src/V1/DeleteSnapshotRequest.php index 093bc6bb4feb..af2313427339 100644 --- a/PubSub/src/V1/DeleteSnapshotRequest.php +++ b/PubSub/src/V1/DeleteSnapshotRequest.php @@ -23,6 +23,21 @@ class DeleteSnapshotRequest extends \Google\Protobuf\Internal\Message */ private $snapshot = ''; + /** + * @param string $snapshot Required. The name of the snapshot to delete. + * Format is `projects/{project}/snapshots/{snap}`. Please see + * {@see SubscriberClient::snapshotName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\DeleteSnapshotRequest + * + * @experimental + */ + public static function build(string $snapshot): self + { + return (new self()) + ->setSnapshot($snapshot); + } + /** * Constructor. * diff --git a/PubSub/src/V1/DeleteSubscriptionRequest.php b/PubSub/src/V1/DeleteSubscriptionRequest.php index dd57554c1f01..24bd06654d42 100644 --- a/PubSub/src/V1/DeleteSubscriptionRequest.php +++ b/PubSub/src/V1/DeleteSubscriptionRequest.php @@ -23,6 +23,21 @@ class DeleteSubscriptionRequest extends \Google\Protobuf\Internal\Message */ private $subscription = ''; + /** + * @param string $subscription Required. The subscription to delete. + * Format is `projects/{project}/subscriptions/{sub}`. Please see + * {@see SubscriberClient::subscriptionName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\DeleteSubscriptionRequest + * + * @experimental + */ + public static function build(string $subscription): self + { + return (new self()) + ->setSubscription($subscription); + } + /** * Constructor. * diff --git a/PubSub/src/V1/DeleteTopicRequest.php b/PubSub/src/V1/DeleteTopicRequest.php index 22cb50567bbf..a0099885c511 100644 --- a/PubSub/src/V1/DeleteTopicRequest.php +++ b/PubSub/src/V1/DeleteTopicRequest.php @@ -23,6 +23,21 @@ class DeleteTopicRequest extends \Google\Protobuf\Internal\Message */ private $topic = ''; + /** + * @param string $topic Required. Name of the topic to delete. + * Format is `projects/{project}/topics/{topic}`. Please see + * {@see PublisherClient::topicName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\DeleteTopicRequest + * + * @experimental + */ + public static function build(string $topic): self + { + return (new self()) + ->setTopic($topic); + } + /** * Constructor. * diff --git a/PubSub/src/V1/GetSchemaRequest.php b/PubSub/src/V1/GetSchemaRequest.php index c2af0c7be000..3f4518e5372e 100644 --- a/PubSub/src/V1/GetSchemaRequest.php +++ b/PubSub/src/V1/GetSchemaRequest.php @@ -30,6 +30,21 @@ class GetSchemaRequest extends \Google\Protobuf\Internal\Message */ private $view = 0; + /** + * @param string $name Required. The name of the schema to get. + * Format is `projects/{project}/schemas/{schema}`. Please see + * {@see SchemaServiceClient::schemaName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\GetSchemaRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/PubSub/src/V1/GetSnapshotRequest.php b/PubSub/src/V1/GetSnapshotRequest.php index fc109f200173..3e4288099d5c 100644 --- a/PubSub/src/V1/GetSnapshotRequest.php +++ b/PubSub/src/V1/GetSnapshotRequest.php @@ -23,6 +23,21 @@ class GetSnapshotRequest extends \Google\Protobuf\Internal\Message */ private $snapshot = ''; + /** + * @param string $snapshot Required. The name of the snapshot to get. + * Format is `projects/{project}/snapshots/{snap}`. Please see + * {@see SubscriberClient::snapshotName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\GetSnapshotRequest + * + * @experimental + */ + public static function build(string $snapshot): self + { + return (new self()) + ->setSnapshot($snapshot); + } + /** * Constructor. * diff --git a/PubSub/src/V1/GetSubscriptionRequest.php b/PubSub/src/V1/GetSubscriptionRequest.php index 9c5711579a00..131b199a5fdc 100644 --- a/PubSub/src/V1/GetSubscriptionRequest.php +++ b/PubSub/src/V1/GetSubscriptionRequest.php @@ -23,6 +23,21 @@ class GetSubscriptionRequest extends \Google\Protobuf\Internal\Message */ private $subscription = ''; + /** + * @param string $subscription Required. The name of the subscription to get. + * Format is `projects/{project}/subscriptions/{sub}`. Please see + * {@see SubscriberClient::subscriptionName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\GetSubscriptionRequest + * + * @experimental + */ + public static function build(string $subscription): self + { + return (new self()) + ->setSubscription($subscription); + } + /** * Constructor. * diff --git a/PubSub/src/V1/GetTopicRequest.php b/PubSub/src/V1/GetTopicRequest.php index e1ec48c86471..a35801bd03f6 100644 --- a/PubSub/src/V1/GetTopicRequest.php +++ b/PubSub/src/V1/GetTopicRequest.php @@ -23,6 +23,21 @@ class GetTopicRequest extends \Google\Protobuf\Internal\Message */ private $topic = ''; + /** + * @param string $topic Required. The name of the topic to get. + * Format is `projects/{project}/topics/{topic}`. Please see + * {@see PublisherClient::topicName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\GetTopicRequest + * + * @experimental + */ + public static function build(string $topic): self + { + return (new self()) + ->setTopic($topic); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ListSchemaRevisionsRequest.php b/PubSub/src/V1/ListSchemaRevisionsRequest.php index d8ebba032a2b..e7480e065f0e 100644 --- a/PubSub/src/V1/ListSchemaRevisionsRequest.php +++ b/PubSub/src/V1/ListSchemaRevisionsRequest.php @@ -43,6 +43,20 @@ class ListSchemaRevisionsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $name Required. The name of the schema to list revisions for. Please see + * {@see SchemaServiceClient::schemaName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\ListSchemaRevisionsRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ListSchemasRequest.php b/PubSub/src/V1/ListSchemasRequest.php index 354af1d13cdf..22503980fb03 100644 --- a/PubSub/src/V1/ListSchemasRequest.php +++ b/PubSub/src/V1/ListSchemasRequest.php @@ -45,6 +45,21 @@ class ListSchemasRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The name of the project in which to list schemas. + * Format is `projects/{project-id}`. Please see + * {@see SchemaServiceClient::projectName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\ListSchemasRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ListSnapshotsRequest.php b/PubSub/src/V1/ListSnapshotsRequest.php index 11d0d596242d..8622dc5e12b4 100644 --- a/PubSub/src/V1/ListSnapshotsRequest.php +++ b/PubSub/src/V1/ListSnapshotsRequest.php @@ -37,6 +37,21 @@ class ListSnapshotsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $project Required. The name of the project in which to list snapshots. + * Format is `projects/{project-id}`. Please see + * {@see SubscriberClient::projectName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\ListSnapshotsRequest + * + * @experimental + */ + public static function build(string $project): self + { + return (new self()) + ->setProject($project); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ListSubscriptionsRequest.php b/PubSub/src/V1/ListSubscriptionsRequest.php index 59ff5d9ecbd4..f80210951ed1 100644 --- a/PubSub/src/V1/ListSubscriptionsRequest.php +++ b/PubSub/src/V1/ListSubscriptionsRequest.php @@ -37,6 +37,21 @@ class ListSubscriptionsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $project Required. The name of the project in which to list subscriptions. + * Format is `projects/{project-id}`. Please see + * {@see SubscriberClient::projectName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\ListSubscriptionsRequest + * + * @experimental + */ + public static function build(string $project): self + { + return (new self()) + ->setProject($project); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ListTopicSnapshotsRequest.php b/PubSub/src/V1/ListTopicSnapshotsRequest.php index b49be4b7d5a6..2b4796b760cd 100644 --- a/PubSub/src/V1/ListTopicSnapshotsRequest.php +++ b/PubSub/src/V1/ListTopicSnapshotsRequest.php @@ -37,6 +37,21 @@ class ListTopicSnapshotsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $topic Required. The name of the topic that snapshots are attached to. + * Format is `projects/{project}/topics/{topic}`. Please see + * {@see PublisherClient::topicName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\ListTopicSnapshotsRequest + * + * @experimental + */ + public static function build(string $topic): self + { + return (new self()) + ->setTopic($topic); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ListTopicSubscriptionsRequest.php b/PubSub/src/V1/ListTopicSubscriptionsRequest.php index 1dc130ae6714..874389b6a141 100644 --- a/PubSub/src/V1/ListTopicSubscriptionsRequest.php +++ b/PubSub/src/V1/ListTopicSubscriptionsRequest.php @@ -37,6 +37,21 @@ class ListTopicSubscriptionsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $topic Required. The name of the topic that subscriptions are attached to. + * Format is `projects/{project}/topics/{topic}`. Please see + * {@see PublisherClient::topicName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\ListTopicSubscriptionsRequest + * + * @experimental + */ + public static function build(string $topic): self + { + return (new self()) + ->setTopic($topic); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ListTopicsRequest.php b/PubSub/src/V1/ListTopicsRequest.php index 6afc7b423434..a2ff6ceca7e2 100644 --- a/PubSub/src/V1/ListTopicsRequest.php +++ b/PubSub/src/V1/ListTopicsRequest.php @@ -37,6 +37,21 @@ class ListTopicsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $project Required. The name of the project in which to list topics. + * Format is `projects/{project-id}`. Please see + * {@see PublisherClient::projectName()} for help formatting this field. + * + * @return \Google\Cloud\PubSub\V1\ListTopicsRequest + * + * @experimental + */ + public static function build(string $project): self + { + return (new self()) + ->setProject($project); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ModifyAckDeadlineRequest.php b/PubSub/src/V1/ModifyAckDeadlineRequest.php index 91cef21230e5..b9d6cc87c7ff 100644 --- a/PubSub/src/V1/ModifyAckDeadlineRequest.php +++ b/PubSub/src/V1/ModifyAckDeadlineRequest.php @@ -42,6 +42,32 @@ class ModifyAckDeadlineRequest extends \Google\Protobuf\Internal\Message */ private $ack_deadline_seconds = 0; + /** + * @param string $subscription Required. The name of the subscription. + * Format is `projects/{project}/subscriptions/{sub}`. Please see + * {@see SubscriberClient::subscriptionName()} for help formatting this field. + * @param string[] $ackIds Required. List of acknowledgment IDs. + * @param int $ackDeadlineSeconds Required. The new ack deadline with respect to the time this request was + * sent to the Pub/Sub system. For example, if the value is 10, the new ack + * deadline will expire 10 seconds after the `ModifyAckDeadline` call was + * made. Specifying zero might immediately make the message available for + * delivery to another subscriber client. This typically results in an + * increase in the rate of message redeliveries (that is, duplicates). + * The minimum deadline you can specify is 0 seconds. + * The maximum deadline you can specify is 600 seconds (10 minutes). + * + * @return \Google\Cloud\PubSub\V1\ModifyAckDeadlineRequest + * + * @experimental + */ + public static function build(string $subscription, array $ackIds, int $ackDeadlineSeconds): self + { + return (new self()) + ->setSubscription($subscription) + ->setAckIds($ackIds) + ->setAckDeadlineSeconds($ackDeadlineSeconds); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ModifyPushConfigRequest.php b/PubSub/src/V1/ModifyPushConfigRequest.php index 712ddd48bccc..79b425db5925 100644 --- a/PubSub/src/V1/ModifyPushConfigRequest.php +++ b/PubSub/src/V1/ModifyPushConfigRequest.php @@ -33,6 +33,28 @@ class ModifyPushConfigRequest extends \Google\Protobuf\Internal\Message */ private $push_config = null; + /** + * @param string $subscription Required. The name of the subscription. + * Format is `projects/{project}/subscriptions/{sub}`. Please see + * {@see SubscriberClient::subscriptionName()} for help formatting this field. + * @param \Google\Cloud\PubSub\V1\PushConfig $pushConfig Required. The push configuration for future deliveries. + * + * An empty `pushConfig` indicates that the Pub/Sub system should + * stop pushing messages from the given subscription and allow + * messages to be pulled and acknowledged - effectively pausing + * the subscription if `Pull` or `StreamingPull` is not called. + * + * @return \Google\Cloud\PubSub\V1\ModifyPushConfigRequest + * + * @experimental + */ + public static function build(string $subscription, \Google\Cloud\PubSub\V1\PushConfig $pushConfig): self + { + return (new self()) + ->setSubscription($subscription) + ->setPushConfig($pushConfig); + } + /** * Constructor. * diff --git a/PubSub/src/V1/PublishRequest.php b/PubSub/src/V1/PublishRequest.php index 86a814db636d..b33ef4dbf990 100644 --- a/PubSub/src/V1/PublishRequest.php +++ b/PubSub/src/V1/PublishRequest.php @@ -29,6 +29,23 @@ class PublishRequest extends \Google\Protobuf\Internal\Message */ private $messages; + /** + * @param string $topic Required. The messages in the request will be published on this topic. + * Format is `projects/{project}/topics/{topic}`. Please see + * {@see PublisherClient::topicName()} for help formatting this field. + * @param \Google\Cloud\PubSub\V1\PubsubMessage[] $messages Required. The messages to publish. + * + * @return \Google\Cloud\PubSub\V1\PublishRequest + * + * @experimental + */ + public static function build(string $topic, array $messages): self + { + return (new self()) + ->setTopic($topic) + ->setMessages($messages); + } + /** * Constructor. * diff --git a/PubSub/src/V1/PullRequest.php b/PubSub/src/V1/PullRequest.php index 0848ec6f9d13..1e2a89a931bf 100644 --- a/PubSub/src/V1/PullRequest.php +++ b/PubSub/src/V1/PullRequest.php @@ -44,6 +44,52 @@ class PullRequest extends \Google\Protobuf\Internal\Message */ private $max_messages = 0; + /** + * @param string $subscription Required. The subscription from which messages should be pulled. + * Format is `projects/{project}/subscriptions/{sub}`. Please see + * {@see SubscriberClient::subscriptionName()} for help formatting this field. + * @param bool $returnImmediately Optional. If this field set to true, the system will respond immediately + * even if it there are no messages available to return in the `Pull` + * response. Otherwise, the system may wait (for a bounded amount of time) + * until at least one message is available, rather than returning no messages. + * Warning: setting this field to `true` is discouraged because it adversely + * impacts the performance of `Pull` operations. We recommend that users do + * not set this field. + * @param int $maxMessages Required. The maximum number of messages to return for this request. Must + * be a positive integer. The Pub/Sub system may return fewer than the number + * specified. + * + * @return \Google\Cloud\PubSub\V1\PullRequest + * + * @experimental + */ + public static function build(string $subscription, bool $returnImmediately, int $maxMessages): self + { + return (new self()) + ->setSubscription($subscription) + ->setReturnImmediately($returnImmediately) + ->setMaxMessages($maxMessages); + } + + /** + * @param string $subscription Required. The subscription from which messages should be pulled. + * Format is `projects/{project}/subscriptions/{sub}`. Please see + * {@see SubscriberClient::subscriptionName()} for help formatting this field. + * @param int $maxMessages Required. The maximum number of messages to return for this request. Must + * be a positive integer. The Pub/Sub system may return fewer than the number + * specified. + * + * @return \Google\Cloud\PubSub\V1\PullRequest + * + * @experimental + */ + public static function buildFromSubscriptionMaxMessages(string $subscription, int $maxMessages): self + { + return (new self()) + ->setSubscription($subscription) + ->setMaxMessages($maxMessages); + } + /** * Constructor. * diff --git a/PubSub/src/V1/PushConfig.php b/PubSub/src/V1/PushConfig.php index a215dfcda9ab..e9be58137944 100644 --- a/PubSub/src/V1/PushConfig.php +++ b/PubSub/src/V1/PushConfig.php @@ -44,6 +44,7 @@ class PushConfig extends \Google\Protobuf\Internal\Message */ private $attributes; protected $authentication_method; + protected $wrapper; /** * Constructor. @@ -74,6 +75,12 @@ class PushConfig extends \Google\Protobuf\Internal\Message * @type \Google\Cloud\PubSub\V1\PushConfig\OidcToken $oidc_token * If specified, Pub/Sub will generate and attach an OIDC JWT token as an * `Authorization` header in the HTTP request for every pushed message. + * @type \Google\Cloud\PubSub\V1\PushConfig\PubsubWrapper $pubsub_wrapper + * When set, the payload to the push endpoint is in the form of the JSON + * representation of a PubsubMessage + * (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage). + * @type \Google\Cloud\PubSub\V1\PushConfig\NoWrapper $no_wrapper + * When set, the payload to the push endpoint is not wrapped. * } */ public function __construct($data = NULL) { @@ -198,6 +205,72 @@ public function setOidcToken($var) return $this; } + /** + * When set, the payload to the push endpoint is in the form of the JSON + * representation of a PubsubMessage + * (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage). + * + * Generated from protobuf field .google.pubsub.v1.PushConfig.PubsubWrapper pubsub_wrapper = 4; + * @return \Google\Cloud\PubSub\V1\PushConfig\PubsubWrapper|null + */ + public function getPubsubWrapper() + { + return $this->readOneof(4); + } + + public function hasPubsubWrapper() + { + return $this->hasOneof(4); + } + + /** + * When set, the payload to the push endpoint is in the form of the JSON + * representation of a PubsubMessage + * (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage). + * + * Generated from protobuf field .google.pubsub.v1.PushConfig.PubsubWrapper pubsub_wrapper = 4; + * @param \Google\Cloud\PubSub\V1\PushConfig\PubsubWrapper $var + * @return $this + */ + public function setPubsubWrapper($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\PubSub\V1\PushConfig\PubsubWrapper::class); + $this->writeOneof(4, $var); + + return $this; + } + + /** + * When set, the payload to the push endpoint is not wrapped. + * + * Generated from protobuf field .google.pubsub.v1.PushConfig.NoWrapper no_wrapper = 5; + * @return \Google\Cloud\PubSub\V1\PushConfig\NoWrapper|null + */ + public function getNoWrapper() + { + return $this->readOneof(5); + } + + public function hasNoWrapper() + { + return $this->hasOneof(5); + } + + /** + * When set, the payload to the push endpoint is not wrapped. + * + * Generated from protobuf field .google.pubsub.v1.PushConfig.NoWrapper no_wrapper = 5; + * @param \Google\Cloud\PubSub\V1\PushConfig\NoWrapper $var + * @return $this + */ + public function setNoWrapper($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\PubSub\V1\PushConfig\NoWrapper::class); + $this->writeOneof(5, $var); + + return $this; + } + /** * @return string */ @@ -206,5 +279,13 @@ public function getAuthenticationMethod() return $this->whichOneof("authentication_method"); } + /** + * @return string + */ + public function getWrapper() + { + return $this->whichOneof("wrapper"); + } + } diff --git a/PubSub/src/V1/PushConfig/NoWrapper.php b/PubSub/src/V1/PushConfig/NoWrapper.php new file mode 100644 index 000000000000..7b1ccedf443c --- /dev/null +++ b/PubSub/src/V1/PushConfig/NoWrapper.php @@ -0,0 +1,78 @@ +google.pubsub.v1.PushConfig.NoWrapper + */ +class NoWrapper extends \Google\Protobuf\Internal\Message +{ + /** + * When true, writes the Pub/Sub message metadata to + * `x-goog-pubsub-:` headers of the HTTP request. Writes the + * Pub/Sub message attributes to `:` headers of the HTTP request. + * + * Generated from protobuf field bool write_metadata = 1; + */ + private $write_metadata = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $write_metadata + * When true, writes the Pub/Sub message metadata to + * `x-goog-pubsub-:` headers of the HTTP request. Writes the + * Pub/Sub message attributes to `:` headers of the HTTP request. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Pubsub\V1\Pubsub::initOnce(); + parent::__construct($data); + } + + /** + * When true, writes the Pub/Sub message metadata to + * `x-goog-pubsub-:` headers of the HTTP request. Writes the + * Pub/Sub message attributes to `:` headers of the HTTP request. + * + * Generated from protobuf field bool write_metadata = 1; + * @return bool + */ + public function getWriteMetadata() + { + return $this->write_metadata; + } + + /** + * When true, writes the Pub/Sub message metadata to + * `x-goog-pubsub-:` headers of the HTTP request. Writes the + * Pub/Sub message attributes to `:` headers of the HTTP request. + * + * Generated from protobuf field bool write_metadata = 1; + * @param bool $var + * @return $this + */ + public function setWriteMetadata($var) + { + GPBUtil::checkBool($var); + $this->write_metadata = $var; + + return $this; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(NoWrapper::class, \Google\Cloud\PubSub\V1\PushConfig_NoWrapper::class); + diff --git a/PubSub/src/V1/PushConfig/PubsubWrapper.php b/PubSub/src/V1/PushConfig/PubsubWrapper.php new file mode 100644 index 000000000000..5053bfb85784 --- /dev/null +++ b/PubSub/src/V1/PushConfig/PubsubWrapper.php @@ -0,0 +1,38 @@ +google.pubsub.v1.PushConfig.PubsubWrapper + */ +class PubsubWrapper extends \Google\Protobuf\Internal\Message +{ + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Pubsub\V1\Pubsub::initOnce(); + parent::__construct($data); + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(PubsubWrapper::class, \Google\Cloud\PubSub\V1\PushConfig_PubsubWrapper::class); + diff --git a/PubSub/src/V1/RollbackSchemaRequest.php b/PubSub/src/V1/RollbackSchemaRequest.php index 0ab3404e3a21..1869cac078b2 100644 --- a/PubSub/src/V1/RollbackSchemaRequest.php +++ b/PubSub/src/V1/RollbackSchemaRequest.php @@ -30,6 +30,25 @@ class RollbackSchemaRequest extends \Google\Protobuf\Internal\Message */ private $revision_id = ''; + /** + * @param string $name Required. The schema being rolled back with revision id. Please see + * {@see SchemaServiceClient::schemaName()} for help formatting this field. + * @param string $revisionId Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * + * Example: c7cfa2a8 + * + * @return \Google\Cloud\PubSub\V1\RollbackSchemaRequest + * + * @experimental + */ + public static function build(string $name, string $revisionId): self + { + return (new self()) + ->setName($name) + ->setRevisionId($revisionId); + } + /** * Constructor. * diff --git a/PubSub/src/V1/Subscription.php b/PubSub/src/V1/Subscription.php index a81474667096..0c32d9716544 100644 --- a/PubSub/src/V1/Subscription.php +++ b/PubSub/src/V1/Subscription.php @@ -205,6 +205,53 @@ class Subscription extends \Google\Protobuf\Internal\Message */ private $state = 0; + /** + * @param string $name Required. The name of the subscription. It must have the format + * `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` must + * start with a letter, and contain only letters (`[A-Za-z]`), numbers + * (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), + * plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters + * in length, and it must not start with `"goog"`. + * @param string $topic Required. The name of the topic from which this subscription is receiving + * messages. Format is `projects/{project}/topics/{topic}`. The value of this + * field will be `_deleted-topic_` if the topic has been deleted. Please see + * {@see SubscriberClient::topicName()} for help formatting this field. + * @param \Google\Cloud\PubSub\V1\PushConfig $pushConfig If push delivery is used with this subscription, this field is + * used to configure it. + * @param int $ackDeadlineSeconds The approximate amount of time (on a best-effort basis) Pub/Sub waits for + * the subscriber to acknowledge receipt before resending the message. In the + * interval after the message is delivered and before it is acknowledged, it + * is considered to be _outstanding_. During that time period, the + * message will not be redelivered (on a best-effort basis). + * + * For pull subscriptions, this value is used as the initial value for the ack + * deadline. To override this value for a given message, call + * `ModifyAckDeadline` with the corresponding `ack_id` if using + * non-streaming pull or send the `ack_id` in a + * `StreamingModifyAckDeadlineRequest` if using streaming pull. + * The minimum custom deadline you can specify is 10 seconds. + * The maximum custom deadline you can specify is 600 seconds (10 minutes). + * If this parameter is 0, a default value of 10 seconds is used. + * + * For push delivery, this value is also used to set the request timeout for + * the call to the push endpoint. + * + * If the subscriber never acknowledges the message, the Pub/Sub + * system will eventually redeliver the message. + * + * @return \Google\Cloud\PubSub\V1\Subscription + * + * @experimental + */ + public static function build(string $name, string $topic, \Google\Cloud\PubSub\V1\PushConfig $pushConfig, int $ackDeadlineSeconds): self + { + return (new self()) + ->setName($name) + ->setTopic($topic) + ->setPushConfig($pushConfig) + ->setAckDeadlineSeconds($ackDeadlineSeconds); + } + /** * Constructor. * diff --git a/PubSub/src/V1/Topic.php b/PubSub/src/V1/Topic.php index a23c9d189ebf..83240a6ef227 100644 --- a/PubSub/src/V1/Topic.php +++ b/PubSub/src/V1/Topic.php @@ -76,6 +76,24 @@ class Topic extends \Google\Protobuf\Internal\Message */ private $message_retention_duration = null; + /** + * @param string $name Required. The name of the topic. It must have the format + * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, + * and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), + * underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent + * signs (`%`). It must be between 3 and 255 characters in length, and it + * must not start with `"goog"`. + * + * @return \Google\Cloud\PubSub\V1\Topic + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/PubSub/src/V1/UpdateSnapshotRequest.php b/PubSub/src/V1/UpdateSnapshotRequest.php index 8e2d217b8e87..cdfff99dca8d 100644 --- a/PubSub/src/V1/UpdateSnapshotRequest.php +++ b/PubSub/src/V1/UpdateSnapshotRequest.php @@ -29,6 +29,22 @@ class UpdateSnapshotRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\PubSub\V1\Snapshot $snapshot Required. The updated snapshot object. + * @param \Google\Protobuf\FieldMask $updateMask Required. Indicates which fields in the provided snapshot to update. + * Must be specified and non-empty. + * + * @return \Google\Cloud\PubSub\V1\UpdateSnapshotRequest + * + * @experimental + */ + public static function build(\Google\Cloud\PubSub\V1\Snapshot $snapshot, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setSnapshot($snapshot) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/PubSub/src/V1/UpdateSubscriptionRequest.php b/PubSub/src/V1/UpdateSubscriptionRequest.php index 77e580ac70f4..ffcf6c63fdbc 100644 --- a/PubSub/src/V1/UpdateSubscriptionRequest.php +++ b/PubSub/src/V1/UpdateSubscriptionRequest.php @@ -29,6 +29,22 @@ class UpdateSubscriptionRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\PubSub\V1\Subscription $subscription Required. The updated subscription object. + * @param \Google\Protobuf\FieldMask $updateMask Required. Indicates which fields in the provided subscription to update. + * Must be specified and non-empty. + * + * @return \Google\Cloud\PubSub\V1\UpdateSubscriptionRequest + * + * @experimental + */ + public static function build(\Google\Cloud\PubSub\V1\Subscription $subscription, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setSubscription($subscription) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/PubSub/src/V1/UpdateTopicRequest.php b/PubSub/src/V1/UpdateTopicRequest.php index 3aac68f959f7..98987675eb5b 100644 --- a/PubSub/src/V1/UpdateTopicRequest.php +++ b/PubSub/src/V1/UpdateTopicRequest.php @@ -32,6 +32,25 @@ class UpdateTopicRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\PubSub\V1\Topic $topic Required. The updated topic object. + * @param \Google\Protobuf\FieldMask $updateMask Required. Indicates which fields in the provided topic to update. Must be + * specified and non-empty. Note that if `update_mask` contains + * "message_storage_policy" but the `message_storage_policy` is not set in + * the `topic` provided above, then the updated value is determined by the + * policy configured at the project or organization level. + * + * @return \Google\Cloud\PubSub\V1\UpdateTopicRequest + * + * @experimental + */ + public static function build(\Google\Cloud\PubSub\V1\Topic $topic, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setTopic($topic) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/PubSub/src/V1/ValidateSchemaRequest.php b/PubSub/src/V1/ValidateSchemaRequest.php index 52ea62f1db86..17ddac3c369b 100644 --- a/PubSub/src/V1/ValidateSchemaRequest.php +++ b/PubSub/src/V1/ValidateSchemaRequest.php @@ -29,6 +29,23 @@ class ValidateSchemaRequest extends \Google\Protobuf\Internal\Message */ private $schema = null; + /** + * @param string $parent Required. The name of the project in which to validate schemas. + * Format is `projects/{project-id}`. Please see + * {@see SchemaServiceClient::projectName()} for help formatting this field. + * @param \Google\Cloud\PubSub\V1\Schema $schema Required. The schema object to validate. + * + * @return \Google\Cloud\PubSub\V1\ValidateSchemaRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\PubSub\V1\Schema $schema): self + { + return (new self()) + ->setParent($parent) + ->setSchema($schema); + } + /** * Constructor. * diff --git a/PubSub/src/V1/resources/publisher_descriptor_config.php b/PubSub/src/V1/resources/publisher_descriptor_config.php index 04010462cdfc..a40d4dbdf363 100644 --- a/PubSub/src/V1/resources/publisher_descriptor_config.php +++ b/PubSub/src/V1/resources/publisher_descriptor_config.php @@ -3,6 +3,54 @@ return [ 'interfaces' => [ 'google.pubsub.v1.Publisher' => [ + 'CreateTopic' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Topic', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteTopic' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'topic', + 'fieldAccessors' => [ + 'getTopic', + ], + ], + ], + ], + 'DetachSubscription' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\DetachSubscriptionResponse', + 'headerParams' => [ + [ + 'keyName' => 'subscription', + 'fieldAccessors' => [ + 'getSubscription', + ], + ], + ], + ], + 'GetTopic' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Topic', + 'headerParams' => [ + [ + 'keyName' => 'topic', + 'fieldAccessors' => [ + 'getTopic', + ], + ], + ], + ], 'ListTopicSnapshots' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +60,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSnapshots', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ListTopicSnapshotsResponse', + 'headerParams' => [ + [ + 'keyName' => 'topic', + 'fieldAccessors' => [ + 'getTopic', + ], + ], + ], ], 'ListTopicSubscriptions' => [ 'pageStreaming' => [ @@ -22,6 +80,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSubscriptions', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ListTopicSubscriptionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'topic', + 'fieldAccessors' => [ + 'getTopic', + ], + ], + ], ], 'ListTopics' => [ 'pageStreaming' => [ @@ -32,16 +100,89 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getTopics', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ListTopicsResponse', + 'headerParams' => [ + [ + 'keyName' => 'project', + 'fieldAccessors' => [ + 'getProject', + ], + ], + ], + ], + 'Publish' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\PublishResponse', + 'headerParams' => [ + [ + 'keyName' => 'topic', + 'fieldAccessors' => [ + 'getTopic', + ], + ], + ], + ], + 'UpdateTopic' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Topic', + 'headerParams' => [ + [ + 'keyName' => 'topic.name', + 'fieldAccessors' => [ + 'getTopic', + 'getName', + ], + ], + ], ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'deletedTopic' => '_deleted-topic_', + 'project' => 'projects/{project}', + 'projectTopic' => 'projects/{project}/topics/{topic}', + 'schema' => 'projects/{project}/schemas/{schema}', + 'subscription' => 'projects/{project}/subscriptions/{subscription}', + 'topic' => 'projects/{project}/topics/{topic}', + ], ], ], ]; diff --git a/PubSub/src/V1/resources/schema_service_descriptor_config.php b/PubSub/src/V1/resources/schema_service_descriptor_config.php index 38d7b0ff4d9a..419ce2442082 100644 --- a/PubSub/src/V1/resources/schema_service_descriptor_config.php +++ b/PubSub/src/V1/resources/schema_service_descriptor_config.php @@ -3,6 +3,66 @@ return [ 'interfaces' => [ 'google.pubsub.v1.SchemaService' => [ + 'CommitSchema' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Schema', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'CreateSchema' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Schema', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteSchema' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteSchemaRevision' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Schema', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetSchema' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Schema', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListSchemaRevisions' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +72,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSchemas', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ListSchemaRevisionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListSchemas' => [ 'pageStreaming' => [ @@ -22,16 +92,96 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSchemas', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ListSchemasResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'RollbackSchema' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Schema', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'ValidateMessage' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ValidateMessageResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ValidateSchema' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ValidateSchemaResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'project' => 'projects/{project}', + 'schema' => 'projects/{project}/schemas/{schema}', + ], ], ], ]; diff --git a/PubSub/src/V1/resources/subscriber_descriptor_config.php b/PubSub/src/V1/resources/subscriber_descriptor_config.php index cb7e2184ca43..497c2fd7960e 100644 --- a/PubSub/src/V1/resources/subscriber_descriptor_config.php +++ b/PubSub/src/V1/resources/subscriber_descriptor_config.php @@ -3,6 +3,90 @@ return [ 'interfaces' => [ 'google.pubsub.v1.Subscriber' => [ + 'Acknowledge' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'subscription', + 'fieldAccessors' => [ + 'getSubscription', + ], + ], + ], + ], + 'CreateSnapshot' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Snapshot', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'CreateSubscription' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Subscription', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteSnapshot' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'snapshot', + 'fieldAccessors' => [ + 'getSnapshot', + ], + ], + ], + ], + 'DeleteSubscription' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'subscription', + 'fieldAccessors' => [ + 'getSubscription', + ], + ], + ], + ], + 'GetSnapshot' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Snapshot', + 'headerParams' => [ + [ + 'keyName' => 'snapshot', + 'fieldAccessors' => [ + 'getSnapshot', + ], + ], + ], + ], + 'GetSubscription' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Subscription', + 'headerParams' => [ + [ + 'keyName' => 'subscription', + 'fieldAccessors' => [ + 'getSubscription', + ], + ], + ], + ], 'ListSnapshots' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +96,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSnapshots', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ListSnapshotsResponse', + 'headerParams' => [ + [ + 'keyName' => 'project', + 'fieldAccessors' => [ + 'getProject', + ], + ], + ], ], 'ListSubscriptions' => [ 'pageStreaming' => [ @@ -22,21 +116,145 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSubscriptions', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\ListSubscriptionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'project', + 'fieldAccessors' => [ + 'getProject', + ], + ], + ], + ], + 'ModifyAckDeadline' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'subscription', + 'fieldAccessors' => [ + 'getSubscription', + ], + ], + ], + ], + 'ModifyPushConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'subscription', + 'fieldAccessors' => [ + 'getSubscription', + ], + ], + ], + ], + 'Pull' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\PullResponse', + 'headerParams' => [ + [ + 'keyName' => 'subscription', + 'fieldAccessors' => [ + 'getSubscription', + ], + ], + ], + ], + 'Seek' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\SeekResponse', + 'headerParams' => [ + [ + 'keyName' => 'subscription', + 'fieldAccessors' => [ + 'getSubscription', + ], + ], + ], ], 'StreamingPull' => [ 'grpcStreaming' => [ 'grpcStreamingType' => 'BidiStreaming', ], + 'callType' => \Google\ApiCore\Call::BIDI_STREAMING_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\StreamingPullResponse', + ], + 'UpdateSnapshot' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Snapshot', + 'headerParams' => [ + [ + 'keyName' => 'snapshot.name', + 'fieldAccessors' => [ + 'getSnapshot', + 'getName', + ], + ], + ], + ], + 'UpdateSubscription' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\PubSub\V1\Subscription', + 'headerParams' => [ + [ + 'keyName' => 'subscription.name', + 'fieldAccessors' => [ + 'getSubscription', + 'getName', + ], + ], + ], ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'deletedTopic' => '_deleted-topic_', + 'project' => 'projects/{project}', + 'projectTopic' => 'projects/{project}/topics/{topic}', + 'snapshot' => 'projects/{project}/snapshots/{snapshot}', + 'subscription' => 'projects/{project}/subscriptions/{subscription}', + 'topic' => 'projects/{project}/topics/{topic}', + ], ], ], ]; diff --git a/PubSub/tests/Unit/V1/Client/PublisherClientTest.php b/PubSub/tests/Unit/V1/Client/PublisherClientTest.php new file mode 100644 index 000000000000..0bd73b8bd560 --- /dev/null +++ b/PubSub/tests/Unit/V1/Client/PublisherClientTest.php @@ -0,0 +1,941 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return PublisherClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new PublisherClient($options); + } + + /** @test */ + public function createTopicTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $kmsKeyName2 = 'kmsKeyName2-1057489140'; + $satisfiesPzs2 = true; + $expectedResponse = new Topic(); + $expectedResponse->setName($name2); + $expectedResponse->setKmsKeyName($kmsKeyName2); + $expectedResponse->setSatisfiesPzs($satisfiesPzs2); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $request = (new Topic()) + ->setName($name); + $response = $gapicClient->createTopic($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/CreateTopic', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createTopicExceptionTest() + { + $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'; + $request = (new Topic()) + ->setName($name); + try { + $gapicClient->createTopic($request); + // 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 deleteTopicTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new DeleteTopicRequest()) + ->setTopic($formattedTopic); + $gapicClient->deleteTopic($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/DeleteTopic', $actualFuncCall); + $actualValue = $actualRequestObject->getTopic(); + $this->assertProtobufEquals($formattedTopic, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteTopicExceptionTest() + { + $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 + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new DeleteTopicRequest()) + ->setTopic($formattedTopic); + try { + $gapicClient->deleteTopic($request); + // 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 detachSubscriptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new DetachSubscriptionResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new DetachSubscriptionRequest()) + ->setSubscription($formattedSubscription); + $response = $gapicClient->detachSubscription($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/DetachSubscription', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function detachSubscriptionExceptionTest() + { + $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 + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new DetachSubscriptionRequest()) + ->setSubscription($formattedSubscription); + try { + $gapicClient->detachSubscription($request); + // 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 getTopicTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $kmsKeyName = 'kmsKeyName2094986649'; + $satisfiesPzs = false; + $expectedResponse = new Topic(); + $expectedResponse->setName($name); + $expectedResponse->setKmsKeyName($kmsKeyName); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new GetTopicRequest()) + ->setTopic($formattedTopic); + $response = $gapicClient->getTopic($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/GetTopic', $actualFuncCall); + $actualValue = $actualRequestObject->getTopic(); + $this->assertProtobufEquals($formattedTopic, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTopicExceptionTest() + { + $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 + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new GetTopicRequest()) + ->setTopic($formattedTopic); + try { + $gapicClient->getTopic($request); + // 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 listTopicSnapshotsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $snapshotsElement = 'snapshotsElement1339034092'; + $snapshots = [ + $snapshotsElement, + ]; + $expectedResponse = new ListTopicSnapshotsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSnapshots($snapshots); + $transport->addResponse($expectedResponse); + // Mock request + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new ListTopicSnapshotsRequest()) + ->setTopic($formattedTopic); + $response = $gapicClient->listTopicSnapshots($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSnapshots()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/ListTopicSnapshots', $actualFuncCall); + $actualValue = $actualRequestObject->getTopic(); + $this->assertProtobufEquals($formattedTopic, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTopicSnapshotsExceptionTest() + { + $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 + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new ListTopicSnapshotsRequest()) + ->setTopic($formattedTopic); + try { + $gapicClient->listTopicSnapshots($request); + // 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 listTopicSubscriptionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $subscriptionsElement = 'subscriptionsElement1698708147'; + $subscriptions = [ + $subscriptionsElement, + ]; + $expectedResponse = new ListTopicSubscriptionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSubscriptions($subscriptions); + $transport->addResponse($expectedResponse); + // Mock request + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new ListTopicSubscriptionsRequest()) + ->setTopic($formattedTopic); + $response = $gapicClient->listTopicSubscriptions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSubscriptions()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/ListTopicSubscriptions', $actualFuncCall); + $actualValue = $actualRequestObject->getTopic(); + $this->assertProtobufEquals($formattedTopic, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTopicSubscriptionsExceptionTest() + { + $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 + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new ListTopicSubscriptionsRequest()) + ->setTopic($formattedTopic); + try { + $gapicClient->listTopicSubscriptions($request); + // 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 listTopicsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $topicsElement = new Topic(); + $topics = [ + $topicsElement, + ]; + $expectedResponse = new ListTopicsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTopics($topics); + $transport->addResponse($expectedResponse); + // Mock request + $formattedProject = $gapicClient->projectName('[PROJECT]'); + $request = (new ListTopicsRequest()) + ->setProject($formattedProject); + $response = $gapicClient->listTopics($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTopics()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/ListTopics', $actualFuncCall); + $actualValue = $actualRequestObject->getProject(); + $this->assertProtobufEquals($formattedProject, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTopicsExceptionTest() + { + $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 + $formattedProject = $gapicClient->projectName('[PROJECT]'); + $request = (new ListTopicsRequest()) + ->setProject($formattedProject); + try { + $gapicClient->listTopics($request); + // 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 publishTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new PublishResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $messages = []; + $request = (new PublishRequest()) + ->setTopic($formattedTopic) + ->setMessages($messages); + $response = $gapicClient->publish($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/Publish', $actualFuncCall); + $actualValue = $actualRequestObject->getTopic(); + $this->assertProtobufEquals($formattedTopic, $actualValue); + $actualValue = $actualRequestObject->getMessages(); + $this->assertProtobufEquals($messages, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function publishExceptionTest() + { + $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 + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $messages = []; + $request = (new PublishRequest()) + ->setTopic($formattedTopic) + ->setMessages($messages); + try { + $gapicClient->publish($request); + // 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 updateTopicTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $kmsKeyName = 'kmsKeyName2094986649'; + $satisfiesPzs = false; + $expectedResponse = new Topic(); + $expectedResponse->setName($name); + $expectedResponse->setKmsKeyName($kmsKeyName); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $transport->addResponse($expectedResponse); + // Mock request + $topic = new Topic(); + $topicName = 'topicName388205658'; + $topic->setName($topicName); + $updateMask = new FieldMask(); + $request = (new UpdateTopicRequest()) + ->setTopic($topic) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateTopic($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/UpdateTopic', $actualFuncCall); + $actualValue = $actualRequestObject->getTopic(); + $this->assertProtobufEquals($topic, $actualValue); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateTopicExceptionTest() + { + $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 + $topic = new Topic(); + $topicName = 'topicName388205658'; + $topic->setName($topicName); + $updateMask = new FieldMask(); + $request = (new UpdateTopicRequest()) + ->setTopic($topic) + ->setUpdateMask($updateMask); + try { + $gapicClient->updateTopic($request); + // 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 getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // 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 setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // 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 testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // 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 createTopicAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $kmsKeyName2 = 'kmsKeyName2-1057489140'; + $satisfiesPzs2 = true; + $expectedResponse = new Topic(); + $expectedResponse->setName($name2); + $expectedResponse->setKmsKeyName($kmsKeyName2); + $expectedResponse->setSatisfiesPzs($satisfiesPzs2); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $request = (new Topic()) + ->setName($name); + $response = $gapicClient->createTopicAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Publisher/CreateTopic', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/PubSub/tests/Unit/V1/Client/SchemaServiceClientTest.php b/PubSub/tests/Unit/V1/Client/SchemaServiceClientTest.php new file mode 100644 index 000000000000..f3d4617842e0 --- /dev/null +++ b/PubSub/tests/Unit/V1/Client/SchemaServiceClientTest.php @@ -0,0 +1,1037 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return SchemaServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new SchemaServiceClient($options); + } + + /** @test */ + public function commitSchemaTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $definition = 'definition-1014418093'; + $revisionId = 'revisionId513861631'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name2); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + $request = (new CommitSchemaRequest()) + ->setName($formattedName) + ->setSchema($schema); + $response = $gapicClient->commitSchema($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/CommitSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getSchema(); + $this->assertProtobufEquals($schema, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function commitSchemaExceptionTest() + { + $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 + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + $request = (new CommitSchemaRequest()) + ->setName($formattedName) + ->setSchema($schema); + try { + $gapicClient->commitSchema($request); + // 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 createSchemaTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $definition = 'definition-1014418093'; + $revisionId = 'revisionId513861631'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + $request = (new CreateSchemaRequest()) + ->setParent($formattedParent) + ->setSchema($schema); + $response = $gapicClient->createSchema($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/CreateSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getSchema(); + $this->assertProtobufEquals($schema, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createSchemaExceptionTest() + { + $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 + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + $request = (new CreateSchemaRequest()) + ->setParent($formattedParent) + ->setSchema($schema); + try { + $gapicClient->createSchema($request); + // 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 deleteSchemaTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $request = (new DeleteSchemaRequest()) + ->setName($formattedName); + $gapicClient->deleteSchema($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/DeleteSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteSchemaExceptionTest() + { + $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 + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $request = (new DeleteSchemaRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteSchema($request); + // 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 deleteSchemaRevisionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $definition = 'definition-1014418093'; + $revisionId2 = 'revisionId2-100208654'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name2); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = 'revisionId513861631'; + $request = (new DeleteSchemaRevisionRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + $response = $gapicClient->deleteSchemaRevision($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/DeleteSchemaRevision', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getRevisionId(); + $this->assertProtobufEquals($revisionId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteSchemaRevisionExceptionTest() + { + $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 + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = 'revisionId513861631'; + $request = (new DeleteSchemaRevisionRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + try { + $gapicClient->deleteSchemaRevision($request); + // 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 getSchemaTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $definition = 'definition-1014418093'; + $revisionId = 'revisionId513861631'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name2); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $request = (new GetSchemaRequest()) + ->setName($formattedName); + $response = $gapicClient->getSchema($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/GetSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSchemaExceptionTest() + { + $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 + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $request = (new GetSchemaRequest()) + ->setName($formattedName); + try { + $gapicClient->getSchema($request); + // 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 listSchemaRevisionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $schemasElement = new Schema(); + $schemas = [ + $schemasElement, + ]; + $expectedResponse = new ListSchemaRevisionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSchemas($schemas); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $request = (new ListSchemaRevisionsRequest()) + ->setName($formattedName); + $response = $gapicClient->listSchemaRevisions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSchemas()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/ListSchemaRevisions', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSchemaRevisionsExceptionTest() + { + $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 + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $request = (new ListSchemaRevisionsRequest()) + ->setName($formattedName); + try { + $gapicClient->listSchemaRevisions($request); + // 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 listSchemasTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $schemasElement = new Schema(); + $schemas = [ + $schemasElement, + ]; + $expectedResponse = new ListSchemasResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSchemas($schemas); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListSchemasRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listSchemas($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSchemas()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/ListSchemas', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSchemasExceptionTest() + { + $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 + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ListSchemasRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listSchemas($request); + // 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 rollbackSchemaTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $definition = 'definition-1014418093'; + $revisionId2 = 'revisionId2-100208654'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name2); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = 'revisionId513861631'; + $request = (new RollbackSchemaRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + $response = $gapicClient->rollbackSchema($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/RollbackSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getRevisionId(); + $this->assertProtobufEquals($revisionId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function rollbackSchemaExceptionTest() + { + $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 + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $revisionId = 'revisionId513861631'; + $request = (new RollbackSchemaRequest()) + ->setName($formattedName) + ->setRevisionId($revisionId); + try { + $gapicClient->rollbackSchema($request); + // 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 validateMessageTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new ValidateMessageResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ValidateMessageRequest()) + ->setParent($formattedParent); + $response = $gapicClient->validateMessage($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/ValidateMessage', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function validateMessageExceptionTest() + { + $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 + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $request = (new ValidateMessageRequest()) + ->setParent($formattedParent); + try { + $gapicClient->validateMessage($request); + // 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 validateSchemaTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new ValidateSchemaResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + $request = (new ValidateSchemaRequest()) + ->setParent($formattedParent) + ->setSchema($schema); + $response = $gapicClient->validateSchema($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/ValidateSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getSchema(); + $this->assertProtobufEquals($schema, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function validateSchemaExceptionTest() + { + $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 + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + $request = (new ValidateSchemaRequest()) + ->setParent($formattedParent) + ->setSchema($schema); + try { + $gapicClient->validateSchema($request); + // 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 getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // 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 setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // 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 testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // 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 commitSchemaAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $definition = 'definition-1014418093'; + $revisionId = 'revisionId513861631'; + $expectedResponse = new Schema(); + $expectedResponse->setName($name2); + $expectedResponse->setDefinition($definition); + $expectedResponse->setRevisionId($revisionId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->schemaName('[PROJECT]', '[SCHEMA]'); + $schema = new Schema(); + $schemaName = 'schemaName-448762932'; + $schema->setName($schemaName); + $request = (new CommitSchemaRequest()) + ->setName($formattedName) + ->setSchema($schema); + $response = $gapicClient->commitSchemaAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.SchemaService/CommitSchema', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getSchema(); + $this->assertProtobufEquals($schema, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/PubSub/tests/Unit/V1/Client/SubscriberClientTest.php b/PubSub/tests/Unit/V1/Client/SubscriberClientTest.php new file mode 100644 index 000000000000..6bc7cdf9d606 --- /dev/null +++ b/PubSub/tests/Unit/V1/Client/SubscriberClientTest.php @@ -0,0 +1,1494 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return SubscriberClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new SubscriberClient($options); + } + + /** @test */ + public function acknowledgeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $ackIds = []; + $request = (new AcknowledgeRequest()) + ->setSubscription($formattedSubscription) + ->setAckIds($ackIds); + $gapicClient->acknowledge($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/Acknowledge', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $actualValue = $actualRequestObject->getAckIds(); + $this->assertProtobufEquals($ackIds, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function acknowledgeExceptionTest() + { + $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 + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $ackIds = []; + $request = (new AcknowledgeRequest()) + ->setSubscription($formattedSubscription) + ->setAckIds($ackIds); + try { + $gapicClient->acknowledge($request); + // 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 createSnapshotTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $topic = 'topic110546223'; + $expectedResponse = new Snapshot(); + $expectedResponse->setName($name2); + $expectedResponse->setTopic($topic); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->snapshotName('[PROJECT]', '[SNAPSHOT]'); + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new CreateSnapshotRequest()) + ->setName($formattedName) + ->setSubscription($formattedSubscription); + $response = $gapicClient->createSnapshot($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/CreateSnapshot', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createSnapshotExceptionTest() + { + $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 + $formattedName = $gapicClient->snapshotName('[PROJECT]', '[SNAPSHOT]'); + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new CreateSnapshotRequest()) + ->setName($formattedName) + ->setSubscription($formattedSubscription); + try { + $gapicClient->createSnapshot($request); + // 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 createSubscriptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $topic2 = 'topic2-1139259102'; + $ackDeadlineSeconds2 = 921632575; + $retainAckedMessages2 = true; + $enableMessageOrdering2 = false; + $filter2 = 'filter2-721168085'; + $detached2 = false; + $enableExactlyOnceDelivery2 = true; + $expectedResponse = new Subscription(); + $expectedResponse->setName($name2); + $expectedResponse->setTopic($topic2); + $expectedResponse->setAckDeadlineSeconds($ackDeadlineSeconds2); + $expectedResponse->setRetainAckedMessages($retainAckedMessages2); + $expectedResponse->setEnableMessageOrdering($enableMessageOrdering2); + $expectedResponse->setFilter($filter2); + $expectedResponse->setDetached($detached2); + $expectedResponse->setEnableExactlyOnceDelivery($enableExactlyOnceDelivery2); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new Subscription()) + ->setName($name) + ->setTopic($formattedTopic); + $response = $gapicClient->createSubscription($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/CreateSubscription', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $actualValue = $actualRequestObject->getTopic(); + $this->assertProtobufEquals($formattedTopic, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createSubscriptionExceptionTest() + { + $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'; + $formattedTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $request = (new Subscription()) + ->setName($name) + ->setTopic($formattedTopic); + try { + $gapicClient->createSubscription($request); + // 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 deleteSnapshotTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSnapshot = $gapicClient->snapshotName('[PROJECT]', '[SNAPSHOT]'); + $request = (new DeleteSnapshotRequest()) + ->setSnapshot($formattedSnapshot); + $gapicClient->deleteSnapshot($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/DeleteSnapshot', $actualFuncCall); + $actualValue = $actualRequestObject->getSnapshot(); + $this->assertProtobufEquals($formattedSnapshot, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteSnapshotExceptionTest() + { + $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 + $formattedSnapshot = $gapicClient->snapshotName('[PROJECT]', '[SNAPSHOT]'); + $request = (new DeleteSnapshotRequest()) + ->setSnapshot($formattedSnapshot); + try { + $gapicClient->deleteSnapshot($request); + // 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 deleteSubscriptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new DeleteSubscriptionRequest()) + ->setSubscription($formattedSubscription); + $gapicClient->deleteSubscription($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/DeleteSubscription', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteSubscriptionExceptionTest() + { + $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 + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new DeleteSubscriptionRequest()) + ->setSubscription($formattedSubscription); + try { + $gapicClient->deleteSubscription($request); + // 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 getSnapshotTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $topic = 'topic110546223'; + $expectedResponse = new Snapshot(); + $expectedResponse->setName($name); + $expectedResponse->setTopic($topic); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSnapshot = $gapicClient->snapshotName('[PROJECT]', '[SNAPSHOT]'); + $request = (new GetSnapshotRequest()) + ->setSnapshot($formattedSnapshot); + $response = $gapicClient->getSnapshot($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/GetSnapshot', $actualFuncCall); + $actualValue = $actualRequestObject->getSnapshot(); + $this->assertProtobufEquals($formattedSnapshot, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSnapshotExceptionTest() + { + $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 + $formattedSnapshot = $gapicClient->snapshotName('[PROJECT]', '[SNAPSHOT]'); + $request = (new GetSnapshotRequest()) + ->setSnapshot($formattedSnapshot); + try { + $gapicClient->getSnapshot($request); + // 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 getSubscriptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $topic = 'topic110546223'; + $ackDeadlineSeconds = 2135351438; + $retainAckedMessages = false; + $enableMessageOrdering = true; + $filter = 'filter-1274492040'; + $detached = true; + $enableExactlyOnceDelivery = false; + $expectedResponse = new Subscription(); + $expectedResponse->setName($name); + $expectedResponse->setTopic($topic); + $expectedResponse->setAckDeadlineSeconds($ackDeadlineSeconds); + $expectedResponse->setRetainAckedMessages($retainAckedMessages); + $expectedResponse->setEnableMessageOrdering($enableMessageOrdering); + $expectedResponse->setFilter($filter); + $expectedResponse->setDetached($detached); + $expectedResponse->setEnableExactlyOnceDelivery($enableExactlyOnceDelivery); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new GetSubscriptionRequest()) + ->setSubscription($formattedSubscription); + $response = $gapicClient->getSubscription($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/GetSubscription', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSubscriptionExceptionTest() + { + $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 + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new GetSubscriptionRequest()) + ->setSubscription($formattedSubscription); + try { + $gapicClient->getSubscription($request); + // 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 listSnapshotsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $snapshotsElement = new Snapshot(); + $snapshots = [ + $snapshotsElement, + ]; + $expectedResponse = new ListSnapshotsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSnapshots($snapshots); + $transport->addResponse($expectedResponse); + // Mock request + $formattedProject = $gapicClient->projectName('[PROJECT]'); + $request = (new ListSnapshotsRequest()) + ->setProject($formattedProject); + $response = $gapicClient->listSnapshots($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSnapshots()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/ListSnapshots', $actualFuncCall); + $actualValue = $actualRequestObject->getProject(); + $this->assertProtobufEquals($formattedProject, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSnapshotsExceptionTest() + { + $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 + $formattedProject = $gapicClient->projectName('[PROJECT]'); + $request = (new ListSnapshotsRequest()) + ->setProject($formattedProject); + try { + $gapicClient->listSnapshots($request); + // 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 listSubscriptionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $subscriptionsElement = new Subscription(); + $subscriptions = [ + $subscriptionsElement, + ]; + $expectedResponse = new ListSubscriptionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSubscriptions($subscriptions); + $transport->addResponse($expectedResponse); + // Mock request + $formattedProject = $gapicClient->projectName('[PROJECT]'); + $request = (new ListSubscriptionsRequest()) + ->setProject($formattedProject); + $response = $gapicClient->listSubscriptions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSubscriptions()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/ListSubscriptions', $actualFuncCall); + $actualValue = $actualRequestObject->getProject(); + $this->assertProtobufEquals($formattedProject, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSubscriptionsExceptionTest() + { + $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 + $formattedProject = $gapicClient->projectName('[PROJECT]'); + $request = (new ListSubscriptionsRequest()) + ->setProject($formattedProject); + try { + $gapicClient->listSubscriptions($request); + // 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 modifyAckDeadlineTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $ackIds = []; + $ackDeadlineSeconds = 2135351438; + $request = (new ModifyAckDeadlineRequest()) + ->setSubscription($formattedSubscription) + ->setAckIds($ackIds) + ->setAckDeadlineSeconds($ackDeadlineSeconds); + $gapicClient->modifyAckDeadline($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/ModifyAckDeadline', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $actualValue = $actualRequestObject->getAckIds(); + $this->assertProtobufEquals($ackIds, $actualValue); + $actualValue = $actualRequestObject->getAckDeadlineSeconds(); + $this->assertProtobufEquals($ackDeadlineSeconds, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function modifyAckDeadlineExceptionTest() + { + $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 + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $ackIds = []; + $ackDeadlineSeconds = 2135351438; + $request = (new ModifyAckDeadlineRequest()) + ->setSubscription($formattedSubscription) + ->setAckIds($ackIds) + ->setAckDeadlineSeconds($ackDeadlineSeconds); + try { + $gapicClient->modifyAckDeadline($request); + // 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 modifyPushConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $pushConfig = new PushConfig(); + $request = (new ModifyPushConfigRequest()) + ->setSubscription($formattedSubscription) + ->setPushConfig($pushConfig); + $gapicClient->modifyPushConfig($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/ModifyPushConfig', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $actualValue = $actualRequestObject->getPushConfig(); + $this->assertProtobufEquals($pushConfig, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function modifyPushConfigExceptionTest() + { + $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 + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $pushConfig = new PushConfig(); + $request = (new ModifyPushConfigRequest()) + ->setSubscription($formattedSubscription) + ->setPushConfig($pushConfig); + try { + $gapicClient->modifyPushConfig($request); + // 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 pullTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new PullResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $maxMessages = 496131527; + $request = (new PullRequest()) + ->setSubscription($formattedSubscription) + ->setMaxMessages($maxMessages); + $response = $gapicClient->pull($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/Pull', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $actualValue = $actualRequestObject->getMaxMessages(); + $this->assertProtobufEquals($maxMessages, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function pullExceptionTest() + { + $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 + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $maxMessages = 496131527; + $request = (new PullRequest()) + ->setSubscription($formattedSubscription) + ->setMaxMessages($maxMessages); + try { + $gapicClient->pull($request); + // 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 seekTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new SeekResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new SeekRequest()) + ->setSubscription($formattedSubscription); + $response = $gapicClient->seek($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/Seek', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function seekExceptionTest() + { + $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 + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $request = (new SeekRequest()) + ->setSubscription($formattedSubscription); + try { + $gapicClient->seek($request); + // 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 streamingPullTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new StreamingPullResponse(); + $transport->addResponse($expectedResponse); + $expectedResponse2 = new StreamingPullResponse(); + $transport->addResponse($expectedResponse2); + $expectedResponse3 = new StreamingPullResponse(); + $transport->addResponse($expectedResponse3); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $streamAckDeadlineSeconds = 1875467245; + $request = new StreamingPullRequest(); + $request->setSubscription($formattedSubscription); + $request->setStreamAckDeadlineSeconds($streamAckDeadlineSeconds); + $formattedSubscription2 = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $streamAckDeadlineSeconds2 = 1562238880; + $request2 = new StreamingPullRequest(); + $request2->setSubscription($formattedSubscription2); + $request2->setStreamAckDeadlineSeconds($streamAckDeadlineSeconds2); + $formattedSubscription3 = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $streamAckDeadlineSeconds3 = 1562238879; + $request3 = new StreamingPullRequest(); + $request3->setSubscription($formattedSubscription3); + $request3->setStreamAckDeadlineSeconds($streamAckDeadlineSeconds3); + $bidi = $gapicClient->streamingPull(); + $this->assertInstanceOf(BidiStream::class, $bidi); + $bidi->write($request); + $responses = []; + $responses[] = $bidi->read(); + $bidi->writeAll([ + $request2, + $request3, + ]); + foreach ($bidi->closeWriteAndReadAll() as $response) { + $responses[] = $response; + } + + $expectedResponses = []; + $expectedResponses[] = $expectedResponse; + $expectedResponses[] = $expectedResponse2; + $expectedResponses[] = $expectedResponse3; + $this->assertEquals($expectedResponses, $responses); + $createStreamRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($createStreamRequests)); + $streamFuncCall = $createStreamRequests[0]->getFuncCall(); + $streamRequestObject = $createStreamRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/StreamingPull', $streamFuncCall); + $this->assertNull($streamRequestObject); + $callObjects = $transport->popCallObjects(); + $this->assertSame(1, count($callObjects)); + $bidiCall = $callObjects[0]; + $writeRequests = $bidiCall->popReceivedCalls(); + $expectedRequests = []; + $expectedRequests[] = $request; + $expectedRequests[] = $request2; + $expectedRequests[] = $request3; + $this->assertEquals($expectedRequests, $writeRequests); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function streamingPullExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $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->setStreamingStatus($status); + $this->assertTrue($transport->isExhausted()); + $bidi = $gapicClient->streamingPull(); + $results = $bidi->closeWriteAndReadAll(); + try { + iterator_to_array($results); + // If the close stream 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 updateSnapshotTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $topic = 'topic110546223'; + $expectedResponse = new Snapshot(); + $expectedResponse->setName($name); + $expectedResponse->setTopic($topic); + $transport->addResponse($expectedResponse); + // Mock request + $snapshot = new Snapshot(); + $updateMask = new FieldMask(); + $request = (new UpdateSnapshotRequest()) + ->setSnapshot($snapshot) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateSnapshot($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/UpdateSnapshot', $actualFuncCall); + $actualValue = $actualRequestObject->getSnapshot(); + $this->assertProtobufEquals($snapshot, $actualValue); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateSnapshotExceptionTest() + { + $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 + $snapshot = new Snapshot(); + $updateMask = new FieldMask(); + $request = (new UpdateSnapshotRequest()) + ->setSnapshot($snapshot) + ->setUpdateMask($updateMask); + try { + $gapicClient->updateSnapshot($request); + // 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 updateSubscriptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $topic = 'topic110546223'; + $ackDeadlineSeconds = 2135351438; + $retainAckedMessages = false; + $enableMessageOrdering = true; + $filter = 'filter-1274492040'; + $detached = true; + $enableExactlyOnceDelivery = false; + $expectedResponse = new Subscription(); + $expectedResponse->setName($name); + $expectedResponse->setTopic($topic); + $expectedResponse->setAckDeadlineSeconds($ackDeadlineSeconds); + $expectedResponse->setRetainAckedMessages($retainAckedMessages); + $expectedResponse->setEnableMessageOrdering($enableMessageOrdering); + $expectedResponse->setFilter($filter); + $expectedResponse->setDetached($detached); + $expectedResponse->setEnableExactlyOnceDelivery($enableExactlyOnceDelivery); + $transport->addResponse($expectedResponse); + // Mock request + $subscription = new Subscription(); + $subscriptionName = 'subscriptionName-515935928'; + $subscription->setName($subscriptionName); + $subscriptionTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $subscription->setTopic($subscriptionTopic); + $updateMask = new FieldMask(); + $request = (new UpdateSubscriptionRequest()) + ->setSubscription($subscription) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateSubscription($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/UpdateSubscription', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($subscription, $actualValue); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateSubscriptionExceptionTest() + { + $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 + $subscription = new Subscription(); + $subscriptionName = 'subscriptionName-515935928'; + $subscription->setName($subscriptionName); + $subscriptionTopic = $gapicClient->topicName('[PROJECT]', '[TOPIC]'); + $subscription->setTopic($subscriptionTopic); + $updateMask = new FieldMask(); + $request = (new UpdateSubscriptionRequest()) + ->setSubscription($subscription) + ->setUpdateMask($updateMask); + try { + $gapicClient->updateSubscription($request); + // 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 getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // 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 setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // 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 testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $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 + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // 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 acknowledgeAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSubscription = $gapicClient->subscriptionName('[PROJECT]', '[SUBSCRIPTION]'); + $ackIds = []; + $request = (new AcknowledgeRequest()) + ->setSubscription($formattedSubscription) + ->setAckIds($ackIds); + $gapicClient->acknowledgeAsync($request)->wait(); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.pubsub.v1.Subscriber/Acknowledge', $actualFuncCall); + $actualValue = $actualRequestObject->getSubscription(); + $this->assertProtobufEquals($formattedSubscription, $actualValue); + $actualValue = $actualRequestObject->getAckIds(); + $this->assertProtobufEquals($ackIds, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +}