diff --git a/Core/src/ServiceBuilder.php b/Core/src/ServiceBuilder.php index 9a5ac3f4f822..3bf33552b834 100644 --- a/Core/src/ServiceBuilder.php +++ b/Core/src/ServiceBuilder.php @@ -29,7 +29,8 @@ use Google\Cloud\Speech\SpeechClient; use Google\Cloud\Storage\StorageClient; use Google\Cloud\Trace\TraceClient; -use Google\Cloud\Translate\V2\TranslateClient; +use Google\Cloud\Translate\V2\TranslateClient as DeprecatedTranslateClient; +use Google\Cloud\Translate\V3\Client\TranslationServiceClient; use Google\Cloud\Vision\VisionClient; use Psr\Cache\CacheItemPoolInterface; @@ -356,51 +357,19 @@ public function vision(array $config = []) } /** - * Google Cloud Translation provides the ability to dynamically translate - * text between thousands of language pairs and lets websites and programs - * integrate with translation service programmatically. - * - * The Google Cloud Translation API is available as a paid - * service. See the [Pricing](https://cloud.google.com/translation/v2/pricing) - * and [FAQ](https://cloud.google.com/translation/v2/faq) pages for details. - * Find more information at the the - * [Google Cloud Translation docs](https://cloud.google.com/translation/docs/). - * - * Please note that while the Google Cloud Translation API supports - * authentication via service account and application default credentials - * like other Cloud Platform APIs, it also supports authentication via a - * public API access key. If you wish to authenticate using an API key, - * follow the - * [before you begin](https://cloud.google.com/translation/v2/translating-text-with-rest#before-you-begin) - * instructions to learn how to generate a key. - * - * Example: - * ``` - * use Google\Cloud\Core\ServiceBuilder; - * - * $builder = new ServiceBuilder([ - * 'key' => 'YOUR_KEY' - * ]); - * - * $translate = $builder->translate(); - * ``` - * - * @param array $config [optional] { - * Configuration options. - * - * @type string $key A public API access key. - * @type string $target The target language to assign to the client. - * Defaults to `en` (English). - * @type callable $httpHandler A handler used to deliver Psr7 requests. - * Only valid for requests sent over REST. - * @type int $retries Number of retries for a failed request. - * **Defaults to** `3`. - * } - * @return TranslateClient + * @deprecated + * @see TranslationServiceClient + * @throws \BadMethodCallException */ public function translate(array $config = []) { - return $this->createClient(TranslateClient::class, 'translate', $config); + if (class_exists(DeprecatedTranslateClient::class)) { + return $this->createClient(DeprecatedTranslateClient::class, 'translate', $config); + } + throw new \BadMethodCallException(sprintf( + 'This method is no longer supported, create %s directly instead.', + TranslationServiceClient::class + )); } /** diff --git a/Core/tests/Snippet/ServiceBuilderTest.php b/Core/tests/Snippet/ServiceBuilderTest.php index d6746317c5d3..2ad7a4da74be 100644 --- a/Core/tests/Snippet/ServiceBuilderTest.php +++ b/Core/tests/Snippet/ServiceBuilderTest.php @@ -29,7 +29,6 @@ use Google\Cloud\Speech\SpeechClient; use Google\Cloud\Storage\StorageClient; use Google\Cloud\Trace\TraceClient; -use Google\Cloud\Translate\TranslateClient; use Google\Cloud\Vision\VisionClient; /** @@ -64,7 +63,6 @@ public function serviceBuilderMethods() ['storage', StorageClient::class, 'storage'], ['trace', TraceClient::class, 'trace'], ['vision', VisionClient::class, 'vision'], - ['translate', TranslateClient::class, 'translate'] ]; } diff --git a/Core/tests/Unit/ServiceBuilderTest.php b/Core/tests/Unit/ServiceBuilderTest.php index 3667628bb299..eac970bca82a 100644 --- a/Core/tests/Unit/ServiceBuilderTest.php +++ b/Core/tests/Unit/ServiceBuilderTest.php @@ -28,7 +28,6 @@ use Google\Cloud\Speech\SpeechClient; use Google\Cloud\Storage\StorageClient; use Google\Cloud\Core\Tests\Unit\Fixtures; -use Google\Cloud\Translate\TranslateClient; use Google\Cloud\Vision\VisionClient; use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase; @@ -68,17 +67,6 @@ public function testBuildsClients($serviceName, $expectedClient, array $args = [ $this->assertInstanceOf($expectedClient, $localConfigClient); } - public function testTranslateClientWithApiKey() - { - $this->checkAndSkipTest([TranslateClient::class]); - - $config = ['key' => 'test_key']; - $serviceBuilder = new ServiceBuilder($config); - - $this->assertInstanceOf(TranslateClient::class, $serviceBuilder->translate()); - $this->assertInstanceOf(TranslateClient::class, $serviceBuilder->translate($config)); - } - /** * @dataProvider serviceProvider */ @@ -187,9 +175,6 @@ public function serviceProvider() ], [ 'storage', StorageClient::class - ], [ - 'translate', - TranslateClient::class ], [ 'vision', VisionClient::class diff --git a/Core/tests/Unit/ServicesNotFoundTest.php b/Core/tests/Unit/ServicesNotFoundTest.php index c4201bf0f703..b24ba6ff827c 100644 --- a/Core/tests/Unit/ServicesNotFoundTest.php +++ b/Core/tests/Unit/ServicesNotFoundTest.php @@ -74,7 +74,6 @@ private static function getApis() "Speech", "Storage", "Trace", - "Translate", "VideoIntelligence", "Vision", ]; @@ -93,7 +92,6 @@ public function serviceBuilderMethods() ['storage'], ['trace'], ['vision'], - ['translate'] ]; } diff --git a/Translate/owlbot.py b/Translate/owlbot.py index 5095cd42dc40..94fd6e990055 100644 --- a/Translate/owlbot.py +++ b/Translate/owlbot.py @@ -1,4 +1,4 @@ -# Copyright 2019 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,41 +30,27 @@ # Added so that we can pass copy_excludes in the owlbot_main() call _tracked_paths.add(src) -php.owlbot_main( - src=src, - dest=dest, - copy_excludes=[ - src / "*/src/V2/TranslateClient.php" - ] -) -# Change the wording for the deprecation warning. -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 +php.owlbot_main(src=src, dest=dest) -# fix relative cloud.google.com links +# remove class_alias code 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/Translate/phpunit-snippets.xml.dist b/Translate/phpunit-snippets.xml.dist deleted file mode 100644 index 319673b50fe0..000000000000 --- a/Translate/phpunit-snippets.xml.dist +++ /dev/null @@ -1,16 +0,0 @@ - - - - - src - - - src/V[!a-zA-Z]* - - - - - tests/Snippet - - - diff --git a/Translate/src/Connection/ConnectionInterface.php b/Translate/src/Connection/ConnectionInterface.php deleted file mode 100644 index 8aae1d3ef51b..000000000000 --- a/Translate/src/Connection/ConnectionInterface.php +++ /dev/null @@ -1,40 +0,0 @@ - __DIR__ . '/ServiceDefinition/translate-v2.json', - 'componentVersion' => TranslateClient::VERSION - ]; - - $this->setRequestWrapper(new RequestWrapper($config)); - $this->setRequestBuilder(new RequestBuilder( - $config['serviceDefinitionPath'], - $this->getApiEndpoint(self::DEFAULT_API_ENDPOINT, $config) - )); - } - - /** - * @param array $args - * @return array - * @throws ServiceException - */ - public function listDetections(array $args = []) - { - return $this->send('detections', 'detect', $args); - } - - /** - * @param array $args - * @return array - * @throws ServiceException - */ - public function listLanguages(array $args = []) - { - return $this->send('languages', 'list', $args); - } - - /** - * @param array $args - * @return array - * @throws ServiceException - */ - public function listTranslations(array $args = []) - { - return $this->send('translations', 'translate', $args); - } -} - -//@codingStandardsIgnoreStart -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(Rest::class, \Google\Cloud\Translate\Connection\Rest::class); -//@codingStandardsIgnoreEnd diff --git a/Translate/src/V2/Connection/ServiceDefinition/translate-v2.json b/Translate/src/V2/Connection/ServiceDefinition/translate-v2.json deleted file mode 100644 index 092ed8ee2c2f..000000000000 --- a/Translate/src/V2/Connection/ServiceDefinition/translate-v2.json +++ /dev/null @@ -1,440 +0,0 @@ -{ - "baseUrl": "https://translation.googleapis.com/language/translate/", - "servicePath": "language/translate/", - "kind": "discovery#restDescription", - "description": "The Google Cloud Translation API lets websites and programs integrate with\n Google Translate programmatically.", - "basePath": "/language/translate/", - "id": "translate:v2", - "documentationLink": "https://code.google.com/apis/language/translate/v2/getting_started.html", - "revision": "20170525", - "discoveryVersion": "v1", - "schemas": { - "TranslationsListResponse": { - "id": "TranslationsListResponse", - "description": "The main language translation response message.", - "type": "object", - "properties": { - "translations": { - "description": "Translations contains list of translation results of given text", - "type": "array", - "items": { - "$ref": "TranslationsResource" - } - } - } - }, - "TranslateTextRequest": { - "description": "The main translation request message for the Cloud Translation API.", - "type": "object", - "properties": { - "target": { - "type": "string", - "description": "The language to use for translation of the input text, set to one of the\nlanguage codes listed in Language Support." - }, - "q": { - "description": "The input text to translate. Repeat this parameter to perform translation\noperations on multiple text inputs.", - "type": "array", - "items": { - "type": "string" - } - }, - "format": { - "type": "string", - "description": "The format of the source text, in either HTML (default) or plain-text. A\nvalue of \"html\" indicates HTML and a value of \"text\" indicates plain-text." - }, - "source": { - "description": "The language of the source text, set to one of the language codes listed in\nLanguage Support. If the source language is not specified, the API will\nattempt to identify the source language automatically and return it within\nthe response.", - "type": "string" - }, - "model": { - "description": "The `model` type requested for this translation. Valid values are\nlisted in public documentation.", - "type": "string" - } - }, - "id": "TranslateTextRequest" - }, - "DetectLanguageRequest": { - "id": "DetectLanguageRequest", - "description": "The request message for language detection.", - "type": "object", - "properties": { - "q": { - "description": "The input text upon which to perform language detection. Repeat this\nparameter to perform language detection on multiple text inputs.", - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "LanguagesResource": { - "type": "object", - "properties": { - "language": { - "description": "Supported language code, generally consisting of its ISO 639-1\nidentifier. (E.g. 'en', 'ja'). In certain cases, BCP-47 codes including\nlanguage + region identifiers are returned (e.g. 'zh-TW' and 'zh-CH')", - "type": "string" - }, - "name": { - "description": "Human readable name of the language localized to the target language.", - "type": "string" - } - }, - "id": "LanguagesResource" - }, - "DetectionsListResponse": { - "type": "object", - "properties": { - "detections": { - "description": "A detections contains detection results of several text", - "type": "array", - "items": { - "$ref": "DetectionsResource" - } - } - }, - "id": "DetectionsListResponse" - }, - "GetSupportedLanguagesRequest": { - "description": "The request message for discovering supported languages.", - "type": "object", - "properties": { - "target": { - "description": "The language to use to return localized, human readable names of supported\nlanguages.", - "type": "string" - } - }, - "id": "GetSupportedLanguagesRequest" - }, - "LanguagesListResponse": { - "type": "object", - "properties": { - "languages": { - "type": "array", - "items": { - "$ref": "LanguagesResource" - }, - "description": "List of source/target languages supported by the translation API. If target parameter is unspecified, the list is sorted by the ASCII code point order of the language code. If target parameter is specified, the list is sorted by the collation order of the language name in the target language." - } - }, - "id": "LanguagesListResponse" - }, - "DetectionsResource": { - "description": "An array of languages which we detect for the given text The most likely language list first.", - "type": "array", - "items": { - "type": "object", - "properties": { - "confidence": { - "description": "The confidence of the detection result of this language.", - "format": "float", - "type": "number" - }, - "isReliable": { - "type": "boolean", - "description": "A boolean to indicate is the language detection result reliable." - }, - "language": { - "description": "The language we detected.", - "type": "string" - } - } - }, - "id": "DetectionsResource" - }, - "TranslationsResource": { - "type": "object", - "properties": { - "model": { - "description": "The `model` type used for this translation. Valid values are\nlisted in public documentation. Can be different from requested `model`.\nPresent only if specific model type was explicitly requested.", - "type": "string" - }, - "translatedText": { - "description": "Text translated into the target language.", - "type": "string" - }, - "detectedSourceLanguage": { - "description": "The source language of the initial request, detected automatically, if\nno source language was passed within the initial request. If the\nsource language was passed, auto-detection of the language will not\noccur and this field will be empty.", - "type": "string" - } - }, - "id": "TranslationsResource" - } - }, - "icons": { - "x16": "https://www.google.com/images/icons/product/translate-16.png", - "x32": "https://www.google.com/images/icons/product/translate-32.png" - }, - "protocol": "rest", - "canonicalName": "Translate", - "auth": { - "oauth2": { - "scopes": { - "https://www.googleapis.com/auth/cloud-platform": { - "description": "View and manage your data across Google Cloud Platform services" - }, - "https://www.googleapis.com/auth/cloud-translation": { - "description": "Translate text from one language to another using Google Translate" - } - } - } - }, - "rootUrl": "https://translation.googleapis.com/", - "ownerDomain": "google.com", - "name": "translate", - "batchPath": "batch/translate", - "features": [ - "dataWrapper" - ], - "title": "Google Cloud Translation API", - "ownerName": "Google", - "resources": { - "detections": { - "methods": { - "list": { - "id": "language.detections.list", - "path": "v2/detect", - "description": "Detects the language of text within a request.", - "httpMethod": "GET", - "response": { - "$ref": "DetectionsListResponse" - }, - "parameterOrder": [ - "q" - ], - "parameters": { - "q": { - "description": "The input text upon which to perform language detection. Repeat this\nparameter to perform language detection on multiple text inputs.", - "type": "string", - "required": true, - "repeated": true, - "location": "query" - } - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-translation", - "https://www.googleapis.com/auth/cloud-platform" - ] - }, - "detect": { - "path": "v2/detect", - "id": "language.detections.detect", - "description": "Detects the language of text within a request.", - "request": { - "$ref": "DetectLanguageRequest" - }, - "response": { - "$ref": "DetectionsListResponse" - }, - "parameterOrder": [], - "httpMethod": "POST", - "parameters": {}, - "scopes": [ - "https://www.googleapis.com/auth/cloud-translation", - "https://www.googleapis.com/auth/cloud-platform" - ] - } - } - }, - "languages": { - "methods": { - "list": { - "id": "language.languages.list", - "path": "v2/languages", - "description": "Returns a list of supported languages for translation.", - "response": { - "$ref": "LanguagesListResponse" - }, - "httpMethod": "GET", - "scopes": [ - "https://www.googleapis.com/auth/cloud-translation", - "https://www.googleapis.com/auth/cloud-platform" - ], - "parameters": { - "target": { - "location": "query", - "description": "The language to use to return localized, human readable names of supported\nlanguages.", - "type": "string" - }, - "model": { - "location": "query", - "description": "The model type for which supported languages should be returned.", - "type": "string" - } - } - } - } - }, - "translations": { - "methods": { - "translate": { - "response": { - "$ref": "TranslationsListResponse" - }, - "parameterOrder": [], - "httpMethod": "POST", - "scopes": [ - "https://www.googleapis.com/auth/cloud-translation", - "https://www.googleapis.com/auth/cloud-platform" - ], - "parameters": {}, - "path": "v2", - "id": "language.translations.translate", - "request": { - "$ref": "TranslateTextRequest" - }, - "description": "Translates input text, returning translated text." - }, - "list": { - "path": "v2", - "id": "language.translations.list", - "description": "Translates input text, returning translated text.", - "response": { - "$ref": "TranslationsListResponse" - }, - "parameterOrder": [ - "q", - "target" - ], - "httpMethod": "GET", - "parameters": { - "target": { - "location": "query", - "description": "The language to use for translation of the input text, set to one of the\nlanguage codes listed in Language Support.", - "type": "string", - "required": true - }, - "format": { - "location": "query", - "enum": [ - "html", - "text" - ], - "description": "The format of the source text, in either HTML (default) or plain-text. A\nvalue of \"html\" indicates HTML and a value of \"text\" indicates plain-text.", - "type": "string", - "enumDescriptions": [ - "Specifies the input is in HTML", - "Specifies the input is in plain textual format" - ] - }, - "model": { - "location": "query", - "description": "The `model` type requested for this translation. Valid values are\nlisted in public documentation.", - "type": "string" - }, - "q": { - "description": "The input text to translate. Repeat this parameter to perform translation\noperations on multiple text inputs.", - "type": "string", - "required": true, - "repeated": true, - "location": "query" - }, - "source": { - "description": "The language of the source text, set to one of the language codes listed in\nLanguage Support. If the source language is not specified, the API will\nattempt to identify the source language automatically and return it within\nthe response.", - "type": "string", - "location": "query" - }, - "cid": { - "description": "The customization id for translate", - "type": "string", - "repeated": true, - "location": "query" - } - }, - "scopes": [ - "https://www.googleapis.com/auth/cloud-translation", - "https://www.googleapis.com/auth/cloud-platform" - ] - } - } - } - }, - "parameters": { - "key": { - "description": "API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.", - "type": "string", - "location": "query" - }, - "access_token": { - "location": "query", - "description": "OAuth access token.", - "type": "string" - }, - "quotaUser": { - "location": "query", - "description": "Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.", - "type": "string" - }, - "pp": { - "description": "Pretty-print response.", - "type": "boolean", - "default": "true", - "location": "query" - }, - "oauth_token": { - "location": "query", - "description": "OAuth 2.0 token for the current user.", - "type": "string" - }, - "bearer_token": { - "description": "OAuth bearer token.", - "type": "string", - "location": "query" - }, - "upload_protocol": { - "description": "Upload protocol for media (e.g. \"raw\", \"multipart\").", - "type": "string", - "location": "query" - }, - "prettyPrint": { - "location": "query", - "description": "Returns response with indentations and line breaks.", - "type": "boolean", - "default": "true" - }, - "fields": { - "type": "string", - "location": "query", - "description": "Selector specifying which fields to include in a partial response." - }, - "uploadType": { - "location": "query", - "description": "Legacy upload protocol for media (e.g. \"media\", \"multipart\").", - "type": "string" - }, - "callback": { - "type": "string", - "location": "query", - "description": "JSONP" - }, - "$.xgafv": { - "type": "string", - "enumDescriptions": [ - "v1 error format", - "v2 error format" - ], - "location": "query", - "enum": [ - "1", - "2" - ], - "description": "V1 error format." - }, - "alt": { - "enum": [ - "json", - "media", - "proto" - ], - "type": "string", - "enumDescriptions": [ - "Responses with Content-Type of application/json", - "Media download with context-dependent Content-Type", - "Responses with Content-Type of application/x-protobuf" - ], - "location": "query", - "description": "Data format for response.", - "default": "json" - } - }, - "version": "v2" -} diff --git a/Translate/src/V2/TranslateClient.php b/Translate/src/V2/TranslateClient.php deleted file mode 100644 index a9b613ea7e97..000000000000 --- a/Translate/src/V2/TranslateClient.php +++ /dev/null @@ -1,438 +0,0 @@ -key = (isset($config['key'])) - ? $config['key'] - : null; - - $this->targetLanguage = $config['target'] ?? self::ENGLISH_LANGUAGE_CODE; - - if (!isset($config['scopes'])) { - $config['scopes'] = [self::FULL_CONTROL_SCOPE]; - } - - if (!$this->key) { - $config = $this->configureAuthentication($config); - } else { - $config['shouldSignRequest'] = false; - } - - unset($config['key']); - unset($config['target']); - - $this->connection = new Rest($config); - } - - /** - * Translate a string from one language to another. - * - * Example: - * ``` - * $result = $translate->translate('Hello world!'); - * - * echo $result['text']; - * ``` - * - * @see https://cloud.google.com/translation/v2/translating-text-with-rest Translating Text - * - * @param string $string The string to translate. - * @param array $options [optional] { - * Configuration Options. - * - * @type string $source The source language to translate from. Must be a - * valid ISO 639-1 language code. If not provided the value will - * be automatically detected by the server. - * @type string $target The target language to translate to. Must be a - * valid ISO 639-1 language code. **Defaults to** the value assigned - * to the client (`"en"` by default). - * @type string $format Indicates whether the string to be translated is - * either plain-text or HTML. Acceptable values are `html` or - * `text`. **Defaults to** `"html"`. - * @type string $model The model to use for the translation request. May - * be `nmt` (for the NMT model) or `base` (for the PBMT model). - * **Defaults to** using the NMT model. If the NMT model is not - * supported for the requested language translation pair, the PBMT - * model will be defaulted instead. For a list of supported - * languages for the model types, please see the - * [Language Support](https://cloud.google.com/translate/docs/languages) - * documentation. - * } - * @return array|null A translation result including a `source` key containing - * the detected or provided language of the provided input, an - * `input` key containing the original string, and a `text` key - * containing the translated result. - * @throws ServiceException - */ - public function translate($string, array $options = []) - { - $res = $this->translateBatch([$string], $options); - if (count($res) > 0) { - return $res[0]; - } - } - - /** - * Translate multiple strings from one language to another. - * - * Example: - * ``` - * $results = $translate->translateBatch([ - * 'Hello world!', - * 'My name is David.' - * ]); - * - * foreach ($results as $result) { - * echo $result['text']; - * } - * ``` - * - * @see https://cloud.google.com/translation/v2/translating-text-with-rest Translating Text - * - * @param array $strings An array of strings to translate. - * @param array $options [optional] { - * Configuration Options. - * - * @type string $source The source language to translate from. Must be a - * valid ISO 639-1 language code. If not provided the value will - * be automatically detected by the server. - * @type string $target The target language to translate to. Must be a - * valid ISO 639-1 language code. **Defaults to** the value assigned - * to the client (`"en"` by default). - * @type string $format Indicates whether the string to be translated is - * either plain-text or HTML. Acceptable values are `html` or - * `text`. **Defaults to** `"html"`. - * @type string $model The model to use for the translation request. May - * be `nmt` (for the NMT model) or `base` (for the PBMT model). - * **Defaults to** using the NMT model. If the NMT model is not - * supported for the requested language translation pair, the PBMT - * model will be defaulted instead. For a list of supported - * languages for the model types, please see the - * [Language Support](https://cloud.google.com/translate/docs/languages) - * documentation. - * } - * @return array A set of translation results. Each result includes a - * `source` key containing the detected or provided language of the - * provided input, an `input` key containing the original string, - * and a `text` key containing the translated result. - * @throws ServiceException - */ - public function translateBatch(array $strings, array $options = []) - { - $options += [ - 'model' => null, - ]; - - $options = array_filter($options + [ - 'q' => $strings, - 'key' => $this->key, - 'target' => $this->targetLanguage, - 'model' => $options['model'] - ], function ($opt) { - return !is_null($opt); - }); - - $response = $this->connection->listTranslations($options); - - $translations = []; - $strings = array_values($strings); - - if (isset($response['data']['translations'])) { - foreach ($response['data']['translations'] as $key => $translation) { - $source = $translation['detectedSourceLanguage'] ?? $options['source']; - - $model = (isset($translation['model'])) - ? $translation['model'] - : null; - - $translations[] = [ - 'source' => $source, - 'input' => $strings[$key], - 'text' => $translation['translatedText'], - 'model' => $model - ]; - } - } - - return $translations; - } - - /** - * Detect the language of a string. - * - * Example: - * ``` - * $result = $translate->detectLanguage('Hello world!'); - * - * echo $result['languageCode']; - * ``` - * - * @see https://cloud.google.com/translation/v2/detecting-language-with-rest Detecting Langauge - * - * @param string $string The string to detect the language of. - * @param array $options [optional] Configuration Options. - * @return array A result including a `languageCode` key - * containing the detected ISO 639-1 language code, an `input` key - * containing the original string, and in most cases a `confidence` - * key containing a value between 0 - 1 signifying the confidence of - * the result. - * @throws ServiceException - */ - public function detectLanguage($string, array $options = []) - { - return $this->detectLanguageBatch([$string], $options)[0]; - } - - /** - * Detect the language of multiple strings. - * - * Example: - * ``` - * $results = $translate->detectLanguageBatch([ - * 'Hello World!', - * 'My name is David.' - * ]); - * - * foreach ($results as $result) { - * echo $result['languageCode']; - * } - * ``` - * - * @see https://cloud.google.com/translation/v2/detecting-language-with-rest Detecting Langauge - * - * @param string $string The string to detect the language of. - * @param array $options [optional] Configuration Options. - * @return array A set of results. Each result includes a `languageCode` key - * containing the detected ISO 639-1 language code, an `input` key - * containing the original string, and in most cases a `confidence` - * key containing a value between 0 - 1 signifying the confidence of - * the result. - * @throws ServiceException - */ - public function detectLanguageBatch(array $strings, array $options = []) - { - $response = $this->connection->listDetections($options + [ - 'q' => $strings, - 'key' => $this->key - ]); - - $detections = []; - - foreach ($response['data']['detections'] as $key => $detection) { - $detection = $detection[0]; - - $detections[] = array_filter( - [ - 'languageCode' => $detection['language'], - 'input' => $strings[$key], - 'confidence' => isset($detection['confidence']) ? $detection['confidence'] : null - ], - function ($value) { - return !is_null($value); - } - ); - } - - return $detections; - } - - /** - * Get all supported languages. - * - * Example: - * ``` - * $languages = $translate->languages(); - * - * foreach ($languages as $language) { - * echo $language; - * } - * ``` - * - * @codingStandardsIgnoreStart - * @see https://cloud.google.com/translation/v2/discovering-supported-languages-with-rest Discovering Supported Languages - * @codingStandardsIgnoreEnd - * - * @param array $options [optional] Configuration Options. - * @return array A list of supported ISO 639-1 language codes. - * @throws ServiceException - */ - public function languages(array $options = []) - { - $response = $this->localizedLanguages($options + ['target' => null]); - - return array_map(function ($language) { - return $language['code']; - }, $response); - } - - /** - * Get the supported languages for translation in the targeted language. - * - * Unlike {@see Google\Cloud\Translate\TranslateClient::languages()} this - * will return the localized language names in addition to the ISO 639-1 - * language codes. - * - * Example: - * ``` - * $languages = $translate->localizedLanguages(); - * - * foreach ($languages as $language) { - * echo $language['code']; - * } - * ``` - * - * @codingStandardsIgnoreStart - * @see https://cloud.google.com/translation/v2/discovering-supported-languages-with-rest Discovering Supported Languages - * @codingStandardsIgnoreEnd - * - * @param array $options [optional] { - * Configuration Options. - * - * @type string $target The language to discover supported languages - * for. Must be a valid ISO 639-1 language code. **Defaults to** the - * value assigned to the client (`"en"` by default). - * } - * @return array A set of language results. Each result includes a `code` - * key containing the ISO 639-1 code for the supported language and - * a `name` key containing the name of the language written in the - * target language. - * @throws ServiceException - */ - public function localizedLanguages(array $options = []) - { - $response = $this->connection->listLanguages($options + [ - 'key' => $this->key, - 'target' => $this->targetLanguage - ]); - - return array_map(function ($language) { - return array_filter([ - 'code' => $language['language'], - 'name' => isset($language['name']) ? $language['name'] : null - ]); - }, $response['data']['languages']); - } -} - -//@codingStandardsIgnoreStart -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(TranslateClient::class, \Google\Cloud\Translate\TranslateClient::class); -//@codingStandardsIgnoreEnd diff --git a/Translate/src/V3/AdaptiveMtDataset.php b/Translate/src/V3/AdaptiveMtDataset.php index 6e032801a948..dce6452a2be6 100644 --- a/Translate/src/V3/AdaptiveMtDataset.php +++ b/Translate/src/V3/AdaptiveMtDataset.php @@ -21,7 +21,7 @@ class AdaptiveMtDataset 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 = ''; /** * The name of the dataset to show in the interface. The name can be * up to 32 characters long and can consist only of ASCII Latin letters A-Z @@ -29,37 +29,37 @@ class AdaptiveMtDataset extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string display_name = 2; */ - private $display_name = ''; + protected $display_name = ''; /** * The BCP-47 language code of the source language. * * Generated from protobuf field string source_language_code = 3; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * The BCP-47 language code of the target language. * * Generated from protobuf field string target_language_code = 4; */ - private $target_language_code = ''; + protected $target_language_code = ''; /** * The number of examples in the dataset. * * Generated from protobuf field int32 example_count = 5; */ - private $example_count = 0; + protected $example_count = 0; /** * Output only. Timestamp when this dataset was created. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 9 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $create_time = null; + protected $create_time = null; /** * Output only. Timestamp when this dataset was last updated. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $update_time = null; + protected $update_time = null; /** * Constructor. diff --git a/Translate/src/V3/AdaptiveMtFile.php b/Translate/src/V3/AdaptiveMtFile.php index f14f4d6ea4b1..fcd6d230e4b7 100644 --- a/Translate/src/V3/AdaptiveMtFile.php +++ b/Translate/src/V3/AdaptiveMtFile.php @@ -21,31 +21,31 @@ class AdaptiveMtFile 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 = ''; /** * The file's display name. * * Generated from protobuf field string display_name = 2; */ - private $display_name = ''; + protected $display_name = ''; /** * The number of entries that the file contains. * * Generated from protobuf field int32 entry_count = 3; */ - private $entry_count = 0; + protected $entry_count = 0; /** * Output only. Timestamp when this file was created. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $create_time = null; + protected $create_time = null; /** * Output only. Timestamp when this file was last updated. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $update_time = null; + protected $update_time = null; /** * Constructor. diff --git a/Translate/src/V3/AdaptiveMtSentence.php b/Translate/src/V3/AdaptiveMtSentence.php index d64dc87880f7..72c6dfe743de 100644 --- a/Translate/src/V3/AdaptiveMtSentence.php +++ b/Translate/src/V3/AdaptiveMtSentence.php @@ -21,31 +21,31 @@ class AdaptiveMtSentence 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 = ''; /** * Required. The source sentence. * * Generated from protobuf field string source_sentence = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $source_sentence = ''; + protected $source_sentence = ''; /** * Required. The target sentence. * * Generated from protobuf field string target_sentence = 3 [(.google.api.field_behavior) = REQUIRED]; */ - private $target_sentence = ''; + protected $target_sentence = ''; /** * Output only. Timestamp when this sentence was created. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $create_time = null; + protected $create_time = null; /** * Output only. Timestamp when this sentence was last updated. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $update_time = null; + protected $update_time = null; /** * Constructor. diff --git a/Translate/src/V3/AdaptiveMtTranslateRequest.php b/Translate/src/V3/AdaptiveMtTranslateRequest.php index f3a4d34522e5..c58d6cec4b91 100644 --- a/Translate/src/V3/AdaptiveMtTranslateRequest.php +++ b/Translate/src/V3/AdaptiveMtTranslateRequest.php @@ -21,14 +21,14 @@ class AdaptiveMtTranslateRequest 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 resource name for the dataset to use for adaptive MT. * `projects/{project}/locations/{location-id}/adaptiveMtDatasets/{dataset}` * * Generated from protobuf field string dataset = 2 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $dataset = ''; + protected $dataset = ''; /** * Required. The content of the input in string format. * @@ -40,7 +40,7 @@ class AdaptiveMtTranslateRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field optional .google.cloud.translation.v3.AdaptiveMtTranslateRequest.ReferenceSentenceConfig reference_sentence_config = 6; */ - private $reference_sentence_config = null; + protected $reference_sentence_config = null; /** * Optional. Glossary to be applied. The glossary must be * within the same region (have the same location-id) as the model, otherwise @@ -48,7 +48,7 @@ class AdaptiveMtTranslateRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field optional .google.cloud.translation.v3.AdaptiveMtTranslateRequest.GlossaryConfig glossary_config = 7 [(.google.api.field_behavior) = OPTIONAL]; */ - private $glossary_config = null; + protected $glossary_config = null; /** * @param string $parent Required. Location to make a regional call. diff --git a/Translate/src/V3/AdaptiveMtTranslateRequest/GlossaryConfig.php b/Translate/src/V3/AdaptiveMtTranslateRequest/GlossaryConfig.php index 3776f46bf9f3..321a7c5a9cef 100644 --- a/Translate/src/V3/AdaptiveMtTranslateRequest/GlossaryConfig.php +++ b/Translate/src/V3/AdaptiveMtTranslateRequest/GlossaryConfig.php @@ -25,21 +25,21 @@ class GlossaryConfig extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string glossary = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $glossary = ''; + protected $glossary = ''; /** * Optional. Indicates match is case insensitive. The default value is * `false` if missing. * * Generated from protobuf field bool ignore_case = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $ignore_case = false; + protected $ignore_case = false; /** * Optional. If set to true, the glossary will be used for contextual * translation. * * Generated from protobuf field bool contextual_translation_enabled = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $contextual_translation_enabled = false; + protected $contextual_translation_enabled = false; /** * Constructor. @@ -155,6 +155,4 @@ public function setContextualTranslationEnabled($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(GlossaryConfig::class, \Google\Cloud\Translate\V3\AdaptiveMtTranslateRequest_GlossaryConfig::class); diff --git a/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentenceConfig.php b/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentenceConfig.php index 09fb6e213206..081ce01da3de 100644 --- a/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentenceConfig.php +++ b/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentenceConfig.php @@ -29,13 +29,13 @@ class ReferenceSentenceConfig extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string source_language_code = 2; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * Target language code. * * Generated from protobuf field string target_language_code = 3; */ - private $target_language_code = ''; + protected $target_language_code = ''; /** * Constructor. @@ -145,6 +145,4 @@ public function setTargetLanguageCode($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ReferenceSentenceConfig::class, \Google\Cloud\Translate\V3\AdaptiveMtTranslateRequest_ReferenceSentenceConfig::class); diff --git a/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentencePair.php b/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentencePair.php index 1ed14654a076..8f8e90c2ef4d 100644 --- a/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentencePair.php +++ b/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentencePair.php @@ -20,13 +20,13 @@ class ReferenceSentencePair extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string source_sentence = 1; */ - private $source_sentence = ''; + protected $source_sentence = ''; /** * Target sentence in the sentence pair. * * Generated from protobuf field string target_sentence = 2; */ - private $target_sentence = ''; + protected $target_sentence = ''; /** * Constructor. @@ -99,6 +99,4 @@ public function setTargetSentence($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ReferenceSentencePair::class, \Google\Cloud\Translate\V3\AdaptiveMtTranslateRequest_ReferenceSentencePair::class); diff --git a/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentencePairList.php b/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentencePairList.php index 4cf1d0cd0b60..e26b095821fd 100644 --- a/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentencePairList.php +++ b/Translate/src/V3/AdaptiveMtTranslateRequest/ReferenceSentencePairList.php @@ -65,6 +65,4 @@ public function setReferenceSentencePairs($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ReferenceSentencePairList::class, \Google\Cloud\Translate\V3\AdaptiveMtTranslateRequest_ReferenceSentencePairList::class); diff --git a/Translate/src/V3/AdaptiveMtTranslateResponse.php b/Translate/src/V3/AdaptiveMtTranslateResponse.php index 04c87686d3ed..23bd73ce8eb5 100644 --- a/Translate/src/V3/AdaptiveMtTranslateResponse.php +++ b/Translate/src/V3/AdaptiveMtTranslateResponse.php @@ -26,7 +26,7 @@ class AdaptiveMtTranslateResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string language_code = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $language_code = ''; + protected $language_code = ''; /** * Text translation response if a glossary is provided in the request. This * could be the same as 'translation' above if no terms apply. diff --git a/Translate/src/V3/AdaptiveMtTranslation.php b/Translate/src/V3/AdaptiveMtTranslation.php index c408c94b5c99..6dd8e9911c65 100644 --- a/Translate/src/V3/AdaptiveMtTranslation.php +++ b/Translate/src/V3/AdaptiveMtTranslation.php @@ -20,7 +20,7 @@ class AdaptiveMtTranslation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string translated_text = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $translated_text = ''; + protected $translated_text = ''; /** * Constructor. diff --git a/Translate/src/V3/BatchTransferResourcesResponse/TransferResourceResponse.php b/Translate/src/V3/BatchTransferResourcesResponse/TransferResourceResponse.php index 47f93f80a21a..61c040d03ffa 100644 --- a/Translate/src/V3/BatchTransferResourcesResponse/TransferResourceResponse.php +++ b/Translate/src/V3/BatchTransferResourcesResponse/TransferResourceResponse.php @@ -20,20 +20,20 @@ class TransferResourceResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string source = 1; */ - private $source = ''; + protected $source = ''; /** * Full name of the new resource successfully transferred from the source * hosted by Translation API. Target will be empty if the transfer failed. * * Generated from protobuf field string target = 2; */ - private $target = ''; + protected $target = ''; /** * The error result in case of failure. * * Generated from protobuf field .google.rpc.Status error = 3; */ - private $error = null; + protected $error = null; /** * Constructor. @@ -147,6 +147,4 @@ public function setError($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(TransferResourceResponse::class, \Google\Cloud\Translate\V3\BatchTransferResourcesResponse_TransferResourceResponse::class); diff --git a/Translate/src/V3/BatchTranslateDocumentMetadata.php b/Translate/src/V3/BatchTranslateDocumentMetadata.php index 56076a056841..578301767c67 100644 --- a/Translate/src/V3/BatchTranslateDocumentMetadata.php +++ b/Translate/src/V3/BatchTranslateDocumentMetadata.php @@ -20,68 +20,68 @@ class BatchTranslateDocumentMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.BatchTranslateDocumentMetadata.State state = 1; */ - private $state = 0; + protected $state = 0; /** * Total number of pages to translate in all documents so far. Documents * without clear page definition (such as XLSX) are not counted. * * Generated from protobuf field int64 total_pages = 2; */ - private $total_pages = 0; + protected $total_pages = 0; /** * Number of successfully translated pages in all documents so far. Documents * without clear page definition (such as XLSX) are not counted. * * Generated from protobuf field int64 translated_pages = 3; */ - private $translated_pages = 0; + protected $translated_pages = 0; /** * Number of pages that failed to process in all documents so far. Documents * without clear page definition (such as XLSX) are not counted. * * Generated from protobuf field int64 failed_pages = 4; */ - private $failed_pages = 0; + protected $failed_pages = 0; /** * Number of billable pages in documents with clear page definition (such as * PDF, DOCX, PPTX) so far. * * Generated from protobuf field int64 total_billable_pages = 5; */ - private $total_billable_pages = 0; + protected $total_billable_pages = 0; /** * Total number of characters (Unicode codepoints) in all documents so far. * * Generated from protobuf field int64 total_characters = 6; */ - private $total_characters = 0; + protected $total_characters = 0; /** * Number of successfully translated characters (Unicode codepoints) in all * documents so far. * * Generated from protobuf field int64 translated_characters = 7; */ - private $translated_characters = 0; + protected $translated_characters = 0; /** * Number of characters that have failed to process (Unicode codepoints) in * all documents so far. * * Generated from protobuf field int64 failed_characters = 8; */ - private $failed_characters = 0; + protected $failed_characters = 0; /** * Number of billable characters (Unicode codepoints) in documents without * clear page definition (such as XLSX) so far. * * Generated from protobuf field int64 total_billable_characters = 9; */ - private $total_billable_characters = 0; + protected $total_billable_characters = 0; /** * Time when the operation was submitted. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 10; */ - private $submit_time = null; + protected $submit_time = null; /** * Constructor. diff --git a/Translate/src/V3/BatchTranslateDocumentMetadata/State.php b/Translate/src/V3/BatchTranslateDocumentMetadata/State.php index 6631a48171fb..3c9807285e29 100644 --- a/Translate/src/V3/BatchTranslateDocumentMetadata/State.php +++ b/Translate/src/V3/BatchTranslateDocumentMetadata/State.php @@ -83,6 +83,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(State::class, \Google\Cloud\Translate\V3\BatchTranslateDocumentMetadata_State::class); diff --git a/Translate/src/V3/BatchTranslateDocumentMetadata_State.php b/Translate/src/V3/BatchTranslateDocumentMetadata_State.php deleted file mode 100644 index 8f0e42f7f9ce..000000000000 --- a/Translate/src/V3/BatchTranslateDocumentMetadata_State.php +++ /dev/null @@ -1,16 +0,0 @@ -string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Required. The ISO-639 language code of the input document if known, for * example, "en-US" or "sr-Latn". Supported language codes are listed in @@ -33,7 +33,7 @@ class BatchTranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string source_language_code = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * Required. The ISO-639 language code to use for translation of the input * document. Specify up to 10 language codes here. @@ -57,7 +57,7 @@ class BatchTranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.BatchDocumentOutputConfig output_config = 5 [(.google.api.field_behavior) = REQUIRED]; */ - private $output_config = null; + protected $output_config = null; /** * Optional. The models to use for translation. Map's key is target language * code. Map's value is the model name. Value can be a built-in general model, @@ -100,7 +100,7 @@ class BatchTranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string customized_attribution = 10 [(.google.api.field_behavior) = OPTIONAL]; */ - private $customized_attribution = ''; + protected $customized_attribution = ''; /** * Optional. If true, use the text removal server to remove the shadow text on * background image for native pdf translation. @@ -109,13 +109,13 @@ class BatchTranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool enable_shadow_removal_native_pdf = 11 [(.google.api.field_behavior) = OPTIONAL]; */ - private $enable_shadow_removal_native_pdf = false; + protected $enable_shadow_removal_native_pdf = false; /** * Optional. If true, enable auto rotation correction in DVS. * * Generated from protobuf field bool enable_rotation_correction = 12 [(.google.api.field_behavior) = OPTIONAL]; */ - private $enable_rotation_correction = false; + protected $enable_rotation_correction = false; /** * @param string $parent Required. Location to make a regional call. diff --git a/Translate/src/V3/BatchTranslateDocumentResponse.php b/Translate/src/V3/BatchTranslateDocumentResponse.php index f3f67678ae20..ac0c68355f78 100644 --- a/Translate/src/V3/BatchTranslateDocumentResponse.php +++ b/Translate/src/V3/BatchTranslateDocumentResponse.php @@ -24,61 +24,61 @@ class BatchTranslateDocumentResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int64 total_pages = 1; */ - private $total_pages = 0; + protected $total_pages = 0; /** * Number of successfully translated pages in all documents. Documents without * clear page definition (such as XLSX) are not counted. * * Generated from protobuf field int64 translated_pages = 2; */ - private $translated_pages = 0; + protected $translated_pages = 0; /** * Number of pages that failed to process in all documents. Documents without * clear page definition (such as XLSX) are not counted. * * Generated from protobuf field int64 failed_pages = 3; */ - private $failed_pages = 0; + protected $failed_pages = 0; /** * Number of billable pages in documents with clear page definition (such as * PDF, DOCX, PPTX) * * Generated from protobuf field int64 total_billable_pages = 4; */ - private $total_billable_pages = 0; + protected $total_billable_pages = 0; /** * Total number of characters (Unicode codepoints) in all documents. * * Generated from protobuf field int64 total_characters = 5; */ - private $total_characters = 0; + protected $total_characters = 0; /** * Number of successfully translated characters (Unicode codepoints) in all * documents. * * Generated from protobuf field int64 translated_characters = 6; */ - private $translated_characters = 0; + protected $translated_characters = 0; /** * Number of characters that have failed to process (Unicode codepoints) in * all documents. * * Generated from protobuf field int64 failed_characters = 7; */ - private $failed_characters = 0; + protected $failed_characters = 0; /** * Number of billable characters (Unicode codepoints) in documents without * clear page definition, such as XLSX. * * Generated from protobuf field int64 total_billable_characters = 8; */ - private $total_billable_characters = 0; + protected $total_billable_characters = 0; /** * Time when the operation was submitted. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 9; */ - private $submit_time = null; + protected $submit_time = null; /** * The time when the operation is finished and * [google.longrunning.Operation.done][google.longrunning.Operation.done] is @@ -86,7 +86,7 @@ class BatchTranslateDocumentResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp end_time = 10; */ - private $end_time = null; + protected $end_time = null; /** * Constructor. diff --git a/Translate/src/V3/BatchTranslateMetadata.php b/Translate/src/V3/BatchTranslateMetadata.php index 4a008316ffea..088d15ac8a90 100644 --- a/Translate/src/V3/BatchTranslateMetadata.php +++ b/Translate/src/V3/BatchTranslateMetadata.php @@ -20,20 +20,20 @@ class BatchTranslateMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.BatchTranslateMetadata.State state = 1; */ - private $state = 0; + protected $state = 0; /** * Number of successfully translated characters so far (Unicode codepoints). * * Generated from protobuf field int64 translated_characters = 2; */ - private $translated_characters = 0; + protected $translated_characters = 0; /** * Number of characters that have failed to process so far (Unicode * codepoints). * * Generated from protobuf field int64 failed_characters = 3; */ - private $failed_characters = 0; + protected $failed_characters = 0; /** * Total number of characters (Unicode codepoints). * This is the total number of codepoints from input files times the number of @@ -41,13 +41,13 @@ class BatchTranslateMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int64 total_characters = 4; */ - private $total_characters = 0; + protected $total_characters = 0; /** * Time when the operation was submitted. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 5; */ - private $submit_time = null; + protected $submit_time = null; /** * Constructor. diff --git a/Translate/src/V3/BatchTranslateMetadata/State.php b/Translate/src/V3/BatchTranslateMetadata/State.php index 287dfff03890..2753a8cf2b79 100644 --- a/Translate/src/V3/BatchTranslateMetadata/State.php +++ b/Translate/src/V3/BatchTranslateMetadata/State.php @@ -84,6 +84,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(State::class, \Google\Cloud\Translate\V3\BatchTranslateMetadata_State::class); diff --git a/Translate/src/V3/BatchTranslateMetadata_State.php b/Translate/src/V3/BatchTranslateMetadata_State.php deleted file mode 100644 index b12a52d2bcc7..000000000000 --- a/Translate/src/V3/BatchTranslateMetadata_State.php +++ /dev/null @@ -1,16 +0,0 @@ -int64 total_characters = 1; */ - private $total_characters = 0; + protected $total_characters = 0; /** * Number of successfully translated characters (Unicode codepoints). * * Generated from protobuf field int64 translated_characters = 2; */ - private $translated_characters = 0; + protected $translated_characters = 0; /** * Number of characters that have failed to process (Unicode codepoints). * * Generated from protobuf field int64 failed_characters = 3; */ - private $failed_characters = 0; + protected $failed_characters = 0; /** * Time when the operation was submitted. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 4; */ - private $submit_time = null; + protected $submit_time = null; /** * The time when the operation is finished and * [google.longrunning.Operation.done][google.longrunning.Operation.done] is @@ -49,7 +49,7 @@ class BatchTranslateResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp end_time = 5; */ - private $end_time = null; + protected $end_time = null; /** * Constructor. diff --git a/Translate/src/V3/BatchTranslateTextRequest.php b/Translate/src/V3/BatchTranslateTextRequest.php index 908bb550a468..79d9d7031130 100644 --- a/Translate/src/V3/BatchTranslateTextRequest.php +++ b/Translate/src/V3/BatchTranslateTextRequest.php @@ -25,13 +25,13 @@ class BatchTranslateTextRequest 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. Source language code. * * Generated from protobuf field string source_language_code = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * Required. Specify up to 10 language codes here. * @@ -69,7 +69,7 @@ class BatchTranslateTextRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.OutputConfig output_config = 6 [(.google.api.field_behavior) = REQUIRED]; */ - private $output_config = null; + protected $output_config = null; /** * Optional. Glossaries to be applied for translation. * It's keyed by target language code. diff --git a/Translate/src/V3/Client/TranslationServiceClient.php b/Translate/src/V3/Client/TranslationServiceClient.php index 42c3d39832d8..54a912eec90c 100644 --- a/Translate/src/V3/Client/TranslationServiceClient.php +++ b/Translate/src/V3/Client/TranslationServiceClient.php @@ -1,6 +1,6 @@ descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $options = isset($this->descriptors[$methodName]['longRunning']) + ? $this->descriptors[$methodName]['longRunning'] + : []; $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); $operation->reload(); return $operation; } + /** + * Create the default operation client for the service. + * + * @param array $options ClientOptions for the client. + * + * @return OperationsClient + */ + private function createOperationsClient(array $options) + { + // Unset client-specific configuration options + unset($options['serviceName'], $options['clientConfig'], $options['descriptorsConfigPath']); + + if (isset($options['operationsClient'])) { + return $options['operationsClient']; + } + + return new OperationsClient($options); + } + /** * Formats a string containing the fully-qualified path to represent a * adaptive_mt_dataset resource. @@ -308,8 +329,12 @@ public static function glossaryName(string $project, string $location, string $g * * @return string The formatted glossary_entry resource. */ - public static function glossaryEntryName(string $project, string $location, string $glossary, string $glossaryEntry): string - { + public static function glossaryEntryName( + string $project, + string $location, + string $glossary, + string $glossaryEntry + ): string { return self::getPathTemplate('glossaryEntry')->render([ 'project' => $project, 'location' => $location, @@ -478,8 +503,10 @@ public function __call($method, $args) * * @throws ApiException Thrown if the API call fails. */ - public function adaptiveMtTranslate(AdaptiveMtTranslateRequest $request, array $callOptions = []): AdaptiveMtTranslateResponse - { + public function adaptiveMtTranslate( + AdaptiveMtTranslateRequest $request, + array $callOptions = [] + ): AdaptiveMtTranslateResponse { return $this->startApiCall('AdaptiveMtTranslate', $request, $callOptions)->wait(); } @@ -511,8 +538,10 @@ public function adaptiveMtTranslate(AdaptiveMtTranslateRequest $request, array $ * * @throws ApiException Thrown if the API call fails. */ - public function batchTranslateDocument(BatchTranslateDocumentRequest $request, array $callOptions = []): OperationResponse - { + public function batchTranslateDocument( + BatchTranslateDocumentRequest $request, + array $callOptions = [] + ): OperationResponse { return $this->startApiCall('BatchTranslateDocument', $request, $callOptions)->wait(); } @@ -571,8 +600,10 @@ public function batchTranslateText(BatchTranslateTextRequest $request, array $ca * * @throws ApiException Thrown if the API call fails. */ - public function createAdaptiveMtDataset(CreateAdaptiveMtDatasetRequest $request, array $callOptions = []): AdaptiveMtDataset - { + public function createAdaptiveMtDataset( + CreateAdaptiveMtDatasetRequest $request, + array $callOptions = [] + ): AdaptiveMtDataset { return $this->startApiCall('CreateAdaptiveMtDataset', $request, $callOptions)->wait(); } @@ -912,8 +943,10 @@ public function exportData(ExportDataRequest $request, array $callOptions = []): * * @throws ApiException Thrown if the API call fails. */ - public function getAdaptiveMtDataset(GetAdaptiveMtDatasetRequest $request, array $callOptions = []): AdaptiveMtDataset - { + public function getAdaptiveMtDataset( + GetAdaptiveMtDatasetRequest $request, + array $callOptions = [] + ): AdaptiveMtDataset { return $this->startApiCall('GetAdaptiveMtDataset', $request, $callOptions)->wait(); } @@ -1070,8 +1103,10 @@ public function getModel(GetModelRequest $request, array $callOptions = []): Mod * * @throws ApiException Thrown if the API call fails. */ - public function getSupportedLanguages(GetSupportedLanguagesRequest $request, array $callOptions = []): SupportedLanguages - { + public function getSupportedLanguages( + GetSupportedLanguagesRequest $request, + array $callOptions = [] + ): SupportedLanguages { return $this->startApiCall('GetSupportedLanguages', $request, $callOptions)->wait(); } @@ -1098,8 +1133,10 @@ public function getSupportedLanguages(GetSupportedLanguagesRequest $request, arr * * @throws ApiException Thrown if the API call fails. */ - public function importAdaptiveMtFile(ImportAdaptiveMtFileRequest $request, array $callOptions = []): ImportAdaptiveMtFileResponse - { + public function importAdaptiveMtFile( + ImportAdaptiveMtFileRequest $request, + array $callOptions = [] + ): ImportAdaptiveMtFileResponse { return $this->startApiCall('ImportAdaptiveMtFile', $request, $callOptions)->wait(); } @@ -1151,8 +1188,10 @@ public function importData(ImportDataRequest $request, array $callOptions = []): * * @throws ApiException Thrown if the API call fails. */ - public function listAdaptiveMtDatasets(ListAdaptiveMtDatasetsRequest $request, array $callOptions = []): PagedListResponse - { + public function listAdaptiveMtDatasets( + ListAdaptiveMtDatasetsRequest $request, + array $callOptions = [] + ): PagedListResponse { return $this->startApiCall('ListAdaptiveMtDatasets', $request, $callOptions); } @@ -1205,8 +1244,10 @@ public function listAdaptiveMtFiles(ListAdaptiveMtFilesRequest $request, array $ * * @throws ApiException Thrown if the API call fails. */ - public function listAdaptiveMtSentences(ListAdaptiveMtSentencesRequest $request, array $callOptions = []): PagedListResponse - { + public function listAdaptiveMtSentences( + ListAdaptiveMtSentencesRequest $request, + array $callOptions = [] + ): PagedListResponse { return $this->startApiCall('ListAdaptiveMtSentences', $request, $callOptions); } @@ -1389,8 +1430,10 @@ public function romanizeText(RomanizeTextRequest $request, array $callOptions = * * @throws ApiException Thrown if the API call fails. */ - public function translateDocument(TranslateDocumentRequest $request, array $callOptions = []): TranslateDocumentResponse - { + public function translateDocument( + TranslateDocumentRequest $request, + array $callOptions = [] + ): TranslateDocumentResponse { return $this->startApiCall('TranslateDocument', $request, $callOptions)->wait(); } diff --git a/Translate/src/V3/CreateAdaptiveMtDatasetRequest.php b/Translate/src/V3/CreateAdaptiveMtDatasetRequest.php index bcb1996b2488..4fe3a22800c2 100644 --- a/Translate/src/V3/CreateAdaptiveMtDatasetRequest.php +++ b/Translate/src/V3/CreateAdaptiveMtDatasetRequest.php @@ -21,13 +21,13 @@ class CreateAdaptiveMtDatasetRequest 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 AdaptiveMtDataset to be created. * * Generated from protobuf field .google.cloud.translation.v3.AdaptiveMtDataset adaptive_mt_dataset = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $adaptive_mt_dataset = null; + protected $adaptive_mt_dataset = null; /** * @param string $parent Required. Name of the parent project. In form of diff --git a/Translate/src/V3/CreateDatasetMetadata.php b/Translate/src/V3/CreateDatasetMetadata.php index 4658cf62d29c..181ae224ce41 100644 --- a/Translate/src/V3/CreateDatasetMetadata.php +++ b/Translate/src/V3/CreateDatasetMetadata.php @@ -20,25 +20,25 @@ class CreateDatasetMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.OperationState state = 1; */ - private $state = 0; + protected $state = 0; /** * The creation time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 2; */ - private $create_time = null; + protected $create_time = null; /** * The last update time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 3; */ - private $update_time = null; + protected $update_time = null; /** * Only populated when operation doesn't succeed. * * Generated from protobuf field .google.rpc.Status error = 4; */ - private $error = null; + protected $error = null; /** * Constructor. diff --git a/Translate/src/V3/CreateDatasetRequest.php b/Translate/src/V3/CreateDatasetRequest.php index bbb214f2cf92..cba93978545d 100644 --- a/Translate/src/V3/CreateDatasetRequest.php +++ b/Translate/src/V3/CreateDatasetRequest.php @@ -20,13 +20,13 @@ class CreateDatasetRequest 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 Dataset to create. * * Generated from protobuf field .google.cloud.translation.v3.Dataset dataset = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $dataset = null; + protected $dataset = null; /** * @param string $parent Required. The project name. Please see diff --git a/Translate/src/V3/CreateGlossaryEntryRequest.php b/Translate/src/V3/CreateGlossaryEntryRequest.php index 0352665e428a..d4c38b6d0acb 100644 --- a/Translate/src/V3/CreateGlossaryEntryRequest.php +++ b/Translate/src/V3/CreateGlossaryEntryRequest.php @@ -20,13 +20,13 @@ class CreateGlossaryEntryRequest 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 glossary entry to create * * Generated from protobuf field .google.cloud.translation.v3.GlossaryEntry glossary_entry = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $glossary_entry = null; + protected $glossary_entry = null; /** * @param string $parent Required. The resource name of the glossary to create the entry under. Please see diff --git a/Translate/src/V3/CreateGlossaryMetadata.php b/Translate/src/V3/CreateGlossaryMetadata.php index f60a30435d09..cf902834a451 100644 --- a/Translate/src/V3/CreateGlossaryMetadata.php +++ b/Translate/src/V3/CreateGlossaryMetadata.php @@ -22,19 +22,19 @@ class CreateGlossaryMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * The current state of the glossary creation operation. * * Generated from protobuf field .google.cloud.translation.v3.CreateGlossaryMetadata.State state = 2; */ - private $state = 0; + protected $state = 0; /** * The time when the operation was submitted to the server. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 3; */ - private $submit_time = null; + protected $submit_time = null; /** * Constructor. diff --git a/Translate/src/V3/CreateGlossaryMetadata/State.php b/Translate/src/V3/CreateGlossaryMetadata/State.php index 3aed3689d193..aa0ec72dce20 100644 --- a/Translate/src/V3/CreateGlossaryMetadata/State.php +++ b/Translate/src/V3/CreateGlossaryMetadata/State.php @@ -81,6 +81,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(State::class, \Google\Cloud\Translate\V3\CreateGlossaryMetadata_State::class); diff --git a/Translate/src/V3/CreateGlossaryMetadata_State.php b/Translate/src/V3/CreateGlossaryMetadata_State.php deleted file mode 100644 index d6477abce7bf..000000000000 --- a/Translate/src/V3/CreateGlossaryMetadata_State.php +++ /dev/null @@ -1,16 +0,0 @@ -string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Required. The glossary to create. * * Generated from protobuf field .google.cloud.translation.v3.Glossary glossary = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $glossary = null; + protected $glossary = null; /** * @param string $parent Required. The project name. Please see diff --git a/Translate/src/V3/CreateModelMetadata.php b/Translate/src/V3/CreateModelMetadata.php index 6ed23081b49c..1cce1eadfba5 100644 --- a/Translate/src/V3/CreateModelMetadata.php +++ b/Translate/src/V3/CreateModelMetadata.php @@ -20,25 +20,25 @@ class CreateModelMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.OperationState state = 1; */ - private $state = 0; + protected $state = 0; /** * The creation time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 2; */ - private $create_time = null; + protected $create_time = null; /** * The last update time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 3; */ - private $update_time = null; + protected $update_time = null; /** * Only populated when operation doesn't succeed. * * Generated from protobuf field .google.rpc.Status error = 4; */ - private $error = null; + protected $error = null; /** * Constructor. diff --git a/Translate/src/V3/CreateModelRequest.php b/Translate/src/V3/CreateModelRequest.php index 2e9c857bdfb4..1084dfbed001 100644 --- a/Translate/src/V3/CreateModelRequest.php +++ b/Translate/src/V3/CreateModelRequest.php @@ -21,13 +21,13 @@ class CreateModelRequest 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 Model to create. * * Generated from protobuf field .google.cloud.translation.v3.Model model = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $model = null; + protected $model = null; /** * @param string $parent Required. The project name, in form of diff --git a/Translate/src/V3/Dataset.php b/Translate/src/V3/Dataset.php index 2582ff7e08a2..4705c6e85305 100644 --- a/Translate/src/V3/Dataset.php +++ b/Translate/src/V3/Dataset.php @@ -22,7 +22,7 @@ class Dataset extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * The name of the dataset to show in the interface. The name can be * up to 32 characters long and can consist only of ASCII Latin letters A-Z @@ -30,55 +30,55 @@ class Dataset extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string display_name = 2; */ - private $display_name = ''; + protected $display_name = ''; /** * The BCP-47 language code of the source language. * * Generated from protobuf field string source_language_code = 3; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * The BCP-47 language code of the target language. * * Generated from protobuf field string target_language_code = 4; */ - private $target_language_code = ''; + protected $target_language_code = ''; /** * Output only. The number of examples in the dataset. * * Generated from protobuf field int32 example_count = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $example_count = 0; + protected $example_count = 0; /** * Output only. Number of training examples (sentence pairs). * * Generated from protobuf field int32 train_example_count = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $train_example_count = 0; + protected $train_example_count = 0; /** * Output only. Number of validation examples (sentence pairs). * * Generated from protobuf field int32 validate_example_count = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $validate_example_count = 0; + protected $validate_example_count = 0; /** * Output only. Number of test examples (sentence pairs). * * Generated from protobuf field int32 test_example_count = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $test_example_count = 0; + protected $test_example_count = 0; /** * Output only. Timestamp when this dataset was created. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 9 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $create_time = null; + protected $create_time = null; /** * Output only. Timestamp when this dataset was last updated. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $update_time = null; + protected $update_time = null; /** * Constructor. diff --git a/Translate/src/V3/DatasetInputConfig/InputFile.php b/Translate/src/V3/DatasetInputConfig/InputFile.php index 1565bf9e5d9f..443abb31d235 100644 --- a/Translate/src/V3/DatasetInputConfig/InputFile.php +++ b/Translate/src/V3/DatasetInputConfig/InputFile.php @@ -21,7 +21,7 @@ class InputFile extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string usage = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $usage = ''; + protected $usage = ''; protected $source; /** @@ -111,6 +111,4 @@ public function getSource() } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(InputFile::class, \Google\Cloud\Translate\V3\DatasetInputConfig_InputFile::class); diff --git a/Translate/src/V3/DeleteAdaptiveMtDatasetRequest.php b/Translate/src/V3/DeleteAdaptiveMtDatasetRequest.php index c24cd05f661f..c0dbe46bc86c 100644 --- a/Translate/src/V3/DeleteAdaptiveMtDatasetRequest.php +++ b/Translate/src/V3/DeleteAdaptiveMtDatasetRequest.php @@ -21,7 +21,7 @@ class DeleteAdaptiveMtDatasetRequest 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. Name of the dataset. In the form of diff --git a/Translate/src/V3/DeleteAdaptiveMtFileRequest.php b/Translate/src/V3/DeleteAdaptiveMtFileRequest.php index 0bdda553e08f..4f3599a6c258 100644 --- a/Translate/src/V3/DeleteAdaptiveMtFileRequest.php +++ b/Translate/src/V3/DeleteAdaptiveMtFileRequest.php @@ -21,7 +21,7 @@ class DeleteAdaptiveMtFileRequest 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 resource name of the file to delete, in form of diff --git a/Translate/src/V3/DeleteDatasetMetadata.php b/Translate/src/V3/DeleteDatasetMetadata.php index d7d7498752e7..df3810c11948 100644 --- a/Translate/src/V3/DeleteDatasetMetadata.php +++ b/Translate/src/V3/DeleteDatasetMetadata.php @@ -20,25 +20,25 @@ class DeleteDatasetMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.OperationState state = 1; */ - private $state = 0; + protected $state = 0; /** * The creation time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 2; */ - private $create_time = null; + protected $create_time = null; /** * The last update time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 3; */ - private $update_time = null; + protected $update_time = null; /** * Only populated when operation doesn't succeed. * * Generated from protobuf field .google.rpc.Status error = 4; */ - private $error = null; + protected $error = null; /** * Constructor. diff --git a/Translate/src/V3/DeleteDatasetRequest.php b/Translate/src/V3/DeleteDatasetRequest.php index d46e66dc2680..633edd278b4a 100644 --- a/Translate/src/V3/DeleteDatasetRequest.php +++ b/Translate/src/V3/DeleteDatasetRequest.php @@ -20,7 +20,7 @@ class DeleteDatasetRequest 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 dataset to delete. Please see diff --git a/Translate/src/V3/DeleteGlossaryEntryRequest.php b/Translate/src/V3/DeleteGlossaryEntryRequest.php index e49e591d70e1..eb176da675a8 100644 --- a/Translate/src/V3/DeleteGlossaryEntryRequest.php +++ b/Translate/src/V3/DeleteGlossaryEntryRequest.php @@ -20,7 +20,7 @@ class DeleteGlossaryEntryRequest 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 resource name of the glossary entry to delete diff --git a/Translate/src/V3/DeleteGlossaryMetadata.php b/Translate/src/V3/DeleteGlossaryMetadata.php index 9bde47fc1d24..4c4c6c924c29 100644 --- a/Translate/src/V3/DeleteGlossaryMetadata.php +++ b/Translate/src/V3/DeleteGlossaryMetadata.php @@ -22,19 +22,19 @@ class DeleteGlossaryMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * The current state of the glossary deletion operation. * * Generated from protobuf field .google.cloud.translation.v3.DeleteGlossaryMetadata.State state = 2; */ - private $state = 0; + protected $state = 0; /** * The time when the operation was submitted to the server. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 3; */ - private $submit_time = null; + protected $submit_time = null; /** * Constructor. diff --git a/Translate/src/V3/DeleteGlossaryMetadata/State.php b/Translate/src/V3/DeleteGlossaryMetadata/State.php index 65fe6b5df28c..cb8eed033563 100644 --- a/Translate/src/V3/DeleteGlossaryMetadata/State.php +++ b/Translate/src/V3/DeleteGlossaryMetadata/State.php @@ -81,6 +81,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(State::class, \Google\Cloud\Translate\V3\DeleteGlossaryMetadata_State::class); diff --git a/Translate/src/V3/DeleteGlossaryMetadata_State.php b/Translate/src/V3/DeleteGlossaryMetadata_State.php deleted file mode 100644 index dce80e40287d..000000000000 --- a/Translate/src/V3/DeleteGlossaryMetadata_State.php +++ /dev/null @@ -1,16 +0,0 @@ -string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $name = ''; + protected $name = ''; /** * @param string $name Required. The name of the glossary to delete. Please see diff --git a/Translate/src/V3/DeleteGlossaryResponse.php b/Translate/src/V3/DeleteGlossaryResponse.php index 9e4493283845..d3bc457df686 100644 --- a/Translate/src/V3/DeleteGlossaryResponse.php +++ b/Translate/src/V3/DeleteGlossaryResponse.php @@ -22,13 +22,13 @@ class DeleteGlossaryResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * The time when the operation was submitted to the server. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 2; */ - private $submit_time = null; + protected $submit_time = null; /** * The time when the glossary deletion is finished and * [google.longrunning.Operation.done][google.longrunning.Operation.done] is @@ -36,7 +36,7 @@ class DeleteGlossaryResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp end_time = 3; */ - private $end_time = null; + protected $end_time = null; /** * Constructor. diff --git a/Translate/src/V3/DeleteModelMetadata.php b/Translate/src/V3/DeleteModelMetadata.php index c7329c3c35e5..e60ed41d67f9 100644 --- a/Translate/src/V3/DeleteModelMetadata.php +++ b/Translate/src/V3/DeleteModelMetadata.php @@ -20,25 +20,25 @@ class DeleteModelMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.OperationState state = 1; */ - private $state = 0; + protected $state = 0; /** * The creation time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 2; */ - private $create_time = null; + protected $create_time = null; /** * The last update time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 3; */ - private $update_time = null; + protected $update_time = null; /** * Only populated when operation doesn't succeed. * * Generated from protobuf field .google.rpc.Status error = 4; */ - private $error = null; + protected $error = null; /** * Constructor. diff --git a/Translate/src/V3/DeleteModelRequest.php b/Translate/src/V3/DeleteModelRequest.php index f16f53e57e69..5b76ab3676fd 100644 --- a/Translate/src/V3/DeleteModelRequest.php +++ b/Translate/src/V3/DeleteModelRequest.php @@ -20,7 +20,7 @@ class DeleteModelRequest 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 model to delete. Please see diff --git a/Translate/src/V3/DetectLanguageRequest.php b/Translate/src/V3/DetectLanguageRequest.php index d38ba6987035..99ceeed57cdc 100644 --- a/Translate/src/V3/DetectLanguageRequest.php +++ b/Translate/src/V3/DetectLanguageRequest.php @@ -27,7 +27,7 @@ class DetectLanguageRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 5 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Optional. The language detection model to be used. * Format: @@ -38,14 +38,14 @@ class DetectLanguageRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string model = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $model = ''; + protected $model = ''; /** * Optional. The format of the source text, for example, "text/html", * "text/plain". If left blank, the MIME type defaults to "text/html". * * Generated from protobuf field string mime_type = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $mime_type = ''; + protected $mime_type = ''; /** * Optional. The labels with user-defined metadata for the request. * Label keys and values can be no longer than 63 characters diff --git a/Translate/src/V3/DetectedLanguage.php b/Translate/src/V3/DetectedLanguage.php index 8d9d6ee4c48f..b0e30fd6ed85 100644 --- a/Translate/src/V3/DetectedLanguage.php +++ b/Translate/src/V3/DetectedLanguage.php @@ -21,13 +21,13 @@ class DetectedLanguage extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string language_code = 1; */ - private $language_code = ''; + protected $language_code = ''; /** * The confidence of the detection result for this language. * * Generated from protobuf field float confidence = 2; */ - private $confidence = 0.0; + protected $confidence = 0.0; /** * Constructor. diff --git a/Translate/src/V3/DocumentInputConfig.php b/Translate/src/V3/DocumentInputConfig.php index 208b30110eca..2285639ebfcf 100644 --- a/Translate/src/V3/DocumentInputConfig.php +++ b/Translate/src/V3/DocumentInputConfig.php @@ -28,7 +28,7 @@ class DocumentInputConfig extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string mime_type = 4; */ - private $mime_type = ''; + protected $mime_type = ''; protected $source; /** diff --git a/Translate/src/V3/DocumentOutputConfig.php b/Translate/src/V3/DocumentOutputConfig.php index 2deb2e85203e..96a6346c7240 100644 --- a/Translate/src/V3/DocumentOutputConfig.php +++ b/Translate/src/V3/DocumentOutputConfig.php @@ -28,7 +28,7 @@ class DocumentOutputConfig extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string mime_type = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $mime_type = ''; + protected $mime_type = ''; protected $destination; /** diff --git a/Translate/src/V3/DocumentTranslation.php b/Translate/src/V3/DocumentTranslation.php index 29cdf06ceb5b..a03fe5adad20 100644 --- a/Translate/src/V3/DocumentTranslation.php +++ b/Translate/src/V3/DocumentTranslation.php @@ -28,7 +28,7 @@ class DocumentTranslation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string mime_type = 2; */ - private $mime_type = ''; + protected $mime_type = ''; /** * The detected language for the input document. * If the user did not provide the source language for the input document, @@ -38,7 +38,7 @@ class DocumentTranslation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string detected_language_code = 3; */ - private $detected_language_code = ''; + protected $detected_language_code = ''; /** * Constructor. diff --git a/Translate/src/V3/Example.php b/Translate/src/V3/Example.php index b43ea8165a0e..65ddb1da9f12 100644 --- a/Translate/src/V3/Example.php +++ b/Translate/src/V3/Example.php @@ -21,25 +21,25 @@ class Example extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $name = ''; + protected $name = ''; /** * Sentence in source language. * * Generated from protobuf field string source_text = 2; */ - private $source_text = ''; + protected $source_text = ''; /** * Sentence in target language. * * Generated from protobuf field string target_text = 3; */ - private $target_text = ''; + protected $target_text = ''; /** * Output only. Usage of the sentence pair. Options are TRAIN|VALIDATION|TEST. * * Generated from protobuf field string usage = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $usage = ''; + protected $usage = ''; /** * Constructor. diff --git a/Translate/src/V3/ExportDataMetadata.php b/Translate/src/V3/ExportDataMetadata.php index 33db3425c9d3..71e5abba7065 100644 --- a/Translate/src/V3/ExportDataMetadata.php +++ b/Translate/src/V3/ExportDataMetadata.php @@ -20,25 +20,25 @@ class ExportDataMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.OperationState state = 1; */ - private $state = 0; + protected $state = 0; /** * The creation time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 2; */ - private $create_time = null; + protected $create_time = null; /** * The last update time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 3; */ - private $update_time = null; + protected $update_time = null; /** * Only populated when operation doesn't succeed. * * Generated from protobuf field .google.rpc.Status error = 4; */ - private $error = null; + protected $error = null; /** * Constructor. diff --git a/Translate/src/V3/ExportDataRequest.php b/Translate/src/V3/ExportDataRequest.php index 610ca6ffe724..a2871613aba5 100644 --- a/Translate/src/V3/ExportDataRequest.php +++ b/Translate/src/V3/ExportDataRequest.php @@ -21,13 +21,13 @@ class ExportDataRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string dataset = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $dataset = ''; + protected $dataset = ''; /** * Required. The config for the output content. * * Generated from protobuf field .google.cloud.translation.v3.DatasetOutputConfig output_config = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $output_config = null; + protected $output_config = null; /** * @param string $dataset Required. Name of the dataset. In form of diff --git a/Translate/src/V3/FileInputSource.php b/Translate/src/V3/FileInputSource.php index d1a1d27d744b..2faf57ac7171 100644 --- a/Translate/src/V3/FileInputSource.php +++ b/Translate/src/V3/FileInputSource.php @@ -20,19 +20,19 @@ class FileInputSource extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string mime_type = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $mime_type = ''; + protected $mime_type = ''; /** * Required. The file's byte contents. * * Generated from protobuf field bytes content = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $content = ''; + protected $content = ''; /** * Required. The file's display name. * * Generated from protobuf field string display_name = 3 [(.google.api.field_behavior) = REQUIRED]; */ - private $display_name = ''; + protected $display_name = ''; /** * Constructor. diff --git a/Translate/src/V3/Gapic/TranslationServiceGapicClient.php b/Translate/src/V3/Gapic/TranslationServiceGapicClient.php deleted file mode 100644 index a144c85d8ccd..000000000000 --- a/Translate/src/V3/Gapic/TranslationServiceGapicClient.php +++ /dev/null @@ -1,3147 +0,0 @@ -locationName('[PROJECT]', '[LOCATION]'); - * $formattedDataset = $translationServiceClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * $content = []; - * $response = $translationServiceClient->adaptiveMtTranslate($formattedParent, $formattedDataset, $content); - * } finally { - * $translationServiceClient->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\Translate\V3\Client\TranslationServiceClient}. - */ -class TranslationServiceGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.cloud.translation.v3.TranslationService'; - - /** - * The default address of the service. - * - * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. - */ - const SERVICE_ADDRESS = 'translate.googleapis.com'; - - /** The address template of the service. */ - private const SERVICE_ADDRESS_TEMPLATE = 'translate.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', - 'https://www.googleapis.com/auth/cloud-translation', - ]; - - private static $adaptiveMtDatasetNameTemplate; - - private static $adaptiveMtFileNameTemplate; - - private static $datasetNameTemplate; - - private static $glossaryNameTemplate; - - private static $glossaryEntryNameTemplate; - - private static $locationNameTemplate; - - private static $modelNameTemplate; - - private static $pathTemplateMap; - - private $operationsClient; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__ . '/../resources/translation_service_client_config.json', - 'descriptorsConfigPath' => __DIR__ . '/../resources/translation_service_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__ . '/../resources/translation_service_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => __DIR__ . '/../resources/translation_service_rest_client_config.php', - ], - ], - ]; - } - - private static function getAdaptiveMtDatasetNameTemplate() - { - if (self::$adaptiveMtDatasetNameTemplate == null) { - self::$adaptiveMtDatasetNameTemplate = new PathTemplate('projects/{project}/locations/{location}/adaptiveMtDatasets/{dataset}'); - } - - return self::$adaptiveMtDatasetNameTemplate; - } - - private static function getAdaptiveMtFileNameTemplate() - { - if (self::$adaptiveMtFileNameTemplate == null) { - self::$adaptiveMtFileNameTemplate = new PathTemplate('projects/{project}/locations/{location}/adaptiveMtDatasets/{dataset}/adaptiveMtFiles/{file}'); - } - - return self::$adaptiveMtFileNameTemplate; - } - - private static function getDatasetNameTemplate() - { - if (self::$datasetNameTemplate == null) { - self::$datasetNameTemplate = new PathTemplate('projects/{project}/locations/{location}/datasets/{dataset}'); - } - - return self::$datasetNameTemplate; - } - - private static function getGlossaryNameTemplate() - { - if (self::$glossaryNameTemplate == null) { - self::$glossaryNameTemplate = new PathTemplate('projects/{project}/locations/{location}/glossaries/{glossary}'); - } - - return self::$glossaryNameTemplate; - } - - private static function getGlossaryEntryNameTemplate() - { - if (self::$glossaryEntryNameTemplate == null) { - self::$glossaryEntryNameTemplate = new PathTemplate('projects/{project}/locations/{location}/glossaries/{glossary}/glossaryEntries/{glossary_entry}'); - } - - return self::$glossaryEntryNameTemplate; - } - - private static function getLocationNameTemplate() - { - if (self::$locationNameTemplate == null) { - self::$locationNameTemplate = new PathTemplate('projects/{project}/locations/{location}'); - } - - return self::$locationNameTemplate; - } - - private static function getModelNameTemplate() - { - if (self::$modelNameTemplate == null) { - self::$modelNameTemplate = new PathTemplate('projects/{project}/locations/{location}/models/{model}'); - } - - return self::$modelNameTemplate; - } - - private static function getPathTemplateMap() - { - if (self::$pathTemplateMap == null) { - self::$pathTemplateMap = [ - 'adaptiveMtDataset' => self::getAdaptiveMtDatasetNameTemplate(), - 'adaptiveMtFile' => self::getAdaptiveMtFileNameTemplate(), - 'dataset' => self::getDatasetNameTemplate(), - 'glossary' => self::getGlossaryNameTemplate(), - 'glossaryEntry' => self::getGlossaryEntryNameTemplate(), - 'location' => self::getLocationNameTemplate(), - 'model' => self::getModelNameTemplate(), - ]; - } - - return self::$pathTemplateMap; - } - - /** - * Formats a string containing the fully-qualified path to represent a - * adaptive_mt_dataset resource. - * - * @param string $project - * @param string $location - * @param string $dataset - * - * @return string The formatted adaptive_mt_dataset resource. - */ - public static function adaptiveMtDatasetName($project, $location, $dataset) - { - return self::getAdaptiveMtDatasetNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - 'dataset' => $dataset, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * adaptive_mt_file resource. - * - * @param string $project - * @param string $location - * @param string $dataset - * @param string $file - * - * @return string The formatted adaptive_mt_file resource. - */ - public static function adaptiveMtFileName($project, $location, $dataset, $file) - { - return self::getAdaptiveMtFileNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - 'dataset' => $dataset, - 'file' => $file, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a dataset - * resource. - * - * @param string $project - * @param string $location - * @param string $dataset - * - * @return string The formatted dataset resource. - */ - public static function datasetName($project, $location, $dataset) - { - return self::getDatasetNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - 'dataset' => $dataset, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a glossary - * resource. - * - * @param string $project - * @param string $location - * @param string $glossary - * - * @return string The formatted glossary resource. - */ - public static function glossaryName($project, $location, $glossary) - { - return self::getGlossaryNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - 'glossary' => $glossary, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * glossary_entry resource. - * - * @param string $project - * @param string $location - * @param string $glossary - * @param string $glossaryEntry - * - * @return string The formatted glossary_entry resource. - */ - public static function glossaryEntryName($project, $location, $glossary, $glossaryEntry) - { - return self::getGlossaryEntryNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - 'glossary' => $glossary, - 'glossary_entry' => $glossaryEntry, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a location - * resource. - * - * @param string $project - * @param string $location - * - * @return string The formatted location resource. - */ - public static function locationName($project, $location) - { - return self::getLocationNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a model - * resource. - * - * @param string $project - * @param string $location - * @param string $model - * - * @return string The formatted model resource. - */ - public static function modelName($project, $location, $model) - { - return self::getModelNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - 'model' => $model, - ]); - } - - /** - * Parses a formatted name string and returns an associative array of the components in the name. - * The following name formats are supported: - * Template: Pattern - * - adaptiveMtDataset: projects/{project}/locations/{location}/adaptiveMtDatasets/{dataset} - * - adaptiveMtFile: projects/{project}/locations/{location}/adaptiveMtDatasets/{dataset}/adaptiveMtFiles/{file} - * - dataset: projects/{project}/locations/{location}/datasets/{dataset} - * - glossary: projects/{project}/locations/{location}/glossaries/{glossary} - * - glossaryEntry: projects/{project}/locations/{location}/glossaries/{glossary}/glossaryEntries/{glossary_entry} - * - location: projects/{project}/locations/{location} - * - model: projects/{project}/locations/{location}/models/{model} - * - * 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"); - } - - /** - * Return an OperationsClient object with the same endpoint as $this. - * - * @return OperationsClient - */ - public function getOperationsClient() - { - return $this->operationsClient; - } - - /** - * Resume an existing long running operation that was previously started by a long - * running API method. If $methodName is not provided, or does not match a long - * running API method, then the operation can still be resumed, but the - * OperationResponse object will not deserialize the final response. - * - * @param string $operationName The name of the long running operation - * @param string $methodName The name of the method used to start the operation - * - * @return OperationResponse - */ - public function resumeOperation($operationName, $methodName = null) - { - $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; - $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); - $operation->reload(); - return $operation; - } - - /** - * 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 'translate.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); - $this->operationsClient = $this->createOperationsClient($clientOptions); - } - - /** - * Translate text using Adaptive MT. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $formattedDataset = $translationServiceClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * $content = []; - * $response = $translationServiceClient->adaptiveMtTranslate($formattedParent, $formattedDataset, $content); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Location to make a regional call. - * - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * @param string $dataset Required. The resource name for the dataset to use for adaptive MT. - * `projects/{project}/locations/{location-id}/adaptiveMtDatasets/{dataset}` - * @param string[] $content Required. The content of the input in string format. - * @param array $optionalArgs { - * Optional. - * - * @type ReferenceSentenceConfig $referenceSentenceConfig - * Configuration for caller provided reference sentences. - * @type GlossaryConfig $glossaryConfig - * Optional. Glossary to be applied. The glossary must be - * within the same region (have the same location-id) as the model, otherwise - * an INVALID_ARGUMENT (400) error is returned. - * @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\Translate\V3\AdaptiveMtTranslateResponse - * - * @throws ApiException if the remote call fails - */ - public function adaptiveMtTranslate($parent, $dataset, $content, array $optionalArgs = []) - { - $request = new AdaptiveMtTranslateRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setDataset($dataset); - $request->setContent($content); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['referenceSentenceConfig'])) { - $request->setReferenceSentenceConfig($optionalArgs['referenceSentenceConfig']); - } - - if (isset($optionalArgs['glossaryConfig'])) { - $request->setGlossaryConfig($optionalArgs['glossaryConfig']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('AdaptiveMtTranslate', AdaptiveMtTranslateResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Translates a large volume of document in asynchronous batch mode. - * This function provides real-time output as the inputs are being processed. - * If caller cancels a request, the partial results (for an input file, it's - * all or nothing) may still be available on the specified output location. - * - * This call returns immediately and you can use - * google.longrunning.Operation.name to poll the status of the call. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $sourceLanguageCode = 'source_language_code'; - * $targetLanguageCodes = []; - * $inputConfigs = []; - * $outputConfig = new BatchDocumentOutputConfig(); - * $operationResponse = $translationServiceClient->batchTranslateDocument($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->batchTranslateDocument($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'batchTranslateDocument'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Location to make a regional call. - * - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * - * The `global` location is not supported for batch translation. - * - * Only AutoML Translation models or glossaries within the same region (have - * the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) - * error is returned. - * @param string $sourceLanguageCode Required. The ISO-639 language code of the input document if known, for - * example, "en-US" or "sr-Latn". Supported language codes are listed in - * [Language Support](https://cloud.google.com/translate/docs/languages). - * @param string[] $targetLanguageCodes Required. The ISO-639 language code to use for translation of the input - * document. Specify up to 10 language codes here. - * @param BatchDocumentInputConfig[] $inputConfigs Required. Input configurations. - * The total number of files matched should be <= 100. - * The total content size to translate should be <= 100M Unicode codepoints. - * The files must use UTF-8 encoding. - * @param BatchDocumentOutputConfig $outputConfig Required. Output configuration. - * If 2 input configs match to the same file (that is, same input path), - * we don't generate output for duplicate inputs. - * @param array $optionalArgs { - * Optional. - * - * @type array $models - * Optional. The models to use for translation. Map's key is target language - * code. Map's value is the model name. Value can be a built-in general model, - * or an AutoML Translation model. - * - * The value format depends on model type: - * - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * - * - * If the map is empty or a specific model is - * not requested for a language pair, then default google model (nmt) is used. - * @type array $glossaries - * Optional. Glossaries to be applied. It's keyed by target language code. - * @type array $formatConversions - * Optional. The file format conversion map that is applied to all input - * files. The map key is the original mime_type. The map value is the target - * mime_type of translated documents. - * - * Supported file format conversion includes: - * - `application/pdf` to - * `application/vnd.openxmlformats-officedocument.wordprocessingml.document` - * - * If nothing specified, output files will be in the same format as the - * original file. - * @type string $customizedAttribution - * Optional. This flag is to support user customized attribution. - * If not provided, the default is `Machine Translated by Google`. - * Customized attribution should follow rules in - * https://cloud.google.com/translate/attribution#attribution_and_logos - * @type bool $enableShadowRemovalNativePdf - * Optional. If true, use the text removal server to remove the shadow text on - * background image for native pdf translation. - * Shadow removal feature can only be enabled when - * is_translate_native_pdf_only: false && pdf_native_only: false - * @type bool $enableRotationCorrection - * Optional. If true, enable auto rotation correction in DVS. - * @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\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function batchTranslateDocument($parent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig, array $optionalArgs = []) - { - $request = new BatchTranslateDocumentRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setSourceLanguageCode($sourceLanguageCode); - $request->setTargetLanguageCodes($targetLanguageCodes); - $request->setInputConfigs($inputConfigs); - $request->setOutputConfig($outputConfig); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['models'])) { - $request->setModels($optionalArgs['models']); - } - - if (isset($optionalArgs['glossaries'])) { - $request->setGlossaries($optionalArgs['glossaries']); - } - - if (isset($optionalArgs['formatConversions'])) { - $request->setFormatConversions($optionalArgs['formatConversions']); - } - - if (isset($optionalArgs['customizedAttribution'])) { - $request->setCustomizedAttribution($optionalArgs['customizedAttribution']); - } - - if (isset($optionalArgs['enableShadowRemovalNativePdf'])) { - $request->setEnableShadowRemovalNativePdf($optionalArgs['enableShadowRemovalNativePdf']); - } - - if (isset($optionalArgs['enableRotationCorrection'])) { - $request->setEnableRotationCorrection($optionalArgs['enableRotationCorrection']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('BatchTranslateDocument', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Translates a large volume of text in asynchronous batch mode. - * This function provides real-time output as the inputs are being processed. - * If caller cancels a request, the partial results (for an input file, it's - * all or nothing) may still be available on the specified output location. - * - * This call returns immediately and you can - * use google.longrunning.Operation.name to poll the status of the call. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $sourceLanguageCode = 'source_language_code'; - * $targetLanguageCodes = []; - * $inputConfigs = []; - * $outputConfig = new OutputConfig(); - * $operationResponse = $translationServiceClient->batchTranslateText($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->batchTranslateText($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'batchTranslateText'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Location to make a call. Must refer to a caller's project. - * - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * - * The `global` location is not supported for batch translation. - * - * Only AutoML Translation models or glossaries within the same region (have - * the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) - * error is returned. - * @param string $sourceLanguageCode Required. Source language code. - * @param string[] $targetLanguageCodes Required. Specify up to 10 language codes here. - * @param InputConfig[] $inputConfigs Required. Input configurations. - * The total number of files matched should be <= 100. - * The total content size should be <= 100M Unicode codepoints. - * The files must use UTF-8 encoding. - * @param OutputConfig $outputConfig Required. Output configuration. - * If 2 input configs match to the same file (that is, same input path), - * we don't generate output for duplicate inputs. - * @param array $optionalArgs { - * Optional. - * - * @type array $models - * Optional. The models to use for translation. Map's key is target language - * code. Map's value is model name. Value can be a built-in general model, - * or an AutoML Translation model. - * - * The value format depends on model type: - * - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * - * - * If the map is empty or a specific model is - * not requested for a language pair, then default google model (nmt) is used. - * @type array $glossaries - * Optional. Glossaries to be applied for translation. - * It's keyed by target language code. - * @type array $labels - * Optional. The labels with user-defined metadata for the request. - * - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - * @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\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function batchTranslateText($parent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig, array $optionalArgs = []) - { - $request = new BatchTranslateTextRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setSourceLanguageCode($sourceLanguageCode); - $request->setTargetLanguageCodes($targetLanguageCodes); - $request->setInputConfigs($inputConfigs); - $request->setOutputConfig($outputConfig); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['models'])) { - $request->setModels($optionalArgs['models']); - } - - if (isset($optionalArgs['glossaries'])) { - $request->setGlossaries($optionalArgs['glossaries']); - } - - if (isset($optionalArgs['labels'])) { - $request->setLabels($optionalArgs['labels']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('BatchTranslateText', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Creates an Adaptive MT dataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $adaptiveMtDataset = new AdaptiveMtDataset(); - * $response = $translationServiceClient->createAdaptiveMtDataset($formattedParent, $adaptiveMtDataset); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Name of the parent project. In form of - * `projects/{project-number-or-id}/locations/{location-id}` - * @param AdaptiveMtDataset $adaptiveMtDataset Required. The AdaptiveMtDataset to be created. - * @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\Translate\V3\AdaptiveMtDataset - * - * @throws ApiException if the remote call fails - */ - public function createAdaptiveMtDataset($parent, $adaptiveMtDataset, array $optionalArgs = []) - { - $request = new CreateAdaptiveMtDatasetRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setAdaptiveMtDataset($adaptiveMtDataset); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('CreateAdaptiveMtDataset', AdaptiveMtDataset::class, $optionalArgs, $request)->wait(); - } - - /** - * Creates a Dataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $dataset = new Dataset(); - * $operationResponse = $translationServiceClient->createDataset($formattedParent, $dataset); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->createDataset($formattedParent, $dataset); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'createDataset'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The project name. - * @param Dataset $dataset Required. The Dataset to create. - * @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\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function createDataset($parent, $dataset, array $optionalArgs = []) - { - $request = new CreateDatasetRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setDataset($dataset); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('CreateDataset', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Creates a glossary and returns the long-running operation. Returns - * NOT_FOUND, if the project doesn't exist. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $glossary = new Glossary(); - * $operationResponse = $translationServiceClient->createGlossary($formattedParent, $glossary); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->createGlossary($formattedParent, $glossary); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'createGlossary'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The project name. - * @param Glossary $glossary Required. The glossary to create. - * @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\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function createGlossary($parent, $glossary, array $optionalArgs = []) - { - $request = new CreateGlossaryRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setGlossary($glossary); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('CreateGlossary', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Creates a glossary entry. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - * $glossaryEntry = new GlossaryEntry(); - * $response = $translationServiceClient->createGlossaryEntry($formattedParent, $glossaryEntry); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The resource name of the glossary to create the entry under. - * @param GlossaryEntry $glossaryEntry Required. The glossary entry to create - * @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\Translate\V3\GlossaryEntry - * - * @throws ApiException if the remote call fails - */ - public function createGlossaryEntry($parent, $glossaryEntry, array $optionalArgs = []) - { - $request = new CreateGlossaryEntryRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setGlossaryEntry($glossaryEntry); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('CreateGlossaryEntry', GlossaryEntry::class, $optionalArgs, $request)->wait(); - } - - /** - * Creates a Model. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $model = new Model(); - * $operationResponse = $translationServiceClient->createModel($formattedParent, $model); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->createModel($formattedParent, $model); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'createModel'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The project name, in form of - * `projects/{project}/locations/{location}` - * @param Model $model Required. The Model to create. - * @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\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function createModel($parent, $model, array $optionalArgs = []) - { - $request = new CreateModelRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setModel($model); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('CreateModel', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Deletes an Adaptive MT dataset, including all its entries and associated - * metadata. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * $translationServiceClient->deleteAdaptiveMtDataset($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. Name of the dataset. In the form of - * `projects/{project-number-or-id}/locations/{location-id}/adaptiveMtDatasets/{adaptive-mt-dataset-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 deleteAdaptiveMtDataset($name, array $optionalArgs = []) - { - $request = new DeleteAdaptiveMtDatasetRequest(); - $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('DeleteAdaptiveMtDataset', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Deletes an AdaptiveMtFile along with its sentences. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - * $translationServiceClient->deleteAdaptiveMtFile($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The resource name of the file to delete, in form of - * `projects/{project-number-or-id}/locations/{location_id}/adaptiveMtDatasets/{dataset}/adaptiveMtFiles/{file}` - * @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 deleteAdaptiveMtFile($name, array $optionalArgs = []) - { - $request = new DeleteAdaptiveMtFileRequest(); - $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('DeleteAdaptiveMtFile', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Deletes a dataset and all of its contents. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * $operationResponse = $translationServiceClient->deleteDataset($formattedName); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->deleteDataset($formattedName); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'deleteDataset'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The name of the dataset to delete. - * @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\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function deleteDataset($name, array $optionalArgs = []) - { - $request = new DeleteDatasetRequest(); - $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->startOperationsCall('DeleteDataset', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Deletes a glossary, or cancels glossary construction - * if the glossary isn't created yet. - * Returns NOT_FOUND, if the glossary doesn't exist. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - * $operationResponse = $translationServiceClient->deleteGlossary($formattedName); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->deleteGlossary($formattedName); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'deleteGlossary'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The name of the glossary to delete. - * @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\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function deleteGlossary($name, array $optionalArgs = []) - { - $request = new DeleteGlossaryRequest(); - $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->startOperationsCall('DeleteGlossary', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Deletes a single entry from the glossary - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - * $translationServiceClient->deleteGlossaryEntry($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The resource name of the glossary entry to delete - * @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 deleteGlossaryEntry($name, array $optionalArgs = []) - { - $request = new DeleteGlossaryEntryRequest(); - $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('DeleteGlossaryEntry', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Deletes a model. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - * $operationResponse = $translationServiceClient->deleteModel($formattedName); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->deleteModel($formattedName); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'deleteModel'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The name of the model to delete. - * @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\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function deleteModel($name, array $optionalArgs = []) - { - $request = new DeleteModelRequest(); - $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->startOperationsCall('DeleteModel', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Detects the language of text within a request. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $response = $translationServiceClient->detectLanguage($formattedParent); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Project or location to make a call. Must refer to a caller's - * project. - * - * Format: `projects/{project-number-or-id}/locations/{location-id}` or - * `projects/{project-number-or-id}`. - * - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * - * Only models within the same region (has same location-id) can be used. - * Otherwise an INVALID_ARGUMENT (400) error is returned. - * @param array $optionalArgs { - * Optional. - * - * @type string $model - * Optional. The language detection model to be used. - * - * Format: - * `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id}` - * - * Only one language detection model is currently supported: - * `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default`. - * - * If not specified, the default model is used. - * @type string $content - * The content of the input stored as a string. - * @type string $mimeType - * Optional. The format of the source text, for example, "text/html", - * "text/plain". If left blank, the MIME type defaults to "text/html". - * @type array $labels - * Optional. The labels with user-defined metadata for the request. - * - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - * @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\Translate\V3\DetectLanguageResponse - * - * @throws ApiException if the remote call fails - */ - public function detectLanguage($parent, array $optionalArgs = []) - { - $request = new DetectLanguageRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['model'])) { - $request->setModel($optionalArgs['model']); - } - - if (isset($optionalArgs['content'])) { - $request->setContent($optionalArgs['content']); - } - - if (isset($optionalArgs['mimeType'])) { - $request->setMimeType($optionalArgs['mimeType']); - } - - if (isset($optionalArgs['labels'])) { - $request->setLabels($optionalArgs['labels']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('DetectLanguage', DetectLanguageResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Exports dataset's data to the provided output location. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $dataset = 'dataset'; - * $outputConfig = new DatasetOutputConfig(); - * $operationResponse = $translationServiceClient->exportData($dataset, $outputConfig); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->exportData($dataset, $outputConfig); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'exportData'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $dataset Required. Name of the dataset. In form of - * `projects/{project-number-or-id}/locations/{location-id}/datasets/{dataset-id}` - * @param DatasetOutputConfig $outputConfig Required. The config for the output content. - * @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\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function exportData($dataset, $outputConfig, array $optionalArgs = []) - { - $request = new ExportDataRequest(); - $requestParamHeaders = []; - $request->setDataset($dataset); - $request->setOutputConfig($outputConfig); - $requestParamHeaders['dataset'] = $dataset; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('ExportData', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Gets the Adaptive MT dataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * $response = $translationServiceClient->getAdaptiveMtDataset($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. Name of the dataset. In the form of - * `projects/{project-number-or-id}/locations/{location-id}/adaptiveMtDatasets/{adaptive-mt-dataset-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\Translate\V3\AdaptiveMtDataset - * - * @throws ApiException if the remote call fails - */ - public function getAdaptiveMtDataset($name, array $optionalArgs = []) - { - $request = new GetAdaptiveMtDatasetRequest(); - $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('GetAdaptiveMtDataset', AdaptiveMtDataset::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets and AdaptiveMtFile - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - * $response = $translationServiceClient->getAdaptiveMtFile($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The resource name of the file, in form of - * `projects/{project-number-or-id}/locations/{location_id}/adaptiveMtDatasets/{dataset}/adaptiveMtFiles/{file}` - * @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\Translate\V3\AdaptiveMtFile - * - * @throws ApiException if the remote call fails - */ - public function getAdaptiveMtFile($name, array $optionalArgs = []) - { - $request = new GetAdaptiveMtFileRequest(); - $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('GetAdaptiveMtFile', AdaptiveMtFile::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets a Dataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * $response = $translationServiceClient->getDataset($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The resource name of the dataset to retrieve. - * @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\Translate\V3\Dataset - * - * @throws ApiException if the remote call fails - */ - public function getDataset($name, array $optionalArgs = []) - { - $request = new GetDatasetRequest(); - $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('GetDataset', Dataset::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets a glossary. Returns NOT_FOUND, if the glossary doesn't - * exist. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - * $response = $translationServiceClient->getGlossary($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The name of the glossary to retrieve. - * @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\Translate\V3\Glossary - * - * @throws ApiException if the remote call fails - */ - public function getGlossary($name, array $optionalArgs = []) - { - $request = new GetGlossaryRequest(); - $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('GetGlossary', Glossary::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets a single glossary entry by the given id. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - * $response = $translationServiceClient->getGlossaryEntry($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The resource name of the glossary entry to get - * @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\Translate\V3\GlossaryEntry - * - * @throws ApiException if the remote call fails - */ - public function getGlossaryEntry($name, array $optionalArgs = []) - { - $request = new GetGlossaryEntryRequest(); - $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('GetGlossaryEntry', GlossaryEntry::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets a model. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedName = $translationServiceClient->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - * $response = $translationServiceClient->getModel($formattedName); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The resource name of the model to retrieve. - * @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\Translate\V3\Model - * - * @throws ApiException if the remote call fails - */ - public function getModel($name, array $optionalArgs = []) - { - $request = new GetModelRequest(); - $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('GetModel', Model::class, $optionalArgs, $request)->wait(); - } - - /** - * Returns a list of supported languages for translation. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $response = $translationServiceClient->getSupportedLanguages($formattedParent); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Project or location to make a call. Must refer to a caller's - * project. - * - * Format: `projects/{project-number-or-id}` or - * `projects/{project-number-or-id}/locations/{location-id}`. - * - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * - * Non-global location is required for AutoML models. - * - * Only models within the same region (have same location-id) can be used, - * otherwise an INVALID_ARGUMENT (400) error is returned. - * @param array $optionalArgs { - * Optional. - * - * @type string $displayLanguageCode - * Optional. The language to use to return localized, human readable names - * of supported languages. If missing, then display names are not returned - * in a response. - * @type string $model - * Optional. Get supported languages of this model. - * - * The format depends on model type: - * - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * - * - * Returns languages supported by the specified model. - * If missing, we get supported languages of Google general NMT model. - * @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\Translate\V3\SupportedLanguages - * - * @throws ApiException if the remote call fails - */ - public function getSupportedLanguages($parent, array $optionalArgs = []) - { - $request = new GetSupportedLanguagesRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['displayLanguageCode'])) { - $request->setDisplayLanguageCode($optionalArgs['displayLanguageCode']); - } - - if (isset($optionalArgs['model'])) { - $request->setModel($optionalArgs['model']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetSupportedLanguages', SupportedLanguages::class, $optionalArgs, $request)->wait(); - } - - /** - * Imports an AdaptiveMtFile and adds all of its sentences into the - * AdaptiveMtDataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * $response = $translationServiceClient->importAdaptiveMtFile($formattedParent); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The resource name of the file, in form of - * `projects/{project-number-or-id}/locations/{location_id}/adaptiveMtDatasets/{dataset}` - * @param array $optionalArgs { - * Optional. - * - * @type FileInputSource $fileInputSource - * Inline file source. - * @type GcsInputSource $gcsInputSource - * Google Cloud Storage file source. - * @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\Translate\V3\ImportAdaptiveMtFileResponse - * - * @throws ApiException if the remote call fails - */ - public function importAdaptiveMtFile($parent, array $optionalArgs = []) - { - $request = new ImportAdaptiveMtFileRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['fileInputSource'])) { - $request->setFileInputSource($optionalArgs['fileInputSource']); - } - - if (isset($optionalArgs['gcsInputSource'])) { - $request->setGcsInputSource($optionalArgs['gcsInputSource']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('ImportAdaptiveMtFile', ImportAdaptiveMtFileResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Import sentence pairs into translation Dataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $dataset = 'dataset'; - * $inputConfig = new DatasetInputConfig(); - * $operationResponse = $translationServiceClient->importData($dataset, $inputConfig); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->importData($dataset, $inputConfig); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'importData'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $dataset Required. Name of the dataset. In form of - * `projects/{project-number-or-id}/locations/{location-id}/datasets/{dataset-id}` - * @param DatasetInputConfig $inputConfig Required. The config for the input content. - * @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\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function importData($dataset, $inputConfig, array $optionalArgs = []) - { - $request = new ImportDataRequest(); - $requestParamHeaders = []; - $request->setDataset($dataset); - $request->setInputConfig($inputConfig); - $requestParamHeaders['dataset'] = $dataset; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('ImportData', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Lists all Adaptive MT datasets for which the caller has read permission. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $translationServiceClient->listAdaptiveMtDatasets($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $translationServiceClient->listAdaptiveMtDatasets($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The resource name of the project from which to list the Adaptive - * MT datasets. `projects/{project-number-or-id}/locations/{location-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 string $filter - * Optional. An expression for filtering the results of the request. - * Filter is not supported yet. - * @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 listAdaptiveMtDatasets($parent, array $optionalArgs = []) - { - $request = new ListAdaptiveMtDatasetsRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListAdaptiveMtDatasets', $optionalArgs, ListAdaptiveMtDatasetsResponse::class, $request); - } - - /** - * Lists all AdaptiveMtFiles associated to an AdaptiveMtDataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * // Iterate over pages of elements - * $pagedResponse = $translationServiceClient->listAdaptiveMtFiles($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $translationServiceClient->listAdaptiveMtFiles($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The resource name of the project from which to list the Adaptive - * MT files. - * `projects/{project}/locations/{location}/adaptiveMtDatasets/{dataset}` - * @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 listAdaptiveMtFiles($parent, array $optionalArgs = []) - { - $request = new ListAdaptiveMtFilesRequest(); - $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('ListAdaptiveMtFiles', $optionalArgs, ListAdaptiveMtFilesResponse::class, $request); - } - - /** - * Lists all AdaptiveMtSentences under a given file/dataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - * // Iterate over pages of elements - * $pagedResponse = $translationServiceClient->listAdaptiveMtSentences($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $translationServiceClient->listAdaptiveMtSentences($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The resource name of the project from which to list the Adaptive - * MT files. The following format lists all sentences under a file. - * `projects/{project}/locations/{location}/adaptiveMtDatasets/{dataset}/adaptiveMtFiles/{file}` - * The following format lists all sentences within a dataset. - * `projects/{project}/locations/{location}/adaptiveMtDatasets/{dataset}` - * @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 listAdaptiveMtSentences($parent, array $optionalArgs = []) - { - $request = new ListAdaptiveMtSentencesRequest(); - $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('ListAdaptiveMtSentences', $optionalArgs, ListAdaptiveMtSentencesResponse::class, $request); - } - - /** - * Lists datasets. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $translationServiceClient->listDatasets($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $translationServiceClient->listDatasets($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Name of the parent project. In form of - * `projects/{project-number-or-id}/locations/{location-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 listDatasets($parent, array $optionalArgs = []) - { - $request = new ListDatasetsRequest(); - $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('ListDatasets', $optionalArgs, ListDatasetsResponse::class, $request); - } - - /** - * Lists sentence pairs in the dataset. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - * // Iterate over pages of elements - * $pagedResponse = $translationServiceClient->listExamples($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $translationServiceClient->listExamples($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Name of the parent dataset. In form of - * `projects/{project-number-or-id}/locations/{location-id}/datasets/{dataset-id}` - * @param array $optionalArgs { - * Optional. - * - * @type string $filter - * Optional. An expression for filtering the examples that will be returned. - * Example filter: - * * `usage=TRAIN` - * @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 listExamples($parent, array $optionalArgs = []) - { - $request = new ListExamplesRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - - 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('ListExamples', $optionalArgs, ListExamplesResponse::class, $request); - } - - /** - * Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't - * exist. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $translationServiceClient->listGlossaries($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $translationServiceClient->listGlossaries($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The name of the project from which to list all of the glossaries. - * @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 string $filter - * Optional. Filter specifying constraints of a list operation. - * Specify the constraint by the format of "key=value", where key must be - * "src" or "tgt", and the value must be a valid language code. - * For multiple restrictions, concatenate them by "AND" (uppercase only), - * such as: "src=en-US AND tgt=zh-CN". Notice that the exact match is used - * here, which means using 'en-US' and 'en' can lead to different results, - * which depends on the language code you used when you create the glossary. - * For the unidirectional glossaries, the "src" and "tgt" add restrictions - * on the source and target language code separately. - * For the equivalent term set glossaries, the "src" and/or "tgt" add - * restrictions on the term set. - * For example: "src=en-US AND tgt=zh-CN" will only pick the unidirectional - * glossaries which exactly match the source language code as "en-US" and the - * target language code "zh-CN", but all equivalent term set glossaries which - * contain "en-US" and "zh-CN" in their language set will be picked. - * If missing, no filtering is performed. - * @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 listGlossaries($parent, array $optionalArgs = []) - { - $request = new ListGlossariesRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListGlossaries', $optionalArgs, ListGlossariesResponse::class, $request); - } - - /** - * List the entries for the glossary. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - * // Iterate over pages of elements - * $pagedResponse = $translationServiceClient->listGlossaryEntries($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $translationServiceClient->listGlossaryEntries($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The parent glossary resource name for listing the glossary's - * entries. - * @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 listGlossaryEntries($parent, array $optionalArgs = []) - { - $request = new ListGlossaryEntriesRequest(); - $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('ListGlossaryEntries', $optionalArgs, ListGlossaryEntriesResponse::class, $request); - } - - /** - * Lists models. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $translationServiceClient->listModels($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $translationServiceClient->listModels($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Name of the parent project. In form of - * `projects/{project-number-or-id}/locations/{location-id}` - * @param array $optionalArgs { - * Optional. - * - * @type string $filter - * Optional. An expression for filtering the models that will be returned. - * Supported filter: - * `dataset_id=${dataset_id}` - * @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 listModels($parent, array $optionalArgs = []) - { - $request = new ListModelsRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - - 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('ListModels', $optionalArgs, ListModelsResponse::class, $request); - } - - /** - * Romanize input text written in non-Latin scripts to Latin text. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $contents = []; - * $response = $translationServiceClient->romanizeText($formattedParent, $contents); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Project or location to make a call. Must refer to a caller's - * project. - * - * Format: `projects/{project-number-or-id}/locations/{location-id}` or - * `projects/{project-number-or-id}`. - * - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * @param string[] $contents Required. The content of the input in string format. - * @param array $optionalArgs { - * Optional. - * - * @type string $sourceLanguageCode - * Optional. The ISO-639 language code of the input text if - * known, for example, "hi" or "zh". If the source language isn't specified, - * the API attempts to identify the source language automatically and returns - * the source language for each content in the response. - * @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\Translate\V3\RomanizeTextResponse - * - * @throws ApiException if the remote call fails - */ - public function romanizeText($parent, $contents, array $optionalArgs = []) - { - $request = new RomanizeTextRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setContents($contents); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['sourceLanguageCode'])) { - $request->setSourceLanguageCode($optionalArgs['sourceLanguageCode']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('RomanizeText', RomanizeTextResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Translates documents in synchronous mode. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $parent = 'parent'; - * $targetLanguageCode = 'target_language_code'; - * $documentInputConfig = new DocumentInputConfig(); - * $response = $translationServiceClient->translateDocument($parent, $targetLanguageCode, $documentInputConfig); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. Location to make a regional call. - * - * Format: `projects/{project-number-or-id}/locations/{location-id}`. - * - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * - * Non-global location is required for requests using AutoML models or custom - * glossaries. - * - * Models and glossaries must be within the same region (have the same - * location-id), otherwise an INVALID_ARGUMENT (400) error is returned. - * @param string $targetLanguageCode Required. The ISO-639 language code to use for translation of the input - * document, set to one of the language codes listed in Language Support. - * @param DocumentInputConfig $documentInputConfig Required. Input configurations. - * @param array $optionalArgs { - * Optional. - * - * @type string $sourceLanguageCode - * Optional. The ISO-639 language code of the input document if known, for - * example, "en-US" or "sr-Latn". Supported language codes are listed in - * Language Support. If the source language isn't specified, the API attempts - * to identify the source language automatically and returns the source - * language within the response. Source language must be specified if the - * request contains a glossary or a custom model. - * @type DocumentOutputConfig $documentOutputConfig - * Optional. Output configurations. - * Defines if the output file should be stored within Cloud Storage as well - * as the desired output format. If not provided the translated file will - * only be returned through a byte-stream and its output mime type will be - * the same as the input file's mime type. - * @type string $model - * Optional. The `model` type requested for this translation. - * - * The format depends on model type: - * - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * - * - * If not provided, the default Google model (NMT) will be used for - * translation. - * @type TranslateTextGlossaryConfig $glossaryConfig - * Optional. Glossary to be applied. The glossary must be within the same - * region (have the same location-id) as the model, otherwise an - * INVALID_ARGUMENT (400) error is returned. - * @type array $labels - * Optional. The labels with user-defined metadata for the request. - * - * Label keys and values can be no longer than 63 characters (Unicode - * codepoints), can only contain lowercase letters, numeric characters, - * underscores and dashes. International characters are allowed. Label values - * are optional. Label keys must start with a letter. - * - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - * @type string $customizedAttribution - * Optional. This flag is to support user customized attribution. - * If not provided, the default is `Machine Translated by Google`. - * Customized attribution should follow rules in - * https://cloud.google.com/translate/attribution#attribution_and_logos - * @type bool $isTranslateNativePdfOnly - * Optional. is_translate_native_pdf_only field for external customers. - * If true, the page limit of online native pdf translation is 300 and only - * native pdf pages will be translated. - * @type bool $enableShadowRemovalNativePdf - * Optional. If true, use the text removal server to remove the shadow text on - * background image for native pdf translation. - * Shadow removal feature can only be enabled when - * is_translate_native_pdf_only: false && pdf_native_only: false - * @type bool $enableRotationCorrection - * Optional. If true, enable auto rotation correction in DVS. - * @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\Translate\V3\TranslateDocumentResponse - * - * @throws ApiException if the remote call fails - */ - public function translateDocument($parent, $targetLanguageCode, $documentInputConfig, array $optionalArgs = []) - { - $request = new TranslateDocumentRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setTargetLanguageCode($targetLanguageCode); - $request->setDocumentInputConfig($documentInputConfig); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['sourceLanguageCode'])) { - $request->setSourceLanguageCode($optionalArgs['sourceLanguageCode']); - } - - if (isset($optionalArgs['documentOutputConfig'])) { - $request->setDocumentOutputConfig($optionalArgs['documentOutputConfig']); - } - - if (isset($optionalArgs['model'])) { - $request->setModel($optionalArgs['model']); - } - - if (isset($optionalArgs['glossaryConfig'])) { - $request->setGlossaryConfig($optionalArgs['glossaryConfig']); - } - - if (isset($optionalArgs['labels'])) { - $request->setLabels($optionalArgs['labels']); - } - - if (isset($optionalArgs['customizedAttribution'])) { - $request->setCustomizedAttribution($optionalArgs['customizedAttribution']); - } - - if (isset($optionalArgs['isTranslateNativePdfOnly'])) { - $request->setIsTranslateNativePdfOnly($optionalArgs['isTranslateNativePdfOnly']); - } - - if (isset($optionalArgs['enableShadowRemovalNativePdf'])) { - $request->setEnableShadowRemovalNativePdf($optionalArgs['enableShadowRemovalNativePdf']); - } - - if (isset($optionalArgs['enableRotationCorrection'])) { - $request->setEnableRotationCorrection($optionalArgs['enableRotationCorrection']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('TranslateDocument', TranslateDocumentResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Translates input text and returns translated text. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $contents = []; - * $targetLanguageCode = 'target_language_code'; - * $formattedParent = $translationServiceClient->locationName('[PROJECT]', '[LOCATION]'); - * $response = $translationServiceClient->translateText($contents, $targetLanguageCode, $formattedParent); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param string[] $contents Required. The content of the input in string format. - * We recommend the total content be less than 30,000 codepoints. The max - * length of this field is 1024. Use BatchTranslateText for larger text. - * @param string $targetLanguageCode Required. The ISO-639 language code to use for translation of the input - * text, set to one of the language codes listed in Language Support. - * @param string $parent Required. Project or location to make a call. Must refer to a caller's - * project. - * - * Format: `projects/{project-number-or-id}` or - * `projects/{project-number-or-id}/locations/{location-id}`. - * - * For global calls, use `projects/{project-number-or-id}/locations/global` or - * `projects/{project-number-or-id}`. - * - * Non-global location is required for requests using AutoML models or - * custom glossaries. - * - * Models and glossaries must be within the same region (have same - * location-id), otherwise an INVALID_ARGUMENT (400) error is returned. - * @param array $optionalArgs { - * Optional. - * - * @type string $mimeType - * Optional. The format of the source text, for example, "text/html", - * "text/plain". If left blank, the MIME type defaults to "text/html". - * @type string $sourceLanguageCode - * Optional. The ISO-639 language code of the input text if - * known, for example, "en-US" or "sr-Latn". Supported language codes are - * listed in Language Support. If the source language isn't specified, the API - * attempts to identify the source language automatically and returns the - * source language within the response. - * @type string $model - * Optional. The `model` type requested for this translation. - * - * The format depends on model type: - * - * - AutoML Translation models: - * `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}` - * - * - General (built-in) models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`, - * - * - Translation LLM models: - * `projects/{project-number-or-id}/locations/{location-id}/models/general/translation-llm`, - * - * For global (non-regionalized) requests, use `location-id` `global`. - * For example, - * `projects/{project-number-or-id}/locations/global/models/general/nmt`. - * - * If not provided, the default Google model (NMT) will be used - * @type TranslateTextGlossaryConfig $glossaryConfig - * Optional. Glossary to be applied. The glossary must be - * within the same region (have the same location-id) as the model, otherwise - * an INVALID_ARGUMENT (400) error is returned. - * @type TransliterationConfig $transliterationConfig - * Optional. Transliteration to be applied. - * @type array $labels - * Optional. The labels with user-defined metadata for the request. - * - * Label keys and values can be no longer than 63 characters - * (Unicode codepoints), can only contain lowercase letters, numeric - * characters, underscores and dashes. International characters are allowed. - * Label values are optional. Label keys must start with a letter. - * - * See https://cloud.google.com/translate/docs/advanced/labels for more - * information. - * @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\Translate\V3\TranslateTextResponse - * - * @throws ApiException if the remote call fails - */ - public function translateText($contents, $targetLanguageCode, $parent, array $optionalArgs = []) - { - $request = new TranslateTextRequest(); - $requestParamHeaders = []; - $request->setContents($contents); - $request->setTargetLanguageCode($targetLanguageCode); - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['mimeType'])) { - $request->setMimeType($optionalArgs['mimeType']); - } - - if (isset($optionalArgs['sourceLanguageCode'])) { - $request->setSourceLanguageCode($optionalArgs['sourceLanguageCode']); - } - - if (isset($optionalArgs['model'])) { - $request->setModel($optionalArgs['model']); - } - - if (isset($optionalArgs['glossaryConfig'])) { - $request->setGlossaryConfig($optionalArgs['glossaryConfig']); - } - - if (isset($optionalArgs['transliterationConfig'])) { - $request->setTransliterationConfig($optionalArgs['transliterationConfig']); - } - - if (isset($optionalArgs['labels'])) { - $request->setLabels($optionalArgs['labels']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('TranslateText', TranslateTextResponse::class, $optionalArgs, $request)->wait(); - } - - /** - * Updates a glossary. A LRO is used since the update can be async if the - * glossary's entry file is updated. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $glossary = new Glossary(); - * $operationResponse = $translationServiceClient->updateGlossary($glossary); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $translationServiceClient->updateGlossary($glossary); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $translationServiceClient->resumeOperation($operationName, 'updateGlossary'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param Glossary $glossary Required. The glossary entry to update. - * @param array $optionalArgs { - * Optional. - * - * @type FieldMask $updateMask - * The list of fields to be updated. Currently only `display_name` and - * 'input_config' - * @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\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function updateGlossary($glossary, array $optionalArgs = []) - { - $request = new UpdateGlossaryRequest(); - $requestParamHeaders = []; - $request->setGlossary($glossary); - $requestParamHeaders['glossary.name'] = $glossary->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->startOperationsCall('UpdateGlossary', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Updates a glossary entry. - * - * Sample code: - * ``` - * $translationServiceClient = new TranslationServiceClient(); - * try { - * $glossaryEntry = new GlossaryEntry(); - * $response = $translationServiceClient->updateGlossaryEntry($glossaryEntry); - * } finally { - * $translationServiceClient->close(); - * } - * ``` - * - * @param GlossaryEntry $glossaryEntry Required. The glossary entry to update. - * @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\Translate\V3\GlossaryEntry - * - * @throws ApiException if the remote call fails - */ - public function updateGlossaryEntry($glossaryEntry, array $optionalArgs = []) - { - $request = new UpdateGlossaryEntryRequest(); - $requestParamHeaders = []; - $request->setGlossaryEntry($glossaryEntry); - $requestParamHeaders['glossary_entry.name'] = $glossaryEntry->getName(); - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('UpdateGlossaryEntry', GlossaryEntry::class, $optionalArgs, $request)->wait(); - } -} diff --git a/Translate/src/V3/GcsDestination.php b/Translate/src/V3/GcsDestination.php index 33e43c4a2613..6294ede95c7d 100644 --- a/Translate/src/V3/GcsDestination.php +++ b/Translate/src/V3/GcsDestination.php @@ -24,7 +24,7 @@ class GcsDestination extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string output_uri_prefix = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $output_uri_prefix = ''; + protected $output_uri_prefix = ''; /** * Constructor. diff --git a/Translate/src/V3/GcsInputSource.php b/Translate/src/V3/GcsInputSource.php index 4e8c9a8c67ea..e4f5d74d11d3 100644 --- a/Translate/src/V3/GcsInputSource.php +++ b/Translate/src/V3/GcsInputSource.php @@ -20,7 +20,7 @@ class GcsInputSource extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string input_uri = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $input_uri = ''; + protected $input_uri = ''; /** * Constructor. diff --git a/Translate/src/V3/GcsOutputDestination.php b/Translate/src/V3/GcsOutputDestination.php index 8b9cdb886b9b..81e9d86f3077 100644 --- a/Translate/src/V3/GcsOutputDestination.php +++ b/Translate/src/V3/GcsOutputDestination.php @@ -22,7 +22,7 @@ class GcsOutputDestination extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string output_uri_prefix = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $output_uri_prefix = ''; + protected $output_uri_prefix = ''; /** * Constructor. diff --git a/Translate/src/V3/GcsSource.php b/Translate/src/V3/GcsSource.php index 2b17b50b6638..9dfda6fc818a 100644 --- a/Translate/src/V3/GcsSource.php +++ b/Translate/src/V3/GcsSource.php @@ -20,7 +20,7 @@ class GcsSource extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string input_uri = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $input_uri = ''; + protected $input_uri = ''; /** * Constructor. diff --git a/Translate/src/V3/GetAdaptiveMtDatasetRequest.php b/Translate/src/V3/GetAdaptiveMtDatasetRequest.php index 99ab219ad9d7..4107de1639f4 100644 --- a/Translate/src/V3/GetAdaptiveMtDatasetRequest.php +++ b/Translate/src/V3/GetAdaptiveMtDatasetRequest.php @@ -21,7 +21,7 @@ class GetAdaptiveMtDatasetRequest 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. Name of the dataset. In the form of diff --git a/Translate/src/V3/GetAdaptiveMtFileRequest.php b/Translate/src/V3/GetAdaptiveMtFileRequest.php index fb79e3f3cbe4..4020332cc0ce 100644 --- a/Translate/src/V3/GetAdaptiveMtFileRequest.php +++ b/Translate/src/V3/GetAdaptiveMtFileRequest.php @@ -21,7 +21,7 @@ class GetAdaptiveMtFileRequest 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 resource name of the file, in form of diff --git a/Translate/src/V3/GetDatasetRequest.php b/Translate/src/V3/GetDatasetRequest.php index e9863cae1372..5b6d6b170012 100644 --- a/Translate/src/V3/GetDatasetRequest.php +++ b/Translate/src/V3/GetDatasetRequest.php @@ -20,7 +20,7 @@ class GetDatasetRequest 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 resource name of the dataset to retrieve. Please see diff --git a/Translate/src/V3/GetGlossaryEntryRequest.php b/Translate/src/V3/GetGlossaryEntryRequest.php index 6da4621abc88..bcc45b5ca1f6 100644 --- a/Translate/src/V3/GetGlossaryEntryRequest.php +++ b/Translate/src/V3/GetGlossaryEntryRequest.php @@ -20,7 +20,7 @@ class GetGlossaryEntryRequest 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 resource name of the glossary entry to get diff --git a/Translate/src/V3/GetGlossaryRequest.php b/Translate/src/V3/GetGlossaryRequest.php index e88b48b243e0..c4b68b01391c 100644 --- a/Translate/src/V3/GetGlossaryRequest.php +++ b/Translate/src/V3/GetGlossaryRequest.php @@ -20,7 +20,7 @@ class GetGlossaryRequest 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 glossary to retrieve. Please see diff --git a/Translate/src/V3/GetModelRequest.php b/Translate/src/V3/GetModelRequest.php index 49ddb43bbed6..9484ddb5b7ce 100644 --- a/Translate/src/V3/GetModelRequest.php +++ b/Translate/src/V3/GetModelRequest.php @@ -20,7 +20,7 @@ class GetModelRequest 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 resource name of the model to retrieve. Please see diff --git a/Translate/src/V3/GetSupportedLanguagesRequest.php b/Translate/src/V3/GetSupportedLanguagesRequest.php index 86d882ae7aca..86dc2cda5a39 100644 --- a/Translate/src/V3/GetSupportedLanguagesRequest.php +++ b/Translate/src/V3/GetSupportedLanguagesRequest.php @@ -28,7 +28,7 @@ class GetSupportedLanguagesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Optional. The language to use to return localized, human readable names * of supported languages. If missing, then display names are not returned @@ -36,7 +36,7 @@ class GetSupportedLanguagesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string display_language_code = 1 [(.google.api.field_behavior) = OPTIONAL]; */ - private $display_language_code = ''; + protected $display_language_code = ''; /** * Optional. Get supported languages of this model. * The format depends on model type: @@ -49,7 +49,7 @@ class GetSupportedLanguagesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string model = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $model = ''; + protected $model = ''; /** * @param string $parent Required. Project or location to make a call. Must refer to a caller's diff --git a/Translate/src/V3/Glossary.php b/Translate/src/V3/Glossary.php index 74fcad43b5df..dac3eb5708c2 100644 --- a/Translate/src/V3/Glossary.php +++ b/Translate/src/V3/Glossary.php @@ -21,38 +21,38 @@ class Glossary extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $name = ''; + protected $name = ''; /** * Required. Provides examples to build the glossary from. * Total glossary must not exceed 10M Unicode codepoints. * * Generated from protobuf field .google.cloud.translation.v3.GlossaryInputConfig input_config = 5; */ - private $input_config = null; + protected $input_config = null; /** * Output only. The number of entries defined in the glossary. * * Generated from protobuf field int32 entry_count = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $entry_count = 0; + protected $entry_count = 0; /** * Output only. When CreateGlossary was called. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $submit_time = null; + protected $submit_time = null; /** * Output only. When the glossary creation was finished. * * Generated from protobuf field .google.protobuf.Timestamp end_time = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $end_time = null; + protected $end_time = null; /** * Optional. The display name of the glossary. * * Generated from protobuf field string display_name = 9 [(.google.api.field_behavior) = OPTIONAL]; */ - private $display_name = ''; + protected $display_name = ''; protected $languages; /** diff --git a/Translate/src/V3/Glossary/LanguageCodePair.php b/Translate/src/V3/Glossary/LanguageCodePair.php index 32fc3faebdae..a4a9d186e9b3 100644 --- a/Translate/src/V3/Glossary/LanguageCodePair.php +++ b/Translate/src/V3/Glossary/LanguageCodePair.php @@ -21,14 +21,14 @@ class LanguageCodePair extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string source_language_code = 1; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * Required. The ISO-639 language code for translation output, for example, * "zh-CN". Expected to be an exact match for GlossaryTerm.language_code. * * Generated from protobuf field string target_language_code = 2; */ - private $target_language_code = ''; + protected $target_language_code = ''; /** * Constructor. @@ -107,6 +107,4 @@ public function setTargetLanguageCode($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(LanguageCodePair::class, \Google\Cloud\Translate\V3\Glossary_LanguageCodePair::class); diff --git a/Translate/src/V3/Glossary/LanguageCodesSet.php b/Translate/src/V3/Glossary/LanguageCodesSet.php index 164d340406c0..a78ef8453d14 100644 --- a/Translate/src/V3/Glossary/LanguageCodesSet.php +++ b/Translate/src/V3/Glossary/LanguageCodesSet.php @@ -73,6 +73,4 @@ public function setLanguageCodes($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(LanguageCodesSet::class, \Google\Cloud\Translate\V3\Glossary_LanguageCodesSet::class); diff --git a/Translate/src/V3/GlossaryEntry.php b/Translate/src/V3/GlossaryEntry.php index 2e188a3e2558..334518294710 100644 --- a/Translate/src/V3/GlossaryEntry.php +++ b/Translate/src/V3/GlossaryEntry.php @@ -22,13 +22,13 @@ class GlossaryEntry extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IDENTIFIER]; */ - private $name = ''; + protected $name = ''; /** * Describes the glossary entry. * * Generated from protobuf field string description = 4; */ - private $description = ''; + protected $description = ''; protected $data; /** diff --git a/Translate/src/V3/GlossaryEntry/GlossaryTermsPair.php b/Translate/src/V3/GlossaryEntry/GlossaryTermsPair.php index e0e9422d7b4b..f0e122643fae 100644 --- a/Translate/src/V3/GlossaryEntry/GlossaryTermsPair.php +++ b/Translate/src/V3/GlossaryEntry/GlossaryTermsPair.php @@ -20,13 +20,13 @@ class GlossaryTermsPair extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.GlossaryTerm source_term = 1; */ - private $source_term = null; + protected $source_term = null; /** * The term that will replace the match source term. * * Generated from protobuf field .google.cloud.translation.v3.GlossaryTerm target_term = 2; */ - private $target_term = null; + protected $target_term = null; /** * Constructor. @@ -119,6 +119,4 @@ public function setTargetTerm($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(GlossaryTermsPair::class, \Google\Cloud\Translate\V3\GlossaryEntry_GlossaryTermsPair::class); diff --git a/Translate/src/V3/GlossaryEntry/GlossaryTermsSet.php b/Translate/src/V3/GlossaryEntry/GlossaryTermsSet.php index a6c6e89c53d8..ca8629b62145 100644 --- a/Translate/src/V3/GlossaryEntry/GlossaryTermsSet.php +++ b/Translate/src/V3/GlossaryEntry/GlossaryTermsSet.php @@ -71,6 +71,4 @@ public function setTerms($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(GlossaryTermsSet::class, \Google\Cloud\Translate\V3\GlossaryEntry_GlossaryTermsSet::class); diff --git a/Translate/src/V3/GlossaryTerm.php b/Translate/src/V3/GlossaryTerm.php index b2659e45d44f..b0579a657ab5 100644 --- a/Translate/src/V3/GlossaryTerm.php +++ b/Translate/src/V3/GlossaryTerm.php @@ -20,13 +20,13 @@ class GlossaryTerm extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string language_code = 1; */ - private $language_code = ''; + protected $language_code = ''; /** * The text for the glossary term. * * Generated from protobuf field string text = 2; */ - private $text = ''; + protected $text = ''; /** * Constructor. diff --git a/Translate/src/V3/Glossary_LanguageCodePair.php b/Translate/src/V3/Glossary_LanguageCodePair.php deleted file mode 100644 index 7bf5ee2d59d0..000000000000 --- a/Translate/src/V3/Glossary_LanguageCodePair.php +++ /dev/null @@ -1,16 +0,0 @@ -string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; protected $source; /** diff --git a/Translate/src/V3/ImportAdaptiveMtFileResponse.php b/Translate/src/V3/ImportAdaptiveMtFileResponse.php index 32ac38ab3154..807aa40206d0 100644 --- a/Translate/src/V3/ImportAdaptiveMtFileResponse.php +++ b/Translate/src/V3/ImportAdaptiveMtFileResponse.php @@ -20,7 +20,7 @@ class ImportAdaptiveMtFileResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.AdaptiveMtFile adaptive_mt_file = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $adaptive_mt_file = null; + protected $adaptive_mt_file = null; /** * Constructor. diff --git a/Translate/src/V3/ImportDataMetadata.php b/Translate/src/V3/ImportDataMetadata.php index 54f75449c04c..da2332653b27 100644 --- a/Translate/src/V3/ImportDataMetadata.php +++ b/Translate/src/V3/ImportDataMetadata.php @@ -20,25 +20,25 @@ class ImportDataMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.OperationState state = 1; */ - private $state = 0; + protected $state = 0; /** * The creation time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 2; */ - private $create_time = null; + protected $create_time = null; /** * The last update time of the operation. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 3; */ - private $update_time = null; + protected $update_time = null; /** * Only populated when operation doesn't succeed. * * Generated from protobuf field .google.rpc.Status error = 4; */ - private $error = null; + protected $error = null; /** * Constructor. diff --git a/Translate/src/V3/ImportDataRequest.php b/Translate/src/V3/ImportDataRequest.php index 37713c19c213..2511822eb678 100644 --- a/Translate/src/V3/ImportDataRequest.php +++ b/Translate/src/V3/ImportDataRequest.php @@ -21,13 +21,13 @@ class ImportDataRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string dataset = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $dataset = ''; + protected $dataset = ''; /** * Required. The config for the input content. * * Generated from protobuf field .google.cloud.translation.v3.DatasetInputConfig input_config = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $input_config = null; + protected $input_config = null; /** * @param string $dataset Required. Name of the dataset. In form of diff --git a/Translate/src/V3/InputConfig.php b/Translate/src/V3/InputConfig.php index e915375fc3cf..ced50d3a94bb 100644 --- a/Translate/src/V3/InputConfig.php +++ b/Translate/src/V3/InputConfig.php @@ -23,7 +23,7 @@ class InputConfig extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string mime_type = 1 [(.google.api.field_behavior) = OPTIONAL]; */ - private $mime_type = ''; + protected $mime_type = ''; protected $source; /** diff --git a/Translate/src/V3/ListAdaptiveMtDatasetsRequest.php b/Translate/src/V3/ListAdaptiveMtDatasetsRequest.php index b5edb32417c1..d056833ac952 100644 --- a/Translate/src/V3/ListAdaptiveMtDatasetsRequest.php +++ b/Translate/src/V3/ListAdaptiveMtDatasetsRequest.php @@ -22,14 +22,14 @@ class ListAdaptiveMtDatasetsRequest 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. Requested page size. The server may return fewer results than * requested. If unspecified, the server picks an appropriate default. * * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. A token identifying a page of results the server should return. * Typically, this is the value of @@ -39,14 +39,14 @@ class ListAdaptiveMtDatasetsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_token = ''; + protected $page_token = ''; /** * Optional. An expression for filtering the results of the request. * Filter is not supported yet. * * Generated from protobuf field string filter = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $filter = ''; + protected $filter = ''; /** * @param string $parent Required. The resource name of the project from which to list the Adaptive diff --git a/Translate/src/V3/ListAdaptiveMtDatasetsResponse.php b/Translate/src/V3/ListAdaptiveMtDatasetsResponse.php index b836d5c7aeeb..6aa796807558 100644 --- a/Translate/src/V3/ListAdaptiveMtDatasetsResponse.php +++ b/Translate/src/V3/ListAdaptiveMtDatasetsResponse.php @@ -28,7 +28,7 @@ class ListAdaptiveMtDatasetsResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/Translate/src/V3/ListAdaptiveMtFilesRequest.php b/Translate/src/V3/ListAdaptiveMtFilesRequest.php index 0f3634b2af81..414b8a8f221e 100644 --- a/Translate/src/V3/ListAdaptiveMtFilesRequest.php +++ b/Translate/src/V3/ListAdaptiveMtFilesRequest.php @@ -22,13 +22,13 @@ class ListAdaptiveMtFilesRequest 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. * * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. A token identifying a page of results the server should return. * Typically, this is the value of @@ -38,7 +38,7 @@ class ListAdaptiveMtFilesRequest 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 resource name of the project from which to list the Adaptive diff --git a/Translate/src/V3/ListAdaptiveMtFilesResponse.php b/Translate/src/V3/ListAdaptiveMtFilesResponse.php index dd11f5e0513a..8f62be3dc154 100644 --- a/Translate/src/V3/ListAdaptiveMtFilesResponse.php +++ b/Translate/src/V3/ListAdaptiveMtFilesResponse.php @@ -28,7 +28,7 @@ class ListAdaptiveMtFilesResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/Translate/src/V3/ListAdaptiveMtSentencesRequest.php b/Translate/src/V3/ListAdaptiveMtSentencesRequest.php index 6c77ac1fbccd..dc0a5b6eca60 100644 --- a/Translate/src/V3/ListAdaptiveMtSentencesRequest.php +++ b/Translate/src/V3/ListAdaptiveMtSentencesRequest.php @@ -24,11 +24,11 @@ class ListAdaptiveMtSentencesRequest 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 = ''; /** * Generated from protobuf field int32 page_size = 2; */ - private $page_size = 0; + protected $page_size = 0; /** * A token identifying a page of results the server should return. * Typically, this is the value of @@ -38,7 +38,7 @@ class ListAdaptiveMtSentencesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string page_token = 3; */ - private $page_token = ''; + protected $page_token = ''; /** * @param string $parent Required. The resource name of the project from which to list the Adaptive diff --git a/Translate/src/V3/ListAdaptiveMtSentencesResponse.php b/Translate/src/V3/ListAdaptiveMtSentencesResponse.php index 599f55ee9cfd..86d22bc4b9e1 100644 --- a/Translate/src/V3/ListAdaptiveMtSentencesResponse.php +++ b/Translate/src/V3/ListAdaptiveMtSentencesResponse.php @@ -26,7 +26,7 @@ class ListAdaptiveMtSentencesResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/Translate/src/V3/ListDatasetsRequest.php b/Translate/src/V3/ListDatasetsRequest.php index 73b7d3128428..9fec40ecfcc6 100644 --- a/Translate/src/V3/ListDatasetsRequest.php +++ b/Translate/src/V3/ListDatasetsRequest.php @@ -21,14 +21,14 @@ class ListDatasetsRequest 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. Requested page size. The server can return fewer results than * requested. * * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. A token identifying a page of results for the server to return. * Typically obtained from next_page_token field in the response of a @@ -36,7 +36,7 @@ class ListDatasetsRequest 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. Name of the parent project. In form of diff --git a/Translate/src/V3/ListDatasetsResponse.php b/Translate/src/V3/ListDatasetsResponse.php index 81f63371d0ee..eabcc76ff92e 100644 --- a/Translate/src/V3/ListDatasetsResponse.php +++ b/Translate/src/V3/ListDatasetsResponse.php @@ -28,7 +28,7 @@ class ListDatasetsResponse 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/Translate/src/V3/ListExamplesRequest.php b/Translate/src/V3/ListExamplesRequest.php index 23df7baae318..3f4dee718cd0 100644 --- a/Translate/src/V3/ListExamplesRequest.php +++ b/Translate/src/V3/ListExamplesRequest.php @@ -21,7 +21,7 @@ class ListExamplesRequest 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. An expression for filtering the examples that will be returned. * Example filter: @@ -29,14 +29,14 @@ class ListExamplesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string filter = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $filter = ''; + protected $filter = ''; /** * Optional. Requested page size. The server can return fewer results than * requested. * * Generated from protobuf field int32 page_size = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. A token identifying a page of results for the server to return. * Typically obtained from next_page_token field in the response of a @@ -44,7 +44,7 @@ class ListExamplesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string page_token = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_token = ''; + protected $page_token = ''; /** * @param string $parent Required. Name of the parent dataset. In form of diff --git a/Translate/src/V3/ListExamplesResponse.php b/Translate/src/V3/ListExamplesResponse.php index 02c16d8ee932..b4ce65bbb934 100644 --- a/Translate/src/V3/ListExamplesResponse.php +++ b/Translate/src/V3/ListExamplesResponse.php @@ -28,7 +28,7 @@ class ListExamplesResponse 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/Translate/src/V3/ListGlossariesRequest.php b/Translate/src/V3/ListGlossariesRequest.php index 5a757ce9ab05..732d892af976 100644 --- a/Translate/src/V3/ListGlossariesRequest.php +++ b/Translate/src/V3/ListGlossariesRequest.php @@ -20,14 +20,14 @@ class ListGlossariesRequest 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. Requested page size. The server may return fewer glossaries than * requested. If unspecified, the server picks an appropriate default. * * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. A token identifying a page of results the server should return. * Typically, this is the value of [ListGlossariesResponse.next_page_token] @@ -36,7 +36,7 @@ class ListGlossariesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_token = ''; + protected $page_token = ''; /** * Optional. Filter specifying constraints of a list operation. * Specify the constraint by the format of "key=value", where key must be @@ -57,7 +57,7 @@ class ListGlossariesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string filter = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $filter = ''; + protected $filter = ''; /** * @param string $parent Required. The name of the project from which to list all of the glossaries. Please see diff --git a/Translate/src/V3/ListGlossariesResponse.php b/Translate/src/V3/ListGlossariesResponse.php index 324fb7fe76a8..4671da068fa9 100644 --- a/Translate/src/V3/ListGlossariesResponse.php +++ b/Translate/src/V3/ListGlossariesResponse.php @@ -28,7 +28,7 @@ class ListGlossariesResponse 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/Translate/src/V3/ListGlossaryEntriesRequest.php b/Translate/src/V3/ListGlossaryEntriesRequest.php index 2dd27dc7d94d..ee2cc959c6b2 100644 --- a/Translate/src/V3/ListGlossaryEntriesRequest.php +++ b/Translate/src/V3/ListGlossaryEntriesRequest.php @@ -21,14 +21,14 @@ class ListGlossaryEntriesRequest 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. Requested page size. The server may return fewer glossary entries * than requested. If unspecified, the server picks an appropriate default. * * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. A token identifying a page of results the server should return. * Typically, this is the value of @@ -37,7 +37,7 @@ class ListGlossaryEntriesRequest 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 glossary resource name for listing the glossary's diff --git a/Translate/src/V3/ListGlossaryEntriesResponse.php b/Translate/src/V3/ListGlossaryEntriesResponse.php index b025ab15c028..fb54f7a450c5 100644 --- a/Translate/src/V3/ListGlossaryEntriesResponse.php +++ b/Translate/src/V3/ListGlossaryEntriesResponse.php @@ -27,7 +27,7 @@ class ListGlossaryEntriesResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/Translate/src/V3/ListModelsRequest.php b/Translate/src/V3/ListModelsRequest.php index c750c74de4e7..0ecd1f15ed6e 100644 --- a/Translate/src/V3/ListModelsRequest.php +++ b/Translate/src/V3/ListModelsRequest.php @@ -21,7 +21,7 @@ class ListModelsRequest 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. An expression for filtering the models that will be returned. * Supported filter: @@ -29,14 +29,14 @@ class ListModelsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string filter = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $filter = ''; + protected $filter = ''; /** * Optional. Requested page size. The server can return fewer results than * requested. * * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $page_size = 0; + protected $page_size = 0; /** * Optional. A token identifying a page of results for the server to return. * Typically obtained from next_page_token field in the response of a @@ -44,7 +44,7 @@ class ListModelsRequest 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. Name of the parent project. In form of diff --git a/Translate/src/V3/ListModelsResponse.php b/Translate/src/V3/ListModelsResponse.php index 03906feab55b..6b412ee82d54 100644 --- a/Translate/src/V3/ListModelsResponse.php +++ b/Translate/src/V3/ListModelsResponse.php @@ -28,7 +28,7 @@ class ListModelsResponse 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/Translate/src/V3/Model.php b/Translate/src/V3/Model.php index 02865c753cd3..a71a45c1b211 100644 --- a/Translate/src/V3/Model.php +++ b/Translate/src/V3/Model.php @@ -21,7 +21,7 @@ class Model extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1; */ - private $name = ''; + protected $name = ''; /** * The name of the model to show in the interface. The name can be * up to 32 characters long and can consist only of ASCII Latin letters A-Z @@ -29,58 +29,58 @@ class Model extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string display_name = 2; */ - private $display_name = ''; + protected $display_name = ''; /** * The dataset from which the model is trained, in form of * `projects/{project-number-or-id}/locations/{location_id}/datasets/{dataset_id}` * * Generated from protobuf field string dataset = 3; */ - private $dataset = ''; + protected $dataset = ''; /** * Output only. The BCP-47 language code of the source language. * * Generated from protobuf field string source_language_code = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * Output only. The BCP-47 language code of the target language. * * Generated from protobuf field string target_language_code = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $target_language_code = ''; + protected $target_language_code = ''; /** * Output only. Number of examples (sentence pairs) used to train the model. * * Generated from protobuf field int32 train_example_count = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $train_example_count = 0; + protected $train_example_count = 0; /** * Output only. Number of examples (sentence pairs) used to validate the * model. * * Generated from protobuf field int32 validate_example_count = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $validate_example_count = 0; + protected $validate_example_count = 0; /** * Output only. Number of examples (sentence pairs) used to test the model. * * Generated from protobuf field int32 test_example_count = 12 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $test_example_count = 0; + protected $test_example_count = 0; /** * Output only. Timestamp when the model resource was created, which is also * when the training started. * * Generated from protobuf field .google.protobuf.Timestamp create_time = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $create_time = null; + protected $create_time = null; /** * Output only. Timestamp when this model was last updated. * * Generated from protobuf field .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $update_time = null; + protected $update_time = null; /** * Constructor. diff --git a/Translate/src/V3/README.md b/Translate/src/V3/README.md deleted file mode 100644 index 55ee44c9648d..000000000000 --- a/Translate/src/V3/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Google Cloud Translate V3 generated client for PHP - -### Sample - -```php -require 'vendor/autoload.php'; - -use Google\Cloud\Translate\V3\TranslationServiceClient; - -$translationClient = new TranslationServiceClient(); -$content = ['one', 'two', 'three']; -$targetLanguage = 'es'; -$response = $translationClient->translateText( - $content, - $targetLanguage, - TranslationServiceClient::locationName('[PROJECT_ID]', 'global') -); - -foreach ($response->getTranslations() as $key => $translation) { - $separator = $key === 2 - ? '!' - : ', '; - echo $translation->getTranslatedText() . $separator; -} -``` diff --git a/Translate/src/V3/Romanization.php b/Translate/src/V3/Romanization.php index 847f3791251a..1e749df25547 100644 --- a/Translate/src/V3/Romanization.php +++ b/Translate/src/V3/Romanization.php @@ -22,7 +22,7 @@ class Romanization extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string romanized_text = 1; */ - private $romanized_text = ''; + protected $romanized_text = ''; /** * The ISO-639 language code of source text in the initial request, detected * automatically, if no source language was passed within the initial @@ -31,7 +31,7 @@ class Romanization extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string detected_language_code = 2; */ - private $detected_language_code = ''; + protected $detected_language_code = ''; /** * Constructor. diff --git a/Translate/src/V3/RomanizeTextRequest.php b/Translate/src/V3/RomanizeTextRequest.php index 79a016a6b518..597960eb3d1f 100644 --- a/Translate/src/V3/RomanizeTextRequest.php +++ b/Translate/src/V3/RomanizeTextRequest.php @@ -25,7 +25,7 @@ class RomanizeTextRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 4 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Required. The content of the input in string format. * @@ -40,7 +40,7 @@ class RomanizeTextRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string source_language_code = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * @param string $parent Required. Project or location to make a call. Must refer to a caller's diff --git a/Translate/src/V3/SupportedLanguage.php b/Translate/src/V3/SupportedLanguage.php index 693d120494d0..cfb8756c2c13 100644 --- a/Translate/src/V3/SupportedLanguage.php +++ b/Translate/src/V3/SupportedLanguage.php @@ -24,26 +24,26 @@ class SupportedLanguage extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string language_code = 1; */ - private $language_code = ''; + protected $language_code = ''; /** * Human-readable name of the language localized in the display language * specified in the request. * * Generated from protobuf field string display_name = 2; */ - private $display_name = ''; + protected $display_name = ''; /** * Can be used as a source language. * * Generated from protobuf field bool support_source = 3; */ - private $support_source = false; + protected $support_source = false; /** * Can be used as a target language. * * Generated from protobuf field bool support_target = 4; */ - private $support_target = false; + protected $support_target = false; /** * Constructor. diff --git a/Translate/src/V3/TranslateDocumentRequest.php b/Translate/src/V3/TranslateDocumentRequest.php index 8038b11f8bdb..ed1a08a279ba 100644 --- a/Translate/src/V3/TranslateDocumentRequest.php +++ b/Translate/src/V3/TranslateDocumentRequest.php @@ -27,7 +27,7 @@ class TranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $parent = ''; + protected $parent = ''; /** * Optional. The ISO-639 language code of the input document if known, for * example, "en-US" or "sr-Latn". Supported language codes are listed in @@ -38,20 +38,20 @@ class TranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string source_language_code = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * Required. The ISO-639 language code to use for translation of the input * document, set to one of the language codes listed in Language Support. * * Generated from protobuf field string target_language_code = 3 [(.google.api.field_behavior) = REQUIRED]; */ - private $target_language_code = ''; + protected $target_language_code = ''; /** * Required. Input configurations. * * Generated from protobuf field .google.cloud.translation.v3.DocumentInputConfig document_input_config = 4 [(.google.api.field_behavior) = REQUIRED]; */ - private $document_input_config = null; + protected $document_input_config = null; /** * Optional. Output configurations. * Defines if the output file should be stored within Cloud Storage as well @@ -61,7 +61,7 @@ class TranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.DocumentOutputConfig document_output_config = 5 [(.google.api.field_behavior) = OPTIONAL]; */ - private $document_output_config = null; + protected $document_output_config = null; /** * Optional. The `model` type requested for this translation. * The format depends on model type: @@ -74,7 +74,7 @@ class TranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string model = 6 [(.google.api.field_behavior) = OPTIONAL]; */ - private $model = ''; + protected $model = ''; /** * Optional. Glossary to be applied. The glossary must be within the same * region (have the same location-id) as the model, otherwise an @@ -82,7 +82,7 @@ class TranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.TranslateTextGlossaryConfig glossary_config = 7 [(.google.api.field_behavior) = OPTIONAL]; */ - private $glossary_config = null; + protected $glossary_config = null; /** * Optional. The labels with user-defined metadata for the request. * Label keys and values can be no longer than 63 characters (Unicode @@ -103,7 +103,7 @@ class TranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string customized_attribution = 10 [(.google.api.field_behavior) = OPTIONAL]; */ - private $customized_attribution = ''; + protected $customized_attribution = ''; /** * Optional. is_translate_native_pdf_only field for external customers. * If true, the page limit of online native pdf translation is 300 and only @@ -111,7 +111,7 @@ class TranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool is_translate_native_pdf_only = 11 [(.google.api.field_behavior) = OPTIONAL]; */ - private $is_translate_native_pdf_only = false; + protected $is_translate_native_pdf_only = false; /** * Optional. If true, use the text removal server to remove the shadow text on * background image for native pdf translation. @@ -120,13 +120,13 @@ class TranslateDocumentRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool enable_shadow_removal_native_pdf = 12 [(.google.api.field_behavior) = OPTIONAL]; */ - private $enable_shadow_removal_native_pdf = false; + protected $enable_shadow_removal_native_pdf = false; /** * Optional. If true, enable auto rotation correction in DVS. * * Generated from protobuf field bool enable_rotation_correction = 13 [(.google.api.field_behavior) = OPTIONAL]; */ - private $enable_rotation_correction = false; + protected $enable_rotation_correction = false; /** * Constructor. diff --git a/Translate/src/V3/TranslateDocumentResponse.php b/Translate/src/V3/TranslateDocumentResponse.php index 667bba6cd85c..cb03652f9530 100644 --- a/Translate/src/V3/TranslateDocumentResponse.php +++ b/Translate/src/V3/TranslateDocumentResponse.php @@ -20,7 +20,7 @@ class TranslateDocumentResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.DocumentTranslation document_translation = 1; */ - private $document_translation = null; + protected $document_translation = null; /** * The document's translation output if a glossary is provided in the request. * This can be the same as [TranslateDocumentResponse.document_translation] @@ -28,7 +28,7 @@ class TranslateDocumentResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.DocumentTranslation glossary_document_translation = 2; */ - private $glossary_document_translation = null; + protected $glossary_document_translation = null; /** * Only present when 'model' is present in the request. * 'model' is normalized to have a project number. @@ -40,13 +40,13 @@ class TranslateDocumentResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string model = 3; */ - private $model = ''; + protected $model = ''; /** * The `glossary_config` used for this translation. * * Generated from protobuf field .google.cloud.translation.v3.TranslateTextGlossaryConfig glossary_config = 4; */ - private $glossary_config = null; + protected $glossary_config = null; /** * Constructor. diff --git a/Translate/src/V3/TranslateTextGlossaryConfig.php b/Translate/src/V3/TranslateTextGlossaryConfig.php index 2edd102cf343..ce2fa4f3fce8 100644 --- a/Translate/src/V3/TranslateTextGlossaryConfig.php +++ b/Translate/src/V3/TranslateTextGlossaryConfig.php @@ -24,21 +24,21 @@ class TranslateTextGlossaryConfig extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string glossary = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $glossary = ''; + protected $glossary = ''; /** * Optional. Indicates match is case insensitive. The default value is `false` * if missing. * * Generated from protobuf field bool ignore_case = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $ignore_case = false; + protected $ignore_case = false; /** * Optional. If set to true, the glossary will be used for contextual * translation. * * Generated from protobuf field bool contextual_translation_enabled = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $contextual_translation_enabled = false; + protected $contextual_translation_enabled = false; /** * Constructor. diff --git a/Translate/src/V3/TranslateTextRequest.php b/Translate/src/V3/TranslateTextRequest.php index da8937bc036d..d916d70eb688 100644 --- a/Translate/src/V3/TranslateTextRequest.php +++ b/Translate/src/V3/TranslateTextRequest.php @@ -29,7 +29,7 @@ class TranslateTextRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string mime_type = 3 [(.google.api.field_behavior) = OPTIONAL]; */ - private $mime_type = ''; + protected $mime_type = ''; /** * Optional. The ISO-639 language code of the input text if * known, for example, "en-US" or "sr-Latn". Supported language codes are @@ -39,14 +39,14 @@ class TranslateTextRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string source_language_code = 4 [(.google.api.field_behavior) = OPTIONAL]; */ - private $source_language_code = ''; + protected $source_language_code = ''; /** * Required. The ISO-639 language code to use for translation of the input * text, set to one of the language codes listed in Language Support. * * Generated from protobuf field string target_language_code = 5 [(.google.api.field_behavior) = REQUIRED]; */ - private $target_language_code = ''; + protected $target_language_code = ''; /** * Required. Project or location to make a call. Must refer to a caller's * project. @@ -61,7 +61,7 @@ class TranslateTextRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 8 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Optional. The `model` type requested for this translation. * The format depends on model type: @@ -78,7 +78,7 @@ class TranslateTextRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string model = 6 [(.google.api.field_behavior) = OPTIONAL]; */ - private $model = ''; + protected $model = ''; /** * Optional. Glossary to be applied. The glossary must be * within the same region (have the same location-id) as the model, otherwise @@ -86,13 +86,13 @@ class TranslateTextRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.TranslateTextGlossaryConfig glossary_config = 7 [(.google.api.field_behavior) = OPTIONAL]; */ - private $glossary_config = null; + protected $glossary_config = null; /** * Optional. Transliteration to be applied. * * Generated from protobuf field .google.cloud.translation.v3.TransliterationConfig transliteration_config = 13 [(.google.api.field_behavior) = OPTIONAL]; */ - private $transliteration_config = null; + protected $transliteration_config = null; /** * Optional. The labels with user-defined metadata for the request. * Label keys and values can be no longer than 63 characters diff --git a/Translate/src/V3/Translation.php b/Translate/src/V3/Translation.php index 82722a76ebe9..f57fa9baac73 100644 --- a/Translate/src/V3/Translation.php +++ b/Translate/src/V3/Translation.php @@ -22,7 +22,7 @@ class Translation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string translated_text = 1; */ - private $translated_text = ''; + protected $translated_text = ''; /** * Only present when `model` is present in the request. * `model` here is normalized to have project number. @@ -34,7 +34,7 @@ class Translation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string model = 2; */ - private $model = ''; + protected $model = ''; /** * The ISO-639 language code of source text in the initial request, detected * automatically, if no source language was passed within the initial @@ -43,13 +43,13 @@ class Translation extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string detected_language_code = 4; */ - private $detected_language_code = ''; + protected $detected_language_code = ''; /** * The `glossary_config` used for this translation. * * Generated from protobuf field .google.cloud.translation.v3.TranslateTextGlossaryConfig glossary_config = 3; */ - private $glossary_config = null; + protected $glossary_config = null; /** * Constructor. diff --git a/Translate/src/V3/TranslationServiceClient.php b/Translate/src/V3/TranslationServiceClient.php deleted file mode 100644 index a58313be8db4..000000000000 --- a/Translate/src/V3/TranslationServiceClient.php +++ /dev/null @@ -1,34 +0,0 @@ -_simpleRequest('/google.cloud.translation.v3.TranslationService/TranslateText', - $argument, - ['\Google\Cloud\Translate\V3\TranslateTextResponse', 'decode'], - $metadata, $options); - } - - /** - * Detects the language of text within a request. - * @param \Google\Cloud\Translate\V3\DetectLanguageRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function DetectLanguage(\Google\Cloud\Translate\V3\DetectLanguageRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/DetectLanguage', - $argument, - ['\Google\Cloud\Translate\V3\DetectLanguageResponse', 'decode'], - $metadata, $options); - } - - /** - * Returns a list of supported languages for translation. - * @param \Google\Cloud\Translate\V3\GetSupportedLanguagesRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function GetSupportedLanguages(\Google\Cloud\Translate\V3\GetSupportedLanguagesRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/GetSupportedLanguages', - $argument, - ['\Google\Cloud\Translate\V3\SupportedLanguages', 'decode'], - $metadata, $options); - } - - /** - * Translates documents in synchronous mode. - * @param \Google\Cloud\Translate\V3\TranslateDocumentRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function TranslateDocument(\Google\Cloud\Translate\V3\TranslateDocumentRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/TranslateDocument', - $argument, - ['\Google\Cloud\Translate\V3\TranslateDocumentResponse', 'decode'], - $metadata, $options); - } - - /** - * Translates a large volume of text in asynchronous batch mode. - * This function provides real-time output as the inputs are being processed. - * If caller cancels a request, the partial results (for an input file, it's - * all or nothing) may still be available on the specified output location. - * - * This call returns immediately and you can - * use google.longrunning.Operation.name to poll the status of the call. - * @param \Google\Cloud\Translate\V3\BatchTranslateTextRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function BatchTranslateText(\Google\Cloud\Translate\V3\BatchTranslateTextRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/BatchTranslateText', - $argument, - ['\Google\LongRunning\Operation', 'decode'], - $metadata, $options); - } - - /** - * Translates a large volume of document in asynchronous batch mode. - * This function provides real-time output as the inputs are being processed. - * If caller cancels a request, the partial results (for an input file, it's - * all or nothing) may still be available on the specified output location. - * - * This call returns immediately and you can use - * google.longrunning.Operation.name to poll the status of the call. - * @param \Google\Cloud\Translate\V3\BatchTranslateDocumentRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function BatchTranslateDocument(\Google\Cloud\Translate\V3\BatchTranslateDocumentRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/BatchTranslateDocument', - $argument, - ['\Google\LongRunning\Operation', 'decode'], - $metadata, $options); - } - - /** - * Creates a glossary and returns the long-running operation. Returns - * NOT_FOUND, if the project doesn't exist. - * @param \Google\Cloud\Translate\V3\CreateGlossaryRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function CreateGlossary(\Google\Cloud\Translate\V3\CreateGlossaryRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/CreateGlossary', - $argument, - ['\Google\LongRunning\Operation', 'decode'], - $metadata, $options); - } - - /** - * Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't - * exist. - * @param \Google\Cloud\Translate\V3\ListGlossariesRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function ListGlossaries(\Google\Cloud\Translate\V3\ListGlossariesRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/ListGlossaries', - $argument, - ['\Google\Cloud\Translate\V3\ListGlossariesResponse', 'decode'], - $metadata, $options); - } - - /** - * Gets a glossary. Returns NOT_FOUND, if the glossary doesn't - * exist. - * @param \Google\Cloud\Translate\V3\GetGlossaryRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function GetGlossary(\Google\Cloud\Translate\V3\GetGlossaryRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/GetGlossary', - $argument, - ['\Google\Cloud\Translate\V3\Glossary', 'decode'], - $metadata, $options); - } - - /** - * Deletes a glossary, or cancels glossary construction - * if the glossary isn't created yet. - * Returns NOT_FOUND, if the glossary doesn't exist. - * @param \Google\Cloud\Translate\V3\DeleteGlossaryRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function DeleteGlossary(\Google\Cloud\Translate\V3\DeleteGlossaryRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.translation.v3.TranslationService/DeleteGlossary', - $argument, - ['\Google\LongRunning\Operation', 'decode'], - $metadata, $options); - } - -} diff --git a/Translate/src/V3/TransliterationConfig.php b/Translate/src/V3/TransliterationConfig.php index e249c3349ef2..3d511df97dc9 100644 --- a/Translate/src/V3/TransliterationConfig.php +++ b/Translate/src/V3/TransliterationConfig.php @@ -21,7 +21,7 @@ class TransliterationConfig extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool enable_transliteration = 1; */ - private $enable_transliteration = false; + protected $enable_transliteration = false; /** * Constructor. diff --git a/Translate/src/V3/UpdateGlossaryEntryRequest.php b/Translate/src/V3/UpdateGlossaryEntryRequest.php index 58715f421716..992f570f73b9 100644 --- a/Translate/src/V3/UpdateGlossaryEntryRequest.php +++ b/Translate/src/V3/UpdateGlossaryEntryRequest.php @@ -20,7 +20,7 @@ class UpdateGlossaryEntryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.GlossaryEntry glossary_entry = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $glossary_entry = null; + protected $glossary_entry = null; /** * @param \Google\Cloud\Translate\V3\GlossaryEntry $glossaryEntry Required. The glossary entry to update. diff --git a/Translate/src/V3/UpdateGlossaryMetadata.php b/Translate/src/V3/UpdateGlossaryMetadata.php index 2279886738ee..14698a198d91 100644 --- a/Translate/src/V3/UpdateGlossaryMetadata.php +++ b/Translate/src/V3/UpdateGlossaryMetadata.php @@ -22,20 +22,20 @@ class UpdateGlossaryMetadata extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.Glossary glossary = 1; */ - private $glossary = null; + protected $glossary = null; /** * The current state of the glossary update operation. If the glossary input * file was not updated this will be completed immediately * * Generated from protobuf field .google.cloud.translation.v3.UpdateGlossaryMetadata.State state = 2; */ - private $state = 0; + protected $state = 0; /** * The time when the operation was submitted to the server. * * Generated from protobuf field .google.protobuf.Timestamp submit_time = 3; */ - private $submit_time = null; + protected $submit_time = null; /** * Constructor. diff --git a/Translate/src/V3/UpdateGlossaryMetadata/State.php b/Translate/src/V3/UpdateGlossaryMetadata/State.php index af62f118b6c5..d36f1d20c35c 100644 --- a/Translate/src/V3/UpdateGlossaryMetadata/State.php +++ b/Translate/src/V3/UpdateGlossaryMetadata/State.php @@ -81,6 +81,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(State::class, \Google\Cloud\Translate\V3\UpdateGlossaryMetadata_State::class); diff --git a/Translate/src/V3/UpdateGlossaryRequest.php b/Translate/src/V3/UpdateGlossaryRequest.php index b16e184da1e8..d4ad17b260d3 100644 --- a/Translate/src/V3/UpdateGlossaryRequest.php +++ b/Translate/src/V3/UpdateGlossaryRequest.php @@ -20,14 +20,14 @@ class UpdateGlossaryRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.translation.v3.Glossary glossary = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $glossary = null; + protected $glossary = null; /** * The list of fields to be updated. Currently only `display_name` and * 'input_config' * * Generated from protobuf field .google.protobuf.FieldMask update_mask = 2; */ - private $update_mask = null; + protected $update_mask = null; /** * @param \Google\Cloud\Translate\V3\Glossary $glossary Required. The glossary entry to update. diff --git a/Translate/tests/Snippet/V2/TranslateClientTest.php b/Translate/tests/Snippet/V2/TranslateClientTest.php deleted file mode 100644 index fee05c79d9d7..000000000000 --- a/Translate/tests/Snippet/V2/TranslateClientTest.php +++ /dev/null @@ -1,199 +0,0 @@ -connection = $this->prophesize(ConnectionInterface::class); - $this->client = TestHelpers::stub(TranslateClient::class); - $this->client->___setProperty('connection', $this->connection->reveal()); - } - - public function testClass() - { - $snippet = $this->snippetFromClass(TranslateClient::class); - $res = $snippet->invoke('translate'); - - $this->assertInstanceOf(TranslateClient::class, $res->returnVal()); - } - - public function testTranslate() - { - $snippet = $this->snippetFromMethod(TranslateClient::class, 'translate'); - $snippet->addLocal('translate', $this->client); - - $this->connection->listTranslations(Argument::any()) - ->shouldBeCalled() - ->willReturn([ - 'data' => [ - 'translations' => [ - [ - 'detectedSourceLanguage' => 'en', - 'translatedText' => 'foobar', - ] - ] - ] - ]); - - $this->client->___setProperty('connection', $this->connection->reveal()); - - $res = $snippet->invoke(); - $this->assertEquals('foobar', $res->output()); - } - - public function testTranslateBatch() - { - $snippet = $this->snippetFromMethod(TranslateClient::class, 'translateBatch'); - $snippet->addLocal('translate', $this->client); - - $this->connection->listTranslations(Argument::any()) - ->shouldBeCalled() - ->willReturn([ - 'data' => [ - 'translations' => [ - [ - 'detectedSourceLanguage' => 'en', - 'translatedText' => 'foobar', - ] - ] - ] - ]); - - $this->client->___setProperty('connection', $this->connection->reveal()); - - $res = $snippet->invoke(); - $this->assertEquals('foobar', $res->output()); - } - - public function testDetectLanguage() - { - $snippet = $this->snippetFromMethod(TranslateClient::class, 'detectLanguage'); - $snippet->addLocal('translate', $this->client); - - $this->connection->listDetections(Argument::any()) - ->shouldBeCalled() - ->willReturn([ - 'data' => [ - 'detections' => [ - [ - [ - 'language' => 'en', - 'confidence' => 1 - ] - ] - ] - ] - ]); - - $this->client->___setProperty('connection', $this->connection->reveal()); - - $res = $snippet->invoke(); - $this->assertEquals('en', $res->output()); - } - - public function testDetectLanguageBatch() - { - $snippet = $this->snippetFromMethod(TranslateClient::class, 'detectLanguageBatch'); - $snippet->addLocal('translate', $this->client); - - $this->connection->listDetections(Argument::any()) - ->shouldBeCalled() - ->willReturn([ - 'data' => [ - 'detections' => [ - [ - [ - 'language' => 'en', - 'confidence' => 1 - ] - ] - ] - ] - ]); - - $this->client->___setProperty('connection', $this->connection->reveal()); - - $res = $snippet->invoke(); - $this->assertEquals('en', $res->output()); - } - - public function testLanguages() - { - $snippet = $this->snippetFromMethod(TranslateClient::class, 'languages'); - $snippet->addLocal('translate', $this->client); - - $this->connection->listLanguages(Argument::any()) - ->shouldbeCalled() - ->willReturn([ - 'data' => [ - 'languages' => [ - [ - 'language' => 'en', - 'name' => 'English' - ] - ] - ] - ]); - - $this->client->___setProperty('connection', $this->connection->reveal()); - - $res = $snippet->invoke(); - $this->assertEquals('en', $res->output()); - } - - public function testLocalizedLanguages() - { - $snippet = $this->snippetFromMethod(TranslateClient::class, 'localizedLanguages'); - $snippet->addLocal('translate', $this->client); - - $this->connection->listLanguages(Argument::any()) - ->shouldbeCalled() - ->willReturn([ - 'data' => [ - 'languages' => [ - [ - 'language' => 'en', - 'name' => 'English' - ] - ] - ] - ]); - - $this->client->___setProperty('connection', $this->connection->reveal()); - - $res = $snippet->invoke(); - $this->assertEquals('en', $res->output()); - } -} diff --git a/Translate/tests/System/V2/TranslateTest.php b/Translate/tests/System/V2/TranslateTest.php deleted file mode 100644 index 54530d6dc5ef..000000000000 --- a/Translate/tests/System/V2/TranslateTest.php +++ /dev/null @@ -1,207 +0,0 @@ -translate(self::INPUT_STRING); - $this->assertEquals(self::INPUT_LANGUAGE, $res['source']); - $this->assertEquals(self::INPUT_STRING, $res['input']); - $this->assertEquals(self::OUTPUT_STRING, $res['text']); - $this->assertNull($res['model']); - } - - public function testTranslateModelNmt() - { - $client = self::$client; - - $res = $client->translate(self::INPUT_STRING, ['model' => 'nmt']); - $this->assertEquals(self::INPUT_LANGUAGE, $res['source']); - $this->assertEquals(self::INPUT_STRING, $res['input']); - $this->assertEquals(self::OUTPUT_STRING, $res['text']); - $this->assertEquals('nmt', $res['model']); - } - - public function testTranslateModelBase() - { - $client = self::$client; - - $res = $client->translate(self::INPUT_STRING, ['model' => 'base']); - $this->assertEquals(self::INPUT_LANGUAGE, $res['source']); - $this->assertEquals(self::INPUT_STRING, $res['input']); - $this->assertEquals(self::OUTPUT_STRING, $res['text']); - $this->assertEquals('nmt', $res['model']); - } - - public function testTranslateInvalidModel() - { - $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); - - self::$client->translate(self::INPUT_STRING, ['model' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); - } - - public function testTranslateInvalidTarget() - { - $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); - - self::$client->translate(self::INPUT_STRING, ['target' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); - } - - public function testTranslateInvalidSource() - { - $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); - - self::$client->translate(self::INPUT_STRING, ['source' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); - } - - public function testTranslateBatch() - { - $client = self::$client; - - $res = $client->translateBatch([self::INPUT_STRING]); - $this->assertEquals(self::INPUT_LANGUAGE, $res[0]['source']); - $this->assertEquals(self::INPUT_STRING, $res[0]['input']); - $this->assertEquals(self::OUTPUT_STRING, $res[0]['text']); - $this->assertNull($res[0]['model']); - } - - public function testTranslateBatchModelNmt() - { - $client = self::$client; - - $res = $client->translateBatch([self::INPUT_STRING], ['model' => 'base']); - $this->assertEquals(self::INPUT_LANGUAGE, $res[0]['source']); - $this->assertEquals(self::INPUT_STRING, $res[0]['input']); - $this->assertEquals(self::OUTPUT_STRING, $res[0]['text']); - $this->assertEquals('nmt', $res[0]['model']); - } - - public function testTranslateBatchModelBase() - { - $client = self::$client; - - $res = $client->translateBatch([self::INPUT_STRING], ['model' => 'base']); - $this->assertEquals(self::INPUT_LANGUAGE, $res[0]['source']); - $this->assertEquals(self::INPUT_STRING, $res[0]['input']); - $this->assertEquals(self::OUTPUT_STRING, $res[0]['text']); - $this->assertEquals('nmt', $res[0]['model']); - } - - public function testTranslateBatchInvalidModel() - { - $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); - - self::$client->translateBatch([self::INPUT_STRING], ['model' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); - } - - public function testTranslateBatchInvalidTarget() - { - $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); - - self::$client->translateBatch([self::INPUT_STRING], ['target' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); - } - - public function testTranslateBatchInvalidSource() - { - $this->expectException('Google\Cloud\Core\Exception\BadRequestException'); - - self::$client->translateBatch([self::INPUT_STRING], ['source' => 'thisDoesntActuallyExistSoGimmeErrorPlease']); - } - - public function testDetectLanguage() - { - $client = self::$client; - - $res = $client->detectLanguage(self::INPUT_STRING); - $this->assertEquals(self::INPUT_LANGUAGE, $res['languageCode']); - $this->assertEquals(self::INPUT_STRING, $res['input']); - $this->assertThat( - $res['confidence'], - $this->logicalOr( - $this->isType('int'), - $this->isType('double') - ) - ); - } - - public function testDetectLanguageUndefined() - { - $client = self::$client; - - $res = $client->detectLanguage(''); - $this->assertEquals('und', $res['languageCode']); - $this->assertEquals(0, $res['confidence']); - } - - public function testDetectLanguageBatch() - { - $client = self::$client; - - $res = $client->detectLanguageBatch([self::INPUT_STRING]); - $this->assertEquals(self::INPUT_LANGUAGE, $res[0]['languageCode']); - $this->assertEquals(self::INPUT_STRING, $res[0]['input']); - $this->assertThat( - $res[0]['confidence'], - $this->logicalOr( - $this->isType('int'), - $this->isType('double') - ) - ); - } - - public function testDetectLanguageBatchUndefined() - { - $client = self::$client; - - $res = $client->detectLanguageBatch(['']); - $this->assertEquals('und', $res[0]['languageCode']); - $this->assertEquals(0, $res[0]['confidence']); - } - - public function testDetectLanguages() - { - $client = self::$client; - - $res = $client->languages(); - $this->assertIsArray($res); - $this->assertContains('en', $res); - $this->assertContains('es', $res); - } - - public function testLocalizedLanguages() - { - $client = self::$client; - - $res = $client->localizedLanguages(); - $this->assertIsArray($res); - $this->assertContains(['code' => 'es', 'name' => 'Spanish'], $res); - $this->assertContains(['code' => 'en', 'name' => 'English'], $res); - } -} diff --git a/Translate/tests/System/V2/TranslateTestCase.php b/Translate/tests/System/V2/TranslateTestCase.php deleted file mode 100644 index 5425c639c9eb..000000000000 --- a/Translate/tests/System/V2/TranslateTestCase.php +++ /dev/null @@ -1,43 +0,0 @@ - $keyFilePath - ]); - } -} diff --git a/Translate/tests/System/V3/TranslationServiceSmokeTest.php b/Translate/tests/System/V3/TranslationServiceSmokeTest.php deleted file mode 100644 index 6ec130e1e3cb..000000000000 --- a/Translate/tests/System/V3/TranslationServiceSmokeTest.php +++ /dev/null @@ -1,55 +0,0 @@ -fail('Environment variable PROJECT_ID must be set for smoke test'); - } - $client = new TranslationServiceClient(); - $res = $client->translateText( - ['one'], - 'es', - $client->locationName($projectId, 'global') - ); - - $this->assertEquals( - 'uno', - $res->getTranslations()[0]->getTranslatedText() - ); - } -} diff --git a/Translate/tests/System/bootstrap.php b/Translate/tests/System/bootstrap.php deleted file mode 100644 index ef978fd2a310..000000000000 --- a/Translate/tests/System/bootstrap.php +++ /dev/null @@ -1,6 +0,0 @@ -requestWrapper = $this->prophesize(RequestWrapper::class); - $this->successBody = '{"canI":"kickIt"}'; - } - - public function testApiEndpoint() - { - $endpoint = 'https://foobar.com/'; - $rest = TestHelpers::stub(Rest::class, [ - [ - 'apiEndpoint' => $endpoint - ] - ], ['requestBuilder']); - - $rb = $rest->___getProperty('requestBuilder'); - $r = new \ReflectionObject($rb); - $p = $r->getProperty('baseUri'); - $p->setAccessible(true); - - $this->assertEquals($endpoint . 'language/translate/', $p->getValue($rb)); - } - - /** - * @dataProvider methodProvider - * @todo revisit this approach - */ - public function testCallBasicMethods($method) - { - $options = []; - $request = new Request('GET', '/somewhere'); - $response = new Response(200, [], $this->successBody); - - $requestBuilder = $this->prophesize(RequestBuilder::class); - $requestBuilder->build( - Argument::type('string'), - Argument::type('string'), - Argument::type('array') - )->willReturn($request); - - $this->requestWrapper->send( - Argument::type(RequestInterface::class), - Argument::type('array') - )->willReturn($response); - - $rest = new Rest(); - $rest->setRequestBuilder($requestBuilder->reveal()); - $rest->setRequestWrapper($this->requestWrapper->reveal()); - - $this->assertEquals(json_decode($this->successBody, true), $rest->$method($options)); - } - - public function methodProvider() - { - return [ - ['listDetections'], - ['listTranslations'], - ['listLanguages'] - ]; - } -} diff --git a/Translate/tests/Unit/V2/TranslateClientTest.php b/Translate/tests/Unit/V2/TranslateClientTest.php deleted file mode 100644 index 60180acd93bc..000000000000 --- a/Translate/tests/Unit/V2/TranslateClientTest.php +++ /dev/null @@ -1,340 +0,0 @@ -client = TestHelpers::stub(TranslateClient::class, [ - ['key' => $this->key] - ]); - $this->connection = $this->prophesize(ConnectionInterface::class); - } - - public function testWithNoKey() - { - $client = TestHelpers::stub(TranslateClient::class); - - $this->connection->listTranslations(Argument::that(function ($args) { - return !isset($args['key']); - }))->shouldBeCalled()->willReturn([]); - - $client->___setProperty('connection', $this->connection->reveal()); - - $client->translate('foo'); - } - - public function testTranslateModel() - { - $this->connection->listTranslations(Argument::that(function ($args) { - if (isset($args['model'])) { - return false; - } - return true; - }))->shouldBeCalled(); - - $this->client->___setProperty('connection', $this->connection->reveal()); - - $this->client->translate('foo bar'); - - $this->connection->listTranslations(Argument::withEntry('model', 'base')) - ->shouldBeCalled(); - - $this->client->___setProperty('connection', $this->connection->reveal()); - $this->client->translate('foo bar', ['model' => 'base']); - } - - public function testTranslate() - { - $expected = $this->getTranslateExpectedData('translate', 'translated', 'en'); - $options = [ - 'source' => $expected['source'], - 'target' => 'de', - 'format' => 'text', - 'model' => 'base' - ]; - $this->connection->listTranslations($options + [ - 'q' => [$expected['input']], - 'key' => $this->key - ])->willReturn([ - 'data' => [ - 'translations' => [ - $this->getTranslateApiData($expected['text']) - ] - ] - ])->shouldBeCalledTimes(1); - - $this->client->___setProperty('connection', $this->connection->reveal()); - $translation = $this->client->translate($expected['input'], $options); - - $this->assertEquals($expected, $translation); - } - - public function testTranslateWithNmtModel() - { - $expected = $this->getTranslateExpectedData('translate', 'translated', 'en', 'nmt'); - - $options = [ - 'source' => $expected['source'], - 'target' => 'de', - 'format' => 'text', - 'model' => 'nmt' - ]; - $this->connection - ->listTranslations($options + [ - 'q' => [$expected['input']], - 'key' => $this->key - ]) - ->willReturn([ - 'data' => [ - 'translations' => [ - $this->getTranslateApiData($expected['text'], null, 'nmt') - ] - ] - ]) - ->shouldBeCalledTimes(1); - $this->client->___setProperty('connection', $this->connection->reveal()); - $translation = $this->client->translate($expected['input'], $options); - - $this->assertEquals($expected, $translation); - } - - public function testTranslateBatch() - { - $expected1 = $this->getTranslateExpectedData('translate', 'translated', 'en'); - $expected2 = $this->getTranslateExpectedData('translate2', 'translated2', 'en'); - $stringsToTranslate = [$expected1['input'], $expected2['input']]; - $target = 'de'; - $this->connection - ->listTranslations([ - 'target' => $target, - 'q' => $stringsToTranslate, - 'key' => $this->key, - 'model' => 'base' - ]) - ->willReturn([ - 'data' => [ - 'translations' => [ - $this->getTranslateApiData($expected1['text'], $expected1['source']), - $this->getTranslateApiData($expected2['text'], $expected2['source']) - ] - ] - ]) - ->shouldBeCalledTimes(1); - $client = TestHelpers::stub(TranslateClient::class, [ - ['key' => $this->key, 'target' => $target] - ]); - $client->___setProperty('connection', $this->connection->reveal()); - $translations = $client->translateBatch($stringsToTranslate, ['model' => 'base']); - - $this->assertEquals($expected1, $translations[0]); - $this->assertEquals($expected2, $translations[1]); - } - - public function testTranslateBatchWithNotZeroIndexedInput() - { - $expected1 = $this->getTranslateExpectedData('translate', 'translated', 'en'); - $expected2 = $this->getTranslateExpectedData('translate2', 'translated2', 'en'); - $stringsToTranslate = [1 => $expected1['input'], 2 => $expected2['input']]; - - $target = 'de'; - $this->connection->listTranslations([ - 'target' => $target, - 'q' => $stringsToTranslate, - 'key' => $this->key, - 'model' => 'base' - ])->willReturn([ - 'data' => [ - 'translations' => [ - $this->getTranslateApiData($expected1['text'], $expected1['source']), - $this->getTranslateApiData($expected2['text'], $expected2['source']) - ] - ] - ])->shouldBeCalledTimes(1); - - $client = TestHelpers::stub(TranslateClient::class, [ - ['key' => $this->key, 'target' => $target] - ]); - $client->___setProperty('connection', $this->connection->reveal()); - $translations = $client->translateBatch($stringsToTranslate, ['model' => 'base']); - - $this->assertEquals($expected1, $translations[0]); - $this->assertEquals($expected2, $translations[1]); - } - - public function testDetectLanguage() - { - $expected = $this->getDetectionExpectedData('text', 'en', .5); - $options = ['format' => 'text']; - $this->connection - ->listDetections($options + [ - 'q' => [$expected['input']], - 'key' => $this->key - ]) - ->willReturn([ - 'data' => [ - 'detections' => [ - $this->getDetectionApiData($expected['languageCode'], $expected['confidence']) - ] - ] - ]) - ->shouldBeCalledTimes(1); - $this->client->___setProperty('connection', $this->connection->reveal()); - $detection = $this->client->detectLanguage($expected['input'], $options); - - $this->assertEquals($expected, $detection); - } - - public function testDetectLanguageBatch() - { - $expected1 = $this->getDetectionExpectedData('text', 'en', .5); - $expected2 = $this->getDetectionExpectedData('text2', 'en', .7); - $stringsToDetect = [$expected1['input'], $expected2['input']]; - $this->connection - ->listDetections([ - 'q' => $stringsToDetect, - 'key' => $this->key - ]) - ->willReturn([ - 'data' => [ - 'detections' => [ - $this->getDetectionApiData($expected1['languageCode'], $expected1['confidence']), - $this->getDetectionApiData($expected2['languageCode'], $expected2['confidence']) - ] - ] - ]) - ->shouldBeCalledTimes(1); - $this->client->___setProperty('connection', $this->connection->reveal()); - $detections = $this->client->detectLanguageBatch($stringsToDetect); - - $this->assertEquals($expected1, $detections[0]); - $this->assertEquals($expected2, $detections[1]); - } - - public function testLocalizedLanguages() - { - $expected = [ - 'code' => 'es', - 'name' => 'Spanish' - ]; - $target = 'fr'; - $this->connection - ->listLanguages([ - 'target' => $target, - 'key' => $this->key - ]) - ->willReturn([ - 'data' => [ - 'languages' => [ - $this->getLanguageApiData($expected['code'], $expected['name']) - ] - ] - ]) - ->shouldBeCalledTimes(1); - $this->client->___setProperty('connection', $this->connection->reveal()); - $languages = $this->client->localizedLanguages(['target' => $target]); - - $this->assertEquals($expected, $languages[0]); - } - - public function testLanguages() - { - $expectedLanguage = 'es'; - $this->connection - ->listLanguages([ - 'target' => null, - 'key' => $this->key - ]) - ->willReturn([ - 'data' => [ - 'languages' => [ - $this->getLanguageApiData($expectedLanguage) - ] - ] - ]) - ->shouldBeCalledTimes(1); - $this->client->___setProperty('connection', $this->connection->reveal()); - $languages = $this->client->languages(); - - $this->assertEquals($expectedLanguage, $languages[0]); - } - - private function getTranslateApiData($translatedText, $source = null, $model = 'base') - { - return array_filter([ - 'translatedText' => $translatedText, - 'detectedSourceLanguage' => $source, - 'model' => $model - ]); - } - - private function getTranslateExpectedData($textToTranslate, $translatedText, $source, $model = 'base') - { - return [ - 'text' => $translatedText, - 'source' => $source, - 'input' => $textToTranslate, - 'model' => $model - ]; - } - - private function getDetectionApiData($language, $confidence) - { - return array_filter([ - [ - 'language' => $language, - 'isReliable' => false, - 'confidence' => $confidence - ] - ]); - } - - private function getDetectionExpectedData($textToDetect, $detectedLanguage, $confidence = null) - { - return array_filter([ - 'input' => $textToDetect, - 'languageCode' => $detectedLanguage, - 'confidence' => $confidence - ]); - } - - private function getLanguageApiData($languageCode, $name = null) - { - return array_filter([ - 'language' => $languageCode, - 'name' => $name - ]); - } -} diff --git a/Translate/tests/Unit/V3/Client/TranslationServiceClientTest.php b/Translate/tests/Unit/V3/Client/TranslationServiceClientTest.php index 516d0054523e..68412c6777fb 100644 --- a/Translate/tests/Unit/V3/Client/TranslationServiceClientTest.php +++ b/Translate/tests/Unit/V3/Client/TranslationServiceClientTest.php @@ -1,6 +1,6 @@ getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + return $this->getMockBuilder(CredentialsWrapper::class) + ->disableOriginalConstructor() + ->getMock(); } /** @return TranslationServiceClient */ @@ -180,12 +182,15 @@ public function adaptiveMtTranslateExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); @@ -328,12 +333,15 @@ public function batchTranslateDocumentExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); @@ -479,12 +487,15 @@ public function batchTranslateTextExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); @@ -574,12 +585,15 @@ public function createAdaptiveMtDatasetExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); @@ -650,9 +664,7 @@ public function createDatasetTest() // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); $dataset = new Dataset(); - $request = (new CreateDatasetRequest()) - ->setParent($formattedParent) - ->setDataset($dataset); + $request = (new CreateDatasetRequest())->setParent($formattedParent)->setDataset($dataset); $response = $gapicClient->createDataset($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -710,19 +722,20 @@ public function createDatasetExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); $dataset = new Dataset(); - $request = (new CreateDatasetRequest()) - ->setParent($formattedParent) - ->setDataset($dataset); + $request = (new CreateDatasetRequest())->setParent($formattedParent)->setDataset($dataset); $response = $gapicClient->createDataset($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -785,9 +798,7 @@ public function createGlossaryTest() $glossary = new Glossary(); $glossaryName = 'glossaryName-297469495'; $glossary->setName($glossaryName); - $request = (new CreateGlossaryRequest()) - ->setParent($formattedParent) - ->setGlossary($glossary); + $request = (new CreateGlossaryRequest())->setParent($formattedParent)->setGlossary($glossary); $response = $gapicClient->createGlossary($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -845,21 +856,22 @@ public function createGlossaryExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); $glossary = new Glossary(); $glossaryName = 'glossaryName-297469495'; $glossary->setName($glossaryName); - $request = (new CreateGlossaryRequest()) - ->setParent($formattedParent) - ->setGlossary($glossary); + $request = (new CreateGlossaryRequest())->setParent($formattedParent)->setGlossary($glossary); $response = $gapicClient->createGlossary($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -900,9 +912,7 @@ public function createGlossaryEntryTest() // Mock request $formattedParent = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); $glossaryEntry = new GlossaryEntry(); - $request = (new CreateGlossaryEntryRequest()) - ->setParent($formattedParent) - ->setGlossaryEntry($glossaryEntry); + $request = (new CreateGlossaryEntryRequest())->setParent($formattedParent)->setGlossaryEntry($glossaryEntry); $response = $gapicClient->createGlossaryEntry($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -928,19 +938,20 @@ public function createGlossaryEntryExceptionTest() $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->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); $glossaryEntry = new GlossaryEntry(); - $request = (new CreateGlossaryEntryRequest()) - ->setParent($formattedParent) - ->setGlossaryEntry($glossaryEntry); + $request = (new CreateGlossaryEntryRequest())->setParent($formattedParent)->setGlossaryEntry($glossaryEntry); try { $gapicClient->createGlossaryEntry($request); // If the $gapicClient method call did not throw, fail the test @@ -1002,9 +1013,7 @@ public function createModelTest() // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); $model = new Model(); - $request = (new CreateModelRequest()) - ->setParent($formattedParent) - ->setModel($model); + $request = (new CreateModelRequest())->setParent($formattedParent)->setModel($model); $response = $gapicClient->createModel($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1062,19 +1071,20 @@ public function createModelExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); $model = new Model(); - $request = (new CreateModelRequest()) - ->setParent($formattedParent) - ->setModel($model); + $request = (new CreateModelRequest())->setParent($formattedParent)->setModel($model); $response = $gapicClient->createModel($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1110,8 +1120,7 @@ public function deleteAdaptiveMtDatasetTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new DeleteAdaptiveMtDatasetRequest()) - ->setName($formattedName); + $request = (new DeleteAdaptiveMtDatasetRequest())->setName($formattedName); $gapicClient->deleteAdaptiveMtDataset($request); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); @@ -1134,17 +1143,19 @@ public function deleteAdaptiveMtDatasetExceptionTest() $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->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new DeleteAdaptiveMtDatasetRequest()) - ->setName($formattedName); + $request = (new DeleteAdaptiveMtDatasetRequest())->setName($formattedName); try { $gapicClient->deleteAdaptiveMtDataset($request); // If the $gapicClient method call did not throw, fail the test @@ -1171,8 +1182,7 @@ public function deleteAdaptiveMtFileTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $request = (new DeleteAdaptiveMtFileRequest()) - ->setName($formattedName); + $request = (new DeleteAdaptiveMtFileRequest())->setName($formattedName); $gapicClient->deleteAdaptiveMtFile($request); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); @@ -1195,17 +1205,19 @@ public function deleteAdaptiveMtFileExceptionTest() $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->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $request = (new DeleteAdaptiveMtFileRequest()) - ->setName($formattedName); + $request = (new DeleteAdaptiveMtFileRequest())->setName($formattedName); try { $gapicClient->deleteAdaptiveMtFile($request); // If the $gapicClient method call did not throw, fail the test @@ -1250,8 +1262,7 @@ public function deleteDatasetTest() $operationsTransport->addResponse($completeOperation); // Mock request $formattedName = $gapicClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new DeleteDatasetRequest()) - ->setName($formattedName); + $request = (new DeleteDatasetRequest())->setName($formattedName); $response = $gapicClient->deleteDataset($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1307,17 +1318,19 @@ public function deleteDatasetExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $formattedName = $gapicClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new DeleteDatasetRequest()) - ->setName($formattedName); + $request = (new DeleteDatasetRequest())->setName($formattedName); $response = $gapicClient->deleteDataset($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1373,8 +1386,7 @@ public function deleteGlossaryTest() $operationsTransport->addResponse($completeOperation); // Mock request $formattedName = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $request = (new DeleteGlossaryRequest()) - ->setName($formattedName); + $request = (new DeleteGlossaryRequest())->setName($formattedName); $response = $gapicClient->deleteGlossary($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1430,17 +1442,19 @@ public function deleteGlossaryExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $formattedName = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $request = (new DeleteGlossaryRequest()) - ->setName($formattedName); + $request = (new DeleteGlossaryRequest())->setName($formattedName); $response = $gapicClient->deleteGlossary($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1476,8 +1490,7 @@ public function deleteGlossaryEntryTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - $request = (new DeleteGlossaryEntryRequest()) - ->setName($formattedName); + $request = (new DeleteGlossaryEntryRequest())->setName($formattedName); $gapicClient->deleteGlossaryEntry($request); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); @@ -1500,17 +1513,19 @@ public function deleteGlossaryEntryExceptionTest() $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->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - $request = (new DeleteGlossaryEntryRequest()) - ->setName($formattedName); + $request = (new DeleteGlossaryEntryRequest())->setName($formattedName); try { $gapicClient->deleteGlossaryEntry($request); // If the $gapicClient method call did not throw, fail the test @@ -1555,8 +1570,7 @@ public function deleteModelTest() $operationsTransport->addResponse($completeOperation); // Mock request $formattedName = $gapicClient->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - $request = (new DeleteModelRequest()) - ->setName($formattedName); + $request = (new DeleteModelRequest())->setName($formattedName); $response = $gapicClient->deleteModel($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1612,17 +1626,19 @@ public function deleteModelExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $formattedName = $gapicClient->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - $request = (new DeleteModelRequest()) - ->setName($formattedName); + $request = (new DeleteModelRequest())->setName($formattedName); $response = $gapicClient->deleteModel($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1658,8 +1674,7 @@ public function detectLanguageTest() $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $request = (new DetectLanguageRequest()) - ->setParent($formattedParent); + $request = (new DetectLanguageRequest())->setParent($formattedParent); $response = $gapicClient->detectLanguage($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -1683,17 +1698,19 @@ public function detectLanguageExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); - $request = (new DetectLanguageRequest()) - ->setParent($formattedParent); + $request = (new DetectLanguageRequest())->setParent($formattedParent); try { $gapicClient->detectLanguage($request); // If the $gapicClient method call did not throw, fail the test @@ -1739,9 +1756,7 @@ public function exportDataTest() // Mock request $dataset = 'dataset1443214456'; $outputConfig = new DatasetOutputConfig(); - $request = (new ExportDataRequest()) - ->setDataset($dataset) - ->setOutputConfig($outputConfig); + $request = (new ExportDataRequest())->setDataset($dataset)->setOutputConfig($outputConfig); $response = $gapicClient->exportData($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1799,19 +1814,20 @@ public function exportDataExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $dataset = 'dataset1443214456'; $outputConfig = new DatasetOutputConfig(); - $request = (new ExportDataRequest()) - ->setDataset($dataset) - ->setOutputConfig($outputConfig); + $request = (new ExportDataRequest())->setDataset($dataset)->setOutputConfig($outputConfig); $response = $gapicClient->exportData($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -1857,8 +1873,7 @@ public function getAdaptiveMtDatasetTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new GetAdaptiveMtDatasetRequest()) - ->setName($formattedName); + $request = (new GetAdaptiveMtDatasetRequest())->setName($formattedName); $response = $gapicClient->getAdaptiveMtDataset($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -1882,17 +1897,19 @@ public function getAdaptiveMtDatasetExceptionTest() $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->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new GetAdaptiveMtDatasetRequest()) - ->setName($formattedName); + $request = (new GetAdaptiveMtDatasetRequest())->setName($formattedName); try { $gapicClient->getAdaptiveMtDataset($request); // If the $gapicClient method call did not throw, fail the test @@ -1925,8 +1942,7 @@ public function getAdaptiveMtFileTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $request = (new GetAdaptiveMtFileRequest()) - ->setName($formattedName); + $request = (new GetAdaptiveMtFileRequest())->setName($formattedName); $response = $gapicClient->getAdaptiveMtFile($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -1950,17 +1966,19 @@ public function getAdaptiveMtFileExceptionTest() $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->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $request = (new GetAdaptiveMtFileRequest()) - ->setName($formattedName); + $request = (new GetAdaptiveMtFileRequest())->setName($formattedName); try { $gapicClient->getAdaptiveMtFile($request); // If the $gapicClient method call did not throw, fail the test @@ -2003,8 +2021,7 @@ public function getDatasetTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new GetDatasetRequest()) - ->setName($formattedName); + $request = (new GetDatasetRequest())->setName($formattedName); $response = $gapicClient->getDataset($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -2028,17 +2045,19 @@ public function getDatasetExceptionTest() $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->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new GetDatasetRequest()) - ->setName($formattedName); + $request = (new GetDatasetRequest())->setName($formattedName); try { $gapicClient->getDataset($request); // If the $gapicClient method call did not throw, fail the test @@ -2071,8 +2090,7 @@ public function getGlossaryTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $request = (new GetGlossaryRequest()) - ->setName($formattedName); + $request = (new GetGlossaryRequest())->setName($formattedName); $response = $gapicClient->getGlossary($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -2096,17 +2114,19 @@ public function getGlossaryExceptionTest() $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->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $request = (new GetGlossaryRequest()) - ->setName($formattedName); + $request = (new GetGlossaryRequest())->setName($formattedName); try { $gapicClient->getGlossary($request); // If the $gapicClient method call did not throw, fail the test @@ -2137,8 +2157,7 @@ public function getGlossaryEntryTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - $request = (new GetGlossaryEntryRequest()) - ->setName($formattedName); + $request = (new GetGlossaryEntryRequest())->setName($formattedName); $response = $gapicClient->getGlossaryEntry($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -2162,17 +2181,19 @@ public function getGlossaryEntryExceptionTest() $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->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - $request = (new GetGlossaryEntryRequest()) - ->setName($formattedName); + $request = (new GetGlossaryEntryRequest())->setName($formattedName); try { $gapicClient->getGlossaryEntry($request); // If the $gapicClient method call did not throw, fail the test @@ -2215,8 +2236,7 @@ public function getModelTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - $request = (new GetModelRequest()) - ->setName($formattedName); + $request = (new GetModelRequest())->setName($formattedName); $response = $gapicClient->getModel($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -2240,17 +2260,19 @@ public function getModelExceptionTest() $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->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - $request = (new GetModelRequest()) - ->setName($formattedName); + $request = (new GetModelRequest())->setName($formattedName); try { $gapicClient->getModel($request); // If the $gapicClient method call did not throw, fail the test @@ -2277,8 +2299,7 @@ public function getSupportedLanguagesTest() $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $request = (new GetSupportedLanguagesRequest()) - ->setParent($formattedParent); + $request = (new GetSupportedLanguagesRequest())->setParent($formattedParent); $response = $gapicClient->getSupportedLanguages($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -2302,17 +2323,19 @@ public function getSupportedLanguagesExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); - $request = (new GetSupportedLanguagesRequest()) - ->setParent($formattedParent); + $request = (new GetSupportedLanguagesRequest())->setParent($formattedParent); try { $gapicClient->getSupportedLanguages($request); // If the $gapicClient method call did not throw, fail the test @@ -2339,8 +2362,7 @@ public function importAdaptiveMtFileTest() $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new ImportAdaptiveMtFileRequest()) - ->setParent($formattedParent); + $request = (new ImportAdaptiveMtFileRequest())->setParent($formattedParent); $response = $gapicClient->importAdaptiveMtFile($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -2364,17 +2386,19 @@ public function importAdaptiveMtFileExceptionTest() $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->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new ImportAdaptiveMtFileRequest()) - ->setParent($formattedParent); + $request = (new ImportAdaptiveMtFileRequest())->setParent($formattedParent); try { $gapicClient->importAdaptiveMtFile($request); // If the $gapicClient method call did not throw, fail the test @@ -2420,9 +2444,7 @@ public function importDataTest() // Mock request $dataset = 'dataset1443214456'; $inputConfig = new DatasetInputConfig(); - $request = (new ImportDataRequest()) - ->setDataset($dataset) - ->setInputConfig($inputConfig); + $request = (new ImportDataRequest())->setDataset($dataset)->setInputConfig($inputConfig); $response = $gapicClient->importData($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -2480,19 +2502,20 @@ public function importDataExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $dataset = 'dataset1443214456'; $inputConfig = new DatasetInputConfig(); - $request = (new ImportDataRequest()) - ->setDataset($dataset) - ->setInputConfig($inputConfig); + $request = (new ImportDataRequest())->setDataset($dataset)->setInputConfig($inputConfig); $response = $gapicClient->importData($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -2526,17 +2549,14 @@ public function listAdaptiveMtDatasetsTest() // Mock response $nextPageToken = ''; $adaptiveMtDatasetsElement = new AdaptiveMtDataset(); - $adaptiveMtDatasets = [ - $adaptiveMtDatasetsElement, - ]; + $adaptiveMtDatasets = [$adaptiveMtDatasetsElement]; $expectedResponse = new ListAdaptiveMtDatasetsResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setAdaptiveMtDatasets($adaptiveMtDatasets); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $request = (new ListAdaptiveMtDatasetsRequest()) - ->setParent($formattedParent); + $request = (new ListAdaptiveMtDatasetsRequest())->setParent($formattedParent); $response = $gapicClient->listAdaptiveMtDatasets($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -2563,17 +2583,19 @@ public function listAdaptiveMtDatasetsExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); - $request = (new ListAdaptiveMtDatasetsRequest()) - ->setParent($formattedParent); + $request = (new ListAdaptiveMtDatasetsRequest())->setParent($formattedParent); try { $gapicClient->listAdaptiveMtDatasets($request); // If the $gapicClient method call did not throw, fail the test @@ -2598,17 +2620,14 @@ public function listAdaptiveMtFilesTest() // Mock response $nextPageToken = ''; $adaptiveMtFilesElement = new AdaptiveMtFile(); - $adaptiveMtFiles = [ - $adaptiveMtFilesElement, - ]; + $adaptiveMtFiles = [$adaptiveMtFilesElement]; $expectedResponse = new ListAdaptiveMtFilesResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setAdaptiveMtFiles($adaptiveMtFiles); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new ListAdaptiveMtFilesRequest()) - ->setParent($formattedParent); + $request = (new ListAdaptiveMtFilesRequest())->setParent($formattedParent); $response = $gapicClient->listAdaptiveMtFiles($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -2635,17 +2654,19 @@ public function listAdaptiveMtFilesExceptionTest() $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->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new ListAdaptiveMtFilesRequest()) - ->setParent($formattedParent); + $request = (new ListAdaptiveMtFilesRequest())->setParent($formattedParent); try { $gapicClient->listAdaptiveMtFiles($request); // If the $gapicClient method call did not throw, fail the test @@ -2670,17 +2691,14 @@ public function listAdaptiveMtSentencesTest() // Mock response $nextPageToken = ''; $adaptiveMtSentencesElement = new AdaptiveMtSentence(); - $adaptiveMtSentences = [ - $adaptiveMtSentencesElement, - ]; + $adaptiveMtSentences = [$adaptiveMtSentencesElement]; $expectedResponse = new ListAdaptiveMtSentencesResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setAdaptiveMtSentences($adaptiveMtSentences); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $request = (new ListAdaptiveMtSentencesRequest()) - ->setParent($formattedParent); + $request = (new ListAdaptiveMtSentencesRequest())->setParent($formattedParent); $response = $gapicClient->listAdaptiveMtSentences($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -2707,17 +2725,19 @@ public function listAdaptiveMtSentencesExceptionTest() $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->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $request = (new ListAdaptiveMtSentencesRequest()) - ->setParent($formattedParent); + $request = (new ListAdaptiveMtSentencesRequest())->setParent($formattedParent); try { $gapicClient->listAdaptiveMtSentences($request); // If the $gapicClient method call did not throw, fail the test @@ -2742,17 +2762,14 @@ public function listDatasetsTest() // Mock response $nextPageToken = ''; $datasetsElement = new Dataset(); - $datasets = [ - $datasetsElement, - ]; + $datasets = [$datasetsElement]; $expectedResponse = new ListDatasetsResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setDatasets($datasets); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $request = (new ListDatasetsRequest()) - ->setParent($formattedParent); + $request = (new ListDatasetsRequest())->setParent($formattedParent); $response = $gapicClient->listDatasets($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -2779,17 +2796,19 @@ public function listDatasetsExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); - $request = (new ListDatasetsRequest()) - ->setParent($formattedParent); + $request = (new ListDatasetsRequest())->setParent($formattedParent); try { $gapicClient->listDatasets($request); // If the $gapicClient method call did not throw, fail the test @@ -2814,17 +2833,14 @@ public function listExamplesTest() // Mock response $nextPageToken = ''; $examplesElement = new Example(); - $examples = [ - $examplesElement, - ]; + $examples = [$examplesElement]; $expectedResponse = new ListExamplesResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setExamples($examples); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new ListExamplesRequest()) - ->setParent($formattedParent); + $request = (new ListExamplesRequest())->setParent($formattedParent); $response = $gapicClient->listExamples($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -2851,17 +2867,19 @@ public function listExamplesExceptionTest() $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->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $request = (new ListExamplesRequest()) - ->setParent($formattedParent); + $request = (new ListExamplesRequest())->setParent($formattedParent); try { $gapicClient->listExamples($request); // If the $gapicClient method call did not throw, fail the test @@ -2886,17 +2904,14 @@ public function listGlossariesTest() // Mock response $nextPageToken = ''; $glossariesElement = new Glossary(); - $glossaries = [ - $glossariesElement, - ]; + $glossaries = [$glossariesElement]; $expectedResponse = new ListGlossariesResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setGlossaries($glossaries); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $request = (new ListGlossariesRequest()) - ->setParent($formattedParent); + $request = (new ListGlossariesRequest())->setParent($formattedParent); $response = $gapicClient->listGlossaries($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -2923,17 +2938,19 @@ public function listGlossariesExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); - $request = (new ListGlossariesRequest()) - ->setParent($formattedParent); + $request = (new ListGlossariesRequest())->setParent($formattedParent); try { $gapicClient->listGlossaries($request); // If the $gapicClient method call did not throw, fail the test @@ -2958,17 +2975,14 @@ public function listGlossaryEntriesTest() // Mock response $nextPageToken = ''; $glossaryEntriesElement = new GlossaryEntry(); - $glossaryEntries = [ - $glossaryEntriesElement, - ]; + $glossaryEntries = [$glossaryEntriesElement]; $expectedResponse = new ListGlossaryEntriesResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setGlossaryEntries($glossaryEntries); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $request = (new ListGlossaryEntriesRequest()) - ->setParent($formattedParent); + $request = (new ListGlossaryEntriesRequest())->setParent($formattedParent); $response = $gapicClient->listGlossaryEntries($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -2995,17 +3009,19 @@ public function listGlossaryEntriesExceptionTest() $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->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $request = (new ListGlossaryEntriesRequest()) - ->setParent($formattedParent); + $request = (new ListGlossaryEntriesRequest())->setParent($formattedParent); try { $gapicClient->listGlossaryEntries($request); // If the $gapicClient method call did not throw, fail the test @@ -3030,17 +3046,14 @@ public function listModelsTest() // Mock response $nextPageToken = ''; $modelsElement = new Model(); - $models = [ - $modelsElement, - ]; + $models = [$modelsElement]; $expectedResponse = new ListModelsResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setModels($models); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $request = (new ListModelsRequest()) - ->setParent($formattedParent); + $request = (new ListModelsRequest())->setParent($formattedParent); $response = $gapicClient->listModels($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -3067,17 +3080,19 @@ public function listModelsExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); - $request = (new ListModelsRequest()) - ->setParent($formattedParent); + $request = (new ListModelsRequest())->setParent($formattedParent); try { $gapicClient->listModels($request); // If the $gapicClient method call did not throw, fail the test @@ -3105,9 +3120,7 @@ public function romanizeTextTest() // Mock request $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); $contents = []; - $request = (new RomanizeTextRequest()) - ->setParent($formattedParent) - ->setContents($contents); + $request = (new RomanizeTextRequest())->setParent($formattedParent)->setContents($contents); $response = $gapicClient->romanizeText($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -3133,19 +3146,20 @@ public function romanizeTextExceptionTest() $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->locationName('[PROJECT]', '[LOCATION]'); $contents = []; - $request = (new RomanizeTextRequest()) - ->setParent($formattedParent) - ->setContents($contents); + $request = (new RomanizeTextRequest())->setParent($formattedParent)->setContents($contents); try { $gapicClient->romanizeText($request); // If the $gapicClient method call did not throw, fail the test @@ -3207,12 +3221,15 @@ public function translateDocumentExceptionTest() $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 $parent = 'parent-995424086'; @@ -3281,12 +3298,15 @@ public function translateTextExceptionTest() $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 $contents = []; @@ -3348,8 +3368,7 @@ public function updateGlossaryTest() $glossary = new Glossary(); $glossaryName = 'glossaryName-297469495'; $glossary->setName($glossaryName); - $request = (new UpdateGlossaryRequest()) - ->setGlossary($glossary); + $request = (new UpdateGlossaryRequest())->setGlossary($glossary); $response = $gapicClient->updateGlossary($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -3405,19 +3424,21 @@ public function updateGlossaryExceptionTest() $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 + ); $operationsTransport->addResponse(null, $status); // Mock request $glossary = new Glossary(); $glossaryName = 'glossaryName-297469495'; $glossary->setName($glossaryName); - $request = (new UpdateGlossaryRequest()) - ->setGlossary($glossary); + $request = (new UpdateGlossaryRequest())->setGlossary($glossary); $response = $gapicClient->updateGlossary($request); $this->assertFalse($response->isDone()); $this->assertNull($response->getResult()); @@ -3457,8 +3478,7 @@ public function updateGlossaryEntryTest() $transport->addResponse($expectedResponse); // Mock request $glossaryEntry = new GlossaryEntry(); - $request = (new UpdateGlossaryEntryRequest()) - ->setGlossaryEntry($glossaryEntry); + $request = (new UpdateGlossaryEntryRequest())->setGlossaryEntry($glossaryEntry); $response = $gapicClient->updateGlossaryEntry($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -3482,17 +3502,19 @@ public function updateGlossaryEntryExceptionTest() $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 $glossaryEntry = new GlossaryEntry(); - $request = (new UpdateGlossaryEntryRequest()) - ->setGlossaryEntry($glossaryEntry); + $request = (new UpdateGlossaryEntryRequest())->setGlossaryEntry($glossaryEntry); try { $gapicClient->updateGlossaryEntry($request); // If the $gapicClient method call did not throw, fail the test diff --git a/Translate/tests/Unit/V3/TranslationServiceClientTest.php b/Translate/tests/Unit/V3/TranslationServiceClientTest.php deleted file mode 100644 index 85f6fe2eb9f1..000000000000 --- a/Translate/tests/Unit/V3/TranslationServiceClientTest.php +++ /dev/null @@ -1,3274 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return TranslationServiceClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new TranslationServiceClient($options); - } - - /** @test */ - public function adaptiveMtTranslateTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $languageCode = 'languageCode-412800396'; - $expectedResponse = new AdaptiveMtTranslateResponse(); - $expectedResponse->setLanguageCode($languageCode); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $formattedDataset = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $content = []; - $response = $gapicClient->adaptiveMtTranslate($formattedParent, $formattedDataset, $content); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/AdaptiveMtTranslate', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getDataset(); - $this->assertProtobufEquals($formattedDataset, $actualValue); - $actualValue = $actualRequestObject->getContent(); - $this->assertProtobufEquals($content, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function adaptiveMtTranslateExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - $formattedDataset = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $content = []; - try { - $gapicClient->adaptiveMtTranslate($formattedParent, $formattedDataset, $content); - // 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 batchTranslateDocumentTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/batchTranslateDocumentTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $totalPages = 396186871; - $translatedPages = 1652747493; - $failedPages = 2002254526; - $totalBillablePages = 1292117569; - $totalCharacters = 1368640955; - $translatedCharacters = 1337326221; - $failedCharacters = 1723028396; - $totalBillableCharacters = 1242495501; - $expectedResponse = new BatchTranslateDocumentResponse(); - $expectedResponse->setTotalPages($totalPages); - $expectedResponse->setTranslatedPages($translatedPages); - $expectedResponse->setFailedPages($failedPages); - $expectedResponse->setTotalBillablePages($totalBillablePages); - $expectedResponse->setTotalCharacters($totalCharacters); - $expectedResponse->setTranslatedCharacters($translatedCharacters); - $expectedResponse->setFailedCharacters($failedCharacters); - $expectedResponse->setTotalBillableCharacters($totalBillableCharacters); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/batchTranslateDocumentTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCodes = []; - $inputConfigs = []; - $outputConfig = new BatchDocumentOutputConfig(); - $response = $gapicClient->batchTranslateDocument($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/BatchTranslateDocument', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualApiRequestObject->getSourceLanguageCode(); - $this->assertProtobufEquals($sourceLanguageCode, $actualValue); - $actualValue = $actualApiRequestObject->getTargetLanguageCodes(); - $this->assertProtobufEquals($targetLanguageCodes, $actualValue); - $actualValue = $actualApiRequestObject->getInputConfigs(); - $this->assertProtobufEquals($inputConfigs, $actualValue); - $actualValue = $actualApiRequestObject->getOutputConfig(); - $this->assertProtobufEquals($outputConfig, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/batchTranslateDocumentTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function batchTranslateDocumentExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/batchTranslateDocumentTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCodes = []; - $inputConfigs = []; - $outputConfig = new BatchDocumentOutputConfig(); - $response = $gapicClient->batchTranslateDocument($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/batchTranslateDocumentTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function batchTranslateTextTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/batchTranslateTextTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $totalCharacters = 1368640955; - $translatedCharacters = 1337326221; - $failedCharacters = 1723028396; - $expectedResponse = new BatchTranslateResponse(); - $expectedResponse->setTotalCharacters($totalCharacters); - $expectedResponse->setTranslatedCharacters($translatedCharacters); - $expectedResponse->setFailedCharacters($failedCharacters); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/batchTranslateTextTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCodes = []; - $inputConfigs = []; - $outputConfig = new OutputConfig(); - $response = $gapicClient->batchTranslateText($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/BatchTranslateText', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualApiRequestObject->getSourceLanguageCode(); - $this->assertProtobufEquals($sourceLanguageCode, $actualValue); - $actualValue = $actualApiRequestObject->getTargetLanguageCodes(); - $this->assertProtobufEquals($targetLanguageCodes, $actualValue); - $actualValue = $actualApiRequestObject->getInputConfigs(); - $this->assertProtobufEquals($inputConfigs, $actualValue); - $actualValue = $actualApiRequestObject->getOutputConfig(); - $this->assertProtobufEquals($outputConfig, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/batchTranslateTextTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function batchTranslateTextExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/batchTranslateTextTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCodes = []; - $inputConfigs = []; - $outputConfig = new OutputConfig(); - $response = $gapicClient->batchTranslateText($formattedParent, $sourceLanguageCode, $targetLanguageCodes, $inputConfigs, $outputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/batchTranslateTextTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function createAdaptiveMtDatasetTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $displayName = 'displayName1615086568'; - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $exampleCount = 1517063674; - $expectedResponse = new AdaptiveMtDataset(); - $expectedResponse->setName($name); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setSourceLanguageCode($sourceLanguageCode); - $expectedResponse->setTargetLanguageCode($targetLanguageCode); - $expectedResponse->setExampleCount($exampleCount); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $adaptiveMtDataset = new AdaptiveMtDataset(); - $adaptiveMtDatasetName = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $adaptiveMtDataset->setName($adaptiveMtDatasetName); - $response = $gapicClient->createAdaptiveMtDataset($formattedParent, $adaptiveMtDataset); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/CreateAdaptiveMtDataset', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getAdaptiveMtDataset(); - $this->assertProtobufEquals($adaptiveMtDataset, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function createAdaptiveMtDatasetExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - $adaptiveMtDataset = new AdaptiveMtDataset(); - $adaptiveMtDatasetName = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $adaptiveMtDataset->setName($adaptiveMtDatasetName); - try { - $gapicClient->createAdaptiveMtDataset($formattedParent, $adaptiveMtDataset); - // 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 createDatasetTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/createDatasetTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name = 'name3373707'; - $displayName = 'displayName1615086568'; - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $exampleCount = 1517063674; - $trainExampleCount = 1755438077; - $validateExampleCount = 159308433; - $testExampleCount = 483147021; - $expectedResponse = new Dataset(); - $expectedResponse->setName($name); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setSourceLanguageCode($sourceLanguageCode); - $expectedResponse->setTargetLanguageCode($targetLanguageCode); - $expectedResponse->setExampleCount($exampleCount); - $expectedResponse->setTrainExampleCount($trainExampleCount); - $expectedResponse->setValidateExampleCount($validateExampleCount); - $expectedResponse->setTestExampleCount($testExampleCount); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/createDatasetTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $dataset = new Dataset(); - $response = $gapicClient->createDataset($formattedParent, $dataset); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/CreateDataset', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualApiRequestObject->getDataset(); - $this->assertProtobufEquals($dataset, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/createDatasetTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function createDatasetExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/createDatasetTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $dataset = new Dataset(); - $response = $gapicClient->createDataset($formattedParent, $dataset); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/createDatasetTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function createGlossaryTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/createGlossaryTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name = 'name3373707'; - $entryCount = 811131134; - $displayName = 'displayName1615086568'; - $expectedResponse = new Glossary(); - $expectedResponse->setName($name); - $expectedResponse->setEntryCount($entryCount); - $expectedResponse->setDisplayName($displayName); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/createGlossaryTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $glossary = new Glossary(); - $glossaryName = 'glossaryName-297469495'; - $glossary->setName($glossaryName); - $response = $gapicClient->createGlossary($formattedParent, $glossary); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/CreateGlossary', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualApiRequestObject->getGlossary(); - $this->assertProtobufEquals($glossary, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/createGlossaryTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function createGlossaryExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/createGlossaryTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $glossary = new Glossary(); - $glossaryName = 'glossaryName-297469495'; - $glossary->setName($glossaryName); - $response = $gapicClient->createGlossary($formattedParent, $glossary); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/createGlossaryTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function createGlossaryEntryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $description = 'description-1724546052'; - $expectedResponse = new GlossaryEntry(); - $expectedResponse->setName($name); - $expectedResponse->setDescription($description); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $glossaryEntry = new GlossaryEntry(); - $response = $gapicClient->createGlossaryEntry($formattedParent, $glossaryEntry); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/CreateGlossaryEntry', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getGlossaryEntry(); - $this->assertProtobufEquals($glossaryEntry, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function createGlossaryEntryExceptionTest() - { - $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->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $glossaryEntry = new GlossaryEntry(); - try { - $gapicClient->createGlossaryEntry($formattedParent, $glossaryEntry); - // 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 createModelTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/createModelTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name = 'name3373707'; - $displayName = 'displayName1615086568'; - $dataset = 'dataset1443214456'; - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $trainExampleCount = 1755438077; - $validateExampleCount = 159308433; - $testExampleCount = 483147021; - $expectedResponse = new Model(); - $expectedResponse->setName($name); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setDataset($dataset); - $expectedResponse->setSourceLanguageCode($sourceLanguageCode); - $expectedResponse->setTargetLanguageCode($targetLanguageCode); - $expectedResponse->setTrainExampleCount($trainExampleCount); - $expectedResponse->setValidateExampleCount($validateExampleCount); - $expectedResponse->setTestExampleCount($testExampleCount); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/createModelTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $model = new Model(); - $response = $gapicClient->createModel($formattedParent, $model); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/CreateModel', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualApiRequestObject->getModel(); - $this->assertProtobufEquals($model, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/createModelTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function createModelExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/createModelTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $model = new Model(); - $response = $gapicClient->createModel($formattedParent, $model); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/createModelTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function deleteAdaptiveMtDatasetTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $gapicClient->deleteAdaptiveMtDataset($formattedName); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/DeleteAdaptiveMtDataset', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteAdaptiveMtDatasetExceptionTest() - { - $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->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - try { - $gapicClient->deleteAdaptiveMtDataset($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 deleteAdaptiveMtFileTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $gapicClient->deleteAdaptiveMtFile($formattedName); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/DeleteAdaptiveMtFile', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteAdaptiveMtFileExceptionTest() - { - $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->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - try { - $gapicClient->deleteAdaptiveMtFile($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 deleteDatasetTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/deleteDatasetTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $expectedResponse = new GPBEmpty(); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/deleteDatasetTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedName = $gapicClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $response = $gapicClient->deleteDataset($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/DeleteDataset', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/deleteDatasetTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function deleteDatasetExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/deleteDatasetTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $response = $gapicClient->deleteDataset($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/deleteDatasetTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function deleteGlossaryTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/deleteGlossaryTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name2 = 'name2-1052831874'; - $expectedResponse = new DeleteGlossaryResponse(); - $expectedResponse->setName($name2); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/deleteGlossaryTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedName = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $response = $gapicClient->deleteGlossary($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/DeleteGlossary', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/deleteGlossaryTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function deleteGlossaryExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/deleteGlossaryTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $response = $gapicClient->deleteGlossary($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/deleteGlossaryTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function deleteGlossaryEntryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - $gapicClient->deleteGlossaryEntry($formattedName); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/DeleteGlossaryEntry', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteGlossaryEntryExceptionTest() - { - $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->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - try { - $gapicClient->deleteGlossaryEntry($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 deleteModelTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/deleteModelTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $expectedResponse = new GPBEmpty(); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/deleteModelTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedName = $gapicClient->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - $response = $gapicClient->deleteModel($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/DeleteModel', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/deleteModelTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function deleteModelExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/deleteModelTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - $response = $gapicClient->deleteModel($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/deleteModelTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function detectLanguageTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new DetectLanguageResponse(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $response = $gapicClient->detectLanguage($formattedParent); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/DetectLanguage', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function detectLanguageExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - try { - $gapicClient->detectLanguage($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 exportDataTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/exportDataTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $expectedResponse = new GPBEmpty(); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/exportDataTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $dataset = 'dataset1443214456'; - $outputConfig = new DatasetOutputConfig(); - $response = $gapicClient->exportData($dataset, $outputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ExportData', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getDataset(); - $this->assertProtobufEquals($dataset, $actualValue); - $actualValue = $actualApiRequestObject->getOutputConfig(); - $this->assertProtobufEquals($outputConfig, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/exportDataTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function exportDataExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/exportDataTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $dataset = 'dataset1443214456'; - $outputConfig = new DatasetOutputConfig(); - $response = $gapicClient->exportData($dataset, $outputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/exportDataTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function getAdaptiveMtDatasetTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $exampleCount = 1517063674; - $expectedResponse = new AdaptiveMtDataset(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setSourceLanguageCode($sourceLanguageCode); - $expectedResponse->setTargetLanguageCode($targetLanguageCode); - $expectedResponse->setExampleCount($exampleCount); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $response = $gapicClient->getAdaptiveMtDataset($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.translation.v3.TranslationService/GetAdaptiveMtDataset', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getAdaptiveMtDatasetExceptionTest() - { - $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->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - try { - $gapicClient->getAdaptiveMtDataset($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 getAdaptiveMtFileTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $entryCount = 811131134; - $expectedResponse = new AdaptiveMtFile(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setEntryCount($entryCount); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $response = $gapicClient->getAdaptiveMtFile($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.translation.v3.TranslationService/GetAdaptiveMtFile', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getAdaptiveMtFileExceptionTest() - { - $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->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - try { - $gapicClient->getAdaptiveMtFile($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 getDatasetTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $exampleCount = 1517063674; - $trainExampleCount = 1755438077; - $validateExampleCount = 159308433; - $testExampleCount = 483147021; - $expectedResponse = new Dataset(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setSourceLanguageCode($sourceLanguageCode); - $expectedResponse->setTargetLanguageCode($targetLanguageCode); - $expectedResponse->setExampleCount($exampleCount); - $expectedResponse->setTrainExampleCount($trainExampleCount); - $expectedResponse->setValidateExampleCount($validateExampleCount); - $expectedResponse->setTestExampleCount($testExampleCount); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $response = $gapicClient->getDataset($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.translation.v3.TranslationService/GetDataset', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getDatasetExceptionTest() - { - $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->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - try { - $gapicClient->getDataset($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 getGlossaryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $entryCount = 811131134; - $displayName = 'displayName1615086568'; - $expectedResponse = new Glossary(); - $expectedResponse->setName($name2); - $expectedResponse->setEntryCount($entryCount); - $expectedResponse->setDisplayName($displayName); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $response = $gapicClient->getGlossary($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.translation.v3.TranslationService/GetGlossary', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getGlossaryExceptionTest() - { - $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->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - try { - $gapicClient->getGlossary($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 getGlossaryEntryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $description = 'description-1724546052'; - $expectedResponse = new GlossaryEntry(); - $expectedResponse->setName($name2); - $expectedResponse->setDescription($description); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - $response = $gapicClient->getGlossaryEntry($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.translation.v3.TranslationService/GetGlossaryEntry', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getGlossaryEntryExceptionTest() - { - $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->glossaryEntryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]', '[GLOSSARY_ENTRY]'); - try { - $gapicClient->getGlossaryEntry($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 getModelTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $dataset = 'dataset1443214456'; - $sourceLanguageCode = 'sourceLanguageCode1687263568'; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $trainExampleCount = 1755438077; - $validateExampleCount = 159308433; - $testExampleCount = 483147021; - $expectedResponse = new Model(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setDataset($dataset); - $expectedResponse->setSourceLanguageCode($sourceLanguageCode); - $expectedResponse->setTargetLanguageCode($targetLanguageCode); - $expectedResponse->setTrainExampleCount($trainExampleCount); - $expectedResponse->setValidateExampleCount($validateExampleCount); - $expectedResponse->setTestExampleCount($testExampleCount); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - $response = $gapicClient->getModel($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.translation.v3.TranslationService/GetModel', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getModelExceptionTest() - { - $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->modelName('[PROJECT]', '[LOCATION]', '[MODEL]'); - try { - $gapicClient->getModel($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 getSupportedLanguagesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new SupportedLanguages(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $response = $gapicClient->getSupportedLanguages($formattedParent); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/GetSupportedLanguages', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getSupportedLanguagesExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - try { - $gapicClient->getSupportedLanguages($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 importAdaptiveMtFileTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new ImportAdaptiveMtFileResponse(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $response = $gapicClient->importAdaptiveMtFile($formattedParent); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ImportAdaptiveMtFile', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function importAdaptiveMtFileExceptionTest() - { - $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->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - try { - $gapicClient->importAdaptiveMtFile($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 importDataTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/importDataTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $expectedResponse = new GPBEmpty(); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/importDataTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $dataset = 'dataset1443214456'; - $inputConfig = new DatasetInputConfig(); - $response = $gapicClient->importData($dataset, $inputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ImportData', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getDataset(); - $this->assertProtobufEquals($dataset, $actualValue); - $actualValue = $actualApiRequestObject->getInputConfig(); - $this->assertProtobufEquals($inputConfig, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/importDataTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function importDataExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/importDataTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $dataset = 'dataset1443214456'; - $inputConfig = new DatasetInputConfig(); - $response = $gapicClient->importData($dataset, $inputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/importDataTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function listAdaptiveMtDatasetsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $adaptiveMtDatasetsElement = new AdaptiveMtDataset(); - $adaptiveMtDatasets = [ - $adaptiveMtDatasetsElement, - ]; - $expectedResponse = new ListAdaptiveMtDatasetsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setAdaptiveMtDatasets($adaptiveMtDatasets); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $response = $gapicClient->listAdaptiveMtDatasets($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getAdaptiveMtDatasets()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ListAdaptiveMtDatasets', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listAdaptiveMtDatasetsExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - try { - $gapicClient->listAdaptiveMtDatasets($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 listAdaptiveMtFilesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $adaptiveMtFilesElement = new AdaptiveMtFile(); - $adaptiveMtFiles = [ - $adaptiveMtFilesElement, - ]; - $expectedResponse = new ListAdaptiveMtFilesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setAdaptiveMtFiles($adaptiveMtFiles); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $response = $gapicClient->listAdaptiveMtFiles($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getAdaptiveMtFiles()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ListAdaptiveMtFiles', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listAdaptiveMtFilesExceptionTest() - { - $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->adaptiveMtDatasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - try { - $gapicClient->listAdaptiveMtFiles($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 listAdaptiveMtSentencesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $adaptiveMtSentencesElement = new AdaptiveMtSentence(); - $adaptiveMtSentences = [ - $adaptiveMtSentencesElement, - ]; - $expectedResponse = new ListAdaptiveMtSentencesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setAdaptiveMtSentences($adaptiveMtSentences); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - $response = $gapicClient->listAdaptiveMtSentences($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getAdaptiveMtSentences()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ListAdaptiveMtSentences', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listAdaptiveMtSentencesExceptionTest() - { - $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->adaptiveMtFileName('[PROJECT]', '[LOCATION]', '[DATASET]', '[FILE]'); - try { - $gapicClient->listAdaptiveMtSentences($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 listDatasetsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $datasetsElement = new Dataset(); - $datasets = [ - $datasetsElement, - ]; - $expectedResponse = new ListDatasetsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setDatasets($datasets); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $response = $gapicClient->listDatasets($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getDatasets()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ListDatasets', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listDatasetsExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - try { - $gapicClient->listDatasets($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 listExamplesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $examplesElement = new Example(); - $examples = [ - $examplesElement, - ]; - $expectedResponse = new ListExamplesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setExamples($examples); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - $response = $gapicClient->listExamples($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getExamples()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ListExamples', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listExamplesExceptionTest() - { - $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->datasetName('[PROJECT]', '[LOCATION]', '[DATASET]'); - try { - $gapicClient->listExamples($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 listGlossariesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $glossariesElement = new Glossary(); - $glossaries = [ - $glossariesElement, - ]; - $expectedResponse = new ListGlossariesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setGlossaries($glossaries); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $response = $gapicClient->listGlossaries($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getGlossaries()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ListGlossaries', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listGlossariesExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - try { - $gapicClient->listGlossaries($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 listGlossaryEntriesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $glossaryEntriesElement = new GlossaryEntry(); - $glossaryEntries = [ - $glossaryEntriesElement, - ]; - $expectedResponse = new ListGlossaryEntriesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setGlossaryEntries($glossaryEntries); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - $response = $gapicClient->listGlossaryEntries($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getGlossaryEntries()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ListGlossaryEntries', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listGlossaryEntriesExceptionTest() - { - $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->glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]'); - try { - $gapicClient->listGlossaryEntries($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 listModelsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $modelsElement = new Model(); - $models = [ - $modelsElement, - ]; - $expectedResponse = new ListModelsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setModels($models); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $response = $gapicClient->listModels($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getModels()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/ListModels', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listModelsExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - try { - $gapicClient->listModels($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 romanizeTextTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new RomanizeTextResponse(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $contents = []; - $response = $gapicClient->romanizeText($formattedParent, $contents); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/RomanizeText', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getContents(); - $this->assertProtobufEquals($contents, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function romanizeTextExceptionTest() - { - $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->locationName('[PROJECT]', '[LOCATION]'); - $contents = []; - try { - $gapicClient->romanizeText($formattedParent, $contents); - // 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 translateDocumentTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $model2 = 'model21226956956'; - $expectedResponse = new TranslateDocumentResponse(); - $expectedResponse->setModel($model2); - $transport->addResponse($expectedResponse); - // Mock request - $parent = 'parent-995424086'; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $documentInputConfig = new DocumentInputConfig(); - $response = $gapicClient->translateDocument($parent, $targetLanguageCode, $documentInputConfig); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/TranslateDocument', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($parent, $actualValue); - $actualValue = $actualRequestObject->getTargetLanguageCode(); - $this->assertProtobufEquals($targetLanguageCode, $actualValue); - $actualValue = $actualRequestObject->getDocumentInputConfig(); - $this->assertProtobufEquals($documentInputConfig, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function translateDocumentExceptionTest() - { - $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 - $parent = 'parent-995424086'; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $documentInputConfig = new DocumentInputConfig(); - try { - $gapicClient->translateDocument($parent, $targetLanguageCode, $documentInputConfig); - // 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 translateTextTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new TranslateTextResponse(); - $transport->addResponse($expectedResponse); - // Mock request - $contents = []; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $response = $gapicClient->translateText($contents, $targetLanguageCode, $formattedParent); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/TranslateText', $actualFuncCall); - $actualValue = $actualRequestObject->getContents(); - $this->assertProtobufEquals($contents, $actualValue); - $actualValue = $actualRequestObject->getTargetLanguageCode(); - $this->assertProtobufEquals($targetLanguageCode, $actualValue); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function translateTextExceptionTest() - { - $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 - $contents = []; - $targetLanguageCode = 'targetLanguageCode1323228230'; - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - try { - $gapicClient->translateText($contents, $targetLanguageCode, $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 updateGlossaryTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/updateGlossaryTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name = 'name3373707'; - $entryCount = 811131134; - $displayName = 'displayName1615086568'; - $expectedResponse = new Glossary(); - $expectedResponse->setName($name); - $expectedResponse->setEntryCount($entryCount); - $expectedResponse->setDisplayName($displayName); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/updateGlossaryTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $glossary = new Glossary(); - $glossaryName = 'glossaryName-297469495'; - $glossary->setName($glossaryName); - $response = $gapicClient->updateGlossary($glossary); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/UpdateGlossary', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getGlossary(); - $this->assertProtobufEquals($glossary, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/updateGlossaryTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function updateGlossaryExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/updateGlossaryTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $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); - $operationsTransport->addResponse(null, $status); - // Mock request - $glossary = new Glossary(); - $glossaryName = 'glossaryName-297469495'; - $glossary->setName($glossaryName); - $response = $gapicClient->updateGlossary($glossary); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/updateGlossaryTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() 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 stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function updateGlossaryEntryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $description = 'description-1724546052'; - $expectedResponse = new GlossaryEntry(); - $expectedResponse->setName($name); - $expectedResponse->setDescription($description); - $transport->addResponse($expectedResponse); - // Mock request - $glossaryEntry = new GlossaryEntry(); - $response = $gapicClient->updateGlossaryEntry($glossaryEntry); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.translation.v3.TranslationService/UpdateGlossaryEntry', $actualFuncCall); - $actualValue = $actualRequestObject->getGlossaryEntry(); - $this->assertProtobufEquals($glossaryEntry, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function updateGlossaryEntryExceptionTest() - { - $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 - $glossaryEntry = new GlossaryEntry(); - try { - $gapicClient->updateGlossaryEntry($glossaryEntry); - // 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()); - } -}