-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit testing for GRPC only clients
- Loading branch information
1 parent
8355a80
commit b667e63
Showing
15 changed files
with
774 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
syntax = "proto3"; | ||
|
||
package testing.basicGrpcOnly; | ||
|
||
// php_namespace option not included; to test generating namespace from proto package. | ||
|
||
import "google/api/annotations.proto"; | ||
import "google/api/client.proto"; | ||
import "google/api/field_behavior.proto"; | ||
|
||
// This is a basicGrpcOnly service. | ||
service BasicGrpcOnly { | ||
option (google.api.default_host) = "basicGrpcOnly.example.com"; | ||
option (google.api.oauth_scopes) = "scope1,scope2"; | ||
|
||
// Test summary text for AMethod | ||
rpc AMethod(Request) returns(Response) { | ||
option (google.api.http) = { | ||
post: "/path:aMethod" | ||
body: "*" | ||
}; | ||
} | ||
|
||
// Test including method args. | ||
rpc MethodWithArgs(RequestWithArgs) returns(Response) { | ||
option (google.api.http) = { | ||
post: "/path:methodWithArgs" | ||
body: "*" | ||
}; | ||
}; | ||
} | ||
|
||
message Request { | ||
} | ||
|
||
message PartOfRequestA {} | ||
message PartOfRequestB {} | ||
message PartOfRequestC {} | ||
|
||
message RequestWithArgs { | ||
// A required field... | ||
string a_string = 1 [(google.api.field_behavior) = REQUIRED]; | ||
// ...and an optional field. | ||
int32 an_int = 2; | ||
// ...and a repeated message type, which checks that an extra import is *not* added, | ||
// in contrast to a paginated method where an extra import *is* added. | ||
repeated PartOfRequestA part_of_request_a = 4 [(google.api.field_behavior) = REQUIRED]; | ||
repeated PartOfRequestB part_of_request_b = 5; | ||
PartOfRequestC part_of_request_c = 6; | ||
} | ||
|
||
message Response { | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/Unit/ProtoTests/BasicGrpcOnly/basic_grpc_only_service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type: google.api.Service | ||
config_version: 3 | ||
|
||
authentication: | ||
rules: | ||
- selector: 'testing.basicGrpcOnly.BasicGrpcOnly.*' | ||
oauth: | ||
canonical_scopes: |- | ||
scope1, | ||
scope2 |
57 changes: 57 additions & 0 deletions
57
tests/Unit/ProtoTests/BasicGrpcOnly/out/samples/BasicGrpcOnlyClient/a_method.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* GENERATED CODE WARNING | ||
* This file was automatically generated - do not edit! | ||
*/ | ||
|
||
require_once __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
// [START basicGrpcOnly_generated_BasicGrpcOnly_AMethod_sync] | ||
use Google\ApiCore\ApiException; | ||
use Testing\BasicGrpcOnly\Client\BasicGrpcOnlyClient; | ||
use Testing\BasicGrpcOnly\Request; | ||
use Testing\BasicGrpcOnly\Response; | ||
|
||
/** | ||
* Test summary text for AMethod | ||
* | ||
* This sample has been automatically generated and should be regarded as a code | ||
* template only. It will require modifications to work: | ||
* - It may require correct/in-range values for request initialization. | ||
* - It may require specifying regional endpoints when creating the service client, | ||
* please see the apiEndpoint client configuration option for more details. | ||
*/ | ||
function a_method_sample(): void | ||
{ | ||
// Create a client. | ||
$basicGrpcOnlyClient = new BasicGrpcOnlyClient(); | ||
|
||
// Prepare the request message. | ||
$request = new Request(); | ||
|
||
// Call the API and handle any network failures. | ||
try { | ||
/** @var Response $response */ | ||
$response = $basicGrpcOnlyClient->aMethod($request); | ||
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); | ||
} catch (ApiException $ex) { | ||
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); | ||
} | ||
} | ||
// [END basicGrpcOnly_generated_BasicGrpcOnly_AMethod_sync] |
73 changes: 73 additions & 0 deletions
73
tests/Unit/ProtoTests/BasicGrpcOnly/out/samples/BasicGrpcOnlyClient/method_with_args.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* GENERATED CODE WARNING | ||
* This file was automatically generated - do not edit! | ||
*/ | ||
|
||
require_once __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
// [START basicGrpcOnly_generated_BasicGrpcOnly_MethodWithArgs_sync] | ||
use Google\ApiCore\ApiException; | ||
use Testing\BasicGrpcOnly\Client\BasicGrpcOnlyClient; | ||
use Testing\BasicGrpcOnly\PartOfRequestA; | ||
use Testing\BasicGrpcOnly\RequestWithArgs; | ||
use Testing\BasicGrpcOnly\Response; | ||
|
||
/** | ||
* Test including method args. | ||
* | ||
* @param string $aString A required field... | ||
*/ | ||
function method_with_args_sample(string $aString): void | ||
{ | ||
// Create a client. | ||
$basicGrpcOnlyClient = new BasicGrpcOnlyClient(); | ||
|
||
// Prepare the request message. | ||
$partOfRequestA = [new PartOfRequestA()]; | ||
$request = (new RequestWithArgs()) | ||
->setAString($aString) | ||
->setPartOfRequestA($partOfRequestA); | ||
|
||
// Call the API and handle any network failures. | ||
try { | ||
/** @var Response $response */ | ||
$response = $basicGrpcOnlyClient->methodWithArgs($request); | ||
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); | ||
} catch (ApiException $ex) { | ||
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Helper to execute the sample. | ||
* | ||
* This sample has been automatically generated and should be regarded as a code | ||
* template only. It will require modifications to work: | ||
* - It may require correct/in-range values for request initialization. | ||
* - It may require specifying regional endpoints when creating the service client, | ||
* please see the apiEndpoint client configuration option for more details. | ||
*/ | ||
function callSample(): void | ||
{ | ||
$aString = '[A_STRING]'; | ||
|
||
method_with_args_sample($aString); | ||
} | ||
// [END basicGrpcOnly_generated_BasicGrpcOnly_MethodWithArgs_sync] |
Oops, something went wrong.