diff --git a/ResourceManager/samples/V3/FoldersClient/create_folder.php b/ResourceManager/samples/V3/FoldersClient/create_folder.php index 9c6c51e8c400..797ac75b30df 100644 --- a/ResourceManager/samples/V3/FoldersClient/create_folder.php +++ b/ResourceManager/samples/V3/FoldersClient/create_folder.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Folders_CreateFolder_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; +use Google\Cloud\ResourceManager\V3\CreateFolderRequest; use Google\Cloud\ResourceManager\V3\Folder; -use Google\Cloud\ResourceManager\V3\FoldersClient; use Google\Rpc\Status; /** @@ -67,14 +68,16 @@ function create_folder_sample(string $folderParent): void // Create a client. $foldersClient = new FoldersClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $folder = (new Folder()) ->setParent($folderParent); + $request = (new CreateFolderRequest()) + ->setFolder($folder); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $foldersClient->createFolder($folder); + $response = $foldersClient->createFolder($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/FoldersClient/delete_folder.php b/ResourceManager/samples/V3/FoldersClient/delete_folder.php index 736b5fb1ea8d..da5660a0a04d 100644 --- a/ResourceManager/samples/V3/FoldersClient/delete_folder.php +++ b/ResourceManager/samples/V3/FoldersClient/delete_folder.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Folders_DeleteFolder_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; +use Google\Cloud\ResourceManager\V3\DeleteFolderRequest; use Google\Cloud\ResourceManager\V3\Folder; -use Google\Cloud\ResourceManager\V3\FoldersClient; use Google\Rpc\Status; /** @@ -51,10 +52,14 @@ function delete_folder_sample(string $formattedName): void // Create a client. $foldersClient = new FoldersClient(); + // Prepare the request message. + $request = (new DeleteFolderRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $foldersClient->deleteFolder($formattedName); + $response = $foldersClient->deleteFolder($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/FoldersClient/get_folder.php b/ResourceManager/samples/V3/FoldersClient/get_folder.php index 7dceec85334f..e51d9ab8d7b4 100644 --- a/ResourceManager/samples/V3/FoldersClient/get_folder.php +++ b/ResourceManager/samples/V3/FoldersClient/get_folder.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Folders_GetFolder_sync] use Google\ApiCore\ApiException; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; use Google\Cloud\ResourceManager\V3\Folder; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\ResourceManager\V3\GetFolderRequest; /** * Retrieves a folder identified by the supplied resource name. @@ -43,10 +44,14 @@ function get_folder_sample(string $formattedName): void // Create a client. $foldersClient = new FoldersClient(); + // Prepare the request message. + $request = (new GetFolderRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Folder $response */ - $response = $foldersClient->getFolder($formattedName); + $response = $foldersClient->getFolder($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/FoldersClient/get_iam_policy.php b/ResourceManager/samples/V3/FoldersClient/get_iam_policy.php index 931070013737..3f88688eccdb 100644 --- a/ResourceManager/samples/V3/FoldersClient/get_iam_policy.php +++ b/ResourceManager/samples/V3/FoldersClient/get_iam_policy.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Folders_GetIamPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; /** * Gets the access control policy for a folder. The returned policy may be @@ -42,10 +43,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $foldersClient = new FoldersClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $foldersClient->getIamPolicy($resource); + $response = $foldersClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/FoldersClient/list_folders.php b/ResourceManager/samples/V3/FoldersClient/list_folders.php index b42fed7ea4ac..abc2f700aa84 100644 --- a/ResourceManager/samples/V3/FoldersClient/list_folders.php +++ b/ResourceManager/samples/V3/FoldersClient/list_folders.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Folders_ListFolders_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; use Google\Cloud\ResourceManager\V3\Folder; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\ResourceManager\V3\ListFoldersRequest; /** * Lists the folders that are direct descendants of supplied parent resource. @@ -52,10 +53,14 @@ function list_folders_sample(string $parent): void // Create a client. $foldersClient = new FoldersClient(); + // Prepare the request message. + $request = (new ListFoldersRequest()) + ->setParent($parent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $foldersClient->listFolders($parent); + $response = $foldersClient->listFolders($request); /** @var Folder $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/FoldersClient/move_folder.php b/ResourceManager/samples/V3/FoldersClient/move_folder.php index d3a8fc6a46c2..fe0045c6780d 100644 --- a/ResourceManager/samples/V3/FoldersClient/move_folder.php +++ b/ResourceManager/samples/V3/FoldersClient/move_folder.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Folders_MoveFolder_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; use Google\Cloud\ResourceManager\V3\Folder; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\ResourceManager\V3\MoveFolderRequest; use Google\Rpc\Status; /** @@ -60,10 +61,15 @@ function move_folder_sample(string $formattedName, string $destinationParent): v // Create a client. $foldersClient = new FoldersClient(); + // Prepare the request message. + $request = (new MoveFolderRequest()) + ->setName($formattedName) + ->setDestinationParent($destinationParent); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $foldersClient->moveFolder($formattedName, $destinationParent); + $response = $foldersClient->moveFolder($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/FoldersClient/search_folders.php b/ResourceManager/samples/V3/FoldersClient/search_folders.php index 22ae631ef24c..d4e1a24e6519 100644 --- a/ResourceManager/samples/V3/FoldersClient/search_folders.php +++ b/ResourceManager/samples/V3/FoldersClient/search_folders.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Folders_SearchFolders_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; use Google\Cloud\ResourceManager\V3\Folder; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\ResourceManager\V3\SearchFoldersRequest; /** * Search for folders that match specific filter criteria. @@ -47,10 +48,13 @@ function search_folders_sample(): void // Create a client. $foldersClient = new FoldersClient(); + // Prepare the request message. + $request = new SearchFoldersRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $foldersClient->searchFolders(); + $response = $foldersClient->searchFolders($request); /** @var Folder $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/FoldersClient/set_iam_policy.php b/ResourceManager/samples/V3/FoldersClient/set_iam_policy.php index cf0329154d73..5ca95ce14f8d 100644 --- a/ResourceManager/samples/V3/FoldersClient/set_iam_policy.php +++ b/ResourceManager/samples/V3/FoldersClient/set_iam_policy.php @@ -25,7 +25,8 @@ // [START cloudresourcemanager_v3_generated_Folders_SetIamPolicy_sync] use Google\ApiCore\ApiException; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; /** * Sets the access control policy on a folder, replacing any existing policy. @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $foldersClient = new FoldersClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $foldersClient->setIamPolicy($resource, $policy); + $response = $foldersClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/FoldersClient/test_iam_permissions.php b/ResourceManager/samples/V3/FoldersClient/test_iam_permissions.php index 302d75760c8f..58584323cb38 100644 --- a/ResourceManager/samples/V3/FoldersClient/test_iam_permissions.php +++ b/ResourceManager/samples/V3/FoldersClient/test_iam_permissions.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Folders_TestIamPermissions_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; /** * Returns permissions that a caller has on the specified folder. @@ -46,13 +47,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $foldersClient = new FoldersClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $foldersClient->testIamPermissions($resource, $permissions); + $response = $foldersClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/FoldersClient/undelete_folder.php b/ResourceManager/samples/V3/FoldersClient/undelete_folder.php index 4493f3fff476..6f93ba547efb 100644 --- a/ResourceManager/samples/V3/FoldersClient/undelete_folder.php +++ b/ResourceManager/samples/V3/FoldersClient/undelete_folder.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Folders_UndeleteFolder_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; use Google\Cloud\ResourceManager\V3\Folder; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\ResourceManager\V3\UndeleteFolderRequest; use Google\Rpc\Status; /** @@ -51,10 +52,14 @@ function undelete_folder_sample(string $formattedName): void // Create a client. $foldersClient = new FoldersClient(); + // Prepare the request message. + $request = (new UndeleteFolderRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $foldersClient->undeleteFolder($formattedName); + $response = $foldersClient->undeleteFolder($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/FoldersClient/update_folder.php b/ResourceManager/samples/V3/FoldersClient/update_folder.php index 361b9545768f..e5022ded0ae3 100644 --- a/ResourceManager/samples/V3/FoldersClient/update_folder.php +++ b/ResourceManager/samples/V3/FoldersClient/update_folder.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Folders_UpdateFolder_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; use Google\Cloud\ResourceManager\V3\Folder; -use Google\Cloud\ResourceManager\V3\FoldersClient; +use Google\Cloud\ResourceManager\V3\UpdateFolderRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -58,15 +59,18 @@ function update_folder_sample(string $folderParent): void // Create a client. $foldersClient = new FoldersClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $folder = (new Folder()) ->setParent($folderParent); $updateMask = new FieldMask(); + $request = (new UpdateFolderRequest()) + ->setFolder($folder) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $foldersClient->updateFolder($folder, $updateMask); + $response = $foldersClient->updateFolder($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/OrganizationsClient/get_iam_policy.php b/ResourceManager/samples/V3/OrganizationsClient/get_iam_policy.php index aee5c1803127..d6c411b16cde 100644 --- a/ResourceManager/samples/V3/OrganizationsClient/get_iam_policy.php +++ b/ResourceManager/samples/V3/OrganizationsClient/get_iam_policy.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Organizations_GetIamPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\OrganizationsClient; +use Google\Cloud\ResourceManager\V3\Client\OrganizationsClient; /** * Gets the access control policy for an organization resource. The policy may @@ -43,10 +44,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $organizationsClient = new OrganizationsClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $organizationsClient->getIamPolicy($resource); + $response = $organizationsClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/OrganizationsClient/get_organization.php b/ResourceManager/samples/V3/OrganizationsClient/get_organization.php index 0f9d66daddf8..fadf426d1bc6 100644 --- a/ResourceManager/samples/V3/OrganizationsClient/get_organization.php +++ b/ResourceManager/samples/V3/OrganizationsClient/get_organization.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Organizations_GetOrganization_sync] use Google\ApiCore\ApiException; +use Google\Cloud\ResourceManager\V3\Client\OrganizationsClient; +use Google\Cloud\ResourceManager\V3\GetOrganizationRequest; use Google\Cloud\ResourceManager\V3\Organization; -use Google\Cloud\ResourceManager\V3\OrganizationsClient; /** * Fetches an organization resource identified by the specified resource name. @@ -40,10 +41,14 @@ function get_organization_sample(string $formattedName): void // Create a client. $organizationsClient = new OrganizationsClient(); + // Prepare the request message. + $request = (new GetOrganizationRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Organization $response */ - $response = $organizationsClient->getOrganization($formattedName); + $response = $organizationsClient->getOrganization($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/OrganizationsClient/search_organizations.php b/ResourceManager/samples/V3/OrganizationsClient/search_organizations.php index 9d998e978b54..cda743204dad 100644 --- a/ResourceManager/samples/V3/OrganizationsClient/search_organizations.php +++ b/ResourceManager/samples/V3/OrganizationsClient/search_organizations.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Organizations_SearchOrganizations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\OrganizationsClient; use Google\Cloud\ResourceManager\V3\Organization; -use Google\Cloud\ResourceManager\V3\OrganizationsClient; +use Google\Cloud\ResourceManager\V3\SearchOrganizationsRequest; /** * Searches organization resources that are visible to the user and satisfy @@ -48,10 +49,13 @@ function search_organizations_sample(): void // Create a client. $organizationsClient = new OrganizationsClient(); + // Prepare the request message. + $request = new SearchOrganizationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $organizationsClient->searchOrganizations(); + $response = $organizationsClient->searchOrganizations($request); /** @var Organization $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/OrganizationsClient/set_iam_policy.php b/ResourceManager/samples/V3/OrganizationsClient/set_iam_policy.php index 8c37d4e8bdbb..6b9b9fd906f5 100644 --- a/ResourceManager/samples/V3/OrganizationsClient/set_iam_policy.php +++ b/ResourceManager/samples/V3/OrganizationsClient/set_iam_policy.php @@ -25,7 +25,8 @@ // [START cloudresourcemanager_v3_generated_Organizations_SetIamPolicy_sync] use Google\ApiCore\ApiException; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\OrganizationsClient; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; +use Google\Cloud\ResourceManager\V3\Client\OrganizationsClient; /** * Sets the access control policy on an organization resource. Replaces any @@ -43,13 +44,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $organizationsClient = new OrganizationsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $organizationsClient->setIamPolicy($resource, $policy); + $response = $organizationsClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/OrganizationsClient/test_iam_permissions.php b/ResourceManager/samples/V3/OrganizationsClient/test_iam_permissions.php index 23e92074460d..04ac6564b06a 100644 --- a/ResourceManager/samples/V3/OrganizationsClient/test_iam_permissions.php +++ b/ResourceManager/samples/V3/OrganizationsClient/test_iam_permissions.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Organizations_TestIamPermissions_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; -use Google\Cloud\ResourceManager\V3\OrganizationsClient; +use Google\Cloud\ResourceManager\V3\Client\OrganizationsClient; /** * Returns the permissions that a caller has on the specified organization. @@ -46,13 +47,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $organizationsClient = new OrganizationsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $organizationsClient->testIamPermissions($resource, $permissions); + $response = $organizationsClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/ProjectsClient/create_project.php b/ResourceManager/samples/V3/ProjectsClient/create_project.php index 429a35de4db7..4e9bfe2ec888 100644 --- a/ResourceManager/samples/V3/ProjectsClient/create_project.php +++ b/ResourceManager/samples/V3/ProjectsClient/create_project.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Projects_CreateProject_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; +use Google\Cloud\ResourceManager\V3\CreateProjectRequest; use Google\Cloud\ResourceManager\V3\Project; -use Google\Cloud\ResourceManager\V3\ProjectsClient; use Google\Rpc\Status; /** @@ -47,13 +48,15 @@ function create_project_sample(): void // Create a client. $projectsClient = new ProjectsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $project = new Project(); + $request = (new CreateProjectRequest()) + ->setProject($project); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $projectsClient->createProject($project); + $response = $projectsClient->createProject($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/ProjectsClient/delete_project.php b/ResourceManager/samples/V3/ProjectsClient/delete_project.php index 6f8e30fd9244..6e5fbf0ff857 100644 --- a/ResourceManager/samples/V3/ProjectsClient/delete_project.php +++ b/ResourceManager/samples/V3/ProjectsClient/delete_project.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Projects_DeleteProject_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; +use Google\Cloud\ResourceManager\V3\DeleteProjectRequest; use Google\Cloud\ResourceManager\V3\Project; -use Google\Cloud\ResourceManager\V3\ProjectsClient; use Google\Rpc\Status; /** @@ -72,10 +73,14 @@ function delete_project_sample(string $formattedName): void // Create a client. $projectsClient = new ProjectsClient(); + // Prepare the request message. + $request = (new DeleteProjectRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $projectsClient->deleteProject($formattedName); + $response = $projectsClient->deleteProject($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/ProjectsClient/get_iam_policy.php b/ResourceManager/samples/V3/ProjectsClient/get_iam_policy.php index 6f9752d0a838..4e207583fb95 100644 --- a/ResourceManager/samples/V3/ProjectsClient/get_iam_policy.php +++ b/ResourceManager/samples/V3/ProjectsClient/get_iam_policy.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Projects_GetIamPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\ProjectsClient; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; /** * Returns the IAM access control policy for the specified project, in the @@ -40,10 +41,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $projectsClient = new ProjectsClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $projectsClient->getIamPolicy($resource); + $response = $projectsClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/ProjectsClient/get_project.php b/ResourceManager/samples/V3/ProjectsClient/get_project.php index 59146e4ffd1c..1e04ac929db1 100644 --- a/ResourceManager/samples/V3/ProjectsClient/get_project.php +++ b/ResourceManager/samples/V3/ProjectsClient/get_project.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Projects_GetProject_sync] use Google\ApiCore\ApiException; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; +use Google\Cloud\ResourceManager\V3\GetProjectRequest; use Google\Cloud\ResourceManager\V3\Project; -use Google\Cloud\ResourceManager\V3\ProjectsClient; /** * Retrieves the project identified by the specified `name` (for example, @@ -42,10 +43,14 @@ function get_project_sample(string $formattedName): void // Create a client. $projectsClient = new ProjectsClient(); + // Prepare the request message. + $request = (new GetProjectRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Project $response */ - $response = $projectsClient->getProject($formattedName); + $response = $projectsClient->getProject($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/ProjectsClient/list_projects.php b/ResourceManager/samples/V3/ProjectsClient/list_projects.php index 2c65b10c7914..1f6713eb54e0 100644 --- a/ResourceManager/samples/V3/ProjectsClient/list_projects.php +++ b/ResourceManager/samples/V3/ProjectsClient/list_projects.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Projects_ListProjects_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; +use Google\Cloud\ResourceManager\V3\ListProjectsRequest; use Google\Cloud\ResourceManager\V3\Project; -use Google\Cloud\ResourceManager\V3\ProjectsClient; /** * Lists projects that are direct children of the specified folder or @@ -48,10 +49,14 @@ function list_projects_sample(string $parent): void // Create a client. $projectsClient = new ProjectsClient(); + // Prepare the request message. + $request = (new ListProjectsRequest()) + ->setParent($parent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $projectsClient->listProjects($parent); + $response = $projectsClient->listProjects($request); /** @var Project $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/ProjectsClient/move_project.php b/ResourceManager/samples/V3/ProjectsClient/move_project.php index f2419c0df8d3..b200daba12cf 100644 --- a/ResourceManager/samples/V3/ProjectsClient/move_project.php +++ b/ResourceManager/samples/V3/ProjectsClient/move_project.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Projects_MoveProject_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; +use Google\Cloud\ResourceManager\V3\MoveProjectRequest; use Google\Cloud\ResourceManager\V3\Project; -use Google\Cloud\ResourceManager\V3\ProjectsClient; use Google\Rpc\Status; /** @@ -56,10 +57,15 @@ function move_project_sample(string $formattedName, string $destinationParent): // Create a client. $projectsClient = new ProjectsClient(); + // Prepare the request message. + $request = (new MoveProjectRequest()) + ->setName($formattedName) + ->setDestinationParent($destinationParent); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $projectsClient->moveProject($formattedName, $destinationParent); + $response = $projectsClient->moveProject($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/ProjectsClient/search_projects.php b/ResourceManager/samples/V3/ProjectsClient/search_projects.php index 146e90b3dd00..253ea3c5739f 100644 --- a/ResourceManager/samples/V3/ProjectsClient/search_projects.php +++ b/ResourceManager/samples/V3/ProjectsClient/search_projects.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Projects_SearchProjects_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; use Google\Cloud\ResourceManager\V3\Project; -use Google\Cloud\ResourceManager\V3\ProjectsClient; +use Google\Cloud\ResourceManager\V3\SearchProjectsRequest; /** * Search for projects that the caller has both `resourcemanager.projects.get` @@ -51,10 +52,13 @@ function search_projects_sample(): void // Create a client. $projectsClient = new ProjectsClient(); + // Prepare the request message. + $request = new SearchProjectsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $projectsClient->searchProjects(); + $response = $projectsClient->searchProjects($request); /** @var Project $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/ProjectsClient/set_iam_policy.php b/ResourceManager/samples/V3/ProjectsClient/set_iam_policy.php index bf947e14a840..fb55b8a80cb7 100644 --- a/ResourceManager/samples/V3/ProjectsClient/set_iam_policy.php +++ b/ResourceManager/samples/V3/ProjectsClient/set_iam_policy.php @@ -25,7 +25,8 @@ // [START cloudresourcemanager_v3_generated_Projects_SetIamPolicy_sync] use Google\ApiCore\ApiException; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\ProjectsClient; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; /** * Sets the IAM access control policy for the specified project, in the @@ -78,13 +79,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $projectsClient = new ProjectsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $projectsClient->setIamPolicy($resource, $policy); + $response = $projectsClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/ProjectsClient/test_iam_permissions.php b/ResourceManager/samples/V3/ProjectsClient/test_iam_permissions.php index d165cb2f12ee..6d248a633990 100644 --- a/ResourceManager/samples/V3/ProjectsClient/test_iam_permissions.php +++ b/ResourceManager/samples/V3/ProjectsClient/test_iam_permissions.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_Projects_TestIamPermissions_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; -use Google\Cloud\ResourceManager\V3\ProjectsClient; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; /** * Returns permissions that a caller has on the specified project, in the @@ -43,13 +44,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $projectsClient = new ProjectsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $projectsClient->testIamPermissions($resource, $permissions); + $response = $projectsClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/ProjectsClient/undelete_project.php b/ResourceManager/samples/V3/ProjectsClient/undelete_project.php index f8472a3a73cd..29bfa0c43c5b 100644 --- a/ResourceManager/samples/V3/ProjectsClient/undelete_project.php +++ b/ResourceManager/samples/V3/ProjectsClient/undelete_project.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Projects_UndeleteProject_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; use Google\Cloud\ResourceManager\V3\Project; -use Google\Cloud\ResourceManager\V3\ProjectsClient; +use Google\Cloud\ResourceManager\V3\UndeleteProjectRequest; use Google\Rpc\Status; /** @@ -50,10 +51,14 @@ function undelete_project_sample(string $formattedName): void // Create a client. $projectsClient = new ProjectsClient(); + // Prepare the request message. + $request = (new UndeleteProjectRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $projectsClient->undeleteProject($formattedName); + $response = $projectsClient->undeleteProject($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/ProjectsClient/update_project.php b/ResourceManager/samples/V3/ProjectsClient/update_project.php index 1b80633735c0..aeb3e5a1634b 100644 --- a/ResourceManager/samples/V3/ProjectsClient/update_project.php +++ b/ResourceManager/samples/V3/ProjectsClient/update_project.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_Projects_UpdateProject_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\ProjectsClient; use Google\Cloud\ResourceManager\V3\Project; -use Google\Cloud\ResourceManager\V3\ProjectsClient; +use Google\Cloud\ResourceManager\V3\UpdateProjectRequest; use Google\Rpc\Status; /** @@ -48,13 +49,15 @@ function update_project_sample(): void // Create a client. $projectsClient = new ProjectsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $project = new Project(); + $request = (new UpdateProjectRequest()) + ->setProject($project); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $projectsClient->updateProject($project); + $response = $projectsClient->updateProject($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagBindingsClient/create_tag_binding.php b/ResourceManager/samples/V3/TagBindingsClient/create_tag_binding.php index 214f774ad420..9c9c41d6d608 100644 --- a/ResourceManager/samples/V3/TagBindingsClient/create_tag_binding.php +++ b/ResourceManager/samples/V3/TagBindingsClient/create_tag_binding.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagBindings_CreateTagBinding_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\TagBindingsClient; +use Google\Cloud\ResourceManager\V3\CreateTagBindingRequest; use Google\Cloud\ResourceManager\V3\TagBinding; -use Google\Cloud\ResourceManager\V3\TagBindingsClient; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function create_tag_binding_sample(): void // Create a client. $tagBindingsClient = new TagBindingsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $tagBinding = new TagBinding(); + $request = (new CreateTagBindingRequest()) + ->setTagBinding($tagBinding); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagBindingsClient->createTagBinding($tagBinding); + $response = $tagBindingsClient->createTagBinding($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagBindingsClient/delete_tag_binding.php b/ResourceManager/samples/V3/TagBindingsClient/delete_tag_binding.php index 964cb356fa50..10079d8e49d4 100644 --- a/ResourceManager/samples/V3/TagBindingsClient/delete_tag_binding.php +++ b/ResourceManager/samples/V3/TagBindingsClient/delete_tag_binding.php @@ -25,7 +25,8 @@ // [START cloudresourcemanager_v3_generated_TagBindings_DeleteTagBinding_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\ResourceManager\V3\TagBindingsClient; +use Google\Cloud\ResourceManager\V3\Client\TagBindingsClient; +use Google\Cloud\ResourceManager\V3\DeleteTagBindingRequest; use Google\Rpc\Status; /** @@ -41,10 +42,14 @@ function delete_tag_binding_sample(string $formattedName): void // Create a client. $tagBindingsClient = new TagBindingsClient(); + // Prepare the request message. + $request = (new DeleteTagBindingRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagBindingsClient->deleteTagBinding($formattedName); + $response = $tagBindingsClient->deleteTagBinding($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagBindingsClient/list_effective_tags.php b/ResourceManager/samples/V3/TagBindingsClient/list_effective_tags.php index 19126e25c07b..84ca7d0146a3 100644 --- a/ResourceManager/samples/V3/TagBindingsClient/list_effective_tags.php +++ b/ResourceManager/samples/V3/TagBindingsClient/list_effective_tags.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagBindings_ListEffectiveTags_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\TagBindingsClient; use Google\Cloud\ResourceManager\V3\EffectiveTag; -use Google\Cloud\ResourceManager\V3\TagBindingsClient; +use Google\Cloud\ResourceManager\V3\ListEffectiveTagsRequest; /** * Return a list of effective tags for the given Google Cloud resource, as @@ -41,10 +42,14 @@ function list_effective_tags_sample(string $parent): void // Create a client. $tagBindingsClient = new TagBindingsClient(); + // Prepare the request message. + $request = (new ListEffectiveTagsRequest()) + ->setParent($parent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $tagBindingsClient->listEffectiveTags($parent); + $response = $tagBindingsClient->listEffectiveTags($request); /** @var EffectiveTag $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/TagBindingsClient/list_tag_bindings.php b/ResourceManager/samples/V3/TagBindingsClient/list_tag_bindings.php index 116b95af2b0b..b143a2c776a4 100644 --- a/ResourceManager/samples/V3/TagBindingsClient/list_tag_bindings.php +++ b/ResourceManager/samples/V3/TagBindingsClient/list_tag_bindings.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagBindings_ListTagBindings_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\TagBindingsClient; +use Google\Cloud\ResourceManager\V3\ListTagBindingsRequest; use Google\Cloud\ResourceManager\V3\TagBinding; -use Google\Cloud\ResourceManager\V3\TagBindingsClient; /** * Lists the TagBindings for the given Google Cloud resource, as specified @@ -44,10 +45,14 @@ function list_tag_bindings_sample(string $parent): void // Create a client. $tagBindingsClient = new TagBindingsClient(); + // Prepare the request message. + $request = (new ListTagBindingsRequest()) + ->setParent($parent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $tagBindingsClient->listTagBindings($parent); + $response = $tagBindingsClient->listTagBindings($request); /** @var TagBinding $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/TagHoldsClient/create_tag_hold.php b/ResourceManager/samples/V3/TagHoldsClient/create_tag_hold.php index 90a14bc61232..1240aa9a5b07 100644 --- a/ResourceManager/samples/V3/TagHoldsClient/create_tag_hold.php +++ b/ResourceManager/samples/V3/TagHoldsClient/create_tag_hold.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagHolds_CreateTagHold_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\TagHoldsClient; +use Google\Cloud\ResourceManager\V3\CreateTagHoldRequest; use Google\Cloud\ResourceManager\V3\TagHold; -use Google\Cloud\ResourceManager\V3\TagHoldsClient; use Google\Rpc\Status; /** @@ -45,14 +46,17 @@ function create_tag_hold_sample(string $formattedParent, string $tagHoldHolder): // Create a client. $tagHoldsClient = new TagHoldsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $tagHold = (new TagHold()) ->setHolder($tagHoldHolder); + $request = (new CreateTagHoldRequest()) + ->setParent($formattedParent) + ->setTagHold($tagHold); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagHoldsClient->createTagHold($formattedParent, $tagHold); + $response = $tagHoldsClient->createTagHold($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagHoldsClient/delete_tag_hold.php b/ResourceManager/samples/V3/TagHoldsClient/delete_tag_hold.php index 24f7a23098a9..680a3dfce1dc 100644 --- a/ResourceManager/samples/V3/TagHoldsClient/delete_tag_hold.php +++ b/ResourceManager/samples/V3/TagHoldsClient/delete_tag_hold.php @@ -25,7 +25,8 @@ // [START cloudresourcemanager_v3_generated_TagHolds_DeleteTagHold_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\ResourceManager\V3\TagHoldsClient; +use Google\Cloud\ResourceManager\V3\Client\TagHoldsClient; +use Google\Cloud\ResourceManager\V3\DeleteTagHoldRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_tag_hold_sample(string $formattedName): void // Create a client. $tagHoldsClient = new TagHoldsClient(); + // Prepare the request message. + $request = (new DeleteTagHoldRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagHoldsClient->deleteTagHold($formattedName); + $response = $tagHoldsClient->deleteTagHold($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagHoldsClient/list_tag_holds.php b/ResourceManager/samples/V3/TagHoldsClient/list_tag_holds.php index fd28f5d5a69e..550724f77e54 100644 --- a/ResourceManager/samples/V3/TagHoldsClient/list_tag_holds.php +++ b/ResourceManager/samples/V3/TagHoldsClient/list_tag_holds.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagHolds_ListTagHolds_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\TagHoldsClient; +use Google\Cloud\ResourceManager\V3\ListTagHoldsRequest; use Google\Cloud\ResourceManager\V3\TagHold; -use Google\Cloud\ResourceManager\V3\TagHoldsClient; /** * Lists TagHolds under a TagValue. @@ -40,10 +41,14 @@ function list_tag_holds_sample(string $formattedParent): void // Create a client. $tagHoldsClient = new TagHoldsClient(); + // Prepare the request message. + $request = (new ListTagHoldsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $tagHoldsClient->listTagHolds($formattedParent); + $response = $tagHoldsClient->listTagHolds($request); /** @var TagHold $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/TagKeysClient/create_tag_key.php b/ResourceManager/samples/V3/TagKeysClient/create_tag_key.php index 62c356318e80..4563dbd6d61e 100644 --- a/ResourceManager/samples/V3/TagKeysClient/create_tag_key.php +++ b/ResourceManager/samples/V3/TagKeysClient/create_tag_key.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagKeys_CreateTagKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; +use Google\Cloud\ResourceManager\V3\CreateTagKeyRequest; use Google\Cloud\ResourceManager\V3\TagKey; -use Google\Cloud\ResourceManager\V3\TagKeysClient; use Google\Rpc\Status; /** @@ -47,14 +48,16 @@ function create_tag_key_sample(string $tagKeyShortName): void // Create a client. $tagKeysClient = new TagKeysClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $tagKey = (new TagKey()) ->setShortName($tagKeyShortName); + $request = (new CreateTagKeyRequest()) + ->setTagKey($tagKey); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagKeysClient->createTagKey($tagKey); + $response = $tagKeysClient->createTagKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagKeysClient/delete_tag_key.php b/ResourceManager/samples/V3/TagKeysClient/delete_tag_key.php index a8d88b0a85a5..4bfc5e744423 100644 --- a/ResourceManager/samples/V3/TagKeysClient/delete_tag_key.php +++ b/ResourceManager/samples/V3/TagKeysClient/delete_tag_key.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagKeys_DeleteTagKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; +use Google\Cloud\ResourceManager\V3\DeleteTagKeyRequest; use Google\Cloud\ResourceManager\V3\TagKey; -use Google\Cloud\ResourceManager\V3\TagKeysClient; use Google\Rpc\Status; /** @@ -43,10 +44,14 @@ function delete_tag_key_sample(string $formattedName): void // Create a client. $tagKeysClient = new TagKeysClient(); + // Prepare the request message. + $request = (new DeleteTagKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagKeysClient->deleteTagKey($formattedName); + $response = $tagKeysClient->deleteTagKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagKeysClient/get_iam_policy.php b/ResourceManager/samples/V3/TagKeysClient/get_iam_policy.php index 3436c94497c0..90d405767c06 100644 --- a/ResourceManager/samples/V3/TagKeysClient/get_iam_policy.php +++ b/ResourceManager/samples/V3/TagKeysClient/get_iam_policy.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_TagKeys_GetIamPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\TagKeysClient; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; /** * Gets the access control policy for a TagKey. The returned policy may be @@ -43,10 +44,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $tagKeysClient = new TagKeysClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $tagKeysClient->getIamPolicy($resource); + $response = $tagKeysClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagKeysClient/get_namespaced_tag_key.php b/ResourceManager/samples/V3/TagKeysClient/get_namespaced_tag_key.php index 7a0fe86e4f2d..e9dc5ebdade7 100644 --- a/ResourceManager/samples/V3/TagKeysClient/get_namespaced_tag_key.php +++ b/ResourceManager/samples/V3/TagKeysClient/get_namespaced_tag_key.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_TagKeys_GetNamespacedTagKey_sync] use Google\ApiCore\ApiException; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; +use Google\Cloud\ResourceManager\V3\GetNamespacedTagKeyRequest; use Google\Cloud\ResourceManager\V3\TagKey; -use Google\Cloud\ResourceManager\V3\TagKeysClient; /** * Retrieves a TagKey by its namespaced name. @@ -43,10 +44,14 @@ function get_namespaced_tag_key_sample(string $formattedName): void // Create a client. $tagKeysClient = new TagKeysClient(); + // Prepare the request message. + $request = (new GetNamespacedTagKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var TagKey $response */ - $response = $tagKeysClient->getNamespacedTagKey($formattedName); + $response = $tagKeysClient->getNamespacedTagKey($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagKeysClient/get_tag_key.php b/ResourceManager/samples/V3/TagKeysClient/get_tag_key.php index 55fce6ac2164..9d2233ded784 100644 --- a/ResourceManager/samples/V3/TagKeysClient/get_tag_key.php +++ b/ResourceManager/samples/V3/TagKeysClient/get_tag_key.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_TagKeys_GetTagKey_sync] use Google\ApiCore\ApiException; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; +use Google\Cloud\ResourceManager\V3\GetTagKeyRequest; use Google\Cloud\ResourceManager\V3\TagKey; -use Google\Cloud\ResourceManager\V3\TagKeysClient; /** * Retrieves a TagKey. This method will return `PERMISSION_DENIED` if the @@ -40,10 +41,14 @@ function get_tag_key_sample(string $formattedName): void // Create a client. $tagKeysClient = new TagKeysClient(); + // Prepare the request message. + $request = (new GetTagKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var TagKey $response */ - $response = $tagKeysClient->getTagKey($formattedName); + $response = $tagKeysClient->getTagKey($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagKeysClient/list_tag_keys.php b/ResourceManager/samples/V3/TagKeysClient/list_tag_keys.php index eeca46427dca..9274385e1f26 100644 --- a/ResourceManager/samples/V3/TagKeysClient/list_tag_keys.php +++ b/ResourceManager/samples/V3/TagKeysClient/list_tag_keys.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagKeys_ListTagKeys_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; +use Google\Cloud\ResourceManager\V3\ListTagKeysRequest; use Google\Cloud\ResourceManager\V3\TagKey; -use Google\Cloud\ResourceManager\V3\TagKeysClient; /** * Lists all TagKeys for a parent resource. @@ -40,10 +41,14 @@ function list_tag_keys_sample(string $parent): void // Create a client. $tagKeysClient = new TagKeysClient(); + // Prepare the request message. + $request = (new ListTagKeysRequest()) + ->setParent($parent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $tagKeysClient->listTagKeys($parent); + $response = $tagKeysClient->listTagKeys($request); /** @var TagKey $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/TagKeysClient/set_iam_policy.php b/ResourceManager/samples/V3/TagKeysClient/set_iam_policy.php index 24c61e8acbc6..34a9640d202a 100644 --- a/ResourceManager/samples/V3/TagKeysClient/set_iam_policy.php +++ b/ResourceManager/samples/V3/TagKeysClient/set_iam_policy.php @@ -25,7 +25,8 @@ // [START cloudresourcemanager_v3_generated_TagKeys_SetIamPolicy_sync] use Google\ApiCore\ApiException; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\TagKeysClient; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; /** * Sets the access control policy on a TagKey, replacing any existing @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $tagKeysClient = new TagKeysClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $tagKeysClient->setIamPolicy($resource, $policy); + $response = $tagKeysClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagKeysClient/test_iam_permissions.php b/ResourceManager/samples/V3/TagKeysClient/test_iam_permissions.php index 8feb038e586c..3603ce38c90e 100644 --- a/ResourceManager/samples/V3/TagKeysClient/test_iam_permissions.php +++ b/ResourceManager/samples/V3/TagKeysClient/test_iam_permissions.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_TagKeys_TestIamPermissions_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; -use Google\Cloud\ResourceManager\V3\TagKeysClient; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; /** * Returns permissions that a caller has on the specified TagKey. @@ -46,13 +47,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $tagKeysClient = new TagKeysClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $tagKeysClient->testIamPermissions($resource, $permissions); + $response = $tagKeysClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagKeysClient/update_tag_key.php b/ResourceManager/samples/V3/TagKeysClient/update_tag_key.php index ba7caf16478c..7be53874efd4 100644 --- a/ResourceManager/samples/V3/TagKeysClient/update_tag_key.php +++ b/ResourceManager/samples/V3/TagKeysClient/update_tag_key.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagKeys_UpdateTagKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\TagKeysClient; use Google\Cloud\ResourceManager\V3\TagKey; -use Google\Cloud\ResourceManager\V3\TagKeysClient; +use Google\Cloud\ResourceManager\V3\UpdateTagKeyRequest; use Google\Rpc\Status; /** @@ -44,14 +45,16 @@ function update_tag_key_sample(string $tagKeyShortName): void // Create a client. $tagKeysClient = new TagKeysClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $tagKey = (new TagKey()) ->setShortName($tagKeyShortName); + $request = (new UpdateTagKeyRequest()) + ->setTagKey($tagKey); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagKeysClient->updateTagKey($tagKey); + $response = $tagKeysClient->updateTagKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagValuesClient/create_tag_value.php b/ResourceManager/samples/V3/TagValuesClient/create_tag_value.php index a8242ab9bf86..cdfb1beae450 100644 --- a/ResourceManager/samples/V3/TagValuesClient/create_tag_value.php +++ b/ResourceManager/samples/V3/TagValuesClient/create_tag_value.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagValues_CreateTagValue_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; +use Google\Cloud\ResourceManager\V3\CreateTagValueRequest; use Google\Cloud\ResourceManager\V3\TagValue; -use Google\Cloud\ResourceManager\V3\TagValuesClient; use Google\Rpc\Status; /** @@ -47,14 +48,16 @@ function create_tag_value_sample(string $tagValueShortName): void // Create a client. $tagValuesClient = new TagValuesClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $tagValue = (new TagValue()) ->setShortName($tagValueShortName); + $request = (new CreateTagValueRequest()) + ->setTagValue($tagValue); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagValuesClient->createTagValue($tagValue); + $response = $tagValuesClient->createTagValue($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagValuesClient/delete_tag_value.php b/ResourceManager/samples/V3/TagValuesClient/delete_tag_value.php index feeefc126b17..cb1c1e85b7a6 100644 --- a/ResourceManager/samples/V3/TagValuesClient/delete_tag_value.php +++ b/ResourceManager/samples/V3/TagValuesClient/delete_tag_value.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagValues_DeleteTagValue_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; +use Google\Cloud\ResourceManager\V3\DeleteTagValueRequest; use Google\Cloud\ResourceManager\V3\TagValue; -use Google\Cloud\ResourceManager\V3\TagValuesClient; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function delete_tag_value_sample(string $formattedName): void // Create a client. $tagValuesClient = new TagValuesClient(); + // Prepare the request message. + $request = (new DeleteTagValueRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagValuesClient->deleteTagValue($formattedName); + $response = $tagValuesClient->deleteTagValue($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/samples/V3/TagValuesClient/get_iam_policy.php b/ResourceManager/samples/V3/TagValuesClient/get_iam_policy.php index 5a7131145c77..6ea4ab175994 100644 --- a/ResourceManager/samples/V3/TagValuesClient/get_iam_policy.php +++ b/ResourceManager/samples/V3/TagValuesClient/get_iam_policy.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_TagValues_GetIamPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\TagValuesClient; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; /** * Gets the access control policy for a TagValue. The returned policy may be @@ -43,10 +44,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $tagValuesClient = new TagValuesClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $tagValuesClient->getIamPolicy($resource); + $response = $tagValuesClient->getIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagValuesClient/get_namespaced_tag_value.php b/ResourceManager/samples/V3/TagValuesClient/get_namespaced_tag_value.php index 9703e6d491af..57d917cca004 100644 --- a/ResourceManager/samples/V3/TagValuesClient/get_namespaced_tag_value.php +++ b/ResourceManager/samples/V3/TagValuesClient/get_namespaced_tag_value.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_TagValues_GetNamespacedTagValue_sync] use Google\ApiCore\ApiException; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; +use Google\Cloud\ResourceManager\V3\GetNamespacedTagValueRequest; use Google\Cloud\ResourceManager\V3\TagValue; -use Google\Cloud\ResourceManager\V3\TagValuesClient; /** * Retrieves a TagValue by its namespaced name. @@ -48,10 +49,14 @@ function get_namespaced_tag_value_sample(string $formattedName): void // Create a client. $tagValuesClient = new TagValuesClient(); + // Prepare the request message. + $request = (new GetNamespacedTagValueRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var TagValue $response */ - $response = $tagValuesClient->getNamespacedTagValue($formattedName); + $response = $tagValuesClient->getNamespacedTagValue($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagValuesClient/get_tag_value.php b/ResourceManager/samples/V3/TagValuesClient/get_tag_value.php index 4fdc8361c72b..3a6c4530e7ef 100644 --- a/ResourceManager/samples/V3/TagValuesClient/get_tag_value.php +++ b/ResourceManager/samples/V3/TagValuesClient/get_tag_value.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_TagValues_GetTagValue_sync] use Google\ApiCore\ApiException; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; +use Google\Cloud\ResourceManager\V3\GetTagValueRequest; use Google\Cloud\ResourceManager\V3\TagValue; -use Google\Cloud\ResourceManager\V3\TagValuesClient; /** * Retrieves a TagValue. This method will return `PERMISSION_DENIED` if the @@ -40,10 +41,14 @@ function get_tag_value_sample(string $formattedName): void // Create a client. $tagValuesClient = new TagValuesClient(); + // Prepare the request message. + $request = (new GetTagValueRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var TagValue $response */ - $response = $tagValuesClient->getTagValue($formattedName); + $response = $tagValuesClient->getTagValue($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagValuesClient/list_tag_values.php b/ResourceManager/samples/V3/TagValuesClient/list_tag_values.php index c3645f21596f..0dc34ea942c5 100644 --- a/ResourceManager/samples/V3/TagValuesClient/list_tag_values.php +++ b/ResourceManager/samples/V3/TagValuesClient/list_tag_values.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagValues_ListTagValues_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; +use Google\Cloud\ResourceManager\V3\ListTagValuesRequest; use Google\Cloud\ResourceManager\V3\TagValue; -use Google\Cloud\ResourceManager\V3\TagValuesClient; /** * Lists all TagValues for a specific TagKey. @@ -38,10 +39,14 @@ function list_tag_values_sample(string $parent): void // Create a client. $tagValuesClient = new TagValuesClient(); + // Prepare the request message. + $request = (new ListTagValuesRequest()) + ->setParent($parent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $tagValuesClient->listTagValues($parent); + $response = $tagValuesClient->listTagValues($request); /** @var TagValue $element */ foreach ($response as $element) { diff --git a/ResourceManager/samples/V3/TagValuesClient/set_iam_policy.php b/ResourceManager/samples/V3/TagValuesClient/set_iam_policy.php index d81e0db16d11..dfcdd02b7503 100644 --- a/ResourceManager/samples/V3/TagValuesClient/set_iam_policy.php +++ b/ResourceManager/samples/V3/TagValuesClient/set_iam_policy.php @@ -25,7 +25,8 @@ // [START cloudresourcemanager_v3_generated_TagValues_SetIamPolicy_sync] use Google\ApiCore\ApiException; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\ResourceManager\V3\TagValuesClient; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; /** * Sets the access control policy on a TagValue, replacing any existing @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $tagValuesClient = new TagValuesClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $tagValuesClient->setIamPolicy($resource, $policy); + $response = $tagValuesClient->setIamPolicy($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagValuesClient/test_iam_permissions.php b/ResourceManager/samples/V3/TagValuesClient/test_iam_permissions.php index 4a7f6dd1f294..1e9b8f56e221 100644 --- a/ResourceManager/samples/V3/TagValuesClient/test_iam_permissions.php +++ b/ResourceManager/samples/V3/TagValuesClient/test_iam_permissions.php @@ -24,8 +24,9 @@ // [START cloudresourcemanager_v3_generated_TagValues_TestIamPermissions_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; -use Google\Cloud\ResourceManager\V3\TagValuesClient; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; /** * Returns permissions that a caller has on the specified TagValue. @@ -46,13 +47,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $tagValuesClient = new TagValuesClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $permissions = [$permissionsElement,]; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); // Call the API and handle any network failures. try { /** @var TestIamPermissionsResponse $response */ - $response = $tagValuesClient->testIamPermissions($resource, $permissions); + $response = $tagValuesClient->testIamPermissions($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/samples/V3/TagValuesClient/update_tag_value.php b/ResourceManager/samples/V3/TagValuesClient/update_tag_value.php index 8fa46231448b..9900dd38b770 100644 --- a/ResourceManager/samples/V3/TagValuesClient/update_tag_value.php +++ b/ResourceManager/samples/V3/TagValuesClient/update_tag_value.php @@ -25,8 +25,9 @@ // [START cloudresourcemanager_v3_generated_TagValues_UpdateTagValue_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\ResourceManager\V3\Client\TagValuesClient; use Google\Cloud\ResourceManager\V3\TagValue; -use Google\Cloud\ResourceManager\V3\TagValuesClient; +use Google\Cloud\ResourceManager\V3\UpdateTagValueRequest; use Google\Rpc\Status; /** @@ -44,14 +45,16 @@ function update_tag_value_sample(string $tagValueShortName): void // Create a client. $tagValuesClient = new TagValuesClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $tagValue = (new TagValue()) ->setShortName($tagValueShortName); + $request = (new UpdateTagValueRequest()) + ->setTagValue($tagValue); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $tagValuesClient->updateTagValue($tagValue); + $response = $tagValuesClient->updateTagValue($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/ResourceManager/src/V3/Client/BaseClient/FoldersBaseClient.php b/ResourceManager/src/V3/Client/BaseClient/FoldersBaseClient.php new file mode 100644 index 000000000000..308817359dfc --- /dev/null +++ b/ResourceManager/src/V3/Client/BaseClient/FoldersBaseClient.php @@ -0,0 +1,638 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/folders_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/folders_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/folders_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/folders_rest_client_config.php', + ], + ], + ]; + } + + /** + * 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; + } + + /** + * Formats a string containing the fully-qualified path to represent a folder + * resource. + * + * @param string $folder + * + * @return string The formatted folder resource. + */ + public static function folderName(string $folder): string + { + return self::getPathTemplate('folder')->render([ + 'folder' => $folder, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - folder: folders/{folder} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'cloudresourcemanager.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a folder in the resource hierarchy. + * Returns an `Operation` which can be used to track the progress of the + * folder creation workflow. + * Upon success, the `Operation.response` field will be populated with the + * created Folder. + * + * In order to succeed, the addition of this new folder must not violate + * the folder naming, height, or fanout constraints. + * + * + The folder's `display_name` must be distinct from all other folders that + * share its parent. + * + The addition of the folder must not cause the active folder hierarchy + * to exceed a height of 10. Note, the full active + deleted folder hierarchy + * is allowed to reach a height of 20; this provides additional headroom when + * moving folders that contain deleted folders. + * + The addition of the folder must not cause the total number of folders + * under its parent to exceed 300. + * + * If the operation fails due to a folder constraint violation, some errors + * may be returned by the `CreateFolder` request, with status code + * `FAILED_PRECONDITION` and an error description. Other folder constraint + * violations will be communicated in the `Operation`, with the specific + * `PreconditionFailure` returned in the details list in the `Operation.error` + * field. + * + * The caller must have `resourcemanager.folders.create` permission on the + * identified parent. + * + * The async variant is {@see self::createFolderAsync()} . + * + * @param CreateFolderRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createFolder(CreateFolderRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateFolder', $request, $callOptions)->wait(); + } + + /** + * Requests deletion of a folder. The folder is moved into the + * [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Folder.State.DELETE_REQUESTED] + * state immediately, and is deleted approximately 30 days later. This method + * may only be called on an empty folder, where a folder is empty if it + * doesn't contain any folders or projects in the + * [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE] state. If + * called on a folder in + * [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Folder.State.DELETE_REQUESTED] + * state the operation will result in a no-op success. + * The caller must have `resourcemanager.folders.delete` permission on the + * identified folder. + * + * The async variant is {@see self::deleteFolderAsync()} . + * + * @param DeleteFolderRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteFolder(DeleteFolderRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteFolder', $request, $callOptions)->wait(); + } + + /** + * Retrieves a folder identified by the supplied resource name. + * Valid folder resource names have the format `folders/{folder_id}` + * (for example, `folders/1234`). + * The caller must have `resourcemanager.folders.get` permission on the + * identified folder. + * + * The async variant is {@see self::getFolderAsync()} . + * + * @param GetFolderRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Folder + * + * @throws ApiException Thrown if the API call fails. + */ + public function getFolder(GetFolderRequest $request, array $callOptions = []): Folder + { + return $this->startApiCall('GetFolder', $request, $callOptions)->wait(); + } + + /** + * Gets the access control policy for a folder. The returned policy may be + * empty if no such policy or resource exists. The `resource` field should + * be the folder's resource name, for example: "folders/1234". + * The caller must have `resourcemanager.folders.getIamPolicy` permission + * on the identified folder. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Lists the folders that are direct descendants of supplied parent resource. + * `list()` provides a strongly consistent view of the folders underneath + * the specified parent resource. + * `list()` returns folders sorted based upon the (ascending) lexical ordering + * of their display_name. + * The caller must have `resourcemanager.folders.list` permission on the + * identified parent. + * + * The async variant is {@see self::listFoldersAsync()} . + * + * @param ListFoldersRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listFolders(ListFoldersRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListFolders', $request, $callOptions); + } + + /** + * Moves a folder under a new resource parent. + * Returns an `Operation` which can be used to track the progress of the + * folder move workflow. + * Upon success, the `Operation.response` field will be populated with the + * moved folder. + * Upon failure, a `FolderOperationError` categorizing the failure cause will + * be returned - if the failure occurs synchronously then the + * `FolderOperationError` will be returned in the `Status.details` field. + * If it occurs asynchronously, then the FolderOperation will be returned + * in the `Operation.error` field. + * In addition, the `Operation.metadata` field will be populated with a + * `FolderOperation` message as an aid to stateless clients. + * Folder moves will be rejected if they violate either the naming, height, + * or fanout constraints described in the + * [CreateFolder][google.cloud.resourcemanager.v3.Folders.CreateFolder] + * documentation. The caller must have `resourcemanager.folders.move` + * permission on the folder's current and proposed new parent. + * + * The async variant is {@see self::moveFolderAsync()} . + * + * @param MoveFolderRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function moveFolder(MoveFolderRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('MoveFolder', $request, $callOptions)->wait(); + } + + /** + * Search for folders that match specific filter criteria. + * `search()` provides an eventually consistent view of the folders a user has + * access to which meet the specified filter criteria. + * + * This will only return folders on which the caller has the + * permission `resourcemanager.folders.get`. + * + * The async variant is {@see self::searchFoldersAsync()} . + * + * @param SearchFoldersRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function searchFolders(SearchFoldersRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchFolders', $request, $callOptions); + } + + /** + * Sets the access control policy on a folder, replacing any existing policy. + * The `resource` field should be the folder's resource name, for example: + * "folders/1234". + * The caller must have `resourcemanager.folders.setIamPolicy` permission + * on the identified folder. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified folder. + * The `resource` field should be the folder's resource name, + * for example: "folders/1234". + * + * There are no permissions required for making this API call. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } + + /** + * Cancels the deletion request for a folder. This method may be called on a + * folder in any state. If the folder is in the + * [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE] state the + * result will be a no-op success. In order to succeed, the folder's parent + * must be in the + * [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE] state. In + * addition, reintroducing the folder into the tree must not violate folder + * naming, height, and fanout constraints described in the + * [CreateFolder][google.cloud.resourcemanager.v3.Folders.CreateFolder] + * documentation. The caller must have `resourcemanager.folders.undelete` + * permission on the identified folder. + * + * The async variant is {@see self::undeleteFolderAsync()} . + * + * @param UndeleteFolderRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function undeleteFolder(UndeleteFolderRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UndeleteFolder', $request, $callOptions)->wait(); + } + + /** + * Updates a folder, changing its `display_name`. + * Changes to the folder `display_name` will be rejected if they violate + * either the `display_name` formatting rules or the naming constraints + * described in the + * [CreateFolder][google.cloud.resourcemanager.v3.Folders.CreateFolder] + * documentation. + * + * The folder's `display_name` must start and end with a letter or digit, + * may contain letters, digits, spaces, hyphens and underscores and can be + * between 3 and 30 characters. This is captured by the regular expression: + * `[\p{L}\p{N}][\p{L}\p{N}_- ]{1,28}[\p{L}\p{N}]`. + * The caller must have `resourcemanager.folders.update` permission on the + * identified folder. + * + * If the update fails due to the unique name constraint then a + * `PreconditionFailure` explaining this violation will be returned + * in the Status.details field. + * + * The async variant is {@see self::updateFolderAsync()} . + * + * @param UpdateFolderRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateFolder(UpdateFolderRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateFolder', $request, $callOptions)->wait(); + } +} diff --git a/ResourceManager/src/V3/Client/BaseClient/OrganizationsBaseClient.php b/ResourceManager/src/V3/Client/BaseClient/OrganizationsBaseClient.php new file mode 100644 index 000000000000..f82fda234ec5 --- /dev/null +++ b/ResourceManager/src/V3/Client/BaseClient/OrganizationsBaseClient.php @@ -0,0 +1,360 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/organizations_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/organizations_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/organizations_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/organizations_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a organization + * resource. + * + * @param string $organization + * + * @return string The formatted organization resource. + */ + public static function organizationName(string $organization): string + { + return self::getPathTemplate('organization')->render([ + 'organization' => $organization, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - organization: organizations/{organization} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'cloudresourcemanager.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Gets the access control policy for an organization resource. The policy may + * be empty if no such policy or resource exists. The `resource` field should + * be the organization's resource name, for example: "organizations/123". + * + * Authorization requires the IAM permission + * `resourcemanager.organizations.getIamPolicy` on the specified organization. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Fetches an organization resource identified by the specified resource name. + * + * The async variant is {@see self::getOrganizationAsync()} . + * + * @param GetOrganizationRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Organization + * + * @throws ApiException Thrown if the API call fails. + */ + public function getOrganization(GetOrganizationRequest $request, array $callOptions = []): Organization + { + return $this->startApiCall('GetOrganization', $request, $callOptions)->wait(); + } + + /** + * Searches organization resources that are visible to the user and satisfy + * the specified filter. This method returns organizations in an unspecified + * order. New organizations do not necessarily appear at the end of the + * results, and may take a small amount of time to appear. + * + * Search will only return organizations on which the user has the permission + * `resourcemanager.organizations.get` + * + * The async variant is {@see self::searchOrganizationsAsync()} . + * + * @param SearchOrganizationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function searchOrganizations(SearchOrganizationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchOrganizations', $request, $callOptions); + } + + /** + * Sets the access control policy on an organization resource. Replaces any + * existing policy. The `resource` field should be the organization's resource + * name, for example: "organizations/123". + * + * Authorization requires the IAM permission + * `resourcemanager.organizations.setIamPolicy` on the specified organization. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns the permissions that a caller has on the specified organization. + * The `resource` field should be the organization's resource name, + * for example: "organizations/123". + * + * There are no permissions required for making this API call. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } +} diff --git a/ResourceManager/src/V3/Client/BaseClient/ProjectsBaseClient.php b/ResourceManager/src/V3/Client/BaseClient/ProjectsBaseClient.php new file mode 100644 index 000000000000..f98d81266b7f --- /dev/null +++ b/ResourceManager/src/V3/Client/BaseClient/ProjectsBaseClient.php @@ -0,0 +1,656 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/projects_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/projects_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/projects_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/projects_rest_client_config.php', + ], + ], + ]; + } + + /** + * 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; + } + + /** + * Formats a string containing the fully-qualified path to represent a project + * resource. + * + * @param string $project + * + * @return string The formatted project resource. + */ + public static function projectName(string $project): string + { + return self::getPathTemplate('project')->render([ + 'project' => $project, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - project: projects/{project} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'cloudresourcemanager.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Request that a new project be created. The result is an `Operation` which + * can be used to track the creation process. This process usually takes a few + * seconds, but can sometimes take much longer. The tracking `Operation` is + * automatically deleted after a few hours, so there is no need to call + * `DeleteOperation`. + * + * The async variant is {@see self::createProjectAsync()} . + * + * @param CreateProjectRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createProject(CreateProjectRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateProject', $request, $callOptions)->wait(); + } + + /** + * Marks the project identified by the specified + * `name` (for example, `projects/415104041262`) for deletion. + * + * This method will only affect the project if it has a lifecycle state of + * [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE]. + * + * This method changes the Project's lifecycle state from + * [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE] + * to + * [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Project.State.DELETE_REQUESTED]. + * The deletion starts at an unspecified time, + * at which point the Project is no longer accessible. + * + * Until the deletion completes, you can check the lifecycle state + * checked by retrieving the project with [GetProject] + * [google.cloud.resourcemanager.v3.Projects.GetProject], + * and the project remains visible to [ListProjects] + * [google.cloud.resourcemanager.v3.Projects.ListProjects]. + * However, you cannot update the project. + * + * After the deletion completes, the project is not retrievable by + * the [GetProject] + * [google.cloud.resourcemanager.v3.Projects.GetProject], + * [ListProjects] + * [google.cloud.resourcemanager.v3.Projects.ListProjects], and + * [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] + * methods. + * + * This method behaves idempotently, such that deleting a `DELETE_REQUESTED` + * project will not cause an error, but also won't do anything. + * + * The caller must have `resourcemanager.projects.delete` permissions for this + * project. + * + * The async variant is {@see self::deleteProjectAsync()} . + * + * @param DeleteProjectRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteProject(DeleteProjectRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteProject', $request, $callOptions)->wait(); + } + + /** + * Returns the IAM access control policy for the specified project, in the + * format `projects/{ProjectIdOrNumber}` e.g. projects/123. + * Permission is denied if the policy or the resource do not exist. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Retrieves the project identified by the specified `name` (for example, + * `projects/415104041262`). + * + * The caller must have `resourcemanager.projects.get` permission + * for this project. + * + * The async variant is {@see self::getProjectAsync()} . + * + * @param GetProjectRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Project + * + * @throws ApiException Thrown if the API call fails. + */ + public function getProject(GetProjectRequest $request, array $callOptions = []): Project + { + return $this->startApiCall('GetProject', $request, $callOptions)->wait(); + } + + /** + * Lists projects that are direct children of the specified folder or + * organization resource. `list()` provides a strongly consistent view of the + * projects underneath the specified parent resource. `list()` returns + * projects sorted based upon the (ascending) lexical ordering of their + * `display_name`. The caller must have `resourcemanager.projects.list` + * permission on the identified parent. + * + * The async variant is {@see self::listProjectsAsync()} . + * + * @param ListProjectsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listProjects(ListProjectsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListProjects', $request, $callOptions); + } + + /** + * Move a project to another place in your resource hierarchy, under a new + * resource parent. + * + * Returns an operation which can be used to track the process of the project + * move workflow. + * Upon success, the `Operation.response` field will be populated with the + * moved project. + * + * The caller must have `resourcemanager.projects.move` permission on the + * project, on the project's current and proposed new parent. + * + * If project has no current parent, or it currently does not have an + * associated organization resource, you will also need the + * `resourcemanager.projects.setIamPolicy` permission in the project. + * + * + * + * The async variant is {@see self::moveProjectAsync()} . + * + * @param MoveProjectRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function moveProject(MoveProjectRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('MoveProject', $request, $callOptions)->wait(); + } + + /** + * Search for projects that the caller has both `resourcemanager.projects.get` + * permission on, and also satisfy the specified query. + * + * This method returns projects in an unspecified order. + * + * This method is eventually consistent with project mutations; this means + * that a newly created project may not appear in the results or recent + * updates to an existing project may not be reflected in the results. To + * retrieve the latest state of a project, use the + * [GetProject][google.cloud.resourcemanager.v3.Projects.GetProject] method. + * + * The async variant is {@see self::searchProjectsAsync()} . + * + * @param SearchProjectsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function searchProjects(SearchProjectsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchProjects', $request, $callOptions); + } + + /** + * Sets the IAM access control policy for the specified project, in the + * format `projects/{ProjectIdOrNumber}` e.g. projects/123. + * + * CAUTION: This method will replace the existing policy, and cannot be used + * to append additional IAM settings. + * + * Note: Removing service accounts from policies or changing their roles can + * render services completely inoperable. It is important to understand how + * the service account is being used before removing or updating its roles. + * + * The following constraints apply when using `setIamPolicy()`: + * + * + Project does not support `allUsers` and `allAuthenticatedUsers` as + * `members` in a `Binding` of a `Policy`. + * + * + The owner role can be granted to a `user`, `serviceAccount`, or a group + * that is part of an organization. For example, + * group@myownpersonaldomain.com could be added as an owner to a project in + * the myownpersonaldomain.com organization, but not the examplepetstore.com + * organization. + * + * + Service accounts can be made owners of a project directly + * without any restrictions. However, to be added as an owner, a user must be + * invited using the Cloud Platform console and must accept the invitation. + * + * + A user cannot be granted the owner role using `setIamPolicy()`. The user + * must be granted the owner role using the Cloud Platform Console and must + * explicitly accept the invitation. + * + * + Invitations to grant the owner role cannot be sent using + * `setIamPolicy()`; + * they must be sent only using the Cloud Platform Console. + * + * + If the project is not part of an organization, there must be at least + * one owner who has accepted the Terms of Service (ToS) agreement in the + * policy. Calling `setIamPolicy()` to remove the last ToS-accepted owner + * from the policy will fail. This restriction also applies to legacy + * projects that no longer have owners who have accepted the ToS. Edits to + * IAM policies will be rejected until the lack of a ToS-accepting owner is + * rectified. If the project is part of an organization, you can remove all + * owners, potentially making the organization inaccessible. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified project, in the + * format `projects/{ProjectIdOrNumber}` e.g. projects/123.. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } + + /** + * Restores the project identified by the specified + * `name` (for example, `projects/415104041262`). + * You can only use this method for a project that has a lifecycle state of + * [DELETE_REQUESTED] + * [Projects.State.DELETE_REQUESTED]. + * After deletion starts, the project cannot be restored. + * + * The caller must have `resourcemanager.projects.undelete` permission for + * this project. + * + * The async variant is {@see self::undeleteProjectAsync()} . + * + * @param UndeleteProjectRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function undeleteProject(UndeleteProjectRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UndeleteProject', $request, $callOptions)->wait(); + } + + /** + * Updates the `display_name` and labels of the project identified by the + * specified `name` (for example, `projects/415104041262`). Deleting all + * labels requires an update mask for labels field. + * + * The caller must have `resourcemanager.projects.update` permission for this + * project. + * + * The async variant is {@see self::updateProjectAsync()} . + * + * @param UpdateProjectRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateProject(UpdateProjectRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateProject', $request, $callOptions)->wait(); + } +} diff --git a/ResourceManager/src/V3/Client/BaseClient/TagBindingsBaseClient.php b/ResourceManager/src/V3/Client/BaseClient/TagBindingsBaseClient.php new file mode 100644 index 000000000000..9754008d533b --- /dev/null +++ b/ResourceManager/src/V3/Client/BaseClient/TagBindingsBaseClient.php @@ -0,0 +1,353 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/tag_bindings_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/tag_bindings_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/tag_bindings_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/tag_bindings_rest_client_config.php', + ], + ], + ]; + } + + /** + * 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; + } + + /** + * Formats a string containing the fully-qualified path to represent a tag_binding + * resource. + * + * @param string $tagBinding + * + * @return string The formatted tag_binding resource. + */ + public static function tagBindingName(string $tagBinding): string + { + return self::getPathTemplate('tagBinding')->render([ + 'tag_binding' => $tagBinding, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - tagBinding: tagBindings/{tag_binding} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'cloudresourcemanager.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a TagBinding between a TagValue and a Google Cloud resource. + * + * The async variant is {@see self::createTagBindingAsync()} . + * + * @param CreateTagBindingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createTagBinding(CreateTagBindingRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateTagBinding', $request, $callOptions)->wait(); + } + + /** + * Deletes a TagBinding. + * + * The async variant is {@see self::deleteTagBindingAsync()} . + * + * @param DeleteTagBindingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteTagBinding(DeleteTagBindingRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteTagBinding', $request, $callOptions)->wait(); + } + + /** + * Return a list of effective tags for the given Google Cloud resource, as + * specified in `parent`. + * + * The async variant is {@see self::listEffectiveTagsAsync()} . + * + * @param ListEffectiveTagsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listEffectiveTags(ListEffectiveTagsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListEffectiveTags', $request, $callOptions); + } + + /** + * Lists the TagBindings for the given Google Cloud resource, as specified + * with `parent`. + * + * NOTE: The `parent` field is expected to be a full resource name: + * https://cloud.google.com/apis/design/resource_names#full_resource_name + * + * The async variant is {@see self::listTagBindingsAsync()} . + * + * @param ListTagBindingsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listTagBindings(ListTagBindingsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTagBindings', $request, $callOptions); + } +} diff --git a/ResourceManager/src/V3/Client/BaseClient/TagHoldsBaseClient.php b/ResourceManager/src/V3/Client/BaseClient/TagHoldsBaseClient.php new file mode 100644 index 000000000000..51503295ac60 --- /dev/null +++ b/ResourceManager/src/V3/Client/BaseClient/TagHoldsBaseClient.php @@ -0,0 +1,344 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/tag_holds_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/tag_holds_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/tag_holds_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/tag_holds_rest_client_config.php', + ], + ], + ]; + } + + /** + * 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; + } + + /** + * Formats a string containing the fully-qualified path to represent a tag_hold + * resource. + * + * @param string $tagValue + * @param string $tagHold + * + * @return string The formatted tag_hold resource. + */ + public static function tagHoldName(string $tagValue, string $tagHold): string + { + return self::getPathTemplate('tagHold')->render([ + 'tag_value' => $tagValue, + 'tag_hold' => $tagHold, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a tag_value + * resource. + * + * @param string $tagValue + * + * @return string The formatted tag_value resource. + */ + public static function tagValueName(string $tagValue): string + { + return self::getPathTemplate('tagValue')->render([ + 'tag_value' => $tagValue, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - tagHold: tagValues/{tag_value}/tagHolds/{tag_hold} + * - tagValue: tagValues/{tag_value} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'cloudresourcemanager.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a TagHold. Returns ALREADY_EXISTS if a TagHold with the same + * resource and origin exists under the same TagValue. + * + * The async variant is {@see self::createTagHoldAsync()} . + * + * @param CreateTagHoldRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createTagHold(CreateTagHoldRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateTagHold', $request, $callOptions)->wait(); + } + + /** + * Deletes a TagHold. + * + * The async variant is {@see self::deleteTagHoldAsync()} . + * + * @param DeleteTagHoldRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteTagHold(DeleteTagHoldRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteTagHold', $request, $callOptions)->wait(); + } + + /** + * Lists TagHolds under a TagValue. + * + * The async variant is {@see self::listTagHoldsAsync()} . + * + * @param ListTagHoldsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listTagHolds(ListTagHoldsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTagHolds', $request, $callOptions); + } +} diff --git a/ResourceManager/src/V3/Client/BaseClient/TagKeysBaseClient.php b/ResourceManager/src/V3/Client/BaseClient/TagKeysBaseClient.php new file mode 100644 index 000000000000..97fbb8550bf1 --- /dev/null +++ b/ResourceManager/src/V3/Client/BaseClient/TagKeysBaseClient.php @@ -0,0 +1,499 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/tag_keys_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/tag_keys_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/tag_keys_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/tag_keys_rest_client_config.php', + ], + ], + ]; + } + + /** + * 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; + } + + /** + * Formats a string containing the fully-qualified path to represent a tag_key + * resource. + * + * @param string $tagKey + * + * @return string The formatted tag_key resource. + */ + public static function tagKeyName(string $tagKey): string + { + return self::getPathTemplate('tagKey')->render([ + 'tag_key' => $tagKey, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - tagKey: tagKeys/{tag_key} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'cloudresourcemanager.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new TagKey. If another request with the same parameters is + * sent while the original request is in process, the second request + * will receive an error. A maximum of 1000 TagKeys can exist under a parent + * at any given time. + * + * The async variant is {@see self::createTagKeyAsync()} . + * + * @param CreateTagKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createTagKey(CreateTagKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateTagKey', $request, $callOptions)->wait(); + } + + /** + * Deletes a TagKey. The TagKey cannot be deleted if it has any child + * TagValues. + * + * The async variant is {@see self::deleteTagKeyAsync()} . + * + * @param DeleteTagKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteTagKey(DeleteTagKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteTagKey', $request, $callOptions)->wait(); + } + + /** + * Gets the access control policy for a TagKey. The returned policy may be + * empty if no such policy or resource exists. The `resource` field should + * be the TagKey's resource name. For example, "tagKeys/1234". + * The caller must have + * `cloudresourcemanager.googleapis.com/tagKeys.getIamPolicy` permission on + * the specified TagKey. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Retrieves a TagKey by its namespaced name. + * This method will return `PERMISSION_DENIED` if the key does not exist + * or the user does not have permission to view it. + * + * The async variant is {@see self::getNamespacedTagKeyAsync()} . + * + * @param GetNamespacedTagKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TagKey + * + * @throws ApiException Thrown if the API call fails. + */ + public function getNamespacedTagKey(GetNamespacedTagKeyRequest $request, array $callOptions = []): TagKey + { + return $this->startApiCall('GetNamespacedTagKey', $request, $callOptions)->wait(); + } + + /** + * Retrieves a TagKey. This method will return `PERMISSION_DENIED` if the + * key does not exist or the user does not have permission to view it. + * + * The async variant is {@see self::getTagKeyAsync()} . + * + * @param GetTagKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TagKey + * + * @throws ApiException Thrown if the API call fails. + */ + public function getTagKey(GetTagKeyRequest $request, array $callOptions = []): TagKey + { + return $this->startApiCall('GetTagKey', $request, $callOptions)->wait(); + } + + /** + * Lists all TagKeys for a parent resource. + * + * The async variant is {@see self::listTagKeysAsync()} . + * + * @param ListTagKeysRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listTagKeys(ListTagKeysRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTagKeys', $request, $callOptions); + } + + /** + * Sets the access control policy on a TagKey, replacing any existing + * policy. The `resource` field should be the TagKey's resource name. + * For example, "tagKeys/1234". + * The caller must have `resourcemanager.tagKeys.setIamPolicy` permission + * on the identified tagValue. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified TagKey. + * The `resource` field should be the TagKey's resource name. + * For example, "tagKeys/1234". + * + * There are no permissions required for making this API call. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } + + /** + * Updates the attributes of the TagKey resource. + * + * The async variant is {@see self::updateTagKeyAsync()} . + * + * @param UpdateTagKeyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateTagKey(UpdateTagKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateTagKey', $request, $callOptions)->wait(); + } +} diff --git a/ResourceManager/src/V3/Client/BaseClient/TagValuesBaseClient.php b/ResourceManager/src/V3/Client/BaseClient/TagValuesBaseClient.php new file mode 100644 index 000000000000..0af2e29fadbf --- /dev/null +++ b/ResourceManager/src/V3/Client/BaseClient/TagValuesBaseClient.php @@ -0,0 +1,499 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/tag_values_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/tag_values_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/tag_values_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/tag_values_rest_client_config.php', + ], + ], + ]; + } + + /** + * 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; + } + + /** + * Formats a string containing the fully-qualified path to represent a tag_value + * resource. + * + * @param string $tagValue + * + * @return string The formatted tag_value resource. + */ + public static function tagValueName(string $tagValue): string + { + return self::getPathTemplate('tagValue')->render([ + 'tag_value' => $tagValue, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - tagValue: tagValues/{tag_value} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'cloudresourcemanager.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); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a TagValue as a child of the specified TagKey. If a another + * request with the same parameters is sent while the original request is in + * process the second request will receive an error. A maximum of 1000 + * TagValues can exist under a TagKey at any given time. + * + * The async variant is {@see self::createTagValueAsync()} . + * + * @param CreateTagValueRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createTagValue(CreateTagValueRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateTagValue', $request, $callOptions)->wait(); + } + + /** + * Deletes a TagValue. The TagValue cannot have any bindings when it is + * deleted. + * + * The async variant is {@see self::deleteTagValueAsync()} . + * + * @param DeleteTagValueRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteTagValue(DeleteTagValueRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteTagValue', $request, $callOptions)->wait(); + } + + /** + * Gets the access control policy for a TagValue. The returned policy may be + * empty if no such policy or resource exists. The `resource` field should + * be the TagValue's resource name. For example: `tagValues/1234`. + * The caller must have the + * `cloudresourcemanager.googleapis.com/tagValues.getIamPolicy` permission on + * the identified TagValue to get the access control policy. + * + * The async variant is {@see self::getIamPolicyAsync()} . + * + * @param GetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getIamPolicy(GetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('GetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Retrieves a TagValue by its namespaced name. + * This method will return `PERMISSION_DENIED` if the value does not exist + * or the user does not have permission to view it. + * + * The async variant is {@see self::getNamespacedTagValueAsync()} . + * + * @param GetNamespacedTagValueRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TagValue + * + * @throws ApiException Thrown if the API call fails. + */ + public function getNamespacedTagValue(GetNamespacedTagValueRequest $request, array $callOptions = []): TagValue + { + return $this->startApiCall('GetNamespacedTagValue', $request, $callOptions)->wait(); + } + + /** + * Retrieves a TagValue. This method will return `PERMISSION_DENIED` if the + * value does not exist or the user does not have permission to view it. + * + * The async variant is {@see self::getTagValueAsync()} . + * + * @param GetTagValueRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TagValue + * + * @throws ApiException Thrown if the API call fails. + */ + public function getTagValue(GetTagValueRequest $request, array $callOptions = []): TagValue + { + return $this->startApiCall('GetTagValue', $request, $callOptions)->wait(); + } + + /** + * Lists all TagValues for a specific TagKey. + * + * The async variant is {@see self::listTagValuesAsync()} . + * + * @param ListTagValuesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listTagValues(ListTagValuesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTagValues', $request, $callOptions); + } + + /** + * Sets the access control policy on a TagValue, replacing any existing + * policy. The `resource` field should be the TagValue's resource name. + * For example: `tagValues/1234`. + * The caller must have `resourcemanager.tagValues.setIamPolicy` permission + * on the identified tagValue. + * + * The async variant is {@see self::setIamPolicyAsync()} . + * + * @param SetIamPolicyRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Policy + * + * @throws ApiException Thrown if the API call fails. + */ + public function setIamPolicy(SetIamPolicyRequest $request, array $callOptions = []): Policy + { + return $this->startApiCall('SetIamPolicy', $request, $callOptions)->wait(); + } + + /** + * Returns permissions that a caller has on the specified TagValue. + * The `resource` field should be the TagValue's resource name. For example: + * `tagValues/1234`. + * + * There are no permissions required for making this API call. + * + * The async variant is {@see self::testIamPermissionsAsync()} . + * + * @param TestIamPermissionsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return TestIamPermissionsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function testIamPermissions(TestIamPermissionsRequest $request, array $callOptions = []): TestIamPermissionsResponse + { + return $this->startApiCall('TestIamPermissions', $request, $callOptions)->wait(); + } + + /** + * Updates the attributes of the TagValue resource. + * + * The async variant is {@see self::updateTagValueAsync()} . + * + * @param UpdateTagValueRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateTagValue(UpdateTagValueRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateTagValue', $request, $callOptions)->wait(); + } +} diff --git a/ResourceManager/src/V3/Client/FoldersClient.php b/ResourceManager/src/V3/Client/FoldersClient.php new file mode 100644 index 000000000000..344306bac158 --- /dev/null +++ b/ResourceManager/src/V3/Client/FoldersClient.php @@ -0,0 +1,40 @@ +setFolder($folder); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/CreateProjectRequest.php b/ResourceManager/src/V3/CreateProjectRequest.php index 93d4b98b0158..b02dd2324832 100644 --- a/ResourceManager/src/V3/CreateProjectRequest.php +++ b/ResourceManager/src/V3/CreateProjectRequest.php @@ -30,6 +30,27 @@ class CreateProjectRequest extends \Google\Protobuf\Internal\Message */ private $project = null; + /** + * @param \Google\Cloud\ResourceManager\V3\Project $project Required. The Project to create. + * + * Project ID is required. If the requested ID is unavailable, the request + * fails. + * + * If the `parent` field is set, the `resourcemanager.projects.create` + * permission is checked on the parent resource. If no parent is set and + * the authorization credentials belong to an Organization, the parent + * will be set to that Organization. + * + * @return \Google\Cloud\ResourceManager\V3\CreateProjectRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ResourceManager\V3\Project $project): self + { + return (new self()) + ->setProject($project); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/CreateTagBindingRequest.php b/ResourceManager/src/V3/CreateTagBindingRequest.php index 7c7cc1d11b24..10e2e98a5a3e 100644 --- a/ResourceManager/src/V3/CreateTagBindingRequest.php +++ b/ResourceManager/src/V3/CreateTagBindingRequest.php @@ -29,6 +29,19 @@ class CreateTagBindingRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param \Google\Cloud\ResourceManager\V3\TagBinding $tagBinding Required. The TagBinding to be created. + * + * @return \Google\Cloud\ResourceManager\V3\CreateTagBindingRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ResourceManager\V3\TagBinding $tagBinding): self + { + return (new self()) + ->setTagBinding($tagBinding); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/CreateTagHoldRequest.php b/ResourceManager/src/V3/CreateTagHoldRequest.php index 256092d08b94..3ad17a83d0d4 100644 --- a/ResourceManager/src/V3/CreateTagHoldRequest.php +++ b/ResourceManager/src/V3/CreateTagHoldRequest.php @@ -36,6 +36,23 @@ class CreateTagHoldRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $parent Required. The resource name of the TagHold's parent TagValue. Must be of + * the form: `tagValues/{tag-value-id}`. Please see + * {@see TagHoldsClient::tagValueName()} for help formatting this field. + * @param \Google\Cloud\ResourceManager\V3\TagHold $tagHold Required. The TagHold to be created. + * + * @return \Google\Cloud\ResourceManager\V3\CreateTagHoldRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\ResourceManager\V3\TagHold $tagHold): self + { + return (new self()) + ->setParent($parent) + ->setTagHold($tagHold); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/CreateTagKeyRequest.php b/ResourceManager/src/V3/CreateTagKeyRequest.php index 9b4bab1f4e21..040b53a8ae06 100644 --- a/ResourceManager/src/V3/CreateTagKeyRequest.php +++ b/ResourceManager/src/V3/CreateTagKeyRequest.php @@ -30,6 +30,20 @@ class CreateTagKeyRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param \Google\Cloud\ResourceManager\V3\TagKey $tagKey Required. The TagKey to be created. Only fields `short_name`, + * `description`, and `parent` are considered during the creation request. + * + * @return \Google\Cloud\ResourceManager\V3\CreateTagKeyRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ResourceManager\V3\TagKey $tagKey): self + { + return (new self()) + ->setTagKey($tagKey); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/CreateTagValueRequest.php b/ResourceManager/src/V3/CreateTagValueRequest.php index fe786ef973f6..110f549ad417 100644 --- a/ResourceManager/src/V3/CreateTagValueRequest.php +++ b/ResourceManager/src/V3/CreateTagValueRequest.php @@ -30,6 +30,20 @@ class CreateTagValueRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param \Google\Cloud\ResourceManager\V3\TagValue $tagValue Required. The TagValue to be created. Only fields `short_name`, + * `description`, and `parent` are considered during the creation request. + * + * @return \Google\Cloud\ResourceManager\V3\CreateTagValueRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ResourceManager\V3\TagValue $tagValue): self + { + return (new self()) + ->setTagValue($tagValue); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/DeleteFolderRequest.php b/ResourceManager/src/V3/DeleteFolderRequest.php index e09f3de5bb55..6fac1b830bdd 100644 --- a/ResourceManager/src/V3/DeleteFolderRequest.php +++ b/ResourceManager/src/V3/DeleteFolderRequest.php @@ -23,6 +23,21 @@ class DeleteFolderRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the folder to be deleted. + * Must be of the form `folders/{folder_id}`. Please see + * {@see FoldersClient::folderName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\DeleteFolderRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/DeleteProjectRequest.php b/ResourceManager/src/V3/DeleteProjectRequest.php index ab8200d413fd..b81e9a41e006 100644 --- a/ResourceManager/src/V3/DeleteProjectRequest.php +++ b/ResourceManager/src/V3/DeleteProjectRequest.php @@ -23,6 +23,20 @@ class DeleteProjectRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the Project (for example, `projects/415104041262`). Please see + * {@see ProjectsClient::projectName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\DeleteProjectRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/DeleteTagBindingRequest.php b/ResourceManager/src/V3/DeleteTagBindingRequest.php index 7c8b4e1916ec..ebcc79cae54a 100644 --- a/ResourceManager/src/V3/DeleteTagBindingRequest.php +++ b/ResourceManager/src/V3/DeleteTagBindingRequest.php @@ -24,6 +24,22 @@ class DeleteTagBindingRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the TagBinding. This is a String of the form: + * `tagBindings/{id}` (e.g. + * `tagBindings/%2F%2Fcloudresourcemanager.googleapis.com%2Fprojects%2F123/tagValues/456`). Please see + * {@see TagBindingsClient::tagBindingName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\DeleteTagBindingRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/DeleteTagHoldRequest.php b/ResourceManager/src/V3/DeleteTagHoldRequest.php index 51ab425e048f..c42550c499b6 100644 --- a/ResourceManager/src/V3/DeleteTagHoldRequest.php +++ b/ResourceManager/src/V3/DeleteTagHoldRequest.php @@ -30,6 +30,21 @@ class DeleteTagHoldRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $name Required. The resource name of the TagHold to delete. Must be of the form: + * `tagValues/{tag-value-id}/tagHolds/{tag-hold-id}`. Please see + * {@see TagHoldsClient::tagHoldName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\DeleteTagHoldRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/DeleteTagKeyRequest.php b/ResourceManager/src/V3/DeleteTagKeyRequest.php index 086f02cf8af5..3ad8668c1966 100644 --- a/ResourceManager/src/V3/DeleteTagKeyRequest.php +++ b/ResourceManager/src/V3/DeleteTagKeyRequest.php @@ -38,6 +38,22 @@ class DeleteTagKeyRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. The resource name of a TagKey to be deleted in the format + * `tagKeys/123`. The TagKey cannot be a parent of any existing TagValues or + * it will not be deleted successfully. Please see + * {@see TagKeysClient::tagKeyName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\DeleteTagKeyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/DeleteTagValueRequest.php b/ResourceManager/src/V3/DeleteTagValueRequest.php index 48cdb4121a46..faf2a369eb97 100644 --- a/ResourceManager/src/V3/DeleteTagValueRequest.php +++ b/ResourceManager/src/V3/DeleteTagValueRequest.php @@ -37,6 +37,21 @@ class DeleteTagValueRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. Resource name for TagValue to be deleted in the format + * tagValues/456. Please see + * {@see TagValuesClient::tagValueName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\DeleteTagValueRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/GetFolderRequest.php b/ResourceManager/src/V3/GetFolderRequest.php index 1aece9a305dd..34c7330571db 100644 --- a/ResourceManager/src/V3/GetFolderRequest.php +++ b/ResourceManager/src/V3/GetFolderRequest.php @@ -23,6 +23,21 @@ class GetFolderRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the folder to retrieve. + * Must be of the form `folders/{folder_id}`. Please see + * {@see FoldersClient::folderName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\GetFolderRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/GetNamespacedTagKeyRequest.php b/ResourceManager/src/V3/GetNamespacedTagKeyRequest.php index 8967dae206fe..566137e209c4 100644 --- a/ResourceManager/src/V3/GetNamespacedTagKeyRequest.php +++ b/ResourceManager/src/V3/GetNamespacedTagKeyRequest.php @@ -25,6 +25,23 @@ class GetNamespacedTagKeyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A namespaced tag key name in the format + * `{parentId}/{tagKeyShort}`, such as `42/foo` for a key with short name + * "foo" under the organization with ID 42 or `r2-d2/bar` for a key with short + * name "bar" under the project `r2-d2`. Please see + * {@see TagKeysClient::tagKeyName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\GetNamespacedTagKeyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/GetNamespacedTagValueRequest.php b/ResourceManager/src/V3/GetNamespacedTagValueRequest.php index 40bf845bf6dc..885501817495 100644 --- a/ResourceManager/src/V3/GetNamespacedTagValueRequest.php +++ b/ResourceManager/src/V3/GetNamespacedTagValueRequest.php @@ -28,6 +28,28 @@ class GetNamespacedTagValueRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A namespaced tag value name in the following format: + * + * `{parentId}/{tagKeyShort}/{tagValueShort}` + * + * Examples: + * - `42/foo/abc` for a value with short name "abc" under the key with short + * name "foo" under the organization with ID 42 + * - `r2-d2/bar/xyz` for a value with short name "xyz" under the key with + * short name "bar" under the project with ID "r2-d2" + * Please see {@see TagValuesClient::tagValueName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\GetNamespacedTagValueRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/GetOrganizationRequest.php b/ResourceManager/src/V3/GetOrganizationRequest.php index e7f61651d833..7eb8fd8a8aca 100644 --- a/ResourceManager/src/V3/GetOrganizationRequest.php +++ b/ResourceManager/src/V3/GetOrganizationRequest.php @@ -25,6 +25,22 @@ class GetOrganizationRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the Organization to fetch. This is the + * organization's relative path in the API, formatted as + * "organizations/[organizationId]". For example, "organizations/1234". Please see + * {@see OrganizationsClient::organizationName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\GetOrganizationRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/GetProjectRequest.php b/ResourceManager/src/V3/GetProjectRequest.php index 00f4950e4d3c..94a5f48f61f7 100644 --- a/ResourceManager/src/V3/GetProjectRequest.php +++ b/ResourceManager/src/V3/GetProjectRequest.php @@ -24,6 +24,20 @@ class GetProjectRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the project (for example, `projects/415104041262`). Please see + * {@see ProjectsClient::projectName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\GetProjectRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/GetTagKeyRequest.php b/ResourceManager/src/V3/GetTagKeyRequest.php index fbd391a7c623..391b472263c6 100644 --- a/ResourceManager/src/V3/GetTagKeyRequest.php +++ b/ResourceManager/src/V3/GetTagKeyRequest.php @@ -23,6 +23,21 @@ class GetTagKeyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. A resource name in the format `tagKeys/{id}`, such as + * `tagKeys/123`. Please see + * {@see TagKeysClient::tagKeyName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\GetTagKeyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/GetTagValueRequest.php b/ResourceManager/src/V3/GetTagValueRequest.php index d8b99d0b94a4..47f7967fcbb8 100644 --- a/ResourceManager/src/V3/GetTagValueRequest.php +++ b/ResourceManager/src/V3/GetTagValueRequest.php @@ -23,6 +23,21 @@ class GetTagValueRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name for TagValue to be fetched in the format + * `tagValues/456`. Please see + * {@see TagValuesClient::tagValueName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\GetTagValueRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/ListEffectiveTagsRequest.php b/ResourceManager/src/V3/ListEffectiveTagsRequest.php index 7b8ee702049a..267e37e0d0cf 100644 --- a/ResourceManager/src/V3/ListEffectiveTagsRequest.php +++ b/ResourceManager/src/V3/ListEffectiveTagsRequest.php @@ -39,6 +39,21 @@ class ListEffectiveTagsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The full resource name of a resource for which you want to list + * the effective tags. E.g. + * "//cloudresourcemanager.googleapis.com/projects/123" + * + * @return \Google\Cloud\ResourceManager\V3\ListEffectiveTagsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/ListFoldersRequest.php b/ResourceManager/src/V3/ListFoldersRequest.php index a6d4bf844a2a..853e26d039c7 100644 --- a/ResourceManager/src/V3/ListFoldersRequest.php +++ b/ResourceManager/src/V3/ListFoldersRequest.php @@ -51,6 +51,27 @@ class ListFoldersRequest extends \Google\Protobuf\Internal\Message */ private $show_deleted = false; + /** + * @param string $parent Required. The name of the parent resource whose folders are being listed. + * Only children of this parent resource are listed; descendants are not + * listed. + * + * If the parent is a folder, use the value `folders/{folder_id}`. If the + * parent is an organization, use the value `organizations/{org_id}`. + * + * Access to this method is controlled by checking the + * `resourcemanager.folders.list` permission on the `parent`. + * + * @return \Google\Cloud\ResourceManager\V3\ListFoldersRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/ListProjectsRequest.php b/ResourceManager/src/V3/ListProjectsRequest.php index be61ac166158..4134e4203893 100644 --- a/ResourceManager/src/V3/ListProjectsRequest.php +++ b/ResourceManager/src/V3/ListProjectsRequest.php @@ -51,6 +51,24 @@ class ListProjectsRequest extends \Google\Protobuf\Internal\Message */ private $show_deleted = false; + /** + * @param string $parent Required. The name of the parent resource whose projects are being listed. + * Only children of this parent resource are listed; descendants are not + * listed. + * + * If the parent is a folder, use the value `folders/{folder_id}`. If the + * parent is an organization, use the value `organizations/{org_id}`. + * + * @return \Google\Cloud\ResourceManager\V3\ListProjectsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/ListTagBindingsRequest.php b/ResourceManager/src/V3/ListTagBindingsRequest.php index 232ff28dbe7e..18862f5b8c01 100644 --- a/ResourceManager/src/V3/ListTagBindingsRequest.php +++ b/ResourceManager/src/V3/ListTagBindingsRequest.php @@ -39,6 +39,21 @@ class ListTagBindingsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The full resource name of a resource for which you want to list + * existing TagBindings. E.g. + * "//cloudresourcemanager.googleapis.com/projects/123" + * + * @return \Google\Cloud\ResourceManager\V3\ListTagBindingsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/ListTagHoldsRequest.php b/ResourceManager/src/V3/ListTagHoldsRequest.php index 9406fe13d8d1..9b2aa3d49a39 100644 --- a/ResourceManager/src/V3/ListTagHoldsRequest.php +++ b/ResourceManager/src/V3/ListTagHoldsRequest.php @@ -53,6 +53,21 @@ class ListTagHoldsRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The resource name of the parent TagValue. Must be of the form: + * `tagValues/{tag-value-id}`. Please see + * {@see TagHoldsClient::tagValueName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\ListTagHoldsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/ListTagKeysRequest.php b/ResourceManager/src/V3/ListTagKeysRequest.php index 470865a00cf7..fb91b900accc 100644 --- a/ResourceManager/src/V3/ListTagKeysRequest.php +++ b/ResourceManager/src/V3/ListTagKeysRequest.php @@ -39,6 +39,21 @@ class ListTagKeysRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The resource name of the TagKey's parent. + * Must be of the form `organizations/{org_id}` or `projects/{project_id}` or + * `projects/{project_number}` + * + * @return \Google\Cloud\ResourceManager\V3\ListTagKeysRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/ListTagValuesRequest.php b/ResourceManager/src/V3/ListTagValuesRequest.php index b3ee999ad6bc..2a196982153b 100644 --- a/ResourceManager/src/V3/ListTagValuesRequest.php +++ b/ResourceManager/src/V3/ListTagValuesRequest.php @@ -39,6 +39,19 @@ class ListTagValuesRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. + * + * @return \Google\Cloud\ResourceManager\V3\ListTagValuesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/MoveFolderRequest.php b/ResourceManager/src/V3/MoveFolderRequest.php index d9f657b59961..d49fbb483d45 100644 --- a/ResourceManager/src/V3/MoveFolderRequest.php +++ b/ResourceManager/src/V3/MoveFolderRequest.php @@ -31,6 +31,25 @@ class MoveFolderRequest extends \Google\Protobuf\Internal\Message */ private $destination_parent = ''; + /** + * @param string $name Required. The resource name of the Folder to move. + * Must be of the form folders/{folder_id} + * Please see {@see FoldersClient::folderName()} for help formatting this field. + * @param string $destinationParent Required. The resource name of the folder or organization which should be + * the folder's new parent. Must be of the form `folders/{folder_id}` or + * `organizations/{org_id}`. + * + * @return \Google\Cloud\ResourceManager\V3\MoveFolderRequest + * + * @experimental + */ + public static function build(string $name, string $destinationParent): self + { + return (new self()) + ->setName($name) + ->setDestinationParent($destinationParent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/MoveProjectRequest.php b/ResourceManager/src/V3/MoveProjectRequest.php index abd598ec0884..33bbc83b2064 100644 --- a/ResourceManager/src/V3/MoveProjectRequest.php +++ b/ResourceManager/src/V3/MoveProjectRequest.php @@ -30,6 +30,22 @@ class MoveProjectRequest extends \Google\Protobuf\Internal\Message */ private $destination_parent = ''; + /** + * @param string $name Required. The name of the project to move. Please see + * {@see ProjectsClient::projectName()} for help formatting this field. + * @param string $destinationParent Required. The new parent to move the Project under. + * + * @return \Google\Cloud\ResourceManager\V3\MoveProjectRequest + * + * @experimental + */ + public static function build(string $name, string $destinationParent): self + { + return (new self()) + ->setName($name) + ->setDestinationParent($destinationParent); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/SearchFoldersRequest.php b/ResourceManager/src/V3/SearchFoldersRequest.php index d1f38459fc9a..635405e62837 100644 --- a/ResourceManager/src/V3/SearchFoldersRequest.php +++ b/ResourceManager/src/V3/SearchFoldersRequest.php @@ -62,6 +62,49 @@ class SearchFoldersRequest extends \Google\Protobuf\Internal\Message */ private $query = ''; + /** + * @param string $query Optional. Search criteria used to select the folders to return. + * If no search criteria is specified then all accessible folders will be + * returned. + * + * Query expressions can be used to restrict results based upon displayName, + * state and parent, where the operators `=` (`:`) `NOT`, `AND` and `OR` + * can be used along with the suffix wildcard symbol `*`. + * + * The `displayName` field in a query expression should use escaped quotes + * for values that include whitespace to prevent unexpected behavior. + * + * ``` + * | Field | Description | + * |-------------------------|----------------------------------------| + * | displayName | Filters by displayName. | + * | parent | Filters by parent (for example: folders/123). | + * | state, lifecycleState | Filters by state. | + * ``` + * + * Some example queries are: + * + * * Query `displayName=Test*` returns Folder resources whose display name + * starts with "Test". + * * Query `state=ACTIVE` returns Folder resources with + * `state` set to `ACTIVE`. + * * Query `parent=folders/123` returns Folder resources that have + * `folders/123` as a parent resource. + * * Query `parent=folders/123 AND state=ACTIVE` returns active + * Folder resources that have `folders/123` as a parent resource. + * * Query `displayName=\\"Test String\\"` returns Folder resources with + * display names that include both "Test" and "String". + * + * @return \Google\Cloud\ResourceManager\V3\SearchFoldersRequest + * + * @experimental + */ + public static function build(string $query): self + { + return (new self()) + ->setQuery($query); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/SearchOrganizationsRequest.php b/ResourceManager/src/V3/SearchOrganizationsRequest.php index 7ffa87d987c6..4dd2b73c7530 100644 --- a/ResourceManager/src/V3/SearchOrganizationsRequest.php +++ b/ResourceManager/src/V3/SearchOrganizationsRequest.php @@ -51,6 +51,37 @@ class SearchOrganizationsRequest extends \Google\Protobuf\Internal\Message */ private $query = ''; + /** + * @param string $query Optional. An optional query string used to filter the Organizations to + * return in the response. Query rules are case-insensitive. + * + * + * ``` + * | Field | Description | + * |------------------|--------------------------------------------| + * | directoryCustomerId, owner.directoryCustomerId | Filters by directory + * customer id. | + * | domain | Filters by domain. | + * ``` + * + * Organizations may be queried by `directoryCustomerId` or by + * `domain`, where the domain is a G Suite domain, for example: + * + * * Query `directorycustomerid:123456789` returns Organization + * resources with `owner.directory_customer_id` equal to `123456789`. + * * Query `domain:google.com` returns Organization resources corresponding + * to the domain `google.com`. + * + * @return \Google\Cloud\ResourceManager\V3\SearchOrganizationsRequest + * + * @experimental + */ + public static function build(string $query): self + { + return (new self()) + ->setQuery($query); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/SearchProjectsRequest.php b/ResourceManager/src/V3/SearchProjectsRequest.php index 3488e4f15bee..818f5eec583f 100644 --- a/ResourceManager/src/V3/SearchProjectsRequest.php +++ b/ResourceManager/src/V3/SearchProjectsRequest.php @@ -66,6 +66,51 @@ class SearchProjectsRequest extends \Google\Protobuf\Internal\Message */ private $page_size = 0; + /** + * @param string $query Optional. A query string for searching for projects that the caller has + * `resourcemanager.projects.get` permission to. If multiple fields are + * included in the query, then it will return results that match any of the + * fields. Some eligible fields are: + * + * - **`displayName`, `name`**: Filters by displayName. + * - **`parent`**: Project's parent (for example: `folders/123`, + * `organizations/*`). Prefer `parent` field over `parent.type` and + * `parent.id`. + * - **`parent.type`**: Parent's type: `folder` or `organization`. + * - **`parent.id`**: Parent's id number (for example: `123`). + * - **`id`, `projectId`**: Filters by projectId. + * - **`state`, `lifecycleState`**: Filters by state. + * - **`labels`**: Filters by label name or value. + * - **`labels.` (where `` is the name of a label)**: Filters by label + * name. + * + * Search expressions are case insensitive. + * + * Some examples queries: + * + * + * - **`name:how*`**: The project's name starts with "how". + * - **`name:Howl`**: The project's name is `Howl` or `howl`. + * - **`name:HOWL`**: Equivalent to above. + * - **`NAME:howl`**: Equivalent to above. + * - **`labels.color:*`**: The project has the label `color`. + * - **`labels.color:red`**: The project's label `color` has the value `red`. + * - **`labels.color:red labels.size:big`**: The project's label `color` has + * the value `red` or its label `size` has the value `big`. + * + * If no query is specified, the call will return projects for which the user + * has the `resourcemanager.projects.get` permission. + * + * @return \Google\Cloud\ResourceManager\V3\SearchProjectsRequest + * + * @experimental + */ + public static function build(string $query): self + { + return (new self()) + ->setQuery($query); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/UndeleteFolderRequest.php b/ResourceManager/src/V3/UndeleteFolderRequest.php index 021ff0ceab44..7035904ffb0c 100644 --- a/ResourceManager/src/V3/UndeleteFolderRequest.php +++ b/ResourceManager/src/V3/UndeleteFolderRequest.php @@ -23,6 +23,21 @@ class UndeleteFolderRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the folder to undelete. + * Must be of the form `folders/{folder_id}`. Please see + * {@see FoldersClient::folderName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\UndeleteFolderRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/UndeleteProjectRequest.php b/ResourceManager/src/V3/UndeleteProjectRequest.php index e1c6c24ce46b..3870d2f33b1e 100644 --- a/ResourceManager/src/V3/UndeleteProjectRequest.php +++ b/ResourceManager/src/V3/UndeleteProjectRequest.php @@ -25,6 +25,22 @@ class UndeleteProjectRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the project (for example, `projects/415104041262`). + * + * Required. Please see + * {@see ProjectsClient::projectName()} for help formatting this field. + * + * @return \Google\Cloud\ResourceManager\V3\UndeleteProjectRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/UpdateFolderRequest.php b/ResourceManager/src/V3/UpdateFolderRequest.php index 7b93c8577bae..fa5cd5bc1fc1 100644 --- a/ResourceManager/src/V3/UpdateFolderRequest.php +++ b/ResourceManager/src/V3/UpdateFolderRequest.php @@ -36,6 +36,23 @@ class UpdateFolderRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\ResourceManager\V3\Folder $folder Required. The new definition of the Folder. It must include the `name` + * field, which cannot be changed. + * @param \Google\Protobuf\FieldMask $updateMask Required. Fields to be updated. + * Only the `display_name` can be updated. + * + * @return \Google\Cloud\ResourceManager\V3\UpdateFolderRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ResourceManager\V3\Folder $folder, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setFolder($folder) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/UpdateProjectRequest.php b/ResourceManager/src/V3/UpdateProjectRequest.php index b95f65c2bf95..ce4a803a2fed 100644 --- a/ResourceManager/src/V3/UpdateProjectRequest.php +++ b/ResourceManager/src/V3/UpdateProjectRequest.php @@ -33,6 +33,21 @@ class UpdateProjectRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\ResourceManager\V3\Project $project Required. The new definition of the project. + * @param \Google\Protobuf\FieldMask $updateMask Optional. An update mask to selectively update fields. + * + * @return \Google\Cloud\ResourceManager\V3\UpdateProjectRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ResourceManager\V3\Project $project, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setProject($project) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/UpdateTagKeyRequest.php b/ResourceManager/src/V3/UpdateTagKeyRequest.php index 067ddf8033f9..4abeda2a47e5 100644 --- a/ResourceManager/src/V3/UpdateTagKeyRequest.php +++ b/ResourceManager/src/V3/UpdateTagKeyRequest.php @@ -40,6 +40,26 @@ class UpdateTagKeyRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param \Google\Cloud\ResourceManager\V3\TagKey $tagKey Required. The new definition of the TagKey. Only the `description` and + * `etag` fields can be updated by this request. If the `etag` field is not + * empty, it must match the `etag` field of the existing tag key. Otherwise, + * `ABORTED` will be returned. + * @param \Google\Protobuf\FieldMask $updateMask Fields to be updated. The mask may only contain `description` or + * `etag`. If omitted entirely, both `description` and `etag` are assumed to + * be significant. + * + * @return \Google\Cloud\ResourceManager\V3\UpdateTagKeyRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ResourceManager\V3\TagKey $tagKey, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setTagKey($tagKey) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/UpdateTagValueRequest.php b/ResourceManager/src/V3/UpdateTagValueRequest.php index 296fe5ee7c1f..704049316131 100644 --- a/ResourceManager/src/V3/UpdateTagValueRequest.php +++ b/ResourceManager/src/V3/UpdateTagValueRequest.php @@ -38,6 +38,24 @@ class UpdateTagValueRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param \Google\Cloud\ResourceManager\V3\TagValue $tagValue Required. The new definition of the TagValue. Only fields `description` and + * `etag` fields can be updated by this request. If the `etag` field is + * nonempty, it must match the `etag` field of the existing ControlGroup. + * Otherwise, `ABORTED` will be returned. + * @param \Google\Protobuf\FieldMask $updateMask Optional. Fields to be updated. + * + * @return \Google\Cloud\ResourceManager\V3\UpdateTagValueRequest + * + * @experimental + */ + public static function build(\Google\Cloud\ResourceManager\V3\TagValue $tagValue, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setTagValue($tagValue) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/ResourceManager/src/V3/resources/folders_descriptor_config.php b/ResourceManager/src/V3/resources/folders_descriptor_config.php index 5a014ae2277a..e4c3bd76be75 100644 --- a/ResourceManager/src/V3/resources/folders_descriptor_config.php +++ b/ResourceManager/src/V3/resources/folders_descriptor_config.php @@ -12,6 +12,7 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, ], 'DeleteFolder' => [ 'longRunning' => [ @@ -22,6 +23,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'MoveFolder' => [ 'longRunning' => [ @@ -32,6 +42,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UndeleteFolder' => [ 'longRunning' => [ @@ -42,6 +61,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateFolder' => [ 'longRunning' => [ @@ -52,6 +80,40 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'folder.name', + 'fieldAccessors' => [ + 'getFolder', + 'getName', + ], + ], + ], + ], + 'GetFolder' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\Folder', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], ], 'ListFolders' => [ 'pageStreaming' => [ @@ -62,6 +124,8 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getFolders', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\ListFoldersResponse', ], 'SearchFolders' => [ 'pageStreaming' => [ @@ -72,6 +136,35 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getFolders', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\SearchFoldersResponse', + ], + 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'templateMap' => [ + 'folder' => 'folders/{folder}', ], ], ], diff --git a/ResourceManager/src/V3/resources/organizations_descriptor_config.php b/ResourceManager/src/V3/resources/organizations_descriptor_config.php index 517a2fee2f3a..78dd5042dd02 100644 --- a/ResourceManager/src/V3/resources/organizations_descriptor_config.php +++ b/ResourceManager/src/V3/resources/organizations_descriptor_config.php @@ -3,6 +3,30 @@ return [ 'interfaces' => [ 'google.cloud.resourcemanager.v3.Organizations' => [ + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'GetOrganization' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\Organization', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'SearchOrganizations' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +36,35 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getOrganizations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\SearchOrganizationsResponse', + ], + 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'templateMap' => [ + 'organization' => 'organizations/{organization}', ], ], ], diff --git a/ResourceManager/src/V3/resources/projects_descriptor_config.php b/ResourceManager/src/V3/resources/projects_descriptor_config.php index 343e1f75bb50..ad80435b422f 100644 --- a/ResourceManager/src/V3/resources/projects_descriptor_config.php +++ b/ResourceManager/src/V3/resources/projects_descriptor_config.php @@ -12,6 +12,7 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, ], 'DeleteProject' => [ 'longRunning' => [ @@ -22,6 +23,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'MoveProject' => [ 'longRunning' => [ @@ -32,6 +42,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UndeleteProject' => [ 'longRunning' => [ @@ -42,6 +61,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateProject' => [ 'longRunning' => [ @@ -52,6 +80,40 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'project.name', + 'fieldAccessors' => [ + 'getProject', + 'getName', + ], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'GetProject' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\Project', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListProjects' => [ 'pageStreaming' => [ @@ -62,6 +124,8 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getProjects', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\ListProjectsResponse', ], 'SearchProjects' => [ 'pageStreaming' => [ @@ -72,6 +136,35 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getProjects', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\SearchProjectsResponse', + ], + 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'templateMap' => [ + 'project' => 'projects/{project}', ], ], ], diff --git a/ResourceManager/src/V3/resources/tag_bindings_descriptor_config.php b/ResourceManager/src/V3/resources/tag_bindings_descriptor_config.php index d5e99aa90b6e..1614f5336c74 100644 --- a/ResourceManager/src/V3/resources/tag_bindings_descriptor_config.php +++ b/ResourceManager/src/V3/resources/tag_bindings_descriptor_config.php @@ -12,6 +12,7 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, ], 'DeleteTagBinding' => [ 'longRunning' => [ @@ -22,6 +23,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListEffectiveTags' => [ 'pageStreaming' => [ @@ -32,6 +42,8 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getEffectiveTags', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\ListEffectiveTagsResponse', ], 'ListTagBindings' => [ 'pageStreaming' => [ @@ -42,6 +54,11 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getTagBindings', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\ListTagBindingsResponse', + ], + 'templateMap' => [ + 'tagBinding' => 'tagBindings/{tag_binding}', ], ], ], diff --git a/ResourceManager/src/V3/resources/tag_holds_descriptor_config.php b/ResourceManager/src/V3/resources/tag_holds_descriptor_config.php index c7e386d4a935..4f43098bce33 100644 --- a/ResourceManager/src/V3/resources/tag_holds_descriptor_config.php +++ b/ResourceManager/src/V3/resources/tag_holds_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteTagHold' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListTagHolds' => [ 'pageStreaming' => [ @@ -32,6 +50,20 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getTagHolds', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\ListTagHoldsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'tagHold' => 'tagValues/{tag_value}/tagHolds/{tag_hold}', + 'tagValue' => 'tagValues/{tag_value}', ], ], ], diff --git a/ResourceManager/src/V3/resources/tag_keys_descriptor_config.php b/ResourceManager/src/V3/resources/tag_keys_descriptor_config.php index 337d4779f7ce..a1a78baeb784 100644 --- a/ResourceManager/src/V3/resources/tag_keys_descriptor_config.php +++ b/ResourceManager/src/V3/resources/tag_keys_descriptor_config.php @@ -12,6 +12,7 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, ], 'DeleteTagKey' => [ 'longRunning' => [ @@ -22,6 +23,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateTagKey' => [ 'longRunning' => [ @@ -32,6 +42,44 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'tag_key.name', + 'fieldAccessors' => [ + 'getTagKey', + 'getName', + ], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'GetNamespacedTagKey' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\TagKey', + ], + 'GetTagKey' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\TagKey', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListTagKeys' => [ 'pageStreaming' => [ @@ -42,6 +90,35 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getTagKeys', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\ListTagKeysResponse', + ], + 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'templateMap' => [ + 'tagKey' => 'tagKeys/{tag_key}', ], ], ], diff --git a/ResourceManager/src/V3/resources/tag_values_descriptor_config.php b/ResourceManager/src/V3/resources/tag_values_descriptor_config.php index 706c5f124be6..ed3a5434f2ba 100644 --- a/ResourceManager/src/V3/resources/tag_values_descriptor_config.php +++ b/ResourceManager/src/V3/resources/tag_values_descriptor_config.php @@ -12,6 +12,7 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, ], 'DeleteTagValue' => [ 'longRunning' => [ @@ -22,6 +23,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateTagValue' => [ 'longRunning' => [ @@ -32,6 +42,44 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'tag_value.name', + 'fieldAccessors' => [ + 'getTagValue', + 'getName', + ], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'GetNamespacedTagValue' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\TagValue', + ], + 'GetTagValue' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\TagValue', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListTagValues' => [ 'pageStreaming' => [ @@ -42,6 +90,35 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getTagValues', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\ResourceManager\V3\ListTagValuesResponse', + ], + 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'templateMap' => [ + 'tagValue' => 'tagValues/{tag_value}', ], ], ], diff --git a/ResourceManager/tests/Unit/V3/Client/FoldersClientTest.php b/ResourceManager/tests/Unit/V3/Client/FoldersClientTest.php new file mode 100644 index 000000000000..a0bbd4e1723a --- /dev/null +++ b/ResourceManager/tests/Unit/V3/Client/FoldersClientTest.php @@ -0,0 +1,1232 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return FoldersClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new FoldersClient($options); + } + + /** @test */ + public function createFolderTest() + { + $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/createFolderTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Folder(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createFolderTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $folder = new Folder(); + $folderParent = 'folderParent-1307212104'; + $folder->setParent($folderParent); + $request = (new CreateFolderRequest()) + ->setFolder($folder); + $response = $gapicClient->createFolder($request); + $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.resourcemanager.v3.Folders/CreateFolder', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getFolder(); + $this->assertProtobufEquals($folder, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createFolderTest'); + $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 createFolderExceptionTest() + { + $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/createFolderTest'); + $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 + $folder = new Folder(); + $folderParent = 'folderParent-1307212104'; + $folder->setParent($folderParent); + $request = (new CreateFolderRequest()) + ->setFolder($folder); + $response = $gapicClient->createFolder($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createFolderTest'); + 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 deleteFolderTest() + { + $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/deleteFolderTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Folder(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteFolderTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->folderName('[FOLDER]'); + $request = (new DeleteFolderRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteFolder($request); + $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.resourcemanager.v3.Folders/DeleteFolder', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteFolderTest'); + $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 deleteFolderExceptionTest() + { + $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/deleteFolderTest'); + $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->folderName('[FOLDER]'); + $request = (new DeleteFolderRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteFolder($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteFolderTest'); + 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 getFolderTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Folder(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->folderName('[FOLDER]'); + $request = (new GetFolderRequest()) + ->setName($formattedName); + $response = $gapicClient->getFolder($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Folders/GetFolder', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getFolderExceptionTest() + { + $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->folderName('[FOLDER]'); + $request = (new GetFolderRequest()) + ->setName($formattedName); + try { + $gapicClient->getFolder($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Folders/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listFoldersTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $foldersElement = new Folder(); + $folders = [ + $foldersElement, + ]; + $expectedResponse = new ListFoldersResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setFolders($folders); + $transport->addResponse($expectedResponse); + // Mock request + $parent = 'parent-995424086'; + $request = (new ListFoldersRequest()) + ->setParent($parent); + $response = $gapicClient->listFolders($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getFolders()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Folders/ListFolders', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($parent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listFoldersExceptionTest() + { + $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'; + $request = (new ListFoldersRequest()) + ->setParent($parent); + try { + $gapicClient->listFolders($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function moveFolderTest() + { + $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/moveFolderTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Folder(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/moveFolderTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->folderName('[FOLDER]'); + $destinationParent = 'destinationParent-1362053637'; + $request = (new MoveFolderRequest()) + ->setName($formattedName) + ->setDestinationParent($destinationParent); + $response = $gapicClient->moveFolder($request); + $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.resourcemanager.v3.Folders/MoveFolder', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualApiRequestObject->getDestinationParent(); + $this->assertProtobufEquals($destinationParent, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/moveFolderTest'); + $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 moveFolderExceptionTest() + { + $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/moveFolderTest'); + $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->folderName('[FOLDER]'); + $destinationParent = 'destinationParent-1362053637'; + $request = (new MoveFolderRequest()) + ->setName($formattedName) + ->setDestinationParent($destinationParent); + $response = $gapicClient->moveFolder($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/moveFolderTest'); + 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 searchFoldersTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $foldersElement = new Folder(); + $folders = [ + $foldersElement, + ]; + $expectedResponse = new SearchFoldersResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setFolders($folders); + $transport->addResponse($expectedResponse); + $request = new SearchFoldersRequest(); + $response = $gapicClient->searchFolders($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getFolders()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Folders/SearchFolders', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchFoldersExceptionTest() + { + $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); + $request = new SearchFoldersRequest(); + try { + $gapicClient->searchFolders($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Folders/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Folders/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function undeleteFolderTest() + { + $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/undeleteFolderTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Folder(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/undeleteFolderTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->folderName('[FOLDER]'); + $request = (new UndeleteFolderRequest()) + ->setName($formattedName); + $response = $gapicClient->undeleteFolder($request); + $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.resourcemanager.v3.Folders/UndeleteFolder', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/undeleteFolderTest'); + $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 undeleteFolderExceptionTest() + { + $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/undeleteFolderTest'); + $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->folderName('[FOLDER]'); + $request = (new UndeleteFolderRequest()) + ->setName($formattedName); + $response = $gapicClient->undeleteFolder($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/undeleteFolderTest'); + 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 updateFolderTest() + { + $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/updateFolderTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Folder(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateFolderTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $folder = new Folder(); + $folderParent = 'folderParent-1307212104'; + $folder->setParent($folderParent); + $updateMask = new FieldMask(); + $request = (new UpdateFolderRequest()) + ->setFolder($folder) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateFolder($request); + $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.resourcemanager.v3.Folders/UpdateFolder', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getFolder(); + $this->assertProtobufEquals($folder, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateFolderTest'); + $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 updateFolderExceptionTest() + { + $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/updateFolderTest'); + $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 + $folder = new Folder(); + $folderParent = 'folderParent-1307212104'; + $folder->setParent($folderParent); + $updateMask = new FieldMask(); + $request = (new UpdateFolderRequest()) + ->setFolder($folder) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateFolder($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateFolderTest'); + 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 createFolderAsyncTest() + { + $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/createFolderTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Folder(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createFolderTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $folder = new Folder(); + $folderParent = 'folderParent-1307212104'; + $folder->setParent($folderParent); + $request = (new CreateFolderRequest()) + ->setFolder($folder); + $response = $gapicClient->createFolderAsync($request)->wait(); + $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.resourcemanager.v3.Folders/CreateFolder', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getFolder(); + $this->assertProtobufEquals($folder, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createFolderTest'); + $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()); + } +} diff --git a/ResourceManager/tests/Unit/V3/Client/OrganizationsClientTest.php b/ResourceManager/tests/Unit/V3/Client/OrganizationsClientTest.php new file mode 100644 index 000000000000..59a54f265e91 --- /dev/null +++ b/ResourceManager/tests/Unit/V3/Client/OrganizationsClientTest.php @@ -0,0 +1,440 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return OrganizationsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new OrganizationsClient($options); + } + + /** @test */ + public function getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Organizations/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getOrganizationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $directoryCustomerId = 'directoryCustomerId813284938'; + $etag = 'etag3123477'; + $expectedResponse = new Organization(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDirectoryCustomerId($directoryCustomerId); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->organizationName('[ORGANIZATION]'); + $request = (new GetOrganizationRequest()) + ->setName($formattedName); + $response = $gapicClient->getOrganization($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Organizations/GetOrganization', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getOrganizationExceptionTest() + { + $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->organizationName('[ORGANIZATION]'); + $request = (new GetOrganizationRequest()) + ->setName($formattedName); + try { + $gapicClient->getOrganization($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchOrganizationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $organizationsElement = new Organization(); + $organizations = [ + $organizationsElement, + ]; + $expectedResponse = new SearchOrganizationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setOrganizations($organizations); + $transport->addResponse($expectedResponse); + $request = new SearchOrganizationsRequest(); + $response = $gapicClient->searchOrganizations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getOrganizations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Organizations/SearchOrganizations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchOrganizationsExceptionTest() + { + $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); + $request = new SearchOrganizationsRequest(); + try { + $gapicClient->searchOrganizations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Organizations/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Organizations/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicyAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Organizations/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/ResourceManager/tests/Unit/V3/Client/ProjectsClientTest.php b/ResourceManager/tests/Unit/V3/Client/ProjectsClientTest.php new file mode 100644 index 000000000000..8919a06cc909 --- /dev/null +++ b/ResourceManager/tests/Unit/V3/Client/ProjectsClientTest.php @@ -0,0 +1,1229 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ProjectsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ProjectsClient($options); + } + + /** @test */ + public function createProjectTest() + { + $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/createProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $projectId = 'projectId-1969970175'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Project(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setProjectId($projectId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $project = new Project(); + $request = (new CreateProjectRequest()) + ->setProject($project); + $response = $gapicClient->createProject($request); + $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.resourcemanager.v3.Projects/CreateProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getProject(); + $this->assertProtobufEquals($project, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createProjectTest'); + $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 createProjectExceptionTest() + { + $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/createProjectTest'); + $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 + $project = new Project(); + $request = (new CreateProjectRequest()) + ->setProject($project); + $response = $gapicClient->createProject($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createProjectTest'); + 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 deleteProjectTest() + { + $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/deleteProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $projectId = 'projectId-1969970175'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Project(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setProjectId($projectId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->projectName('[PROJECT]'); + $request = (new DeleteProjectRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteProject($request); + $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.resourcemanager.v3.Projects/DeleteProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteProjectTest'); + $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 deleteProjectExceptionTest() + { + $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/deleteProjectTest'); + $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->projectName('[PROJECT]'); + $request = (new DeleteProjectRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteProject($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteProjectTest'); + 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 getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Projects/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getProjectTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $projectId = 'projectId-1969970175'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Project(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setProjectId($projectId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->projectName('[PROJECT]'); + $request = (new GetProjectRequest()) + ->setName($formattedName); + $response = $gapicClient->getProject($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Projects/GetProject', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getProjectExceptionTest() + { + $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->projectName('[PROJECT]'); + $request = (new GetProjectRequest()) + ->setName($formattedName); + try { + $gapicClient->getProject($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProjectsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $projectsElement = new Project(); + $projects = [ + $projectsElement, + ]; + $expectedResponse = new ListProjectsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProjects($projects); + $transport->addResponse($expectedResponse); + // Mock request + $parent = 'parent-995424086'; + $request = (new ListProjectsRequest()) + ->setParent($parent); + $response = $gapicClient->listProjects($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProjects()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Projects/ListProjects', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($parent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProjectsExceptionTest() + { + $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'; + $request = (new ListProjectsRequest()) + ->setParent($parent); + try { + $gapicClient->listProjects($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function moveProjectTest() + { + $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/moveProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $projectId = 'projectId-1969970175'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Project(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setProjectId($projectId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/moveProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->projectName('[PROJECT]'); + $destinationParent = 'destinationParent-1362053637'; + $request = (new MoveProjectRequest()) + ->setName($formattedName) + ->setDestinationParent($destinationParent); + $response = $gapicClient->moveProject($request); + $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.resourcemanager.v3.Projects/MoveProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualApiRequestObject->getDestinationParent(); + $this->assertProtobufEquals($destinationParent, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/moveProjectTest'); + $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 moveProjectExceptionTest() + { + $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/moveProjectTest'); + $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->projectName('[PROJECT]'); + $destinationParent = 'destinationParent-1362053637'; + $request = (new MoveProjectRequest()) + ->setName($formattedName) + ->setDestinationParent($destinationParent); + $response = $gapicClient->moveProject($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/moveProjectTest'); + 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 searchProjectsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $projectsElement = new Project(); + $projects = [ + $projectsElement, + ]; + $expectedResponse = new SearchProjectsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProjects($projects); + $transport->addResponse($expectedResponse); + $request = new SearchProjectsRequest(); + $response = $gapicClient->searchProjects($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProjects()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Projects/SearchProjects', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchProjectsExceptionTest() + { + $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); + $request = new SearchProjectsRequest(); + try { + $gapicClient->searchProjects($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Projects/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.Projects/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function undeleteProjectTest() + { + $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/undeleteProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $projectId = 'projectId-1969970175'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Project(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setProjectId($projectId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/undeleteProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->projectName('[PROJECT]'); + $request = (new UndeleteProjectRequest()) + ->setName($formattedName); + $response = $gapicClient->undeleteProject($request); + $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.resourcemanager.v3.Projects/UndeleteProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/undeleteProjectTest'); + $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 undeleteProjectExceptionTest() + { + $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/undeleteProjectTest'); + $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->projectName('[PROJECT]'); + $request = (new UndeleteProjectRequest()) + ->setName($formattedName); + $response = $gapicClient->undeleteProject($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/undeleteProjectTest'); + 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 updateProjectTest() + { + $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/updateProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $projectId = 'projectId-1969970175'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Project(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setProjectId($projectId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $project = new Project(); + $request = (new UpdateProjectRequest()) + ->setProject($project); + $response = $gapicClient->updateProject($request); + $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.resourcemanager.v3.Projects/UpdateProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getProject(); + $this->assertProtobufEquals($project, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateProjectTest'); + $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 updateProjectExceptionTest() + { + $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/updateProjectTest'); + $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 + $project = new Project(); + $request = (new UpdateProjectRequest()) + ->setProject($project); + $response = $gapicClient->updateProject($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateProjectTest'); + 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 createProjectAsyncTest() + { + $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/createProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $projectId = 'projectId-1969970175'; + $displayName = 'displayName1615086568'; + $etag = 'etag3123477'; + $expectedResponse = new Project(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setProjectId($projectId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $project = new Project(); + $request = (new CreateProjectRequest()) + ->setProject($project); + $response = $gapicClient->createProjectAsync($request)->wait(); + $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.resourcemanager.v3.Projects/CreateProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getProject(); + $this->assertProtobufEquals($project, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createProjectTest'); + $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()); + } +} diff --git a/ResourceManager/tests/Unit/V3/Client/TagBindingsClientTest.php b/ResourceManager/tests/Unit/V3/Client/TagBindingsClientTest.php new file mode 100644 index 000000000000..8633209b1539 --- /dev/null +++ b/ResourceManager/tests/Unit/V3/Client/TagBindingsClientTest.php @@ -0,0 +1,539 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return TagBindingsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new TagBindingsClient($options); + } + + /** @test */ + public function createTagBindingTest() + { + $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/createTagBindingTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $tagValue = 'tagValue2092898444'; + $tagValueNamespacedName = 'tagValueNamespacedName1368345838'; + $expectedResponse = new TagBinding(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setTagValue($tagValue); + $expectedResponse->setTagValueNamespacedName($tagValueNamespacedName); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTagBindingTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $tagBinding = new TagBinding(); + $request = (new CreateTagBindingRequest()) + ->setTagBinding($tagBinding); + $response = $gapicClient->createTagBinding($request); + $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.resourcemanager.v3.TagBindings/CreateTagBinding', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTagBinding(); + $this->assertProtobufEquals($tagBinding, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagBindingTest'); + $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 createTagBindingExceptionTest() + { + $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/createTagBindingTest'); + $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 + $tagBinding = new TagBinding(); + $request = (new CreateTagBindingRequest()) + ->setTagBinding($tagBinding); + $response = $gapicClient->createTagBinding($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagBindingTest'); + 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 deleteTagBindingTest() + { + $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/deleteTagBindingTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteTagBindingTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->tagBindingName('[TAG_BINDING]'); + $request = (new DeleteTagBindingRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTagBinding($request); + $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.resourcemanager.v3.TagBindings/DeleteTagBinding', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTagBindingTest'); + $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 deleteTagBindingExceptionTest() + { + $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/deleteTagBindingTest'); + $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->tagBindingName('[TAG_BINDING]'); + $request = (new DeleteTagBindingRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTagBinding($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTagBindingTest'); + 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 listEffectiveTagsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $effectiveTagsElement = new EffectiveTag(); + $effectiveTags = [ + $effectiveTagsElement, + ]; + $expectedResponse = new ListEffectiveTagsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setEffectiveTags($effectiveTags); + $transport->addResponse($expectedResponse); + // Mock request + $parent = 'parent-995424086'; + $request = (new ListEffectiveTagsRequest()) + ->setParent($parent); + $response = $gapicClient->listEffectiveTags($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getEffectiveTags()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagBindings/ListEffectiveTags', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($parent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listEffectiveTagsExceptionTest() + { + $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'; + $request = (new ListEffectiveTagsRequest()) + ->setParent($parent); + try { + $gapicClient->listEffectiveTags($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTagBindingsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $tagBindingsElement = new TagBinding(); + $tagBindings = [ + $tagBindingsElement, + ]; + $expectedResponse = new ListTagBindingsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTagBindings($tagBindings); + $transport->addResponse($expectedResponse); + // Mock request + $parent = 'parent-995424086'; + $request = (new ListTagBindingsRequest()) + ->setParent($parent); + $response = $gapicClient->listTagBindings($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTagBindings()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagBindings/ListTagBindings', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($parent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTagBindingsExceptionTest() + { + $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'; + $request = (new ListTagBindingsRequest()) + ->setParent($parent); + try { + $gapicClient->listTagBindings($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createTagBindingAsyncTest() + { + $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/createTagBindingTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $tagValue = 'tagValue2092898444'; + $tagValueNamespacedName = 'tagValueNamespacedName1368345838'; + $expectedResponse = new TagBinding(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setTagValue($tagValue); + $expectedResponse->setTagValueNamespacedName($tagValueNamespacedName); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTagBindingTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $tagBinding = new TagBinding(); + $request = (new CreateTagBindingRequest()) + ->setTagBinding($tagBinding); + $response = $gapicClient->createTagBindingAsync($request)->wait(); + $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.resourcemanager.v3.TagBindings/CreateTagBinding', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTagBinding(); + $this->assertProtobufEquals($tagBinding, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagBindingTest'); + $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()); + } +} diff --git a/ResourceManager/tests/Unit/V3/Client/TagHoldsClientTest.php b/ResourceManager/tests/Unit/V3/Client/TagHoldsClientTest.php new file mode 100644 index 000000000000..eaa7f5b47a3c --- /dev/null +++ b/ResourceManager/tests/Unit/V3/Client/TagHoldsClientTest.php @@ -0,0 +1,480 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return TagHoldsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new TagHoldsClient($options); + } + + /** @test */ + public function createTagHoldTest() + { + $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/createTagHoldTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $holder = 'holder-1211707988'; + $origin = 'origin-1008619738'; + $helpLink = 'helpLink1297152568'; + $expectedResponse = new TagHold(); + $expectedResponse->setName($name); + $expectedResponse->setHolder($holder); + $expectedResponse->setOrigin($origin); + $expectedResponse->setHelpLink($helpLink); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTagHoldTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->tagValueName('[TAG_VALUE]'); + $tagHold = new TagHold(); + $tagHoldHolder = 'tagHoldHolder-501201275'; + $tagHold->setHolder($tagHoldHolder); + $request = (new CreateTagHoldRequest()) + ->setParent($formattedParent) + ->setTagHold($tagHold); + $response = $gapicClient->createTagHold($request); + $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.resourcemanager.v3.TagHolds/CreateTagHold', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getTagHold(); + $this->assertProtobufEquals($tagHold, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagHoldTest'); + $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 createTagHoldExceptionTest() + { + $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/createTagHoldTest'); + $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->tagValueName('[TAG_VALUE]'); + $tagHold = new TagHold(); + $tagHoldHolder = 'tagHoldHolder-501201275'; + $tagHold->setHolder($tagHoldHolder); + $request = (new CreateTagHoldRequest()) + ->setParent($formattedParent) + ->setTagHold($tagHold); + $response = $gapicClient->createTagHold($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagHoldTest'); + 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 deleteTagHoldTest() + { + $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/deleteTagHoldTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteTagHoldTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->tagHoldName('[TAG_VALUE]', '[TAG_HOLD]'); + $request = (new DeleteTagHoldRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTagHold($request); + $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.resourcemanager.v3.TagHolds/DeleteTagHold', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTagHoldTest'); + $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 deleteTagHoldExceptionTest() + { + $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/deleteTagHoldTest'); + $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->tagHoldName('[TAG_VALUE]', '[TAG_HOLD]'); + $request = (new DeleteTagHoldRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTagHold($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTagHoldTest'); + 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 listTagHoldsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $tagHoldsElement = new TagHold(); + $tagHolds = [ + $tagHoldsElement, + ]; + $expectedResponse = new ListTagHoldsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTagHolds($tagHolds); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->tagValueName('[TAG_VALUE]'); + $request = (new ListTagHoldsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listTagHolds($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTagHolds()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagHolds/ListTagHolds', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTagHoldsExceptionTest() + { + $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->tagValueName('[TAG_VALUE]'); + $request = (new ListTagHoldsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listTagHolds($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createTagHoldAsyncTest() + { + $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/createTagHoldTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $holder = 'holder-1211707988'; + $origin = 'origin-1008619738'; + $helpLink = 'helpLink1297152568'; + $expectedResponse = new TagHold(); + $expectedResponse->setName($name); + $expectedResponse->setHolder($holder); + $expectedResponse->setOrigin($origin); + $expectedResponse->setHelpLink($helpLink); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTagHoldTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->tagValueName('[TAG_VALUE]'); + $tagHold = new TagHold(); + $tagHoldHolder = 'tagHoldHolder-501201275'; + $tagHold->setHolder($tagHoldHolder); + $request = (new CreateTagHoldRequest()) + ->setParent($formattedParent) + ->setTagHold($tagHold); + $response = $gapicClient->createTagHoldAsync($request)->wait(); + $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.resourcemanager.v3.TagHolds/CreateTagHold', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getTagHold(); + $this->assertProtobufEquals($tagHold, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagHoldTest'); + $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()); + } +} diff --git a/ResourceManager/tests/Unit/V3/Client/TagKeysClientTest.php b/ResourceManager/tests/Unit/V3/Client/TagKeysClientTest.php new file mode 100644 index 000000000000..ab103825e272 --- /dev/null +++ b/ResourceManager/tests/Unit/V3/Client/TagKeysClientTest.php @@ -0,0 +1,988 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return TagKeysClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new TagKeysClient($options); + } + + /** @test */ + public function createTagKeyTest() + { + $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/createTagKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagKey(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTagKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $tagKey = new TagKey(); + $tagKeyShortName = 'tagKeyShortName-1212707262'; + $tagKey->setShortName($tagKeyShortName); + $request = (new CreateTagKeyRequest()) + ->setTagKey($tagKey); + $response = $gapicClient->createTagKey($request); + $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.resourcemanager.v3.TagKeys/CreateTagKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTagKey(); + $this->assertProtobufEquals($tagKey, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagKeyTest'); + $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 createTagKeyExceptionTest() + { + $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/createTagKeyTest'); + $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 + $tagKey = new TagKey(); + $tagKeyShortName = 'tagKeyShortName-1212707262'; + $tagKey->setShortName($tagKeyShortName); + $request = (new CreateTagKeyRequest()) + ->setTagKey($tagKey); + $response = $gapicClient->createTagKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagKeyTest'); + 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 deleteTagKeyTest() + { + $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/deleteTagKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new TagKey(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteTagKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->tagKeyName('[TAG_KEY]'); + $request = (new DeleteTagKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTagKey($request); + $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.resourcemanager.v3.TagKeys/DeleteTagKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTagKeyTest'); + $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 deleteTagKeyExceptionTest() + { + $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/deleteTagKeyTest'); + $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->tagKeyName('[TAG_KEY]'); + $request = (new DeleteTagKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTagKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTagKeyTest'); + 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 getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagKeys/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNamespacedTagKeyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagKey(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->tagKeyName('[TAG_KEY]'); + $request = (new GetNamespacedTagKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->getNamespacedTagKey($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagKeys/GetNamespacedTagKey', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNamespacedTagKeyExceptionTest() + { + $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->tagKeyName('[TAG_KEY]'); + $request = (new GetNamespacedTagKeyRequest()) + ->setName($formattedName); + try { + $gapicClient->getNamespacedTagKey($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTagKeyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagKey(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->tagKeyName('[TAG_KEY]'); + $request = (new GetTagKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->getTagKey($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagKeys/GetTagKey', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTagKeyExceptionTest() + { + $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->tagKeyName('[TAG_KEY]'); + $request = (new GetTagKeyRequest()) + ->setName($formattedName); + try { + $gapicClient->getTagKey($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTagKeysTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $tagKeysElement = new TagKey(); + $tagKeys = [ + $tagKeysElement, + ]; + $expectedResponse = new ListTagKeysResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTagKeys($tagKeys); + $transport->addResponse($expectedResponse); + // Mock request + $parent = 'parent-995424086'; + $request = (new ListTagKeysRequest()) + ->setParent($parent); + $response = $gapicClient->listTagKeys($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTagKeys()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagKeys/ListTagKeys', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($parent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTagKeysExceptionTest() + { + $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'; + $request = (new ListTagKeysRequest()) + ->setParent($parent); + try { + $gapicClient->listTagKeys($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagKeys/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagKeys/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateTagKeyTest() + { + $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/updateTagKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagKey(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateTagKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $tagKey = new TagKey(); + $tagKeyShortName = 'tagKeyShortName-1212707262'; + $tagKey->setShortName($tagKeyShortName); + $request = (new UpdateTagKeyRequest()) + ->setTagKey($tagKey); + $response = $gapicClient->updateTagKey($request); + $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.resourcemanager.v3.TagKeys/UpdateTagKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTagKey(); + $this->assertProtobufEquals($tagKey, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateTagKeyTest'); + $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 updateTagKeyExceptionTest() + { + $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/updateTagKeyTest'); + $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 + $tagKey = new TagKey(); + $tagKeyShortName = 'tagKeyShortName-1212707262'; + $tagKey->setShortName($tagKeyShortName); + $request = (new UpdateTagKeyRequest()) + ->setTagKey($tagKey); + $response = $gapicClient->updateTagKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateTagKeyTest'); + 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 createTagKeyAsyncTest() + { + $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/createTagKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagKey(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTagKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $tagKey = new TagKey(); + $tagKeyShortName = 'tagKeyShortName-1212707262'; + $tagKey->setShortName($tagKeyShortName); + $request = (new CreateTagKeyRequest()) + ->setTagKey($tagKey); + $response = $gapicClient->createTagKeyAsync($request)->wait(); + $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.resourcemanager.v3.TagKeys/CreateTagKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTagKey(); + $this->assertProtobufEquals($tagKey, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagKeyTest'); + $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()); + } +} diff --git a/ResourceManager/tests/Unit/V3/Client/TagValuesClientTest.php b/ResourceManager/tests/Unit/V3/Client/TagValuesClientTest.php new file mode 100644 index 000000000000..1826ca90dff0 --- /dev/null +++ b/ResourceManager/tests/Unit/V3/Client/TagValuesClientTest.php @@ -0,0 +1,988 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return TagValuesClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new TagValuesClient($options); + } + + /** @test */ + public function createTagValueTest() + { + $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/createTagValueTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagValue(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTagValueTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $tagValue = new TagValue(); + $tagValueShortName = 'tagValueShortName397125872'; + $tagValue->setShortName($tagValueShortName); + $request = (new CreateTagValueRequest()) + ->setTagValue($tagValue); + $response = $gapicClient->createTagValue($request); + $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.resourcemanager.v3.TagValues/CreateTagValue', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTagValue(); + $this->assertProtobufEquals($tagValue, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagValueTest'); + $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 createTagValueExceptionTest() + { + $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/createTagValueTest'); + $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 + $tagValue = new TagValue(); + $tagValueShortName = 'tagValueShortName397125872'; + $tagValue->setShortName($tagValueShortName); + $request = (new CreateTagValueRequest()) + ->setTagValue($tagValue); + $response = $gapicClient->createTagValue($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagValueTest'); + 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 deleteTagValueTest() + { + $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/deleteTagValueTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new TagValue(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteTagValueTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->tagValueName('[TAG_VALUE]'); + $request = (new DeleteTagValueRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTagValue($request); + $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.resourcemanager.v3.TagValues/DeleteTagValue', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTagValueTest'); + $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 deleteTagValueExceptionTest() + { + $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/deleteTagValueTest'); + $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->tagValueName('[TAG_VALUE]'); + $request = (new DeleteTagValueRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTagValue($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTagValueTest'); + 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 getIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + $response = $gapicClient->getIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagValues/GetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + try { + $gapicClient->getIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNamespacedTagValueTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagValue(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->tagValueName('[TAG_VALUE]'); + $request = (new GetNamespacedTagValueRequest()) + ->setName($formattedName); + $response = $gapicClient->getNamespacedTagValue($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagValues/GetNamespacedTagValue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNamespacedTagValueExceptionTest() + { + $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->tagValueName('[TAG_VALUE]'); + $request = (new GetNamespacedTagValueRequest()) + ->setName($formattedName); + try { + $gapicClient->getNamespacedTagValue($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTagValueTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagValue(); + $expectedResponse->setName($name2); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->tagValueName('[TAG_VALUE]'); + $request = (new GetTagValueRequest()) + ->setName($formattedName); + $response = $gapicClient->getTagValue($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagValues/GetTagValue', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTagValueExceptionTest() + { + $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->tagValueName('[TAG_VALUE]'); + $request = (new GetTagValueRequest()) + ->setName($formattedName); + try { + $gapicClient->getTagValue($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTagValuesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $tagValuesElement = new TagValue(); + $tagValues = [ + $tagValuesElement, + ]; + $expectedResponse = new ListTagValuesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTagValues($tagValues); + $transport->addResponse($expectedResponse); + // Mock request + $parent = 'parent-995424086'; + $request = (new ListTagValuesRequest()) + ->setParent($parent); + $response = $gapicClient->listTagValues($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTagValues()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagValues/ListTagValues', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($parent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTagValuesExceptionTest() + { + $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'; + $request = (new ListTagValuesRequest()) + ->setParent($parent); + try { + $gapicClient->listTagValues($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $version = 351608024; + $etag = '21'; + $expectedResponse = new Policy(); + $expectedResponse->setVersion($version); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + $response = $gapicClient->setIamPolicy($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagValues/SetIamPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPolicy(); + $this->assertProtobufEquals($policy, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function setIamPolicyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $policy = new Policy(); + $request = (new SetIamPolicyRequest()) + ->setResource($resource) + ->setPolicy($policy); + try { + $gapicClient->setIamPolicy($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new TestIamPermissionsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + $response = $gapicClient->testIamPermissions($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.resourcemanager.v3.TagValues/TestIamPermissions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getPermissions(); + $this->assertProtobufEquals($permissions, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function testIamPermissionsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $resource = 'resource-341064690'; + $permissions = []; + $request = (new TestIamPermissionsRequest()) + ->setResource($resource) + ->setPermissions($permissions); + try { + $gapicClient->testIamPermissions($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateTagValueTest() + { + $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/updateTagValueTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagValue(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateTagValueTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $tagValue = new TagValue(); + $tagValueShortName = 'tagValueShortName397125872'; + $tagValue->setShortName($tagValueShortName); + $request = (new UpdateTagValueRequest()) + ->setTagValue($tagValue); + $response = $gapicClient->updateTagValue($request); + $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.resourcemanager.v3.TagValues/UpdateTagValue', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTagValue(); + $this->assertProtobufEquals($tagValue, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateTagValueTest'); + $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 updateTagValueExceptionTest() + { + $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/updateTagValueTest'); + $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 + $tagValue = new TagValue(); + $tagValueShortName = 'tagValueShortName397125872'; + $tagValue->setShortName($tagValueShortName); + $request = (new UpdateTagValueRequest()) + ->setTagValue($tagValue); + $response = $gapicClient->updateTagValue($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateTagValueTest'); + 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 createTagValueAsyncTest() + { + $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/createTagValueTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $parent = 'parent-995424086'; + $shortName = 'shortName1565793390'; + $namespacedName = 'namespacedName1945728673'; + $description = 'description-1724546052'; + $etag = 'etag3123477'; + $expectedResponse = new TagValue(); + $expectedResponse->setName($name); + $expectedResponse->setParent($parent); + $expectedResponse->setShortName($shortName); + $expectedResponse->setNamespacedName($namespacedName); + $expectedResponse->setDescription($description); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTagValueTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $tagValue = new TagValue(); + $tagValueShortName = 'tagValueShortName397125872'; + $tagValue->setShortName($tagValueShortName); + $request = (new CreateTagValueRequest()) + ->setTagValue($tagValue); + $response = $gapicClient->createTagValueAsync($request)->wait(); + $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.resourcemanager.v3.TagValues/CreateTagValue', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTagValue(); + $this->assertProtobufEquals($tagValue, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTagValueTest'); + $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()); + } +}