From 23f30b989af78527b417a01c1eb98101b7adfceb Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 13 Jun 2024 15:04:29 -0700 Subject: [PATCH] chore!: promote EssentialContacts to v1 (#7398) --- .repo-metadata-full.json | 2 +- EssentialContacts/README.md | 5 +- EssentialContacts/owlbot.py | 53 +- .../Client/EssentialContactsServiceClient.php | 9 +- .../src/V1/ComputeContactsRequest.php | 6 +- .../src/V1/ComputeContactsResponse.php | 2 +- EssentialContacts/src/V1/Contact.php | 10 +- .../src/V1/CreateContactRequest.php | 4 +- .../src/V1/DeleteContactRequest.php | 2 +- .../src/V1/EssentialContactsServiceClient.php | 34 - .../V1/EssentialContactsServiceGrpcClient.php | 144 --- .../EssentialContactsServiceGapicClient.php | 829 ------------------ .../src/V1/GetContactRequest.php | 2 +- .../src/V1/ListContactsRequest.php | 6 +- .../src/V1/ListContactsResponse.php | 2 +- .../src/V1/SendTestMessageRequest.php | 4 +- .../src/V1/UpdateContactRequest.php | 4 +- .../EssentialContactsServiceClientTest.php | 187 ++-- .../V1/EssentialContactsServiceClientTest.php | 547 ------------ 19 files changed, 147 insertions(+), 1705 deletions(-) delete mode 100644 EssentialContacts/src/V1/EssentialContactsServiceClient.php delete mode 100644 EssentialContacts/src/V1/EssentialContactsServiceGrpcClient.php delete mode 100644 EssentialContacts/src/V1/Gapic/EssentialContactsServiceGapicClient.php delete mode 100644 EssentialContacts/tests/Unit/V1/EssentialContactsServiceClientTest.php diff --git a/.repo-metadata-full.json b/.repo-metadata-full.json index 18f238cd734..a142b2b10ca 100644 --- a/.repo-metadata-full.json +++ b/.repo-metadata-full.json @@ -640,7 +640,7 @@ "EssentialContacts": { "language": "php", "distribution_name": "google/cloud-essential-contacts", - "release_level": "preview", + "release_level": "stable", "client_documentation": "https://cloud.google.com/php/docs/reference/cloud-essential-contacts/latest", "library_type": "GAPIC_AUTO", "api_shortname": "essentialcontacts" diff --git a/EssentialContacts/README.md b/EssentialContacts/README.md index a1ea945b53a..c992cdebfaf 100644 --- a/EssentialContacts/README.md +++ b/EssentialContacts/README.md @@ -30,9 +30,8 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Version -This component is considered beta. As such, it should be expected to be mostly -stable and we're working towards a release candidate. We will address issues -and requests with a higher priority. +This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in +any minor or patch releases. We will address issues and requests with the highest priority. ### Next Steps diff --git a/EssentialContacts/owlbot.py b/EssentialContacts/owlbot.py index 87283d22362..ac492678cec 100644 --- a/EssentialContacts/owlbot.py +++ b/EssentialContacts/owlbot.py @@ -1,4 +1,4 @@ -# Copyright 2021 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,34 +32,25 @@ php.owlbot_main(src=src, dest=dest) -# Change the wording for the deprecation warning. +# remove class_alias code s.replace( - 'src/*/*_*.php', - r'will be removed in the next major release', - 'will be removed in a future release') - -### [START] protoc backwards compatibility fixes - -# roll back to private properties. -s.replace( - "src/**/V*/**/*.php", - r"Generated from protobuf field ([^\n]{0,})\n\s{5}\*/\n\s{4}protected \$", - r"""Generated from protobuf field \1 - */ - private $""") - -# Replace "Unwrapped" with "Value" for method names. -s.replace( - "src/**/V*/**/*.php", - r"public function ([s|g]\w{3,})Unwrapped", - r"public function \1Value" -) - -### [END] protoc backwards compatibility fixes - -# fix relative cloud.google.com links -s.replace( - "src/**/V*/**/*.php", - r"(.{0,})\]\((/.{0,})\)", - r"\1](https://cloud.google.com\2)" -) + "src/V*/**/*.php", + r"^// Adding a class alias for backwards compatibility with the previous class name.$" + + "\n" + + r"^class_alias\(.*\);$" + + "\n", + '') + +# format generated clients +subprocess.run([ + 'npm', + 'exec', + '--yes', + '--package=@prettier/plugin-php@^0.16', + '--', + 'prettier', + '**/Client/*', + '--write', + '--parser=php', + '--single-quote', + '--print-width=120']) diff --git a/EssentialContacts/src/V1/Client/EssentialContactsServiceClient.php b/EssentialContacts/src/V1/Client/EssentialContactsServiceClient.php index cba8798b43b..b9a6ddbf1f3 100644 --- a/EssentialContacts/src/V1/Client/EssentialContactsServiceClient.php +++ b/EssentialContacts/src/V1/Client/EssentialContactsServiceClient.php @@ -1,6 +1,6 @@ [ 'rest' => [ - 'restClientConfigPath' => __DIR__ . '/../resources/essential_contacts_service_rest_client_config.php', + 'restClientConfigPath' => + __DIR__ . '/../resources/essential_contacts_service_rest_client_config.php', ], ], ]; diff --git a/EssentialContacts/src/V1/ComputeContactsRequest.php b/EssentialContacts/src/V1/ComputeContactsRequest.php index 5693b0e7bae..a00eed430a0 100644 --- a/EssentialContacts/src/V1/ComputeContactsRequest.php +++ b/EssentialContacts/src/V1/ComputeContactsRequest.php @@ -22,7 +22,7 @@ class ComputeContactsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * The categories of notifications to compute contacts for. If ALL is included * in this list, contacts subscribed to any notification category will be @@ -39,7 +39,7 @@ class ComputeContactsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int32 page_size = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. If present, retrieves the next batch of results from the * preceding call to this method. `page_token` must be the value of @@ -48,7 +48,7 @@ class ComputeContactsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string page_token = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_token = ''; + protected $page_token = ''; /** * Constructor. diff --git a/EssentialContacts/src/V1/ComputeContactsResponse.php b/EssentialContacts/src/V1/ComputeContactsResponse.php index f3b72a17e8c..3bd97e666fd 100644 --- a/EssentialContacts/src/V1/ComputeContactsResponse.php +++ b/EssentialContacts/src/V1/ComputeContactsResponse.php @@ -31,7 +31,7 @@ class ComputeContactsResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/EssentialContacts/src/V1/Contact.php b/EssentialContacts/src/V1/Contact.php index 96038a7147c..c0a08d7aeb7 100644 --- a/EssentialContacts/src/V1/Contact.php +++ b/EssentialContacts/src/V1/Contact.php @@ -21,14 +21,14 @@ class Contact extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $name = ''; + protected $name = ''; /** * Required. The email address to send notifications to. The email address * does not need to be a Google Account. * * Generated from protobuf field string email = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $email = ''; + protected $email = ''; /** * Required. The categories of notifications that the contact will receive * communications for. @@ -44,14 +44,14 @@ class Contact extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string language_tag = 4 [(.google.api.field_behavior) = REQUIRED]; */ - private $language_tag = ''; + protected $language_tag = ''; /** * The validity of the contact. A contact is considered valid if it is the * correct recipient for notifications for a particular resource. * * Generated from protobuf field .google.cloud.essentialcontacts.v1.ValidationState validation_state = 8; */ - private $validation_state = 0; + protected $validation_state = 0; /** * The last time the validation_state was updated, either manually or * automatically. A contact is considered stale if its validation state was @@ -59,7 +59,7 @@ class Contact extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp validate_time = 9; */ - private $validate_time = null; + protected $validate_time = null; /** * Constructor. diff --git a/EssentialContacts/src/V1/CreateContactRequest.php b/EssentialContacts/src/V1/CreateContactRequest.php index 6c985b03222..aa04a1644f4 100644 --- a/EssentialContacts/src/V1/CreateContactRequest.php +++ b/EssentialContacts/src/V1/CreateContactRequest.php @@ -22,14 +22,14 @@ class CreateContactRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Required. The contact to create. Must specify an email address and language * tag. * * Generated from protobuf field .google.cloud.essentialcontacts.v1.Contact contact = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $contact = null; + protected $contact = null; /** * @param string $parent Required. The resource to save this contact for. diff --git a/EssentialContacts/src/V1/DeleteContactRequest.php b/EssentialContacts/src/V1/DeleteContactRequest.php index a33fc9f8375..f07753c9588 100644 --- a/EssentialContacts/src/V1/DeleteContactRequest.php +++ b/EssentialContacts/src/V1/DeleteContactRequest.php @@ -23,7 +23,7 @@ class DeleteContactRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $name = ''; + protected $name = ''; /** * @param string $name Required. The name of the contact to delete. diff --git a/EssentialContacts/src/V1/EssentialContactsServiceClient.php b/EssentialContacts/src/V1/EssentialContactsServiceClient.php deleted file mode 100644 index 387279b3275..00000000000 --- a/EssentialContacts/src/V1/EssentialContactsServiceClient.php +++ /dev/null @@ -1,34 +0,0 @@ -_simpleRequest('/google.cloud.essentialcontacts.v1.EssentialContactsService/CreateContact', - $argument, - ['\Google\Cloud\EssentialContacts\V1\Contact', 'decode'], - $metadata, $options); - } - - /** - * Updates a contact. - * Note: A contact's email address cannot be changed. - * @param \Google\Cloud\EssentialContacts\V1\UpdateContactRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function UpdateContact(\Google\Cloud\EssentialContacts\V1\UpdateContactRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.essentialcontacts.v1.EssentialContactsService/UpdateContact', - $argument, - ['\Google\Cloud\EssentialContacts\V1\Contact', 'decode'], - $metadata, $options); - } - - /** - * Lists the contacts that have been set on a resource. - * @param \Google\Cloud\EssentialContacts\V1\ListContactsRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function ListContacts(\Google\Cloud\EssentialContacts\V1\ListContactsRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.essentialcontacts.v1.EssentialContactsService/ListContacts', - $argument, - ['\Google\Cloud\EssentialContacts\V1\ListContactsResponse', 'decode'], - $metadata, $options); - } - - /** - * Gets a single contact. - * @param \Google\Cloud\EssentialContacts\V1\GetContactRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function GetContact(\Google\Cloud\EssentialContacts\V1\GetContactRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.essentialcontacts.v1.EssentialContactsService/GetContact', - $argument, - ['\Google\Cloud\EssentialContacts\V1\Contact', 'decode'], - $metadata, $options); - } - - /** - * Deletes a contact. - * @param \Google\Cloud\EssentialContacts\V1\DeleteContactRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function DeleteContact(\Google\Cloud\EssentialContacts\V1\DeleteContactRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.essentialcontacts.v1.EssentialContactsService/DeleteContact', - $argument, - ['\Google\Protobuf\GPBEmpty', 'decode'], - $metadata, $options); - } - - /** - * Lists all contacts for the resource that are subscribed to the - * specified notification categories, including contacts inherited from - * any parent resources. - * @param \Google\Cloud\EssentialContacts\V1\ComputeContactsRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function ComputeContacts(\Google\Cloud\EssentialContacts\V1\ComputeContactsRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.essentialcontacts.v1.EssentialContactsService/ComputeContacts', - $argument, - ['\Google\Cloud\EssentialContacts\V1\ComputeContactsResponse', 'decode'], - $metadata, $options); - } - - /** - * Allows a contact admin to send a test message to contact to verify that it - * has been configured correctly. - * @param \Google\Cloud\EssentialContacts\V1\SendTestMessageRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function SendTestMessage(\Google\Cloud\EssentialContacts\V1\SendTestMessageRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.essentialcontacts.v1.EssentialContactsService/SendTestMessage', - $argument, - ['\Google\Protobuf\GPBEmpty', 'decode'], - $metadata, $options); - } - -} diff --git a/EssentialContacts/src/V1/Gapic/EssentialContactsServiceGapicClient.php b/EssentialContacts/src/V1/Gapic/EssentialContactsServiceGapicClient.php deleted file mode 100644 index 5920dc108fd..00000000000 --- a/EssentialContacts/src/V1/Gapic/EssentialContactsServiceGapicClient.php +++ /dev/null @@ -1,829 +0,0 @@ -projectName('[PROJECT]'); - * // Iterate over pages of elements - * $pagedResponse = $essentialContactsServiceClient->computeContacts($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $essentialContactsServiceClient->computeContacts($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $essentialContactsServiceClient->close(); - * } - * ``` - * - * Many parameters require resource names to be formatted in a particular way. To - * assist with these names, this class includes a format method for each type of - * name, and additionally a parseName method to extract the individual identifiers - * contained within formatted names that are returned by the API. - * - * @deprecated Please use the new service client {@see \Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient}. - */ -class EssentialContactsServiceGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.cloud.essentialcontacts.v1.EssentialContactsService'; - - /** - * The default address of the service. - * - * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. - */ - const SERVICE_ADDRESS = 'essentialcontacts.googleapis.com'; - - /** The address template of the service. */ - private const SERVICE_ADDRESS_TEMPLATE = 'essentialcontacts.UNIVERSE_DOMAIN'; - - /** The default port of the service. */ - const DEFAULT_SERVICE_PORT = 443; - - /** The name of the code generator, to be included in the agent header. */ - const CODEGEN_NAME = 'gapic'; - - /** The default scopes required by the service. */ - public static $serviceScopes = [ - 'https://www.googleapis.com/auth/cloud-platform', - ]; - - private static $contactNameTemplate; - - private static $folderNameTemplate; - - private static $folderContactNameTemplate; - - private static $organizationNameTemplate; - - private static $organizationContactNameTemplate; - - private static $projectNameTemplate; - - private static $projectContactNameTemplate; - - private static $pathTemplateMap; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__ . '/../resources/essential_contacts_service_client_config.json', - 'descriptorsConfigPath' => __DIR__ . '/../resources/essential_contacts_service_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__ . '/../resources/essential_contacts_service_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => __DIR__ . '/../resources/essential_contacts_service_rest_client_config.php', - ], - ], - ]; - } - - private static function getContactNameTemplate() - { - if (self::$contactNameTemplate == null) { - self::$contactNameTemplate = new PathTemplate('projects/{project}/contacts/{contact}'); - } - - return self::$contactNameTemplate; - } - - private static function getFolderNameTemplate() - { - if (self::$folderNameTemplate == null) { - self::$folderNameTemplate = new PathTemplate('folders/{folder}'); - } - - return self::$folderNameTemplate; - } - - private static function getFolderContactNameTemplate() - { - if (self::$folderContactNameTemplate == null) { - self::$folderContactNameTemplate = new PathTemplate('folders/{folder}/contacts/{contact}'); - } - - return self::$folderContactNameTemplate; - } - - private static function getOrganizationNameTemplate() - { - if (self::$organizationNameTemplate == null) { - self::$organizationNameTemplate = new PathTemplate('organizations/{organization}'); - } - - return self::$organizationNameTemplate; - } - - private static function getOrganizationContactNameTemplate() - { - if (self::$organizationContactNameTemplate == null) { - self::$organizationContactNameTemplate = new PathTemplate('organizations/{organization}/contacts/{contact}'); - } - - return self::$organizationContactNameTemplate; - } - - private static function getProjectNameTemplate() - { - if (self::$projectNameTemplate == null) { - self::$projectNameTemplate = new PathTemplate('projects/{project}'); - } - - return self::$projectNameTemplate; - } - - private static function getProjectContactNameTemplate() - { - if (self::$projectContactNameTemplate == null) { - self::$projectContactNameTemplate = new PathTemplate('projects/{project}/contacts/{contact}'); - } - - return self::$projectContactNameTemplate; - } - - private static function getPathTemplateMap() - { - if (self::$pathTemplateMap == null) { - self::$pathTemplateMap = [ - 'contact' => self::getContactNameTemplate(), - 'folder' => self::getFolderNameTemplate(), - 'folderContact' => self::getFolderContactNameTemplate(), - 'organization' => self::getOrganizationNameTemplate(), - 'organizationContact' => self::getOrganizationContactNameTemplate(), - 'project' => self::getProjectNameTemplate(), - 'projectContact' => self::getProjectContactNameTemplate(), - ]; - } - - return self::$pathTemplateMap; - } - - /** - * Formats a string containing the fully-qualified path to represent a contact - * resource. - * - * @param string $project - * @param string $contact - * - * @return string The formatted contact resource. - */ - public static function contactName($project, $contact) - { - return self::getContactNameTemplate()->render([ - 'project' => $project, - 'contact' => $contact, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a folder - * resource. - * - * @param string $folder - * - * @return string The formatted folder resource. - */ - public static function folderName($folder) - { - return self::getFolderNameTemplate()->render([ - 'folder' => $folder, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * folder_contact resource. - * - * @param string $folder - * @param string $contact - * - * @return string The formatted folder_contact resource. - */ - public static function folderContactName($folder, $contact) - { - return self::getFolderContactNameTemplate()->render([ - 'folder' => $folder, - 'contact' => $contact, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a organization - * resource. - * - * @param string $organization - * - * @return string The formatted organization resource. - */ - public static function organizationName($organization) - { - return self::getOrganizationNameTemplate()->render([ - 'organization' => $organization, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * organization_contact resource. - * - * @param string $organization - * @param string $contact - * - * @return string The formatted organization_contact resource. - */ - public static function organizationContactName($organization, $contact) - { - return self::getOrganizationContactNameTemplate()->render([ - 'organization' => $organization, - 'contact' => $contact, - ]); - } - - /** - * 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($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * project_contact resource. - * - * @param string $project - * @param string $contact - * - * @return string The formatted project_contact resource. - */ - public static function projectContactName($project, $contact) - { - return self::getProjectContactNameTemplate()->render([ - 'project' => $project, - 'contact' => $contact, - ]); - } - - /** - * Parses a formatted name string and returns an associative array of the components in the name. - * The following name formats are supported: - * Template: Pattern - * - contact: projects/{project}/contacts/{contact} - * - folder: folders/{folder} - * - folderContact: folders/{folder}/contacts/{contact} - * - organization: organizations/{organization} - * - organizationContact: organizations/{organization}/contacts/{contact} - * - project: projects/{project} - * - projectContact: projects/{project}/contacts/{contact} - * - * 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($formattedName, $template = null) - { - $templateMap = self::getPathTemplateMap(); - if ($template) { - if (!isset($templateMap[$template])) { - throw new ValidationException("Template name $template does not exist"); - } - - return $templateMap[$template]->match($formattedName); - } - - foreach ($templateMap as $templateName => $pathTemplate) { - try { - return $pathTemplate->match($formattedName); - } catch (ValidationException $ex) { - // Swallow the exception to continue trying other path templates - } - } - - throw new ValidationException("Input did not match any known format. Input: $formattedName"); - } - - /** - * 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 'essentialcontacts.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); - } - - /** - * Lists all contacts for the resource that are subscribed to the - * specified notification categories, including contacts inherited from - * any parent resources. - * - * Sample code: - * ``` - * $essentialContactsServiceClient = new EssentialContactsServiceClient(); - * try { - * $formattedParent = $essentialContactsServiceClient->projectName('[PROJECT]'); - * // Iterate over pages of elements - * $pagedResponse = $essentialContactsServiceClient->computeContacts($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $essentialContactsServiceClient->computeContacts($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $essentialContactsServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The name of the resource to compute contacts for. - * Format: organizations/{organization_id}, - * folders/{folder_id} or projects/{project_id} - * @param array $optionalArgs { - * Optional. - * - * @type int[] $notificationCategories - * The categories of notifications to compute contacts for. If ALL is included - * in this list, contacts subscribed to any notification category will be - * returned. - * For allowed values, use constants defined on {@see \Google\Cloud\EssentialContacts\V1\NotificationCategory} - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function computeContacts($parent, array $optionalArgs = []) - { - $request = new ComputeContactsRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['notificationCategories'])) { - $request->setNotificationCategories($optionalArgs['notificationCategories']); - } - - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ComputeContacts', $optionalArgs, ComputeContactsResponse::class, $request); - } - - /** - * Adds a new contact for a resource. - * - * Sample code: - * ``` - * $essentialContactsServiceClient = new EssentialContactsServiceClient(); - * try { - * $formattedParent = $essentialContactsServiceClient->projectName('[PROJECT]'); - * $contact = new Contact(); - * $response = $essentialContactsServiceClient->createContact($formattedParent, $contact); - * } finally { - * $essentialContactsServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The resource to save this contact for. - * Format: organizations/{organization_id}, folders/{folder_id} or - * projects/{project_id} - * @param Contact $contact Required. The contact to create. Must specify an email address and language - * tag. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\EssentialContacts\V1\Contact - * - * @throws ApiException if the remote call fails - */ - public function createContact($parent, $contact, array $optionalArgs = []) - { - $request = new CreateContactRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setContact($contact); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('CreateContact', Contact::class, $optionalArgs, $request)->wait(); - } - - /** - * Deletes a contact. - * - * Sample code: - * ``` - * $essentialContactsServiceClient = new EssentialContactsServiceClient(); - * try { - * $formattedName = $essentialContactsServiceClient->contactName('[PROJECT]', '[CONTACT]'); - * $essentialContactsServiceClient->deleteContact($formattedName); - * } finally { - * $essentialContactsServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The name of the contact to delete. - * Format: organizations/{organization_id}/contacts/{contact_id}, - * folders/{folder_id}/contacts/{contact_id} or - * projects/{project_id}/contacts/{contact_id} - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - */ - public function deleteContact($name, array $optionalArgs = []) - { - $request = new DeleteContactRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('DeleteContact', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets a single contact. - * - * Sample code: - * ``` - * $essentialContactsServiceClient = new EssentialContactsServiceClient(); - * try { - * $formattedName = $essentialContactsServiceClient->contactName('[PROJECT]', '[CONTACT]'); - * $response = $essentialContactsServiceClient->getContact($formattedName); - * } finally { - * $essentialContactsServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The name of the contact to retrieve. - * Format: organizations/{organization_id}/contacts/{contact_id}, - * folders/{folder_id}/contacts/{contact_id} or - * projects/{project_id}/contacts/{contact_id} - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\EssentialContacts\V1\Contact - * - * @throws ApiException if the remote call fails - */ - public function getContact($name, array $optionalArgs = []) - { - $request = new GetContactRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetContact', Contact::class, $optionalArgs, $request)->wait(); - } - - /** - * Lists the contacts that have been set on a resource. - * - * Sample code: - * ``` - * $essentialContactsServiceClient = new EssentialContactsServiceClient(); - * try { - * $formattedParent = $essentialContactsServiceClient->projectName('[PROJECT]'); - * // Iterate over pages of elements - * $pagedResponse = $essentialContactsServiceClient->listContacts($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $essentialContactsServiceClient->listContacts($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $essentialContactsServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The parent resource name. - * Format: organizations/{organization_id}, folders/{folder_id} or - * projects/{project_id} - * @param array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listContacts($parent, array $optionalArgs = []) - { - $request = new ListContactsRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListContacts', $optionalArgs, ListContactsResponse::class, $request); - } - - /** - * Allows a contact admin to send a test message to contact to verify that it - * has been configured correctly. - * - * Sample code: - * ``` - * $essentialContactsServiceClient = new EssentialContactsServiceClient(); - * try { - * $formattedContacts = [ - * $essentialContactsServiceClient->contactName('[PROJECT]', '[CONTACT]'), - * ]; - * $formattedResource = $essentialContactsServiceClient->projectName('[PROJECT]'); - * $notificationCategory = NotificationCategory::NOTIFICATION_CATEGORY_UNSPECIFIED; - * $essentialContactsServiceClient->sendTestMessage($formattedContacts, $formattedResource, $notificationCategory); - * } finally { - * $essentialContactsServiceClient->close(); - * } - * ``` - * - * @param string[] $contacts Required. The list of names of the contacts to send a test message to. - * Format: organizations/{organization_id}/contacts/{contact_id}, - * folders/{folder_id}/contacts/{contact_id} or - * projects/{project_id}/contacts/{contact_id} - * @param string $resource Required. The name of the resource to send the test message for. All - * contacts must either be set directly on this resource or inherited from - * another resource that is an ancestor of this one. Format: - * organizations/{organization_id}, folders/{folder_id} or - * projects/{project_id} - * @param int $notificationCategory Required. The notification category to send the test message for. All - * contacts must be subscribed to this category. - * For allowed values, use constants defined on {@see \Google\Cloud\EssentialContacts\V1\NotificationCategory} - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - */ - public function sendTestMessage($contacts, $resource, $notificationCategory, array $optionalArgs = []) - { - $request = new SendTestMessageRequest(); - $requestParamHeaders = []; - $request->setContacts($contacts); - $request->setResource($resource); - $request->setNotificationCategory($notificationCategory); - $requestParamHeaders['resource'] = $resource; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('SendTestMessage', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Updates a contact. - * Note: A contact's email address cannot be changed. - * - * Sample code: - * ``` - * $essentialContactsServiceClient = new EssentialContactsServiceClient(); - * try { - * $contact = new Contact(); - * $response = $essentialContactsServiceClient->updateContact($contact); - * } finally { - * $essentialContactsServiceClient->close(); - * } - * ``` - * - * @param Contact $contact Required. The contact resource to replace the existing saved contact. Note: - * the email address of the contact cannot be modified. - * @param array $optionalArgs { - * Optional. - * - * @type FieldMask $updateMask - * Optional. The update mask applied to the resource. For the `FieldMask` - * definition, see - * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\EssentialContacts\V1\Contact - * - * @throws ApiException if the remote call fails - */ - public function updateContact($contact, array $optionalArgs = []) - { - $request = new UpdateContactRequest(); - $requestParamHeaders = []; - $request->setContact($contact); - $requestParamHeaders['contact.name'] = $contact->getName(); - if (isset($optionalArgs['updateMask'])) { - $request->setUpdateMask($optionalArgs['updateMask']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('UpdateContact', Contact::class, $optionalArgs, $request)->wait(); - } -} diff --git a/EssentialContacts/src/V1/GetContactRequest.php b/EssentialContacts/src/V1/GetContactRequest.php index e95874e58c9..dbdbff500ad 100644 --- a/EssentialContacts/src/V1/GetContactRequest.php +++ b/EssentialContacts/src/V1/GetContactRequest.php @@ -23,7 +23,7 @@ class GetContactRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $name = ''; + protected $name = ''; /** * @param string $name Required. The name of the contact to retrieve. diff --git a/EssentialContacts/src/V1/ListContactsRequest.php b/EssentialContacts/src/V1/ListContactsRequest.php index 11bb0290cbb..4cb6c56e7bb 100644 --- a/EssentialContacts/src/V1/ListContactsRequest.php +++ b/EssentialContacts/src/V1/ListContactsRequest.php @@ -22,7 +22,7 @@ class ListContactsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Optional. The maximum number of results to return from this request. * Non-positive values are ignored. The presence of `next_page_token` in the @@ -31,7 +31,7 @@ class ListContactsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. If present, retrieves the next batch of results from the * preceding call to this method. `page_token` must be the value of @@ -40,7 +40,7 @@ class ListContactsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_token = ''; + protected $page_token = ''; /** * @param string $parent Required. The parent resource name. diff --git a/EssentialContacts/src/V1/ListContactsResponse.php b/EssentialContacts/src/V1/ListContactsResponse.php index 35d0b8a4821..7d094531e0d 100644 --- a/EssentialContacts/src/V1/ListContactsResponse.php +++ b/EssentialContacts/src/V1/ListContactsResponse.php @@ -29,7 +29,7 @@ class ListContactsResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/EssentialContacts/src/V1/SendTestMessageRequest.php b/EssentialContacts/src/V1/SendTestMessageRequest.php index 6eb343d8e77..e756f41f0c3 100644 --- a/EssentialContacts/src/V1/SendTestMessageRequest.php +++ b/EssentialContacts/src/V1/SendTestMessageRequest.php @@ -33,14 +33,14 @@ class SendTestMessageRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string resource = 2 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $resource = ''; + protected $resource = ''; /** * Required. The notification category to send the test message for. All * contacts must be subscribed to this category. * * Generated from protobuf field .google.cloud.essentialcontacts.v1.NotificationCategory notification_category = 3 [(.google.api.field_behavior) = REQUIRED]; */ - private $notification_category = 0; + protected $notification_category = 0; /** * Constructor. diff --git a/EssentialContacts/src/V1/UpdateContactRequest.php b/EssentialContacts/src/V1/UpdateContactRequest.php index d72808e8c35..33f95f31b4a 100644 --- a/EssentialContacts/src/V1/UpdateContactRequest.php +++ b/EssentialContacts/src/V1/UpdateContactRequest.php @@ -21,7 +21,7 @@ class UpdateContactRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.essentialcontacts.v1.Contact contact = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $contact = null; + protected $contact = null; /** * Optional. The update mask applied to the resource. For the `FieldMask` * definition, see @@ -29,7 +29,7 @@ class UpdateContactRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.FieldMask update_mask = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $update_mask = null; + protected $update_mask = null; /** * @param \Google\Cloud\EssentialContacts\V1\Contact $contact Required. The contact resource to replace the existing saved contact. Note: diff --git a/EssentialContacts/tests/Unit/V1/Client/EssentialContactsServiceClientTest.php b/EssentialContacts/tests/Unit/V1/Client/EssentialContactsServiceClientTest.php index 5fca404df55..778a6dce89e 100644 --- a/EssentialContacts/tests/Unit/V1/Client/EssentialContactsServiceClientTest.php +++ b/EssentialContacts/tests/Unit/V1/Client/EssentialContactsServiceClientTest.php @@ -1,6 +1,6 @@ getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + return $this->getMockBuilder(CredentialsWrapper::class) + ->disableOriginalConstructor() + ->getMock(); } /** @return EssentialContactsServiceClient */ @@ -81,17 +83,14 @@ public function computeContactsTest() // Mock response $nextPageToken = ''; $contactsElement = new Contact(); - $contacts = [ - $contactsElement, - ]; + $contacts = [$contactsElement]; $expectedResponse = new ComputeContactsResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setContacts($contacts); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); - $request = (new ComputeContactsRequest()) - ->setParent($formattedParent); + $request = (new ComputeContactsRequest())->setParent($formattedParent); $response = $gapicClient->computeContacts($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -101,7 +100,10 @@ public function computeContactsTest() $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/ComputeContacts', $actualFuncCall); + $this->assertSame( + '/google.cloud.essentialcontacts.v1.EssentialContactsService/ComputeContacts', + $actualFuncCall + ); $actualValue = $actualRequestObject->getParent(); $this->assertProtobufEquals($formattedParent, $actualValue); $this->assertTrue($transport->isExhausted()); @@ -118,17 +120,19 @@ public function computeContactsExceptionTest() $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); + $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 ComputeContactsRequest()) - ->setParent($formattedParent); + $request = (new ComputeContactsRequest())->setParent($formattedParent); try { $gapicClient->computeContacts($request); // If the $gapicClient method call did not throw, fail the test @@ -168,9 +172,7 @@ public function createContactTest() $contact->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions); $contactLanguageTag = 'contactLanguageTag229803234'; $contact->setLanguageTag($contactLanguageTag); - $request = (new CreateContactRequest()) - ->setParent($formattedParent) - ->setContact($contact); + $request = (new CreateContactRequest())->setParent($formattedParent)->setContact($contact); $response = $gapicClient->createContact($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -196,12 +198,15 @@ public function createContactExceptionTest() $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); + $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]'); @@ -212,9 +217,7 @@ public function createContactExceptionTest() $contact->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions); $contactLanguageTag = 'contactLanguageTag229803234'; $contact->setLanguageTag($contactLanguageTag); - $request = (new CreateContactRequest()) - ->setParent($formattedParent) - ->setContact($contact); + $request = (new CreateContactRequest())->setParent($formattedParent)->setContact($contact); try { $gapicClient->createContact($request); // If the $gapicClient method call did not throw, fail the test @@ -241,8 +244,7 @@ public function deleteContactTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->contactName('[PROJECT]', '[CONTACT]'); - $request = (new DeleteContactRequest()) - ->setName($formattedName); + $request = (new DeleteContactRequest())->setName($formattedName); $gapicClient->deleteContact($request); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); @@ -265,17 +267,19 @@ public function deleteContactExceptionTest() $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); + $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->contactName('[PROJECT]', '[CONTACT]'); - $request = (new DeleteContactRequest()) - ->setName($formattedName); + $request = (new DeleteContactRequest())->setName($formattedName); try { $gapicClient->deleteContact($request); // If the $gapicClient method call did not throw, fail the test @@ -308,8 +312,7 @@ public function getContactTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->contactName('[PROJECT]', '[CONTACT]'); - $request = (new GetContactRequest()) - ->setName($formattedName); + $request = (new GetContactRequest())->setName($formattedName); $response = $gapicClient->getContact($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -333,17 +336,19 @@ public function getContactExceptionTest() $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); + $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->contactName('[PROJECT]', '[CONTACT]'); - $request = (new GetContactRequest()) - ->setName($formattedName); + $request = (new GetContactRequest())->setName($formattedName); try { $gapicClient->getContact($request); // If the $gapicClient method call did not throw, fail the test @@ -368,17 +373,14 @@ public function listContactsTest() // Mock response $nextPageToken = ''; $contactsElement = new Contact(); - $contacts = [ - $contactsElement, - ]; + $contacts = [$contactsElement]; $expectedResponse = new ListContactsResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setContacts($contacts); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); - $request = (new ListContactsRequest()) - ->setParent($formattedParent); + $request = (new ListContactsRequest())->setParent($formattedParent); $response = $gapicClient->listContacts($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -405,17 +407,19 @@ public function listContactsExceptionTest() $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); + $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 ListContactsRequest()) - ->setParent($formattedParent); + $request = (new ListContactsRequest())->setParent($formattedParent); try { $gapicClient->listContacts($request); // If the $gapicClient method call did not throw, fail the test @@ -441,9 +445,7 @@ public function sendTestMessageTest() $expectedResponse = new GPBEmpty(); $transport->addResponse($expectedResponse); // Mock request - $formattedContacts = [ - $gapicClient->contactName('[PROJECT]', '[CONTACT]'), - ]; + $formattedContacts = [$gapicClient->contactName('[PROJECT]', '[CONTACT]')]; $formattedResource = $gapicClient->projectName('[PROJECT]'); $notificationCategory = NotificationCategory::NOTIFICATION_CATEGORY_UNSPECIFIED; $request = (new SendTestMessageRequest()) @@ -455,7 +457,10 @@ public function sendTestMessageTest() $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/SendTestMessage', $actualFuncCall); + $this->assertSame( + '/google.cloud.essentialcontacts.v1.EssentialContactsService/SendTestMessage', + $actualFuncCall + ); $actualValue = $actualRequestObject->getContacts(); $this->assertProtobufEquals($formattedContacts, $actualValue); $actualValue = $actualRequestObject->getResource(); @@ -476,17 +481,18 @@ public function sendTestMessageExceptionTest() $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); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request - $formattedContacts = [ - $gapicClient->contactName('[PROJECT]', '[CONTACT]'), - ]; + $formattedContacts = [$gapicClient->contactName('[PROJECT]', '[CONTACT]')]; $formattedResource = $gapicClient->projectName('[PROJECT]'); $notificationCategory = NotificationCategory::NOTIFICATION_CATEGORY_UNSPECIFIED; $request = (new SendTestMessageRequest()) @@ -531,8 +537,7 @@ public function updateContactTest() $contact->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions); $contactLanguageTag = 'contactLanguageTag229803234'; $contact->setLanguageTag($contactLanguageTag); - $request = (new UpdateContactRequest()) - ->setContact($contact); + $request = (new UpdateContactRequest())->setContact($contact); $response = $gapicClient->updateContact($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -556,12 +561,15 @@ public function updateContactExceptionTest() $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); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $contact = new Contact(); @@ -571,8 +579,7 @@ public function updateContactExceptionTest() $contact->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions); $contactLanguageTag = 'contactLanguageTag229803234'; $contact->setLanguageTag($contactLanguageTag); - $request = (new UpdateContactRequest()) - ->setContact($contact); + $request = (new UpdateContactRequest())->setContact($contact); try { $gapicClient->updateContact($request); // If the $gapicClient method call did not throw, fail the test @@ -597,17 +604,14 @@ public function computeContactsAsyncTest() // Mock response $nextPageToken = ''; $contactsElement = new Contact(); - $contacts = [ - $contactsElement, - ]; + $contacts = [$contactsElement]; $expectedResponse = new ComputeContactsResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setContacts($contacts); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); - $request = (new ComputeContactsRequest()) - ->setParent($formattedParent); + $request = (new ComputeContactsRequest())->setParent($formattedParent); $response = $gapicClient->computeContactsAsync($request)->wait(); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -617,7 +621,10 @@ public function computeContactsAsyncTest() $this->assertSame(1, count($actualRequests)); $actualFuncCall = $actualRequests[0]->getFuncCall(); $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/ComputeContacts', $actualFuncCall); + $this->assertSame( + '/google.cloud.essentialcontacts.v1.EssentialContactsService/ComputeContacts', + $actualFuncCall + ); $actualValue = $actualRequestObject->getParent(); $this->assertProtobufEquals($formattedParent, $actualValue); $this->assertTrue($transport->isExhausted()); diff --git a/EssentialContacts/tests/Unit/V1/EssentialContactsServiceClientTest.php b/EssentialContacts/tests/Unit/V1/EssentialContactsServiceClientTest.php deleted file mode 100644 index ee25269971f..00000000000 --- a/EssentialContacts/tests/Unit/V1/EssentialContactsServiceClientTest.php +++ /dev/null @@ -1,547 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return EssentialContactsServiceClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new EssentialContactsServiceClient($options); - } - - /** @test */ - public function computeContactsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $contactsElement = new Contact(); - $contacts = [ - $contactsElement, - ]; - $expectedResponse = new ComputeContactsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setContacts($contacts); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - $response = $gapicClient->computeContacts($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getContacts()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/ComputeContacts', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function computeContactsExceptionTest() - { - $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]'); - try { - $gapicClient->computeContacts($formattedParent); - // 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 createContactTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $email = 'email96619420'; - $languageTag = 'languageTag-2091510221'; - $expectedResponse = new Contact(); - $expectedResponse->setName($name); - $expectedResponse->setEmail($email); - $expectedResponse->setLanguageTag($languageTag); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - $contact = new Contact(); - $contactEmail = 'contactEmail1253690204'; - $contact->setEmail($contactEmail); - $contactNotificationCategorySubscriptions = []; - $contact->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions); - $contactLanguageTag = 'contactLanguageTag229803234'; - $contact->setLanguageTag($contactLanguageTag); - $response = $gapicClient->createContact($formattedParent, $contact); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/CreateContact', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getContact(); - $this->assertProtobufEquals($contact, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function createContactExceptionTest() - { - $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]'); - $contact = new Contact(); - $contactEmail = 'contactEmail1253690204'; - $contact->setEmail($contactEmail); - $contactNotificationCategorySubscriptions = []; - $contact->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions); - $contactLanguageTag = 'contactLanguageTag229803234'; - $contact->setLanguageTag($contactLanguageTag); - try { - $gapicClient->createContact($formattedParent, $contact); - // 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 deleteContactTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->contactName('[PROJECT]', '[CONTACT]'); - $gapicClient->deleteContact($formattedName); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/DeleteContact', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteContactExceptionTest() - { - $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->contactName('[PROJECT]', '[CONTACT]'); - try { - $gapicClient->deleteContact($formattedName); - // 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 getContactTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $email = 'email96619420'; - $languageTag = 'languageTag-2091510221'; - $expectedResponse = new Contact(); - $expectedResponse->setName($name2); - $expectedResponse->setEmail($email); - $expectedResponse->setLanguageTag($languageTag); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->contactName('[PROJECT]', '[CONTACT]'); - $response = $gapicClient->getContact($formattedName); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/GetContact', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getContactExceptionTest() - { - $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->contactName('[PROJECT]', '[CONTACT]'); - try { - $gapicClient->getContact($formattedName); - // 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 listContactsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $contactsElement = new Contact(); - $contacts = [ - $contactsElement, - ]; - $expectedResponse = new ListContactsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setContacts($contacts); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - $response = $gapicClient->listContacts($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getContacts()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/ListContacts', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listContactsExceptionTest() - { - $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]'); - try { - $gapicClient->listContacts($formattedParent); - // 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 sendTestMessageTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedContacts = [ - $gapicClient->contactName('[PROJECT]', '[CONTACT]'), - ]; - $formattedResource = $gapicClient->projectName('[PROJECT]'); - $notificationCategory = NotificationCategory::NOTIFICATION_CATEGORY_UNSPECIFIED; - $gapicClient->sendTestMessage($formattedContacts, $formattedResource, $notificationCategory); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/SendTestMessage', $actualFuncCall); - $actualValue = $actualRequestObject->getContacts(); - $this->assertProtobufEquals($formattedContacts, $actualValue); - $actualValue = $actualRequestObject->getResource(); - $this->assertProtobufEquals($formattedResource, $actualValue); - $actualValue = $actualRequestObject->getNotificationCategory(); - $this->assertProtobufEquals($notificationCategory, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function sendTestMessageExceptionTest() - { - $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 - $formattedContacts = [ - $gapicClient->contactName('[PROJECT]', '[CONTACT]'), - ]; - $formattedResource = $gapicClient->projectName('[PROJECT]'); - $notificationCategory = NotificationCategory::NOTIFICATION_CATEGORY_UNSPECIFIED; - try { - $gapicClient->sendTestMessage($formattedContacts, $formattedResource, $notificationCategory); - // 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 updateContactTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $email = 'email96619420'; - $languageTag = 'languageTag-2091510221'; - $expectedResponse = new Contact(); - $expectedResponse->setName($name); - $expectedResponse->setEmail($email); - $expectedResponse->setLanguageTag($languageTag); - $transport->addResponse($expectedResponse); - // Mock request - $contact = new Contact(); - $contactEmail = 'contactEmail1253690204'; - $contact->setEmail($contactEmail); - $contactNotificationCategorySubscriptions = []; - $contact->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions); - $contactLanguageTag = 'contactLanguageTag229803234'; - $contact->setLanguageTag($contactLanguageTag); - $response = $gapicClient->updateContact($contact); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.essentialcontacts.v1.EssentialContactsService/UpdateContact', $actualFuncCall); - $actualValue = $actualRequestObject->getContact(); - $this->assertProtobufEquals($contact, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function updateContactExceptionTest() - { - $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 - $contact = new Contact(); - $contactEmail = 'contactEmail1253690204'; - $contact->setEmail($contactEmail); - $contactNotificationCategorySubscriptions = []; - $contact->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions); - $contactLanguageTag = 'contactLanguageTag229803234'; - $contact->setLanguageTag($contactLanguageTag); - try { - $gapicClient->updateContact($contact); - // 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()); - } -}