Skip to content

Commit 9ad9168

Browse files
committed
add keywords test files
1 parent 60be60f commit 9ad9168

8 files changed

Lines changed: 735 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/*
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START keywords_generated_Keywords_Method1_sync]
26+
use Google\ApiCore\ApiException;
27+
use Testing\Keywords\Client\KeywordsClient;
28+
use Testing\Keywords\Request;
29+
use Testing\Keywords\Response;
30+
31+
/** @param int $status check words in tests */
32+
function method1_sample(int $status): void
33+
{
34+
// Create a client.
35+
$keywordsClient = new KeywordsClient();
36+
37+
// Prepare the request message.
38+
$request = (new Request())
39+
->setStatus($status);
40+
41+
// Call the API and handle any network failures.
42+
try {
43+
/** @var Response $response */
44+
$response = $keywordsClient->method1($request);
45+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
46+
} catch (ApiException $ex) {
47+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
48+
}
49+
}
50+
51+
/**
52+
* Helper to execute the sample.
53+
*
54+
* This sample has been automatically generated and should be regarded as a code
55+
* template only. It will require modifications to work:
56+
* - It may require correct/in-range values for request initialization.
57+
* - It may require specifying regional endpoints when creating the service client,
58+
* please see the apiEndpoint client configuration option for more details.
59+
*/
60+
function callSample(): void
61+
{
62+
$status = 0;
63+
64+
method1_sample($status);
65+
}
66+
// [END keywords_generated_Keywords_Method1_sync]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/*
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START keywords_generated_Keywords_Method2_sync]
26+
use Google\ApiCore\ApiException;
27+
use Testing\Keywords\Client\KeywordsClient;
28+
use Testing\Keywords\Resource;
29+
use Testing\Keywords\Response;
30+
31+
/**
32+
* This sample has been automatically generated and should be regarded as a code
33+
* template only. It will require modifications to work:
34+
* - It may require correct/in-range values for request initialization.
35+
* - It may require specifying regional endpoints when creating the service client,
36+
* please see the apiEndpoint client configuration option for more details.
37+
*/
38+
function method2_sample(): void
39+
{
40+
// Create a client.
41+
$keywordsClient = new KeywordsClient();
42+
43+
// Prepare the request message.
44+
$request = new Resource();
45+
46+
// Call the API and handle any network failures.
47+
try {
48+
/** @var Response $response */
49+
$response = $keywordsClient->method2($request);
50+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
51+
} catch (ApiException $ex) {
52+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
53+
}
54+
}
55+
// [END keywords_generated_Keywords_Method2_sync]
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
<?php
2+
/*
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* Generated by gapic-generator-php from the file
21+
* https://github.com/googleapis/googleapis/blob/master/tests/Unit/ProtoTests/Keywords/keywords.proto
22+
* Updates to the above are reflected here through a refresh process.
23+
*/
24+
25+
namespace Testing\Keywords\Client;
26+
27+
use Google\ApiCore\ApiException;
28+
use Google\ApiCore\CredentialsWrapper;
29+
use Google\ApiCore\GapicClientTrait;
30+
use Google\ApiCore\Options\ClientOptions;
31+
use Google\ApiCore\ResourceHelperTrait;
32+
use Google\ApiCore\RetrySettings;
33+
use Google\ApiCore\Transport\TransportInterface;
34+
use Google\ApiCore\ValidationException;
35+
use Google\Auth\FetchAuthTokenInterface;
36+
use GuzzleHttp\Promise\PromiseInterface;
37+
use Psr\Log\LoggerInterface;
38+
use Testing\Keywords\Request;
39+
use Testing\Keywords\Resource;
40+
use Testing\Keywords\Response;
41+
42+
/**
43+
* Service Description:
44+
*
45+
* This class provides the ability to make remote calls to the backing service through method
46+
* calls that map to API methods.
47+
*
48+
* Many parameters require resource names to be formatted in a particular way. To
49+
* assist with these names, this class includes a format method for each type of
50+
* name, and additionally a parseName method to extract the individual identifiers
51+
* contained within formatted names that are returned by the API.
52+
*
53+
* @method PromiseInterface<Response> method1Async(Request $request, array $optionalArgs = [])
54+
* @method PromiseInterface<Response> method2Async(Resource $request, array $optionalArgs = [])
55+
*/
56+
final class KeywordsClient
57+
{
58+
use GapicClientTrait;
59+
use ResourceHelperTrait;
60+
61+
/** The name of the service. */
62+
private const SERVICE_NAME = 'testing.keywords.Keywords';
63+
64+
/** The default address of the service. */
65+
private const SERVICE_ADDRESS = 'keywords.example.com';
66+
67+
/** The default port of the service. */
68+
private const DEFAULT_SERVICE_PORT = 443;
69+
70+
/** The name of the code generator, to be included in the agent header. */
71+
private const CODEGEN_NAME = 'gapic';
72+
73+
/** The default scopes required by the service. */
74+
public static $serviceScopes = [];
75+
76+
private static function getClientDefaults()
77+
{
78+
return [
79+
'serviceName' => self::SERVICE_NAME,
80+
'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT,
81+
'clientConfig' => __DIR__ . '/../resources/keywords_client_config.json',
82+
'descriptorsConfigPath' => __DIR__ . '/../resources/keywords_descriptor_config.php',
83+
'gcpApiConfigPath' => __DIR__ . '/../resources/keywords_grpc_config.json',
84+
'credentialsConfig' => [
85+
'defaultScopes' => self::$serviceScopes,
86+
],
87+
'transportConfig' => [
88+
'rest' => [
89+
'restClientConfigPath' => __DIR__ . '/../resources/keywords_rest_client_config.php',
90+
],
91+
],
92+
];
93+
}
94+
95+
/**
96+
* Formats a string containing the fully-qualified path to represent a resource
97+
* resource.
98+
*
99+
* @param string $itemId
100+
*
101+
* @return string The formatted resource resource.
102+
*/
103+
public static function resourceName(string $itemId): string
104+
{
105+
return self::getPathTemplate('resource')->render([
106+
'item_id' => $itemId,
107+
]);
108+
}
109+
110+
/**
111+
* Parses a formatted name string and returns an associative array of the components in the name.
112+
* The following name formats are supported:
113+
* Template: Pattern
114+
* - resource: items/{item_id}
115+
*
116+
* The optional $template argument can be supplied to specify a particular pattern,
117+
* and must match one of the templates listed above. If no $template argument is
118+
* provided, or if the $template argument does not match one of the templates
119+
* listed, then parseName will check each of the supported templates, and return
120+
* the first match.
121+
*
122+
* @param string $formattedName The formatted name string
123+
* @param ?string $template Optional name of template to match
124+
*
125+
* @return array An associative array from name component IDs to component values.
126+
*
127+
* @throws ValidationException If $formattedName could not be matched.
128+
*/
129+
public static function parseName(string $formattedName, ?string $template = null): array
130+
{
131+
return self::parseFormattedName($formattedName, $template);
132+
}
133+
134+
/**
135+
* Constructor.
136+
*
137+
* @param array|ClientOptions $options {
138+
* Optional. Options for configuring the service API wrapper.
139+
*
140+
* @type string $apiEndpoint
141+
* The address of the API remote host. May optionally include the port, formatted
142+
* as "<uri>:<port>". Default 'keywords.example.com:443'.
143+
* @type FetchAuthTokenInterface|CredentialsWrapper $credentials
144+
* This option should only be used with a pre-constructed
145+
* {@see FetchAuthTokenInterface} or {@see CredentialsWrapper} object. Note that
146+
* when one of these objects are provided, any settings in $credentialsConfig will
147+
* be ignored.
148+
* **Important**: If you are providing a path to a credentials file, or a decoded
149+
* credentials file as a PHP array, this usage is now DEPRECATED. Providing an
150+
* unvalidated credential configuration to Google APIs can compromise the security
151+
* of your systems and data. It is recommended to create the credentials explicitly
152+
* ```
153+
* use Google\Auth\Credentials\ServiceAccountCredentials;
154+
* use Testing\Keywords\KeywordsClient;
155+
* $creds = new ServiceAccountCredentials($scopes, $json);
156+
* $options = new KeywordsClient(['credentials' => $creds]);
157+
* ```
158+
* {@see
159+
* https://cloud.google.com/docs/authentication/external/externally-sourced-credentials}
160+
* @type array $credentialsConfig
161+
* Options used to configure credentials, including auth token caching, for the
162+
* client. For a full list of supporting configuration options, see
163+
* {@see \Google\ApiCore\CredentialsWrapper::build()} .
164+
* @type bool $disableRetries
165+
* Determines whether or not retries defined by the client configuration should be
166+
* disabled. Defaults to `false`.
167+
* @type string|array $clientConfig
168+
* Client method configuration, including retry settings. This option can be either
169+
* a path to a JSON file, or a PHP array containing the decoded JSON data. By
170+
* default this settings points to the default client config file, which is
171+
* provided in the resources folder.
172+
* @type string|TransportInterface $transport
173+
* The transport used for executing network requests. May be either the string
174+
* `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system.
175+
* *Advanced usage*: Additionally, it is possible to pass in an already
176+
* instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note
177+
* that when this object is provided, any settings in $transportConfig, and any
178+
* $apiEndpoint setting, will be ignored.
179+
* @type array $transportConfig
180+
* Configuration options that will be used to construct the transport. Options for
181+
* each supported transport type should be passed in a key for that transport. For
182+
* example:
183+
* $transportConfig = [
184+
* 'grpc' => [...],
185+
* 'rest' => [...],
186+
* ];
187+
* See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and
188+
* {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the
189+
* supported options.
190+
* @type callable $clientCertSource
191+
* A callable which returns the client cert as a string. This can be used to
192+
* provide a certificate and private key to the transport layer for mTLS.
193+
* @type false|LoggerInterface $logger
194+
* A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the
195+
* 'GOOGLE_SDK_PHP_LOGGING' environment flag
196+
* @type string $universeDomain
197+
* The service domain for the client. Defaults to 'googleapis.com'.
198+
* }
199+
*
200+
* @throws ValidationException
201+
*/
202+
public function __construct(array|ClientOptions $options = [])
203+
{
204+
$clientOptions = $this->buildClientOptions($options);
205+
$this->setClientOptions($clientOptions);
206+
}
207+
208+
/** Handles execution of the async variants for each documented method. */
209+
public function __call($method, $args)
210+
{
211+
if (substr($method, -5) !== 'Async') {
212+
trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR);
213+
}
214+
215+
array_unshift($args, substr($method, 0, -5));
216+
return call_user_func_array([$this, 'startAsyncCall'], $args);
217+
}
218+
219+
/**
220+
* The async variant is {@see KeywordsClient::method1Async()} .
221+
*
222+
* @example samples/KeywordsClient/method1.php
223+
*
224+
* @param Request $request A request to house fields associated with the call.
225+
* @param array $callOptions {
226+
* Optional.
227+
*
228+
* @type RetrySettings|array $retrySettings
229+
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
230+
* associative array of retry settings parameters. See the documentation on
231+
* {@see RetrySettings} for example usage.
232+
* }
233+
*
234+
* @return Response
235+
*
236+
* @throws ApiException Thrown if the API call fails.
237+
*/
238+
public function method1(Request $request, array $callOptions = []): Response
239+
{
240+
return $this->startApiCall('Method1', $request, $callOptions)->wait();
241+
}
242+
243+
/**
244+
* The async variant is {@see KeywordsClient::method2Async()} .
245+
*
246+
* @example samples/KeywordsClient/method2.php
247+
*
248+
* @param Resource $request A request to house fields associated with the call.
249+
* @param array $callOptions {
250+
* Optional.
251+
*
252+
* @type RetrySettings|array $retrySettings
253+
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
254+
* associative array of retry settings parameters. See the documentation on
255+
* {@see RetrySettings} for example usage.
256+
* }
257+
*
258+
* @return Response
259+
*
260+
* @throws ApiException Thrown if the API call fails.
261+
*/
262+
public function method2(Resource $request, array $callOptions = []): Response
263+
{
264+
return $this->startApiCall('Method2', $request, $callOptions)->wait();
265+
}
266+
}

0 commit comments

Comments
 (0)