From bc464d215bd7145dfbed9505df39ee9a3ebc1658 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 12 May 2023 07:51:06 -0700 Subject: [PATCH] feat: add new client surface to preview clients (#6204) chore: update the gapic generator to 1.7.4 PiperOrigin-RevId: 530731364 Source-Link: https://github.com/googleapis/googleapis/commit/cbddac7303b74af94550ced0f43651747f1f64ed Source-Link: https://github.com/googleapis/googleapis-gen/commit/539cbcf4b41e886d52a3e2d82ab9fdc446ba0e04 Copy-Tag: eyJwIjoiUHJpdmF0ZUNhdGFsb2cvLk93bEJvdC55YW1sIiwiaCI6IjUzOWNiY2Y0YjQxZTg4NmQ1MmEzZTJkODJhYjlmZGM0NDZiYTBlMDQifQ== Copy-Tag: eyJwIjoiUmVjb21tZW5kYXRpb25FbmdpbmUvLk93bEJvdC55YW1sIiwiaCI6IjUzOWNiY2Y0YjQxZTg4NmQ1MmEzZTJkODJhYjlmZGM0NDZiYTBlMDQifQ== Copy-Tag: eyJwIjoiUnVuLy5Pd2xCb3QueWFtbCIsImgiOiI1MzljYmNmNGI0MWU4ODZkNTJhM2UyZDgyYWI5ZmRjNDQ2YmEwZTA0In0= Copy-Tag: eyJwIjoiU2VjdXJpdHlQdWJsaWNDQS8uT3dsQm90LnlhbWwiLCJoIjoiNTM5Y2JjZjRiNDFlODg2ZDUyYTNlMmQ4MmFiOWZkYzQ0NmJhMGUwNCJ9 Copy-Tag: eyJwIjoiU3RvcmFnZUluc2lnaHRzLy5Pd2xCb3QueWFtbCIsImgiOiI1MzljYmNmNGI0MWU4ODZkNTJhM2UyZDgyYWI5ZmRjNDQ2YmEwZTA0In0= Copy-Tag: eyJwIjoiVmlkZW9MaXZlU3RyZWFtLy5Pd2xCb3QueWFtbCIsImgiOiI1MzljYmNmNGI0MWU4ODZkNTJhM2UyZDgyYWI5ZmRjNDQ2YmEwZTA0In0= Copy-Tag: eyJwIjoiVmlkZW9TdGl0Y2hlci8uT3dsQm90LnlhbWwiLCJoIjoiNTM5Y2JjZjRiNDFlODg2ZDUyYTNlMmQ4MmFiOWZkYzQ0NmJhMGUwNCJ9 Copy-Tag: eyJwIjoiVmlkZW9UcmFuc2NvZGVyLy5Pd2xCb3QueWFtbCIsImgiOiI1MzljYmNmNGI0MWU4ODZkNTJhM2UyZDgyYWI5ZmRjNDQ2YmEwZTA0In0= Copy-Tag: eyJwIjoiVm1NaWdyYXRpb24vLk93bEJvdC55YW1sIiwiaCI6IjUzOWNiY2Y0YjQxZTg4NmQ1MmEzZTJkODJhYjlmZGM0NDZiYTBlMDQifQ== Copy-Tag: eyJwIjoiVm13YXJlRW5naW5lLy5Pd2xCb3QueWFtbCIsImgiOiI1MzljYmNmNGI0MWU4ODZkNTJhM2UyZDgyYWI5ZmRjNDQ2YmEwZTA0In0= --- .../PrivateCatalogClient/search_catalogs.php | 9 +- .../PrivateCatalogClient/search_products.php | 9 +- .../PrivateCatalogClient/search_versions.php | 10 +- .../BaseClient/PrivateCatalogBaseClient.php | 271 + .../V1beta1/Client/PrivateCatalogClient.php | 42 + .../private_catalog_descriptor_config.php | 30 + .../Client/PrivateCatalogClientTest.php | 328 ++ .../create_catalog_item.php | 10 +- .../delete_catalog_item.php | 9 +- .../CatalogServiceClient/get_catalog_item.php | 9 +- .../import_catalog_items.php | 10 +- .../list_catalog_items.php | 9 +- .../update_catalog_item.php | 10 +- ...create_prediction_api_key_registration.php | 13 +- ...delete_prediction_api_key_registration.php | 9 +- .../list_prediction_api_key_registrations.php | 9 +- .../PredictionServiceClient/predict.php | 10 +- .../collect_user_event.php | 10 +- .../import_user_events.php | 10 +- .../list_user_events.php | 9 +- .../purge_user_events.php | 10 +- .../write_user_event.php | 10 +- .../BaseClient/CatalogServiceBaseClient.php | 454 ++ .../PredictionApiKeyRegistryBaseClient.php | 333 ++ .../PredictionServiceBaseClient.php | 253 + .../BaseClient/UserEventServiceBaseClient.php | 415 ++ .../V1beta1/Client/CatalogServiceClient.php | 42 + .../Client/PredictionApiKeyRegistryClient.php | 42 + .../Client/PredictionServiceClient.php | 42 + .../V1beta1/Client/UserEventServiceClient.php | 42 + .../src/V1beta1/CollectUserEventRequest.php | 26 + .../src/V1beta1/CreateCatalogItemRequest.php | 17 + ...atePredictionApiKeyRegistrationRequest.php | 17 + .../src/V1beta1/DeleteCatalogItemRequest.php | 15 + ...etePredictionApiKeyRegistrationRequest.php | 15 + .../src/V1beta1/GetCatalogItemRequest.php | 15 + .../src/V1beta1/ImportCatalogItemsRequest.php | 23 + .../src/V1beta1/ImportUserEventsRequest.php | 26 + .../src/V1beta1/ListCatalogItemsRequest.php | 17 + ...stPredictionApiKeyRegistrationsRequest.php | 15 + .../src/V1beta1/ListUserEventsRequest.php | 48 + .../src/V1beta1/PredictRequest.php | 47 + .../src/V1beta1/PurgeUserEventsRequest.php | 39 + .../src/V1beta1/UpdateCatalogItemRequest.php | 21 + .../src/V1beta1/WriteUserEventRequest.php | 17 + .../catalog_service_descriptor_config.php | 71 + ...ion_api_key_registry_descriptor_config.php | 38 + .../prediction_service_descriptor_config.php | 13 + .../user_event_service_descriptor_config.php | 55 + .../Client/CatalogServiceClientTest.php | 634 ++ .../PredictionApiKeyRegistryClientTest.php | 302 + .../Client/PredictionServiceClientTest.php | 210 + .../Client/UserEventServiceClientTest.php | 593 ++ .../V2/ExecutionsClient/delete_execution.php | 9 +- .../V2/ExecutionsClient/get_execution.php | 9 +- .../V2/ExecutionsClient/list_executions.php | 9 +- Run/samples/V2/JobsClient/create_job.php | 11 +- Run/samples/V2/JobsClient/delete_job.php | 9 +- Run/samples/V2/JobsClient/get_iam_policy.php | 9 +- Run/samples/V2/JobsClient/get_job.php | 9 +- Run/samples/V2/JobsClient/list_jobs.php | 9 +- Run/samples/V2/JobsClient/run_job.php | 9 +- Run/samples/V2/JobsClient/set_iam_policy.php | 10 +- .../V2/JobsClient/test_iam_permissions.php | 10 +- Run/samples/V2/JobsClient/update_job.php | 9 +- .../V2/RevisionsClient/delete_revision.php | 9 +- .../V2/RevisionsClient/get_revision.php | 9 +- .../V2/RevisionsClient/list_revisions.php | 9 +- .../V2/ServicesClient/create_service.php | 11 +- .../V2/ServicesClient/delete_service.php | 9 +- .../V2/ServicesClient/get_iam_policy.php | 9 +- Run/samples/V2/ServicesClient/get_service.php | 9 +- .../V2/ServicesClient/list_services.php | 9 +- .../V2/ServicesClient/set_iam_policy.php | 10 +- .../ServicesClient/test_iam_permissions.php | 10 +- .../V2/ServicesClient/update_service.php | 9 +- Run/samples/V2/TasksClient/get_task.php | 9 +- Run/samples/V2/TasksClient/list_tasks.php | 9 +- .../BaseClient/ExecutionsBaseClient.php | 346 ++ .../V2/Client/BaseClient/JobsBaseClient.php | 607 ++ .../Client/BaseClient/RevisionsBaseClient.php | 346 ++ .../Client/BaseClient/ServicesBaseClient.php | 582 ++ .../V2/Client/BaseClient/TasksBaseClient.php | 289 + Run/src/V2/Client/ExecutionsClient.php | 40 + Run/src/V2/Client/JobsClient.php | 40 + Run/src/V2/Client/RevisionsClient.php | 40 + Run/src/V2/Client/ServicesClient.php | 40 + Run/src/V2/Client/TasksClient.php | 40 + Run/src/V2/CreateJobRequest.php | 21 + Run/src/V2/CreateServiceRequest.php | 22 + Run/src/V2/DeleteExecutionRequest.php | 17 + Run/src/V2/DeleteJobRequest.php | 16 + Run/src/V2/DeleteRevisionRequest.php | 16 + Run/src/V2/DeleteServiceRequest.php | 16 + Run/src/V2/GetExecutionRequest.php | 17 + Run/src/V2/GetJobRequest.php | 16 + Run/src/V2/GetRevisionRequest.php | 16 + Run/src/V2/GetServiceRequest.php | 16 + Run/src/V2/GetTaskRequest.php | 16 + Run/src/V2/ListExecutionsRequest.php | 17 + Run/src/V2/ListJobsRequest.php | 16 + Run/src/V2/ListRevisionsRequest.php | 17 + Run/src/V2/ListServicesRequest.php | 17 + Run/src/V2/ListTasksRequest.php | 17 + Run/src/V2/RunJobRequest.php | 16 + Run/src/V2/UpdateJobRequest.php | 13 + Run/src/V2/UpdateServiceRequest.php | 13 + .../executions_descriptor_config.php | 35 + .../V2/resources/jobs_descriptor_config.php | 104 + .../resources/revisions_descriptor_config.php | 38 + .../resources/services_descriptor_config.php | 100 + .../V2/resources/tasks_descriptor_config.php | 26 + .../Unit/V2/Client/ExecutionsClientTest.php | 484 ++ Run/tests/Unit/V2/Client/JobsClientTest.php | 1160 ++++ .../Unit/V2/Client/RevisionsClientTest.php | 466 ++ .../Unit/V2/Client/ServicesClientTest.php | 1024 ++++ Run/tests/Unit/V2/Client/TasksClientTest.php | 285 + .../create_external_account_key.php | 13 +- ...cCertificateAuthorityServiceBaseClient.php | 268 + ...ublicCertificateAuthorityServiceClient.php | 42 + .../CreateExternalAccountKeyRequest.php | 21 + ...te_authority_service_descriptor_config.php | 19 +- ...cCertificateAuthorityServiceClientTest.php | 173 + .../create_report_config.php | 10 +- .../delete_report_config.php | 9 +- .../V1/StorageInsightsClient/get_location.php | 8 +- .../get_report_config.php | 9 +- .../get_report_detail.php | 9 +- .../StorageInsightsClient/list_locations.php | 8 +- .../list_report_configs.php | 9 +- .../list_report_details.php | 9 +- .../update_report_config.php | 10 +- .../BaseClient/StorageInsightsBaseClient.php | 485 ++ .../src/V1/Client/StorageInsightsClient.php | 40 + .../src/V1/CreateReportConfigRequest.php | 16 + .../src/V1/DeleteReportConfigRequest.php | 14 + .../src/V1/GetReportConfigRequest.php | 14 + .../src/V1/GetReportDetailRequest.php | 14 + .../src/V1/ListReportConfigsRequest.php | 14 + .../src/V1/ListReportDetailsRequest.php | 14 + .../src/V1/UpdateReportConfigRequest.php | 19 + .../storage_insights_descriptor_config.php | 106 + .../V1/Client/StorageInsightsClientTest.php | 719 +++ .../create_channel.php | 11 +- .../LivestreamServiceClient/create_event.php | 11 +- .../LivestreamServiceClient/create_input.php | 11 +- .../delete_channel.php | 9 +- .../LivestreamServiceClient/delete_event.php | 9 +- .../LivestreamServiceClient/delete_input.php | 9 +- .../LivestreamServiceClient/get_channel.php | 9 +- .../V1/LivestreamServiceClient/get_event.php | 9 +- .../V1/LivestreamServiceClient/get_input.php | 9 +- .../LivestreamServiceClient/get_location.php | 8 +- .../LivestreamServiceClient/list_channels.php | 9 +- .../LivestreamServiceClient/list_events.php | 9 +- .../LivestreamServiceClient/list_inputs.php | 9 +- .../list_locations.php | 8 +- .../LivestreamServiceClient/start_channel.php | 9 +- .../LivestreamServiceClient/stop_channel.php | 9 +- .../update_channel.php | 9 +- .../LivestreamServiceClient/update_input.php | 9 +- .../LivestreamServiceBaseClient.php | 802 +++ .../src/V1/Client/LivestreamServiceClient.php | 40 + .../src/V1/CreateChannelRequest.php | 21 + VideoLiveStream/src/V1/CreateEventRequest.php | 21 + VideoLiveStream/src/V1/CreateInputRequest.php | 21 + .../src/V1/DeleteChannelRequest.php | 15 + VideoLiveStream/src/V1/DeleteEventRequest.php | 15 + VideoLiveStream/src/V1/DeleteInputRequest.php | 15 + VideoLiveStream/src/V1/GetChannelRequest.php | 15 + VideoLiveStream/src/V1/GetEventRequest.php | 15 + VideoLiveStream/src/V1/GetInputRequest.php | 15 + .../src/V1/ListChannelsRequest.php | 15 + VideoLiveStream/src/V1/ListEventsRequest.php | 15 + VideoLiveStream/src/V1/ListInputsRequest.php | 15 + .../src/V1/StartChannelRequest.php | 15 + VideoLiveStream/src/V1/StopChannelRequest.php | 15 + .../src/V1/UpdateChannelRequest.php | 34 + VideoLiveStream/src/V1/UpdateInputRequest.php | 26 + .../livestream_service_descriptor_config.php | 191 + .../V1/Client/LivestreamServiceClientTest.php | 1869 ++++++ .../create_cdn_key.php | 11 +- .../create_live_config.php | 15 +- .../create_live_session.php | 10 +- .../create_slate.php | 11 +- .../create_vod_session.php | 10 +- .../delete_cdn_key.php | 9 +- .../delete_live_config.php | 9 +- .../delete_slate.php | 9 +- .../get_cdn_key.php | 9 +- .../get_live_ad_tag_detail.php | 9 +- .../get_live_config.php | 9 +- .../get_live_session.php | 9 +- .../VideoStitcherServiceClient/get_slate.php | 9 +- .../get_vod_ad_tag_detail.php | 9 +- .../get_vod_session.php | 9 +- .../get_vod_stitch_detail.php | 9 +- .../list_cdn_keys.php | 9 +- .../list_live_ad_tag_details.php | 9 +- .../list_live_configs.php | 9 +- .../list_slates.php | 9 +- .../list_vod_ad_tag_details.php | 9 +- .../list_vod_stitch_details.php | 9 +- .../update_cdn_key.php | 10 +- .../update_slate.php | 10 +- .../VideoStitcherServiceBaseClient.php | 1052 ++++ .../V1/Client/VideoStitcherServiceClient.php | 40 + VideoStitcher/src/V1/CreateCdnKeyRequest.php | 24 + .../src/V1/CreateLiveConfigRequest.php | 19 + .../src/V1/CreateLiveSessionRequest.php | 17 + VideoStitcher/src/V1/CreateSlateRequest.php | 22 + .../src/V1/CreateVodSessionRequest.php | 17 + VideoStitcher/src/V1/DeleteCdnKeyRequest.php | 15 + .../src/V1/DeleteLiveConfigRequest.php | 15 + VideoStitcher/src/V1/DeleteSlateRequest.php | 15 + VideoStitcher/src/V1/GetCdnKeyRequest.php | 15 + .../src/V1/GetLiveAdTagDetailRequest.php | 15 + VideoStitcher/src/V1/GetLiveConfigRequest.php | 16 + .../src/V1/GetLiveSessionRequest.php | 15 + VideoStitcher/src/V1/GetSlateRequest.php | 15 + .../src/V1/GetVodAdTagDetailRequest.php | 16 + VideoStitcher/src/V1/GetVodSessionRequest.php | 15 + .../src/V1/GetVodStitchDetailRequest.php | 16 + VideoStitcher/src/V1/ListCdnKeysRequest.php | 15 + .../src/V1/ListLiveAdTagDetailsRequest.php | 15 + .../src/V1/ListLiveConfigsRequest.php | 15 + VideoStitcher/src/V1/ListSlatesRequest.php | 15 + .../src/V1/ListVodAdTagDetailsRequest.php | 15 + .../src/V1/ListVodStitchDetailsRequest.php | 15 + VideoStitcher/src/V1/UpdateCdnKeyRequest.php | 17 + VideoStitcher/src/V1/UpdateSlateRequest.php | 15 + ...deo_stitcher_service_descriptor_config.php | 265 + .../Client/VideoStitcherServiceClientTest.php | 2363 ++++++++ .../V1/TranscoderServiceClient/create_job.php | 10 +- .../create_job_template.php | 15 +- .../V1/TranscoderServiceClient/delete_job.php | 9 +- .../delete_job_template.php | 9 +- .../V1/TranscoderServiceClient/get_job.php | 9 +- .../get_job_template.php | 9 +- .../list_job_templates.php | 9 +- .../V1/TranscoderServiceClient/list_jobs.php | 9 +- .../TranscoderServiceBaseClient.php | 459 ++ .../src/V1/Client/TranscoderServiceClient.php | 40 + VideoTranscoder/src/V1/CreateJobRequest.php | 17 + .../src/V1/CreateJobTemplateRequest.php | 23 + VideoTranscoder/src/V1/DeleteJobRequest.php | 15 + .../src/V1/DeleteJobTemplateRequest.php | 15 + VideoTranscoder/src/V1/GetJobRequest.php | 15 + .../src/V1/GetJobTemplateRequest.php | 16 + .../src/V1/ListJobTemplatesRequest.php | 15 + VideoTranscoder/src/V1/ListJobsRequest.php | 14 + .../transcoder_service_descriptor_config.php | 97 + .../V1/Client/TranscoderServiceClientTest.php | 670 +++ .../VmMigrationClient/add_group_migration.php | 9 +- .../V1/VmMigrationClient/cancel_clone_job.php | 9 +- .../VmMigrationClient/cancel_cutover_job.php | 9 +- .../V1/VmMigrationClient/create_clone_job.php | 11 +- .../VmMigrationClient/create_cutover_job.php | 11 +- .../create_datacenter_connector.php | 15 +- .../V1/VmMigrationClient/create_group.php | 11 +- .../VmMigrationClient/create_migrating_vm.php | 11 +- .../V1/VmMigrationClient/create_source.php | 11 +- .../create_target_project.php | 15 +- .../create_utilization_report.php | 15 +- .../delete_datacenter_connector.php | 9 +- .../V1/VmMigrationClient/delete_group.php | 9 +- .../VmMigrationClient/delete_migrating_vm.php | 9 +- .../V1/VmMigrationClient/delete_source.php | 9 +- .../delete_target_project.php | 9 +- .../delete_utilization_report.php | 9 +- .../V1/VmMigrationClient/fetch_inventory.php | 9 +- .../VmMigrationClient/finalize_migration.php | 9 +- .../V1/VmMigrationClient/get_clone_job.php | 9 +- .../V1/VmMigrationClient/get_cutover_job.php | 9 +- .../get_datacenter_connector.php | 9 +- .../V1/VmMigrationClient/get_group.php | 9 +- .../V1/VmMigrationClient/get_location.php | 8 +- .../V1/VmMigrationClient/get_migrating_vm.php | 9 +- .../get_replication_cycle.php | 9 +- .../V1/VmMigrationClient/get_source.php | 9 +- .../VmMigrationClient/get_target_project.php | 9 +- .../get_utilization_report.php | 9 +- .../V1/VmMigrationClient/list_clone_jobs.php | 10 +- .../VmMigrationClient/list_cutover_jobs.php | 10 +- .../list_datacenter_connectors.php | 10 +- .../V1/VmMigrationClient/list_groups.php | 10 +- .../V1/VmMigrationClient/list_locations.php | 8 +- .../VmMigrationClient/list_migrating_vms.php | 10 +- .../list_replication_cycles.php | 10 +- .../V1/VmMigrationClient/list_sources.php | 10 +- .../list_target_projects.php | 10 +- .../list_utilization_reports.php | 10 +- .../V1/VmMigrationClient/pause_migration.php | 9 +- .../remove_group_migration.php | 9 +- .../V1/VmMigrationClient/resume_migration.php | 9 +- .../V1/VmMigrationClient/start_migration.php | 9 +- .../V1/VmMigrationClient/update_group.php | 9 +- .../VmMigrationClient/update_migrating_vm.php | 9 +- .../V1/VmMigrationClient/update_source.php | 9 +- .../update_target_project.php | 9 +- .../VmMigrationClient/upgrade_appliance.php | 9 +- .../src/V1/AddGroupMigrationRequest.php | 14 + VmMigration/src/V1/CancelCloneJobRequest.php | 14 + .../src/V1/CancelCutoverJobRequest.php | 14 + .../BaseClient/VmMigrationBaseClient.php | 1729 ++++++ .../src/V1/Client/VmMigrationClient.php | 40 + VmMigration/src/V1/CreateCloneJobRequest.php | 18 + .../src/V1/CreateCutoverJobRequest.php | 18 + .../V1/CreateDatacenterConnectorRequest.php | 21 + VmMigration/src/V1/CreateGroupRequest.php | 18 + .../src/V1/CreateMigratingVmRequest.php | 18 + VmMigration/src/V1/CreateSourceRequest.php | 18 + .../src/V1/CreateTargetProjectRequest.php | 18 + .../src/V1/CreateUtilizationReportRequest.php | 23 + .../V1/DeleteDatacenterConnectorRequest.php | 14 + VmMigration/src/V1/DeleteGroupRequest.php | 14 + .../src/V1/DeleteMigratingVmRequest.php | 14 + VmMigration/src/V1/DeleteSourceRequest.php | 14 + .../src/V1/DeleteTargetProjectRequest.php | 14 + .../src/V1/DeleteUtilizationReportRequest.php | 14 + VmMigration/src/V1/FetchInventoryRequest.php | 14 + .../src/V1/FinalizeMigrationRequest.php | 14 + VmMigration/src/V1/GetCloneJobRequest.php | 14 + VmMigration/src/V1/GetCutoverJobRequest.php | 14 + .../src/V1/GetDatacenterConnectorRequest.php | 14 + VmMigration/src/V1/GetGroupRequest.php | 14 + VmMigration/src/V1/GetMigratingVmRequest.php | 14 + .../src/V1/GetReplicationCycleRequest.php | 14 + VmMigration/src/V1/GetSourceRequest.php | 14 + .../src/V1/GetTargetProjectRequest.php | 14 + .../src/V1/GetUtilizationReportRequest.php | 14 + VmMigration/src/V1/ListCloneJobsRequest.php | 14 + VmMigration/src/V1/ListCutoverJobsRequest.php | 14 + .../V1/ListDatacenterConnectorsRequest.php | 14 + VmMigration/src/V1/ListGroupsRequest.php | 14 + .../src/V1/ListMigratingVmsRequest.php | 14 + .../src/V1/ListReplicationCyclesRequest.php | 14 + VmMigration/src/V1/ListSourcesRequest.php | 14 + .../src/V1/ListTargetProjectsRequest.php | 14 + .../src/V1/ListUtilizationReportsRequest.php | 14 + .../src/V1/RemoveGroupMigrationRequest.php | 14 + VmMigration/src/V1/StartMigrationRequest.php | 14 + VmMigration/src/V1/UpdateGroupRequest.php | 19 + .../src/V1/UpdateMigratingVmRequest.php | 19 + VmMigration/src/V1/UpdateSourceRequest.php | 19 + .../src/V1/UpdateTargetProjectRequest.php | 19 + .../vm_migration_descriptor_config.php | 489 ++ .../Unit/V1/Client/VmMigrationClientTest.php | 5156 +++++++++++++++++ .../V1/VmwareEngineClient/create_cluster.php | 11 +- .../create_hcx_activation_key.php | 15 +- .../create_network_policy.php | 15 +- .../create_private_cloud.php | 15 +- .../create_vmware_engine_network.php | 15 +- .../V1/VmwareEngineClient/delete_cluster.php | 9 +- .../delete_network_policy.php | 9 +- .../delete_private_cloud.php | 9 +- .../delete_vmware_engine_network.php | 9 +- .../V1/VmwareEngineClient/get_cluster.php | 9 +- .../get_hcx_activation_key.php | 9 +- .../V1/VmwareEngineClient/get_iam_policy.php | 9 +- .../V1/VmwareEngineClient/get_location.php | 8 +- .../VmwareEngineClient/get_network_policy.php | 9 +- .../V1/VmwareEngineClient/get_node_type.php | 9 +- .../VmwareEngineClient/get_private_cloud.php | 9 +- .../get_vmware_engine_network.php | 9 +- .../V1/VmwareEngineClient/list_clusters.php | 9 +- .../list_hcx_activation_keys.php | 9 +- .../V1/VmwareEngineClient/list_locations.php | 8 +- .../list_network_policies.php | 9 +- .../V1/VmwareEngineClient/list_node_types.php | 9 +- .../list_private_clouds.php | 9 +- .../V1/VmwareEngineClient/list_subnets.php | 9 +- .../list_vmware_engine_networks.php | 9 +- .../reset_nsx_credentials.php | 9 +- .../reset_vcenter_credentials.php | 9 +- .../V1/VmwareEngineClient/set_iam_policy.php | 10 +- .../show_nsx_credentials.php | 9 +- .../show_vcenter_credentials.php | 9 +- .../test_iam_permissions.php | 10 +- .../undelete_private_cloud.php | 9 +- .../V1/VmwareEngineClient/update_cluster.php | 10 +- .../update_network_policy.php | 10 +- .../update_private_cloud.php | 10 +- .../update_vmware_engine_network.php | 10 +- .../BaseClient/VmwareEngineBaseClient.php | 1408 +++++ .../src/V1/Client/VmwareEngineClient.php | 40 + VmwareEngine/src/V1/CreateClusterRequest.php | 32 + .../src/V1/CreateHcxActivationKeyRequest.php | 33 + .../src/V1/CreateNetworkPolicyRequest.php | 34 + .../src/V1/CreatePrivateCloudRequest.php | 32 + .../V1/CreateVmwareEngineNetworkRequest.php | 37 + VmwareEngine/src/V1/DeleteClusterRequest.php | 18 + .../src/V1/DeleteNetworkPolicyRequest.php | 18 + .../src/V1/DeletePrivateCloudRequest.php | 18 + .../V1/DeleteVmwareEngineNetworkRequest.php | 18 + VmwareEngine/src/V1/GetClusterRequest.php | 18 + .../src/V1/GetHcxActivationKeyRequest.php | 18 + .../src/V1/GetNetworkPolicyRequest.php | 18 + VmwareEngine/src/V1/GetNodeTypeRequest.php | 18 + .../src/V1/GetPrivateCloudRequest.php | 18 + .../src/V1/GetVmwareEngineNetworkRequest.php | 18 + VmwareEngine/src/V1/ListClustersRequest.php | 18 + .../src/V1/ListHcxActivationKeysRequest.php | 19 + .../src/V1/ListNetworkPoliciesRequest.php | 17 + VmwareEngine/src/V1/ListNodeTypesRequest.php | 18 + .../src/V1/ListPrivateCloudsRequest.php | 18 + VmwareEngine/src/V1/ListSubnetsRequest.php | 19 + .../V1/ListVmwareEngineNetworksRequest.php | 17 + .../src/V1/ResetNsxCredentialsRequest.php | 19 + .../src/V1/ResetVcenterCredentialsRequest.php | 19 + .../src/V1/ShowNsxCredentialsRequest.php | 19 + .../src/V1/ShowVcenterCredentialsRequest.php | 19 + .../src/V1/UndeletePrivateCloudRequest.php | 18 + VmwareEngine/src/V1/UpdateClusterRequest.php | 19 + .../src/V1/UpdateNetworkPolicyRequest.php | 19 + .../src/V1/UpdatePrivateCloudRequest.php | 19 + .../V1/UpdateVmwareEngineNetworkRequest.php | 20 + .../vmware_engine_descriptor_config.php | 374 ++ .../Unit/V1/Client/VmwareEngineClientTest.php | 3818 ++++++++++++ 419 files changed, 37335 insertions(+), 472 deletions(-) create mode 100644 PrivateCatalog/src/V1beta1/Client/BaseClient/PrivateCatalogBaseClient.php create mode 100644 PrivateCatalog/src/V1beta1/Client/PrivateCatalogClient.php create mode 100644 PrivateCatalog/tests/Unit/V1beta1/Client/PrivateCatalogClientTest.php create mode 100644 RecommendationEngine/src/V1beta1/Client/BaseClient/CatalogServiceBaseClient.php create mode 100644 RecommendationEngine/src/V1beta1/Client/BaseClient/PredictionApiKeyRegistryBaseClient.php create mode 100644 RecommendationEngine/src/V1beta1/Client/BaseClient/PredictionServiceBaseClient.php create mode 100644 RecommendationEngine/src/V1beta1/Client/BaseClient/UserEventServiceBaseClient.php create mode 100644 RecommendationEngine/src/V1beta1/Client/CatalogServiceClient.php create mode 100644 RecommendationEngine/src/V1beta1/Client/PredictionApiKeyRegistryClient.php create mode 100644 RecommendationEngine/src/V1beta1/Client/PredictionServiceClient.php create mode 100644 RecommendationEngine/src/V1beta1/Client/UserEventServiceClient.php create mode 100644 RecommendationEngine/tests/Unit/V1beta1/Client/CatalogServiceClientTest.php create mode 100644 RecommendationEngine/tests/Unit/V1beta1/Client/PredictionApiKeyRegistryClientTest.php create mode 100644 RecommendationEngine/tests/Unit/V1beta1/Client/PredictionServiceClientTest.php create mode 100644 RecommendationEngine/tests/Unit/V1beta1/Client/UserEventServiceClientTest.php create mode 100644 Run/src/V2/Client/BaseClient/ExecutionsBaseClient.php create mode 100644 Run/src/V2/Client/BaseClient/JobsBaseClient.php create mode 100644 Run/src/V2/Client/BaseClient/RevisionsBaseClient.php create mode 100644 Run/src/V2/Client/BaseClient/ServicesBaseClient.php create mode 100644 Run/src/V2/Client/BaseClient/TasksBaseClient.php create mode 100644 Run/src/V2/Client/ExecutionsClient.php create mode 100644 Run/src/V2/Client/JobsClient.php create mode 100644 Run/src/V2/Client/RevisionsClient.php create mode 100644 Run/src/V2/Client/ServicesClient.php create mode 100644 Run/src/V2/Client/TasksClient.php create mode 100644 Run/tests/Unit/V2/Client/ExecutionsClientTest.php create mode 100644 Run/tests/Unit/V2/Client/JobsClientTest.php create mode 100644 Run/tests/Unit/V2/Client/RevisionsClientTest.php create mode 100644 Run/tests/Unit/V2/Client/ServicesClientTest.php create mode 100644 Run/tests/Unit/V2/Client/TasksClientTest.php create mode 100644 SecurityPublicCA/src/V1beta1/Client/BaseClient/PublicCertificateAuthorityServiceBaseClient.php create mode 100644 SecurityPublicCA/src/V1beta1/Client/PublicCertificateAuthorityServiceClient.php create mode 100644 SecurityPublicCA/tests/Unit/V1beta1/Client/PublicCertificateAuthorityServiceClientTest.php create mode 100644 StorageInsights/src/V1/Client/BaseClient/StorageInsightsBaseClient.php create mode 100644 StorageInsights/src/V1/Client/StorageInsightsClient.php create mode 100644 StorageInsights/tests/Unit/V1/Client/StorageInsightsClientTest.php create mode 100644 VideoLiveStream/src/V1/Client/BaseClient/LivestreamServiceBaseClient.php create mode 100644 VideoLiveStream/src/V1/Client/LivestreamServiceClient.php create mode 100644 VideoLiveStream/tests/Unit/V1/Client/LivestreamServiceClientTest.php create mode 100644 VideoStitcher/src/V1/Client/BaseClient/VideoStitcherServiceBaseClient.php create mode 100644 VideoStitcher/src/V1/Client/VideoStitcherServiceClient.php create mode 100644 VideoStitcher/tests/Unit/V1/Client/VideoStitcherServiceClientTest.php create mode 100644 VideoTranscoder/src/V1/Client/BaseClient/TranscoderServiceBaseClient.php create mode 100644 VideoTranscoder/src/V1/Client/TranscoderServiceClient.php create mode 100644 VideoTranscoder/tests/Unit/V1/Client/TranscoderServiceClientTest.php create mode 100644 VmMigration/src/V1/Client/BaseClient/VmMigrationBaseClient.php create mode 100644 VmMigration/src/V1/Client/VmMigrationClient.php create mode 100644 VmMigration/tests/Unit/V1/Client/VmMigrationClientTest.php create mode 100644 VmwareEngine/src/V1/Client/BaseClient/VmwareEngineBaseClient.php create mode 100644 VmwareEngine/src/V1/Client/VmwareEngineClient.php create mode 100644 VmwareEngine/tests/Unit/V1/Client/VmwareEngineClientTest.php diff --git a/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_catalogs.php b/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_catalogs.php index ee96c12e6c64..8d74aac1faba 100644 --- a/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_catalogs.php +++ b/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_catalogs.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\PrivateCatalog\V1beta1\Catalog; -use Google\Cloud\PrivateCatalog\V1beta1\PrivateCatalogClient; +use Google\Cloud\PrivateCatalog\V1beta1\Client\PrivateCatalogClient; +use Google\Cloud\PrivateCatalog\V1beta1\SearchCatalogsRequest; /** * Search [Catalog][google.cloud.privatecatalog.v1beta1.Catalog] resources that consumers have access to, within the @@ -43,10 +44,14 @@ function search_catalogs_sample(string $resource): void // Create a client. $privateCatalogClient = new PrivateCatalogClient(); + // Prepare the request message. + $request = (new SearchCatalogsRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $privateCatalogClient->searchCatalogs($resource); + $response = $privateCatalogClient->searchCatalogs($request); /** @var Catalog $element */ foreach ($response as $element) { diff --git a/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_products.php b/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_products.php index 8266f8fa451d..204e83774c1d 100644 --- a/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_products.php +++ b/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_products.php @@ -25,8 +25,9 @@ // [START cloudprivatecatalog_v1beta1_generated_PrivateCatalog_SearchProducts_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\PrivateCatalog\V1beta1\PrivateCatalogClient; +use Google\Cloud\PrivateCatalog\V1beta1\Client\PrivateCatalogClient; use Google\Cloud\PrivateCatalog\V1beta1\Product; +use Google\Cloud\PrivateCatalog\V1beta1\SearchProductsRequest; /** * Search [Product][google.cloud.privatecatalog.v1beta1.Product] resources that consumers have access to, within the @@ -40,10 +41,14 @@ function search_products_sample(string $resource): void // Create a client. $privateCatalogClient = new PrivateCatalogClient(); + // Prepare the request message. + $request = (new SearchProductsRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $privateCatalogClient->searchProducts($resource); + $response = $privateCatalogClient->searchProducts($request); /** @var Product $element */ foreach ($response as $element) { diff --git a/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_versions.php b/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_versions.php index 95a8428b6b8e..1ebd3291ca62 100644 --- a/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_versions.php +++ b/PrivateCatalog/samples/V1beta1/PrivateCatalogClient/search_versions.php @@ -25,7 +25,8 @@ // [START cloudprivatecatalog_v1beta1_generated_PrivateCatalog_SearchVersions_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\PrivateCatalog\V1beta1\PrivateCatalogClient; +use Google\Cloud\PrivateCatalog\V1beta1\Client\PrivateCatalogClient; +use Google\Cloud\PrivateCatalog\V1beta1\SearchVersionsRequest; use Google\Cloud\PrivateCatalog\V1beta1\Version; /** @@ -47,10 +48,15 @@ function search_versions_sample(string $resource, string $query): void // Create a client. $privateCatalogClient = new PrivateCatalogClient(); + // Prepare the request message. + $request = (new SearchVersionsRequest()) + ->setResource($resource) + ->setQuery($query); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $privateCatalogClient->searchVersions($resource, $query); + $response = $privateCatalogClient->searchVersions($request); /** @var Version $element */ foreach ($response as $element) { diff --git a/PrivateCatalog/src/V1beta1/Client/BaseClient/PrivateCatalogBaseClient.php b/PrivateCatalog/src/V1beta1/Client/BaseClient/PrivateCatalogBaseClient.php new file mode 100644 index 000000000000..f65892318474 --- /dev/null +++ b/PrivateCatalog/src/V1beta1/Client/BaseClient/PrivateCatalogBaseClient.php @@ -0,0 +1,271 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/private_catalog_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/private_catalog_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/private_catalog_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/private_catalog_rest_client_config.php', + ], + ], + ]; + } + + /** + * 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 'cloudprivatecatalog.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 + * + * @experimental + */ + 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); + } + + /** + * Search [Catalog][google.cloud.privatecatalog.v1beta1.Catalog] resources that consumers have access to, within the + * scope of the consumer cloud resource hierarchy context. + * + * The async variant is {@see self::searchCatalogsAsync()} . + * + * @param SearchCatalogsRequest $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. + * + * @experimental + */ + public function searchCatalogs(SearchCatalogsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchCatalogs', $request, $callOptions); + } + + /** + * Search [Product][google.cloud.privatecatalog.v1beta1.Product] resources that consumers have access to, within the + * scope of the consumer cloud resource hierarchy context. + * + * The async variant is {@see self::searchProductsAsync()} . + * + * @param SearchProductsRequest $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. + * + * @experimental + */ + public function searchProducts(SearchProductsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchProducts', $request, $callOptions); + } + + /** + * Search [Version][google.cloud.privatecatalog.v1beta1.Version] resources that consumers have access to, within the + * scope of the consumer cloud resource hierarchy context. + * + * The async variant is {@see self::searchVersionsAsync()} . + * + * @param SearchVersionsRequest $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. + * + * @experimental + */ + public function searchVersions(SearchVersionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('SearchVersions', $request, $callOptions); + } +} diff --git a/PrivateCatalog/src/V1beta1/Client/PrivateCatalogClient.php b/PrivateCatalog/src/V1beta1/Client/PrivateCatalogClient.php new file mode 100644 index 000000000000..ba068a903df9 --- /dev/null +++ b/PrivateCatalog/src/V1beta1/Client/PrivateCatalogClient.php @@ -0,0 +1,42 @@ + 'getNextPageToken', 'resourcesGetMethod' => 'getCatalogs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PrivateCatalog\V1beta1\SearchCatalogsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], ], 'SearchProducts' => [ 'pageStreaming' => [ @@ -22,6 +32,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getProducts', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PrivateCatalog\V1beta1\SearchProductsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], ], 'SearchVersions' => [ 'pageStreaming' => [ @@ -32,6 +52,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getVersions', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\PrivateCatalog\V1beta1\SearchVersionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], ], ], ], diff --git a/PrivateCatalog/tests/Unit/V1beta1/Client/PrivateCatalogClientTest.php b/PrivateCatalog/tests/Unit/V1beta1/Client/PrivateCatalogClientTest.php new file mode 100644 index 000000000000..67d01c4bcb2d --- /dev/null +++ b/PrivateCatalog/tests/Unit/V1beta1/Client/PrivateCatalogClientTest.php @@ -0,0 +1,328 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return PrivateCatalogClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new PrivateCatalogClient($options); + } + + /** @test */ + public function searchCatalogsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $catalogsElement = new Catalog(); + $catalogs = [ + $catalogsElement, + ]; + $expectedResponse = new SearchCatalogsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCatalogs($catalogs); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new SearchCatalogsRequest()) + ->setResource($resource); + $response = $gapicClient->searchCatalogs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCatalogs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchCatalogs', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchCatalogsExceptionTest() + { + $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 SearchCatalogsRequest()) + ->setResource($resource); + try { + $gapicClient->searchCatalogs($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 searchProductsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $productsElement = new Product(); + $products = [ + $productsElement, + ]; + $expectedResponse = new SearchProductsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProducts($products); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new SearchProductsRequest()) + ->setResource($resource); + $response = $gapicClient->searchProducts($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProducts()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchProducts', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchProductsExceptionTest() + { + $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 SearchProductsRequest()) + ->setResource($resource); + try { + $gapicClient->searchProducts($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 searchVersionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $versionsElement = new Version(); + $versions = [ + $versionsElement, + ]; + $expectedResponse = new SearchVersionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setVersions($versions); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $query = 'query107944136'; + $request = (new SearchVersionsRequest()) + ->setResource($resource) + ->setQuery($query); + $response = $gapicClient->searchVersions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getVersions()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchVersions', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $actualValue = $actualRequestObject->getQuery(); + $this->assertProtobufEquals($query, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchVersionsExceptionTest() + { + $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'; + $query = 'query107944136'; + $request = (new SearchVersionsRequest()) + ->setResource($resource) + ->setQuery($query); + try { + $gapicClient->searchVersions($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 searchCatalogsAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $catalogsElement = new Catalog(); + $catalogs = [ + $catalogsElement, + ]; + $expectedResponse = new SearchCatalogsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCatalogs($catalogs); + $transport->addResponse($expectedResponse); + // Mock request + $resource = 'resource-341064690'; + $request = (new SearchCatalogsRequest()) + ->setResource($resource); + $response = $gapicClient->searchCatalogsAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCatalogs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchCatalogs', $actualFuncCall); + $actualValue = $actualRequestObject->getResource(); + $this->assertProtobufEquals($resource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/create_catalog_item.php b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/create_catalog_item.php index e595e20a413d..0ce55142e894 100644 --- a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/create_catalog_item.php +++ b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/create_catalog_item.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\Cloud\RecommendationEngine\V1beta1\CatalogItem; use Google\Cloud\RecommendationEngine\V1beta1\CatalogItem\CategoryHierarchy; -use Google\Cloud\RecommendationEngine\V1beta1\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\Client\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\CreateCatalogItemRequest; /** * Creates a catalog item. @@ -57,7 +58,7 @@ function create_catalog_item_sample( // Create a client. $catalogServiceClient = new CatalogServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $catalogItemCategoryHierarchiesCategories = [$catalogItemCategoryHierarchiesCategoriesElement,]; $categoryHierarchy = (new CategoryHierarchy()) ->setCategories($catalogItemCategoryHierarchiesCategories); @@ -66,11 +67,14 @@ function create_catalog_item_sample( ->setId($catalogItemId) ->setCategoryHierarchies($catalogItemCategoryHierarchies) ->setTitle($catalogItemTitle); + $request = (new CreateCatalogItemRequest()) + ->setParent($formattedParent) + ->setCatalogItem($catalogItem); // Call the API and handle any network failures. try { /** @var CatalogItem $response */ - $response = $catalogServiceClient->createCatalogItem($formattedParent, $catalogItem); + $response = $catalogServiceClient->createCatalogItem($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/RecommendationEngine/samples/V1beta1/CatalogServiceClient/delete_catalog_item.php b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/delete_catalog_item.php index f3873d0a8cc5..1c1e5037829d 100644 --- a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/delete_catalog_item.php +++ b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/delete_catalog_item.php @@ -24,7 +24,8 @@ // [START recommendationengine_v1beta1_generated_CatalogService_DeleteCatalogItem_sync] use Google\ApiCore\ApiException; -use Google\Cloud\RecommendationEngine\V1beta1\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\Client\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\DeleteCatalogItemRequest; /** * Deletes a catalog item. @@ -38,9 +39,13 @@ function delete_catalog_item_sample(string $formattedName): void // Create a client. $catalogServiceClient = new CatalogServiceClient(); + // Prepare the request message. + $request = (new DeleteCatalogItemRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $catalogServiceClient->deleteCatalogItem($formattedName); + $catalogServiceClient->deleteCatalogItem($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/get_catalog_item.php b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/get_catalog_item.php index e24d4182a8c7..f36e36124135 100644 --- a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/get_catalog_item.php +++ b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/get_catalog_item.php @@ -25,7 +25,8 @@ // [START recommendationengine_v1beta1_generated_CatalogService_GetCatalogItem_sync] use Google\ApiCore\ApiException; use Google\Cloud\RecommendationEngine\V1beta1\CatalogItem; -use Google\Cloud\RecommendationEngine\V1beta1\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\Client\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\GetCatalogItemRequest; /** * Gets a specific catalog item. @@ -39,10 +40,14 @@ function get_catalog_item_sample(string $formattedName): void // Create a client. $catalogServiceClient = new CatalogServiceClient(); + // Prepare the request message. + $request = (new GetCatalogItemRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var CatalogItem $response */ - $response = $catalogServiceClient->getCatalogItem($formattedName); + $response = $catalogServiceClient->getCatalogItem($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/RecommendationEngine/samples/V1beta1/CatalogServiceClient/import_catalog_items.php b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/import_catalog_items.php index 08f018dd0d50..efa9af3e76cc 100644 --- a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/import_catalog_items.php +++ b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/import_catalog_items.php @@ -25,7 +25,8 @@ // [START recommendationengine_v1beta1_generated_CatalogService_ImportCatalogItems_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\RecommendationEngine\V1beta1\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\Client\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\ImportCatalogItemsRequest; use Google\Cloud\RecommendationEngine\V1beta1\ImportCatalogItemsResponse; use Google\Cloud\RecommendationEngine\V1beta1\InputConfig; use Google\Rpc\Status; @@ -46,13 +47,16 @@ function import_catalog_items_sample(string $formattedParent): void // Create a client. $catalogServiceClient = new CatalogServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $inputConfig = new InputConfig(); + $request = (new ImportCatalogItemsRequest()) + ->setParent($formattedParent) + ->setInputConfig($inputConfig); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $catalogServiceClient->importCatalogItems($formattedParent, $inputConfig); + $response = $catalogServiceClient->importCatalogItems($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/list_catalog_items.php b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/list_catalog_items.php index 0256a788fd7c..8cee497bfede 100644 --- a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/list_catalog_items.php +++ b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/list_catalog_items.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\RecommendationEngine\V1beta1\CatalogItem; -use Google\Cloud\RecommendationEngine\V1beta1\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\Client\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\ListCatalogItemsRequest; /** * Gets a list of catalog items. @@ -40,10 +41,14 @@ function list_catalog_items_sample(string $formattedParent): void // Create a client. $catalogServiceClient = new CatalogServiceClient(); + // Prepare the request message. + $request = (new ListCatalogItemsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $catalogServiceClient->listCatalogItems($formattedParent); + $response = $catalogServiceClient->listCatalogItems($request); /** @var CatalogItem $element */ foreach ($response as $element) { diff --git a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/update_catalog_item.php b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/update_catalog_item.php index aab327391858..c09419ab3668 100644 --- a/RecommendationEngine/samples/V1beta1/CatalogServiceClient/update_catalog_item.php +++ b/RecommendationEngine/samples/V1beta1/CatalogServiceClient/update_catalog_item.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\Cloud\RecommendationEngine\V1beta1\CatalogItem; use Google\Cloud\RecommendationEngine\V1beta1\CatalogItem\CategoryHierarchy; -use Google\Cloud\RecommendationEngine\V1beta1\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\Client\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\UpdateCatalogItemRequest; /** * Updates a catalog item. Partial updating is supported. Non-existing @@ -58,7 +59,7 @@ function update_catalog_item_sample( // Create a client. $catalogServiceClient = new CatalogServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $catalogItemCategoryHierarchiesCategories = [$catalogItemCategoryHierarchiesCategoriesElement,]; $categoryHierarchy = (new CategoryHierarchy()) ->setCategories($catalogItemCategoryHierarchiesCategories); @@ -67,11 +68,14 @@ function update_catalog_item_sample( ->setId($catalogItemId) ->setCategoryHierarchies($catalogItemCategoryHierarchies) ->setTitle($catalogItemTitle); + $request = (new UpdateCatalogItemRequest()) + ->setName($formattedName) + ->setCatalogItem($catalogItem); // Call the API and handle any network failures. try { /** @var CatalogItem $response */ - $response = $catalogServiceClient->updateCatalogItem($formattedName, $catalogItem); + $response = $catalogServiceClient->updateCatalogItem($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/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/create_prediction_api_key_registration.php b/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/create_prediction_api_key_registration.php index cc3b4ad11710..51ce1c623098 100644 --- a/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/create_prediction_api_key_registration.php +++ b/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/create_prediction_api_key_registration.php @@ -24,8 +24,9 @@ // [START recommendationengine_v1beta1_generated_PredictionApiKeyRegistry_CreatePredictionApiKeyRegistration_sync] use Google\ApiCore\ApiException; +use Google\Cloud\RecommendationEngine\V1beta1\Client\PredictionApiKeyRegistryClient; +use Google\Cloud\RecommendationEngine\V1beta1\CreatePredictionApiKeyRegistrationRequest; use Google\Cloud\RecommendationEngine\V1beta1\PredictionApiKeyRegistration; -use Google\Cloud\RecommendationEngine\V1beta1\PredictionApiKeyRegistryClient; /** * Register an API key for use with predict method. @@ -39,16 +40,16 @@ function create_prediction_api_key_registration_sample(string $formattedParent): // Create a client. $predictionApiKeyRegistryClient = new PredictionApiKeyRegistryClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $predictionApiKeyRegistration = new PredictionApiKeyRegistration(); + $request = (new CreatePredictionApiKeyRegistrationRequest()) + ->setParent($formattedParent) + ->setPredictionApiKeyRegistration($predictionApiKeyRegistration); // Call the API and handle any network failures. try { /** @var PredictionApiKeyRegistration $response */ - $response = $predictionApiKeyRegistryClient->createPredictionApiKeyRegistration( - $formattedParent, - $predictionApiKeyRegistration - ); + $response = $predictionApiKeyRegistryClient->createPredictionApiKeyRegistration($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/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/delete_prediction_api_key_registration.php b/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/delete_prediction_api_key_registration.php index 828a2e845220..b091673468b6 100644 --- a/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/delete_prediction_api_key_registration.php +++ b/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/delete_prediction_api_key_registration.php @@ -24,7 +24,8 @@ // [START recommendationengine_v1beta1_generated_PredictionApiKeyRegistry_DeletePredictionApiKeyRegistration_sync] use Google\ApiCore\ApiException; -use Google\Cloud\RecommendationEngine\V1beta1\PredictionApiKeyRegistryClient; +use Google\Cloud\RecommendationEngine\V1beta1\Client\PredictionApiKeyRegistryClient; +use Google\Cloud\RecommendationEngine\V1beta1\DeletePredictionApiKeyRegistrationRequest; /** * Unregister an apiKey from using for predict method. @@ -38,9 +39,13 @@ function delete_prediction_api_key_registration_sample(string $formattedName): v // Create a client. $predictionApiKeyRegistryClient = new PredictionApiKeyRegistryClient(); + // Prepare the request message. + $request = (new DeletePredictionApiKeyRegistrationRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $predictionApiKeyRegistryClient->deletePredictionApiKeyRegistration($formattedName); + $predictionApiKeyRegistryClient->deletePredictionApiKeyRegistration($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/list_prediction_api_key_registrations.php b/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/list_prediction_api_key_registrations.php index bdc668f9c941..0aeec83bc053 100644 --- a/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/list_prediction_api_key_registrations.php +++ b/RecommendationEngine/samples/V1beta1/PredictionApiKeyRegistryClient/list_prediction_api_key_registrations.php @@ -25,8 +25,9 @@ // [START recommendationengine_v1beta1_generated_PredictionApiKeyRegistry_ListPredictionApiKeyRegistrations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\RecommendationEngine\V1beta1\Client\PredictionApiKeyRegistryClient; +use Google\Cloud\RecommendationEngine\V1beta1\ListPredictionApiKeyRegistrationsRequest; use Google\Cloud\RecommendationEngine\V1beta1\PredictionApiKeyRegistration; -use Google\Cloud\RecommendationEngine\V1beta1\PredictionApiKeyRegistryClient; /** * List the registered apiKeys for use with predict method. @@ -40,10 +41,14 @@ function list_prediction_api_key_registrations_sample(string $formattedParent): // Create a client. $predictionApiKeyRegistryClient = new PredictionApiKeyRegistryClient(); + // Prepare the request message. + $request = (new ListPredictionApiKeyRegistrationsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $predictionApiKeyRegistryClient->listPredictionApiKeyRegistrations($formattedParent); + $response = $predictionApiKeyRegistryClient->listPredictionApiKeyRegistrations($request); /** @var PredictionApiKeyRegistration $element */ foreach ($response as $element) { diff --git a/RecommendationEngine/samples/V1beta1/PredictionServiceClient/predict.php b/RecommendationEngine/samples/V1beta1/PredictionServiceClient/predict.php index 0fbe666ef247..38f0db24130d 100644 --- a/RecommendationEngine/samples/V1beta1/PredictionServiceClient/predict.php +++ b/RecommendationEngine/samples/V1beta1/PredictionServiceClient/predict.php @@ -25,8 +25,9 @@ // [START recommendationengine_v1beta1_generated_PredictionService_Predict_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\RecommendationEngine\V1beta1\Client\PredictionServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\PredictRequest; use Google\Cloud\RecommendationEngine\V1beta1\PredictResponse\PredictionResult; -use Google\Cloud\RecommendationEngine\V1beta1\PredictionServiceClient; use Google\Cloud\RecommendationEngine\V1beta1\UserEvent; use Google\Cloud\RecommendationEngine\V1beta1\UserInfo; @@ -100,17 +101,20 @@ function predict_sample( // Create a client. $predictionServiceClient = new PredictionServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $userEventUserInfo = (new UserInfo()) ->setVisitorId($userEventUserInfoVisitorId); $userEvent = (new UserEvent()) ->setEventType($userEventEventType) ->setUserInfo($userEventUserInfo); + $request = (new PredictRequest()) + ->setName($formattedName) + ->setUserEvent($userEvent); // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $predictionServiceClient->predict($formattedName, $userEvent); + $response = $predictionServiceClient->predict($request); /** @var PredictionResult $element */ foreach ($response as $element) { diff --git a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/collect_user_event.php b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/collect_user_event.php index 855b20ed9c3f..2e520566f9c4 100644 --- a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/collect_user_event.php +++ b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/collect_user_event.php @@ -25,7 +25,8 @@ // [START recommendationengine_v1beta1_generated_UserEventService_CollectUserEvent_sync] use Google\ApiCore\ApiException; use Google\Api\HttpBody; -use Google\Cloud\RecommendationEngine\V1beta1\UserEventServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\Client\UserEventServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\CollectUserEventRequest; /** * Writes a single user event from the browser. This uses a GET request to @@ -44,10 +45,15 @@ function collect_user_event_sample(string $formattedParent, string $userEvent): // Create a client. $userEventServiceClient = new UserEventServiceClient(); + // Prepare the request message. + $request = (new CollectUserEventRequest()) + ->setParent($formattedParent) + ->setUserEvent($userEvent); + // Call the API and handle any network failures. try { /** @var HttpBody $response */ - $response = $userEventServiceClient->collectUserEvent($formattedParent, $userEvent); + $response = $userEventServiceClient->collectUserEvent($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/RecommendationEngine/samples/V1beta1/UserEventServiceClient/import_user_events.php b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/import_user_events.php index 8b23f3050ba7..00706c118aa1 100644 --- a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/import_user_events.php +++ b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/import_user_events.php @@ -25,9 +25,10 @@ // [START recommendationengine_v1beta1_generated_UserEventService_ImportUserEvents_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\RecommendationEngine\V1beta1\Client\UserEventServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\ImportUserEventsRequest; use Google\Cloud\RecommendationEngine\V1beta1\ImportUserEventsResponse; use Google\Cloud\RecommendationEngine\V1beta1\InputConfig; -use Google\Cloud\RecommendationEngine\V1beta1\UserEventServiceClient; use Google\Rpc\Status; /** @@ -48,13 +49,16 @@ function import_user_events_sample(string $formattedParent): void // Create a client. $userEventServiceClient = new UserEventServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $inputConfig = new InputConfig(); + $request = (new ImportUserEventsRequest()) + ->setParent($formattedParent) + ->setInputConfig($inputConfig); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $userEventServiceClient->importUserEvents($formattedParent, $inputConfig); + $response = $userEventServiceClient->importUserEvents($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/list_user_events.php b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/list_user_events.php index 3ad3fd63f41a..f153b9661a41 100644 --- a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/list_user_events.php +++ b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/list_user_events.php @@ -25,8 +25,9 @@ // [START recommendationengine_v1beta1_generated_UserEventService_ListUserEvents_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\RecommendationEngine\V1beta1\Client\UserEventServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\ListUserEventsRequest; use Google\Cloud\RecommendationEngine\V1beta1\UserEvent; -use Google\Cloud\RecommendationEngine\V1beta1\UserEventServiceClient; /** * Gets a list of user events within a time range, with potential filtering. @@ -40,10 +41,14 @@ function list_user_events_sample(string $formattedParent): void // Create a client. $userEventServiceClient = new UserEventServiceClient(); + // Prepare the request message. + $request = (new ListUserEventsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $userEventServiceClient->listUserEvents($formattedParent); + $response = $userEventServiceClient->listUserEvents($request); /** @var UserEvent $element */ foreach ($response as $element) { diff --git a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/purge_user_events.php b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/purge_user_events.php index 8602266d59ff..9f6202c21010 100644 --- a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/purge_user_events.php +++ b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/purge_user_events.php @@ -25,8 +25,9 @@ // [START recommendationengine_v1beta1_generated_UserEventService_PurgeUserEvents_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\RecommendationEngine\V1beta1\Client\UserEventServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\PurgeUserEventsRequest; use Google\Cloud\RecommendationEngine\V1beta1\PurgeUserEventsResponse; -use Google\Cloud\RecommendationEngine\V1beta1\UserEventServiceClient; use Google\Rpc\Status; /** @@ -63,10 +64,15 @@ function purge_user_events_sample(string $formattedParent, string $filter): void // Create a client. $userEventServiceClient = new UserEventServiceClient(); + // Prepare the request message. + $request = (new PurgeUserEventsRequest()) + ->setParent($formattedParent) + ->setFilter($filter); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $userEventServiceClient->purgeUserEvents($formattedParent, $filter); + $response = $userEventServiceClient->purgeUserEvents($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/write_user_event.php b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/write_user_event.php index f6b2060604c7..3622db50e329 100644 --- a/RecommendationEngine/samples/V1beta1/UserEventServiceClient/write_user_event.php +++ b/RecommendationEngine/samples/V1beta1/UserEventServiceClient/write_user_event.php @@ -24,9 +24,10 @@ // [START recommendationengine_v1beta1_generated_UserEventService_WriteUserEvent_sync] use Google\ApiCore\ApiException; +use Google\Cloud\RecommendationEngine\V1beta1\Client\UserEventServiceClient; use Google\Cloud\RecommendationEngine\V1beta1\UserEvent; -use Google\Cloud\RecommendationEngine\V1beta1\UserEventServiceClient; use Google\Cloud\RecommendationEngine\V1beta1\UserInfo; +use Google\Cloud\RecommendationEngine\V1beta1\WriteUserEventRequest; /** * Writes a single user event. @@ -68,17 +69,20 @@ function write_user_event_sample( // Create a client. $userEventServiceClient = new UserEventServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $userEventUserInfo = (new UserInfo()) ->setVisitorId($userEventUserInfoVisitorId); $userEvent = (new UserEvent()) ->setEventType($userEventEventType) ->setUserInfo($userEventUserInfo); + $request = (new WriteUserEventRequest()) + ->setParent($formattedParent) + ->setUserEvent($userEvent); // Call the API and handle any network failures. try { /** @var UserEvent $response */ - $response = $userEventServiceClient->writeUserEvent($formattedParent, $userEvent); + $response = $userEventServiceClient->writeUserEvent($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/RecommendationEngine/src/V1beta1/Client/BaseClient/CatalogServiceBaseClient.php b/RecommendationEngine/src/V1beta1/Client/BaseClient/CatalogServiceBaseClient.php new file mode 100644 index 000000000000..95cc21615d43 --- /dev/null +++ b/RecommendationEngine/src/V1beta1/Client/BaseClient/CatalogServiceBaseClient.php @@ -0,0 +1,454 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/catalog_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/catalog_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/catalog_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/catalog_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + * + * @experimental + */ + 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 + * + * @experimental + */ + 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 catalog + * resource. + * + * @param string $project + * @param string $location + * @param string $catalog + * + * @return string The formatted catalog resource. + * + * @experimental + */ + public static function catalogName(string $project, string $location, string $catalog): string + { + return self::getPathTemplate('catalog')->render([ + 'project' => $project, + 'location' => $location, + 'catalog' => $catalog, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * catalog_item_path resource. + * + * @param string $project + * @param string $location + * @param string $catalog + * @param string $catalogItemPath + * + * @return string The formatted catalog_item_path resource. + * + * @experimental + */ + public static function catalogItemPathName(string $project, string $location, string $catalog, string $catalogItemPath): string + { + return self::getPathTemplate('catalogItemPath')->render([ + 'project' => $project, + 'location' => $location, + 'catalog' => $catalog, + 'catalog_item_path' => $catalogItemPath, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - catalog: projects/{project}/locations/{location}/catalogs/{catalog} + * - catalogItemPath: projects/{project}/locations/{location}/catalogs/{catalog}/catalogItems/{catalog_item_path} + * + * 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. + * + * @experimental + */ + 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 'recommendationengine.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 + * + * @experimental + */ + 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 catalog item. + * + * The async variant is {@see self::createCatalogItemAsync()} . + * + * @param CreateCatalogItemRequest $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 CatalogItem + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createCatalogItem(CreateCatalogItemRequest $request, array $callOptions = []): CatalogItem + { + return $this->startApiCall('CreateCatalogItem', $request, $callOptions)->wait(); + } + + /** + * Deletes a catalog item. + * + * The async variant is {@see self::deleteCatalogItemAsync()} . + * + * @param DeleteCatalogItemRequest $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. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deleteCatalogItem(DeleteCatalogItemRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteCatalogItem', $request, $callOptions)->wait(); + } + + /** + * Gets a specific catalog item. + * + * The async variant is {@see self::getCatalogItemAsync()} . + * + * @param GetCatalogItemRequest $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 CatalogItem + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function getCatalogItem(GetCatalogItemRequest $request, array $callOptions = []): CatalogItem + { + return $this->startApiCall('GetCatalogItem', $request, $callOptions)->wait(); + } + + /** + * Bulk import of multiple catalog items. Request processing may be + * synchronous. No partial updating supported. Non-existing items will be + * created. + * + * Operation.response is of type ImportResponse. Note that it is + * possible for a subset of the items to be successfully updated. + * + * The async variant is {@see self::importCatalogItemsAsync()} . + * + * @param ImportCatalogItemsRequest $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. + * + * @experimental + */ + public function importCatalogItems(ImportCatalogItemsRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ImportCatalogItems', $request, $callOptions)->wait(); + } + + /** + * Gets a list of catalog items. + * + * The async variant is {@see self::listCatalogItemsAsync()} . + * + * @param ListCatalogItemsRequest $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. + * + * @experimental + */ + public function listCatalogItems(ListCatalogItemsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCatalogItems', $request, $callOptions); + } + + /** + * Updates a catalog item. Partial updating is supported. Non-existing + * items will be created. + * + * The async variant is {@see self::updateCatalogItemAsync()} . + * + * @param UpdateCatalogItemRequest $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 CatalogItem + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function updateCatalogItem(UpdateCatalogItemRequest $request, array $callOptions = []): CatalogItem + { + return $this->startApiCall('UpdateCatalogItem', $request, $callOptions)->wait(); + } +} diff --git a/RecommendationEngine/src/V1beta1/Client/BaseClient/PredictionApiKeyRegistryBaseClient.php b/RecommendationEngine/src/V1beta1/Client/BaseClient/PredictionApiKeyRegistryBaseClient.php new file mode 100644 index 000000000000..bd7c85c89abe --- /dev/null +++ b/RecommendationEngine/src/V1beta1/Client/BaseClient/PredictionApiKeyRegistryBaseClient.php @@ -0,0 +1,333 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/prediction_api_key_registry_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/prediction_api_key_registry_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/prediction_api_key_registry_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/prediction_api_key_registry_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a event_store + * resource. + * + * @param string $project + * @param string $location + * @param string $catalog + * @param string $eventStore + * + * @return string The formatted event_store resource. + * + * @experimental + */ + public static function eventStoreName(string $project, string $location, string $catalog, string $eventStore): string + { + return self::getPathTemplate('eventStore')->render([ + 'project' => $project, + 'location' => $location, + 'catalog' => $catalog, + 'event_store' => $eventStore, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * prediction_api_key_registration resource. + * + * @param string $project + * @param string $location + * @param string $catalog + * @param string $eventStore + * @param string $predictionApiKeyRegistration + * + * @return string The formatted prediction_api_key_registration resource. + * + * @experimental + */ + public static function predictionApiKeyRegistrationName(string $project, string $location, string $catalog, string $eventStore, string $predictionApiKeyRegistration): string + { + return self::getPathTemplate('predictionApiKeyRegistration')->render([ + 'project' => $project, + 'location' => $location, + 'catalog' => $catalog, + 'event_store' => $eventStore, + 'prediction_api_key_registration' => $predictionApiKeyRegistration, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - eventStore: projects/{project}/locations/{location}/catalogs/{catalog}/eventStores/{event_store} + * - predictionApiKeyRegistration: projects/{project}/locations/{location}/catalogs/{catalog}/eventStores/{event_store}/predictionApiKeyRegistrations/{prediction_api_key_registration} + * + * 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. + * + * @experimental + */ + 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 'recommendationengine.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 + * + * @experimental + */ + 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); + } + + /** + * Register an API key for use with predict method. + * + * The async variant is {@see self::createPredictionApiKeyRegistrationAsync()} . + * + * @param CreatePredictionApiKeyRegistrationRequest $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 PredictionApiKeyRegistration + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createPredictionApiKeyRegistration(CreatePredictionApiKeyRegistrationRequest $request, array $callOptions = []): PredictionApiKeyRegistration + { + return $this->startApiCall('CreatePredictionApiKeyRegistration', $request, $callOptions)->wait(); + } + + /** + * Unregister an apiKey from using for predict method. + * + * The async variant is {@see self::deletePredictionApiKeyRegistrationAsync()} . + * + * @param DeletePredictionApiKeyRegistrationRequest $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. + * } + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function deletePredictionApiKeyRegistration(DeletePredictionApiKeyRegistrationRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeletePredictionApiKeyRegistration', $request, $callOptions)->wait(); + } + + /** + * List the registered apiKeys for use with predict method. + * + * The async variant is {@see self::listPredictionApiKeyRegistrationsAsync()} . + * + * @param ListPredictionApiKeyRegistrationsRequest $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. + * + * @experimental + */ + public function listPredictionApiKeyRegistrations(ListPredictionApiKeyRegistrationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListPredictionApiKeyRegistrations', $request, $callOptions); + } +} diff --git a/RecommendationEngine/src/V1beta1/Client/BaseClient/PredictionServiceBaseClient.php b/RecommendationEngine/src/V1beta1/Client/BaseClient/PredictionServiceBaseClient.php new file mode 100644 index 000000000000..aed2000716a2 --- /dev/null +++ b/RecommendationEngine/src/V1beta1/Client/BaseClient/PredictionServiceBaseClient.php @@ -0,0 +1,253 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/prediction_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/prediction_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/prediction_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/prediction_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a placement + * resource. + * + * @param string $project + * @param string $location + * @param string $catalog + * @param string $eventStore + * @param string $placement + * + * @return string The formatted placement resource. + * + * @experimental + */ + public static function placementName(string $project, string $location, string $catalog, string $eventStore, string $placement): string + { + return self::getPathTemplate('placement')->render([ + 'project' => $project, + 'location' => $location, + 'catalog' => $catalog, + 'event_store' => $eventStore, + 'placement' => $placement, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - placement: projects/{project}/locations/{location}/catalogs/{catalog}/eventStores/{event_store}/placements/{placement} + * + * 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. + * + * @experimental + */ + 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 'recommendationengine.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 + * + * @experimental + */ + 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); + } + + /** + * Makes a recommendation prediction. If using API Key based authentication, + * the API Key must be registered using the + * [PredictionApiKeyRegistry][google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry] + * service. [Learn more](https://cloud.google.com/recommendations-ai/docs/setting-up#register-key). + * + * The async variant is {@see self::predictAsync()} . + * + * @param PredictRequest $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. + * + * @experimental + */ + public function predict(PredictRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('Predict', $request, $callOptions); + } +} diff --git a/RecommendationEngine/src/V1beta1/Client/BaseClient/UserEventServiceBaseClient.php b/RecommendationEngine/src/V1beta1/Client/BaseClient/UserEventServiceBaseClient.php new file mode 100644 index 000000000000..7fac56ab6a2e --- /dev/null +++ b/RecommendationEngine/src/V1beta1/Client/BaseClient/UserEventServiceBaseClient.php @@ -0,0 +1,415 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/user_event_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/user_event_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/user_event_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/user_event_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + * + * @experimental + */ + 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 + * + * @experimental + */ + 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 event_store + * resource. + * + * @param string $project + * @param string $location + * @param string $catalog + * @param string $eventStore + * + * @return string The formatted event_store resource. + * + * @experimental + */ + public static function eventStoreName(string $project, string $location, string $catalog, string $eventStore): string + { + return self::getPathTemplate('eventStore')->render([ + 'project' => $project, + 'location' => $location, + 'catalog' => $catalog, + 'event_store' => $eventStore, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - eventStore: projects/{project}/locations/{location}/catalogs/{catalog}/eventStores/{event_store} + * + * 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. + * + * @experimental + */ + 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 'recommendationengine.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 + * + * @experimental + */ + 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); + } + + /** + * Writes a single user event from the browser. This uses a GET request to + * due to browser restriction of POST-ing to a 3rd party domain. + * + * This method is used only by the Recommendations AI JavaScript pixel. + * Users should not call this method directly. + * + * The async variant is {@see self::collectUserEventAsync()} . + * + * @param CollectUserEventRequest $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 HttpBody + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function collectUserEvent(CollectUserEventRequest $request, array $callOptions = []): HttpBody + { + return $this->startApiCall('CollectUserEvent', $request, $callOptions)->wait(); + } + + /** + * Bulk import of User events. Request processing might be + * synchronous. Events that already exist are skipped. + * Use this method for backfilling historical user events. + * + * Operation.response is of type ImportResponse. Note that it is + * possible for a subset of the items to be successfully inserted. + * Operation.metadata is of type ImportMetadata. + * + * The async variant is {@see self::importUserEventsAsync()} . + * + * @param ImportUserEventsRequest $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. + * + * @experimental + */ + public function importUserEvents(ImportUserEventsRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ImportUserEvents', $request, $callOptions)->wait(); + } + + /** + * Gets a list of user events within a time range, with potential filtering. + * + * The async variant is {@see self::listUserEventsAsync()} . + * + * @param ListUserEventsRequest $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. + * + * @experimental + */ + public function listUserEvents(ListUserEventsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListUserEvents', $request, $callOptions); + } + + /** + * Deletes permanently all user events specified by the filter provided. + * Depending on the number of events specified by the filter, this operation + * could take hours or days to complete. To test a filter, use the list + * command first. + * + * The async variant is {@see self::purgeUserEventsAsync()} . + * + * @param PurgeUserEventsRequest $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. + * + * @experimental + */ + public function purgeUserEvents(PurgeUserEventsRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('PurgeUserEvents', $request, $callOptions)->wait(); + } + + /** + * Writes a single user event. + * + * The async variant is {@see self::writeUserEventAsync()} . + * + * @param WriteUserEventRequest $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 UserEvent + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function writeUserEvent(WriteUserEventRequest $request, array $callOptions = []): UserEvent + { + return $this->startApiCall('WriteUserEvent', $request, $callOptions)->wait(); + } +} diff --git a/RecommendationEngine/src/V1beta1/Client/CatalogServiceClient.php b/RecommendationEngine/src/V1beta1/Client/CatalogServiceClient.php new file mode 100644 index 000000000000..00593a1be823 --- /dev/null +++ b/RecommendationEngine/src/V1beta1/Client/CatalogServiceClient.php @@ -0,0 +1,42 @@ +setParent($parent) + ->setUserEvent($userEvent) + ->setUri($uri) + ->setEts($ets); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/CreateCatalogItemRequest.php b/RecommendationEngine/src/V1beta1/CreateCatalogItemRequest.php index 2b8b8a7641c6..8375c0957290 100644 --- a/RecommendationEngine/src/V1beta1/CreateCatalogItemRequest.php +++ b/RecommendationEngine/src/V1beta1/CreateCatalogItemRequest.php @@ -29,6 +29,23 @@ class CreateCatalogItemRequest extends \Google\Protobuf\Internal\Message */ private $catalog_item = null; + /** + * @param string $parent Required. The parent catalog resource name, such as + * `projects/*/locations/global/catalogs/default_catalog`. Please see + * {@see CatalogServiceClient::catalogName()} for help formatting this field. + * @param \Google\Cloud\RecommendationEngine\V1beta1\CatalogItem $catalogItem Required. The catalog item to create. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\CreateCatalogItemRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\RecommendationEngine\V1beta1\CatalogItem $catalogItem): self + { + return (new self()) + ->setParent($parent) + ->setCatalogItem($catalogItem); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/CreatePredictionApiKeyRegistrationRequest.php b/RecommendationEngine/src/V1beta1/CreatePredictionApiKeyRegistrationRequest.php index fca0700e9206..f60e2e8c292f 100644 --- a/RecommendationEngine/src/V1beta1/CreatePredictionApiKeyRegistrationRequest.php +++ b/RecommendationEngine/src/V1beta1/CreatePredictionApiKeyRegistrationRequest.php @@ -29,6 +29,23 @@ class CreatePredictionApiKeyRegistrationRequest extends \Google\Protobuf\Interna */ private $prediction_api_key_registration = null; + /** + * @param string $parent Required. The parent resource path. + * `projects/*/locations/global/catalogs/default_catalog/eventStores/default_event_store`. Please see + * {@see PredictionApiKeyRegistryClient::eventStoreName()} for help formatting this field. + * @param \Google\Cloud\RecommendationEngine\V1beta1\PredictionApiKeyRegistration $predictionApiKeyRegistration Required. The prediction API key registration. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\CreatePredictionApiKeyRegistrationRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\RecommendationEngine\V1beta1\PredictionApiKeyRegistration $predictionApiKeyRegistration): self + { + return (new self()) + ->setParent($parent) + ->setPredictionApiKeyRegistration($predictionApiKeyRegistration); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/DeleteCatalogItemRequest.php b/RecommendationEngine/src/V1beta1/DeleteCatalogItemRequest.php index 85a179215658..0caa4c72fc39 100644 --- a/RecommendationEngine/src/V1beta1/DeleteCatalogItemRequest.php +++ b/RecommendationEngine/src/V1beta1/DeleteCatalogItemRequest.php @@ -23,6 +23,21 @@ class DeleteCatalogItemRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Full resource name of catalog item, such as + * `projects/*/locations/global/catalogs/default_catalog/catalogItems/some_catalog_item_id`. Please see + * {@see CatalogServiceClient::catalogItemPathName()} for help formatting this field. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\DeleteCatalogItemRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/DeletePredictionApiKeyRegistrationRequest.php b/RecommendationEngine/src/V1beta1/DeletePredictionApiKeyRegistrationRequest.php index e0462f160788..ddbdd6225073 100644 --- a/RecommendationEngine/src/V1beta1/DeletePredictionApiKeyRegistrationRequest.php +++ b/RecommendationEngine/src/V1beta1/DeletePredictionApiKeyRegistrationRequest.php @@ -23,6 +23,21 @@ class DeletePredictionApiKeyRegistrationRequest extends \Google\Protobuf\Interna */ private $name = ''; + /** + * @param string $name Required. The API key to unregister including full resource path. + * `projects/*/locations/global/catalogs/default_catalog/eventStores/default_event_store/predictionApiKeyRegistrations/` + * Please see {@see PredictionApiKeyRegistryClient::predictionApiKeyRegistrationName()} for help formatting this field. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\DeletePredictionApiKeyRegistrationRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/GetCatalogItemRequest.php b/RecommendationEngine/src/V1beta1/GetCatalogItemRequest.php index 36bbf685fb43..98cefb396ca7 100644 --- a/RecommendationEngine/src/V1beta1/GetCatalogItemRequest.php +++ b/RecommendationEngine/src/V1beta1/GetCatalogItemRequest.php @@ -23,6 +23,21 @@ class GetCatalogItemRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Full resource name of catalog item, such as + * `projects/*/locations/global/catalogs/default_catalog/catalogitems/some_catalog_item_id`. Please see + * {@see CatalogServiceClient::catalogItemPathName()} for help formatting this field. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\GetCatalogItemRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/ImportCatalogItemsRequest.php b/RecommendationEngine/src/V1beta1/ImportCatalogItemsRequest.php index 81ebc3b10845..ce88ed0bd288 100644 --- a/RecommendationEngine/src/V1beta1/ImportCatalogItemsRequest.php +++ b/RecommendationEngine/src/V1beta1/ImportCatalogItemsRequest.php @@ -43,6 +43,29 @@ class ImportCatalogItemsRequest extends \Google\Protobuf\Internal\Message */ private $errors_config = null; + /** + * @param string $parent Required. `projects/1234/locations/global/catalogs/default_catalog` + * Please see {@see CatalogServiceClient::catalogName()} for help formatting this field. + * @param string $requestId Optional. Unique identifier provided by client, within the ancestor + * dataset scope. Ensures idempotency and used for request deduplication. + * Server-generated if unspecified. Up to 128 characters long. This is + * returned as google.longrunning.Operation.name in the response. + * @param \Google\Cloud\RecommendationEngine\V1beta1\InputConfig $inputConfig Required. The desired input location of the data. + * @param \Google\Cloud\RecommendationEngine\V1beta1\ImportErrorsConfig $errorsConfig Optional. The desired location of errors incurred during the Import. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\ImportCatalogItemsRequest + * + * @experimental + */ + public static function build(string $parent, string $requestId, \Google\Cloud\RecommendationEngine\V1beta1\InputConfig $inputConfig, \Google\Cloud\RecommendationEngine\V1beta1\ImportErrorsConfig $errorsConfig): self + { + return (new self()) + ->setParent($parent) + ->setRequestId($requestId) + ->setInputConfig($inputConfig) + ->setErrorsConfig($errorsConfig); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/ImportUserEventsRequest.php b/RecommendationEngine/src/V1beta1/ImportUserEventsRequest.php index 514831013488..0b7923123d92 100644 --- a/RecommendationEngine/src/V1beta1/ImportUserEventsRequest.php +++ b/RecommendationEngine/src/V1beta1/ImportUserEventsRequest.php @@ -46,6 +46,32 @@ class ImportUserEventsRequest extends \Google\Protobuf\Internal\Message */ private $errors_config = null; + /** + * @param string $parent Required. + * `projects/1234/locations/global/catalogs/default_catalog/eventStores/default_event_store` + * Please see {@see UserEventServiceClient::eventStoreName()} for help formatting this field. + * @param string $requestId Optional. Unique identifier provided by client, within the ancestor + * dataset scope. Ensures idempotency for expensive long running operations. + * Server-generated if unspecified. Up to 128 characters long. This is + * returned as google.longrunning.Operation.name in the response. Note that + * this field must not be set if the desired input config is + * catalog_inline_source. + * @param \Google\Cloud\RecommendationEngine\V1beta1\InputConfig $inputConfig Required. The desired input location of the data. + * @param \Google\Cloud\RecommendationEngine\V1beta1\ImportErrorsConfig $errorsConfig Optional. The desired location of errors incurred during the Import. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\ImportUserEventsRequest + * + * @experimental + */ + public static function build(string $parent, string $requestId, \Google\Cloud\RecommendationEngine\V1beta1\InputConfig $inputConfig, \Google\Cloud\RecommendationEngine\V1beta1\ImportErrorsConfig $errorsConfig): self + { + return (new self()) + ->setParent($parent) + ->setRequestId($requestId) + ->setInputConfig($inputConfig) + ->setErrorsConfig($errorsConfig); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/ListCatalogItemsRequest.php b/RecommendationEngine/src/V1beta1/ListCatalogItemsRequest.php index d191dc60e3cb..316dc961bd33 100644 --- a/RecommendationEngine/src/V1beta1/ListCatalogItemsRequest.php +++ b/RecommendationEngine/src/V1beta1/ListCatalogItemsRequest.php @@ -42,6 +42,23 @@ class ListCatalogItemsRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The parent catalog resource name, such as + * `projects/*/locations/global/catalogs/default_catalog`. Please see + * {@see CatalogServiceClient::catalogName()} for help formatting this field. + * @param string $filter Optional. A filter to apply on the list results. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\ListCatalogItemsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/ListPredictionApiKeyRegistrationsRequest.php b/RecommendationEngine/src/V1beta1/ListPredictionApiKeyRegistrationsRequest.php index 6fb2f3f71497..d3ac5e2c6180 100644 --- a/RecommendationEngine/src/V1beta1/ListPredictionApiKeyRegistrationsRequest.php +++ b/RecommendationEngine/src/V1beta1/ListPredictionApiKeyRegistrationsRequest.php @@ -36,6 +36,21 @@ class ListPredictionApiKeyRegistrationsRequest extends \Google\Protobuf\Internal */ private $page_token = ''; + /** + * @param string $parent Required. The parent placement resource name such as + * `projects/1234/locations/global/catalogs/default_catalog/eventStores/default_event_store` + * Please see {@see PredictionApiKeyRegistryClient::eventStoreName()} for help formatting this field. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\ListPredictionApiKeyRegistrationsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/ListUserEventsRequest.php b/RecommendationEngine/src/V1beta1/ListUserEventsRequest.php index 3c1e9645821c..0c29ab12d3f4 100644 --- a/RecommendationEngine/src/V1beta1/ListUserEventsRequest.php +++ b/RecommendationEngine/src/V1beta1/ListUserEventsRequest.php @@ -67,6 +67,54 @@ class ListUserEventsRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The parent eventStore resource name, such as + * `projects/*/locations/*/catalogs/default_catalog/eventStores/default_event_store`. Please see + * {@see UserEventServiceClient::eventStoreName()} for help formatting this field. + * @param string $filter Optional. Filtering expression to specify restrictions over + * returned events. This is a sequence of terms, where each term applies some + * kind of a restriction to the returned user events. Use this expression to + * restrict results to a specific time range, or filter events by eventType. + * eg: eventTime > "2012-04-23T18:25:43.511Z" eventsMissingCatalogItems + * eventTime<"2012-04-23T18:25:43.511Z" eventType=search + * + * We expect only 3 types of fields: + * + * * eventTime: this can be specified a maximum of 2 times, once with a + * less than operator and once with a greater than operator. The + * eventTime restrict should result in one contiguous valid eventTime + * range. + * + * * eventType: only 1 eventType restriction can be specified. + * + * * eventsMissingCatalogItems: specififying this will restrict results + * to events for which catalog items were not found in the catalog. The + * default behavior is to return only those events for which catalog + * items were found. + * + * Some examples of valid filters expressions: + * + * * Example 1: eventTime > "2012-04-23T18:25:43.511Z" + * eventTime < "2012-04-23T18:30:43.511Z" + * * Example 2: eventTime > "2012-04-23T18:25:43.511Z" + * eventType = detail-page-view + * * Example 3: eventsMissingCatalogItems + * eventType = search eventTime < "2018-04-23T18:30:43.511Z" + * * Example 4: eventTime > "2012-04-23T18:25:43.511Z" + * * Example 5: eventType = search + * * Example 6: eventsMissingCatalogItems + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\ListUserEventsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/PredictRequest.php b/RecommendationEngine/src/V1beta1/PredictRequest.php index 030053fa35ca..ba05301e5c05 100644 --- a/RecommendationEngine/src/V1beta1/PredictRequest.php +++ b/RecommendationEngine/src/V1beta1/PredictRequest.php @@ -123,6 +123,53 @@ class PredictRequest extends \Google\Protobuf\Internal\Message */ private $labels; + /** + * @param string $name Required. Full resource name of the format: + * `{name=projects/*/locations/global/catalogs/default_catalog/eventStores/default_event_store/placements/*}` + * The id of the recommendation engine placement. This id is used to identify + * the set of models that will be used to make the prediction. + * + * We currently support three placements with the following IDs by default: + * + * * `shopping_cart`: Predicts items frequently bought together with one or + * more catalog items in the same shopping session. Commonly displayed after + * `add-to-cart` events, on product detail pages, or on the shopping cart + * page. + * + * * `home_page`: Predicts the next product that a user will most likely + * engage with or purchase based on the shopping or viewing history of the + * specified `userId` or `visitorId`. For example - Recommendations for you. + * + * * `product_detail`: Predicts the next product that a user will most likely + * engage with or purchase. The prediction is based on the shopping or + * viewing history of the specified `userId` or `visitorId` and its + * relevance to a specified `CatalogItem`. Typically used on product detail + * pages. For example - More items like this. + * + * * `recently_viewed_default`: Returns up to 75 items recently viewed by the + * specified `userId` or `visitorId`, most recent ones first. Returns + * nothing if neither of them has viewed any items yet. For example - + * Recently viewed. + * + * The full list of available placements can be seen at + * https://console.cloud.google.com/recommendation/datafeeds/default_catalog/dashboard + * Please see {@see PredictionServiceClient::placementName()} for help formatting this field. + * @param \Google\Cloud\RecommendationEngine\V1beta1\UserEvent $userEvent Required. Context about the user, what they are looking at and what action + * they took to trigger the predict request. Note that this user event detail + * won't be ingested to userEvent logs. Thus, a separate userEvent write + * request is required for event logging. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\PredictRequest + * + * @experimental + */ + public static function build(string $name, \Google\Cloud\RecommendationEngine\V1beta1\UserEvent $userEvent): self + { + return (new self()) + ->setName($name) + ->setUserEvent($userEvent); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/PurgeUserEventsRequest.php b/RecommendationEngine/src/V1beta1/PurgeUserEventsRequest.php index 974406925630..544385253229 100644 --- a/RecommendationEngine/src/V1beta1/PurgeUserEventsRequest.php +++ b/RecommendationEngine/src/V1beta1/PurgeUserEventsRequest.php @@ -55,6 +55,45 @@ class PurgeUserEventsRequest extends \Google\Protobuf\Internal\Message */ private $force = false; + /** + * @param string $parent Required. The resource name of the event_store under which the events are + * created. The format is + * `projects/${projectId}/locations/global/catalogs/${catalogId}/eventStores/${eventStoreId}` + * Please see {@see UserEventServiceClient::eventStoreName()} for help formatting this field. + * @param string $filter Required. The filter string to specify the events to be deleted. Empty + * string filter is not allowed. This filter can also be used with + * ListUserEvents API to list events that will be deleted. The eligible fields + * for filtering are: + * * eventType - UserEvent.eventType field of type string. + * * eventTime - in ISO 8601 "zulu" format. + * * visitorId - field of type string. Specifying this will delete all events + * associated with a visitor. + * * userId - field of type string. Specifying this will delete all events + * associated with a user. + * Example 1: Deleting all events in a time range. + * `eventTime > "2012-04-23T18:25:43.511Z" eventTime < + * "2012-04-23T18:30:43.511Z"` + * Example 2: Deleting specific eventType in time range. + * `eventTime > "2012-04-23T18:25:43.511Z" eventType = "detail-page-view"` + * Example 3: Deleting all events for a specific visitor + * `visitorId = visitor1024` + * The filtering fields are assumed to have an implicit AND. + * @param bool $force Optional. The default value is false. Override this flag to true to + * actually perform the purge. If the field is not set to true, a sampling of + * events to be deleted will be returned. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\PurgeUserEventsRequest + * + * @experimental + */ + public static function build(string $parent, string $filter, bool $force): self + { + return (new self()) + ->setParent($parent) + ->setFilter($filter) + ->setForce($force); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/UpdateCatalogItemRequest.php b/RecommendationEngine/src/V1beta1/UpdateCatalogItemRequest.php index 394e897825b5..e82360c0369f 100644 --- a/RecommendationEngine/src/V1beta1/UpdateCatalogItemRequest.php +++ b/RecommendationEngine/src/V1beta1/UpdateCatalogItemRequest.php @@ -37,6 +37,27 @@ class UpdateCatalogItemRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param string $name Required. Full resource name of catalog item, such as + * `projects/*/locations/global/catalogs/default_catalog/catalogItems/some_catalog_item_id`. Please see + * {@see CatalogServiceClient::catalogItemPathName()} for help formatting this field. + * @param \Google\Cloud\RecommendationEngine\V1beta1\CatalogItem $catalogItem Required. The catalog item to update/create. The 'catalog_item_id' field + * has to match that in the 'name'. + * @param \Google\Protobuf\FieldMask $updateMask Optional. Indicates which fields in the provided 'item' to update. If not + * set, will by default update all fields. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\UpdateCatalogItemRequest + * + * @experimental + */ + public static function build(string $name, \Google\Cloud\RecommendationEngine\V1beta1\CatalogItem $catalogItem, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setName($name) + ->setCatalogItem($catalogItem) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/WriteUserEventRequest.php b/RecommendationEngine/src/V1beta1/WriteUserEventRequest.php index 9c882a93e926..59707d0853b3 100644 --- a/RecommendationEngine/src/V1beta1/WriteUserEventRequest.php +++ b/RecommendationEngine/src/V1beta1/WriteUserEventRequest.php @@ -29,6 +29,23 @@ class WriteUserEventRequest extends \Google\Protobuf\Internal\Message */ private $user_event = null; + /** + * @param string $parent Required. The parent eventStore resource name, such as + * `projects/1234/locations/global/catalogs/default_catalog/eventStores/default_event_store`. Please see + * {@see UserEventServiceClient::eventStoreName()} for help formatting this field. + * @param \Google\Cloud\RecommendationEngine\V1beta1\UserEvent $userEvent Required. User event to write. + * + * @return \Google\Cloud\RecommendationEngine\V1beta1\WriteUserEventRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\RecommendationEngine\V1beta1\UserEvent $userEvent): self + { + return (new self()) + ->setParent($parent) + ->setUserEvent($userEvent); + } + /** * Constructor. * diff --git a/RecommendationEngine/src/V1beta1/resources/catalog_service_descriptor_config.php b/RecommendationEngine/src/V1beta1/resources/catalog_service_descriptor_config.php index 4626e83d3b40..160a5c9b4209 100644 --- a/RecommendationEngine/src/V1beta1/resources/catalog_service_descriptor_config.php +++ b/RecommendationEngine/src/V1beta1/resources/catalog_service_descriptor_config.php @@ -12,6 +12,51 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateCatalogItem' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\CatalogItem', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteCatalogItem' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetCatalogItem' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\CatalogItem', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListCatalogItems' => [ 'pageStreaming' => [ @@ -22,6 +67,32 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getCatalogItems', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\ListCatalogItemsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'UpdateCatalogItem' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\CatalogItem', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'templateMap' => [ + 'catalog' => 'projects/{project}/locations/{location}/catalogs/{catalog}', + 'catalogItemPath' => 'projects/{project}/locations/{location}/catalogs/{catalog}/catalogItems/{catalog_item_path}', ], ], ], diff --git a/RecommendationEngine/src/V1beta1/resources/prediction_api_key_registry_descriptor_config.php b/RecommendationEngine/src/V1beta1/resources/prediction_api_key_registry_descriptor_config.php index 489c66c61dfc..54302de06b55 100644 --- a/RecommendationEngine/src/V1beta1/resources/prediction_api_key_registry_descriptor_config.php +++ b/RecommendationEngine/src/V1beta1/resources/prediction_api_key_registry_descriptor_config.php @@ -3,6 +3,30 @@ return [ 'interfaces' => [ 'google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry' => [ + 'CreatePredictionApiKeyRegistration' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\PredictionApiKeyRegistration', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeletePredictionApiKeyRegistration' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListPredictionApiKeyRegistrations' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +36,20 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getPredictionApiKeyRegistrations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\ListPredictionApiKeyRegistrationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'eventStore' => 'projects/{project}/locations/{location}/catalogs/{catalog}/eventStores/{event_store}', + 'predictionApiKeyRegistration' => 'projects/{project}/locations/{location}/catalogs/{catalog}/eventStores/{event_store}/predictionApiKeyRegistrations/{prediction_api_key_registration}', ], ], ], diff --git a/RecommendationEngine/src/V1beta1/resources/prediction_service_descriptor_config.php b/RecommendationEngine/src/V1beta1/resources/prediction_service_descriptor_config.php index 52e2175fe76c..b839d7cb4423 100644 --- a/RecommendationEngine/src/V1beta1/resources/prediction_service_descriptor_config.php +++ b/RecommendationEngine/src/V1beta1/resources/prediction_service_descriptor_config.php @@ -12,6 +12,19 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getResults', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\PredictResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'templateMap' => [ + 'placement' => 'projects/{project}/locations/{location}/catalogs/{catalog}/eventStores/{event_store}/placements/{placement}', ], ], ], diff --git a/RecommendationEngine/src/V1beta1/resources/user_event_service_descriptor_config.php b/RecommendationEngine/src/V1beta1/resources/user_event_service_descriptor_config.php index 886947166e6f..b1a3aad3fd3b 100644 --- a/RecommendationEngine/src/V1beta1/resources/user_event_service_descriptor_config.php +++ b/RecommendationEngine/src/V1beta1/resources/user_event_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'PurgeUserEvents' => [ 'longRunning' => [ @@ -22,6 +31,27 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CollectUserEvent' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Api\HttpBody', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListUserEvents' => [ 'pageStreaming' => [ @@ -32,6 +62,31 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getUserEvents', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\ListUserEventsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'WriteUserEvent' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\RecommendationEngine\V1beta1\UserEvent', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'eventStore' => 'projects/{project}/locations/{location}/catalogs/{catalog}/eventStores/{event_store}', ], ], ], diff --git a/RecommendationEngine/tests/Unit/V1beta1/Client/CatalogServiceClientTest.php b/RecommendationEngine/tests/Unit/V1beta1/Client/CatalogServiceClientTest.php new file mode 100644 index 000000000000..8b08c930b337 --- /dev/null +++ b/RecommendationEngine/tests/Unit/V1beta1/Client/CatalogServiceClientTest.php @@ -0,0 +1,634 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return CatalogServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new CatalogServiceClient($options); + } + + /** @test */ + public function createCatalogItemTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $title = 'title110371416'; + $description = 'description-1724546052'; + $languageCode = 'languageCode-412800396'; + $itemGroupId = 'itemGroupId894431879'; + $expectedResponse = new CatalogItem(); + $expectedResponse->setId($id); + $expectedResponse->setTitle($title); + $expectedResponse->setDescription($description); + $expectedResponse->setLanguageCode($languageCode); + $expectedResponse->setItemGroupId($itemGroupId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->catalogName('[PROJECT]', '[LOCATION]', '[CATALOG]'); + $catalogItem = new CatalogItem(); + $catalogItemId = 'catalogItemId-1850269433'; + $catalogItem->setId($catalogItemId); + $catalogItemCategoryHierarchies = []; + $catalogItem->setCategoryHierarchies($catalogItemCategoryHierarchies); + $catalogItemTitle = 'catalogItemTitle244020972'; + $catalogItem->setTitle($catalogItemTitle); + $request = (new CreateCatalogItemRequest()) + ->setParent($formattedParent) + ->setCatalogItem($catalogItem); + $response = $gapicClient->createCatalogItem($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.recommendationengine.v1beta1.CatalogService/CreateCatalogItem', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getCatalogItem(); + $this->assertProtobufEquals($catalogItem, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createCatalogItemExceptionTest() + { + $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->catalogName('[PROJECT]', '[LOCATION]', '[CATALOG]'); + $catalogItem = new CatalogItem(); + $catalogItemId = 'catalogItemId-1850269433'; + $catalogItem->setId($catalogItemId); + $catalogItemCategoryHierarchies = []; + $catalogItem->setCategoryHierarchies($catalogItemCategoryHierarchies); + $catalogItemTitle = 'catalogItemTitle244020972'; + $catalogItem->setTitle($catalogItemTitle); + $request = (new CreateCatalogItemRequest()) + ->setParent($formattedParent) + ->setCatalogItem($catalogItem); + try { + $gapicClient->createCatalogItem($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 deleteCatalogItemTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->catalogItemPathName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[CATALOG_ITEM_PATH]'); + $request = (new DeleteCatalogItemRequest()) + ->setName($formattedName); + $gapicClient->deleteCatalogItem($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.recommendationengine.v1beta1.CatalogService/DeleteCatalogItem', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteCatalogItemExceptionTest() + { + $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->catalogItemPathName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[CATALOG_ITEM_PATH]'); + $request = (new DeleteCatalogItemRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteCatalogItem($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 getCatalogItemTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $title = 'title110371416'; + $description = 'description-1724546052'; + $languageCode = 'languageCode-412800396'; + $itemGroupId = 'itemGroupId894431879'; + $expectedResponse = new CatalogItem(); + $expectedResponse->setId($id); + $expectedResponse->setTitle($title); + $expectedResponse->setDescription($description); + $expectedResponse->setLanguageCode($languageCode); + $expectedResponse->setItemGroupId($itemGroupId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->catalogItemPathName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[CATALOG_ITEM_PATH]'); + $request = (new GetCatalogItemRequest()) + ->setName($formattedName); + $response = $gapicClient->getCatalogItem($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.recommendationengine.v1beta1.CatalogService/GetCatalogItem', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCatalogItemExceptionTest() + { + $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->catalogItemPathName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[CATALOG_ITEM_PATH]'); + $request = (new GetCatalogItemRequest()) + ->setName($formattedName); + try { + $gapicClient->getCatalogItem($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 importCatalogItemsTest() + { + $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/importCatalogItemsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new ImportCatalogItemsResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/importCatalogItemsTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->catalogName('[PROJECT]', '[LOCATION]', '[CATALOG]'); + $inputConfig = new InputConfig(); + $request = (new ImportCatalogItemsRequest()) + ->setParent($formattedParent) + ->setInputConfig($inputConfig); + $response = $gapicClient->importCatalogItems($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.recommendationengine.v1beta1.CatalogService/ImportCatalogItems', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInputConfig(); + $this->assertProtobufEquals($inputConfig, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/importCatalogItemsTest'); + $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 importCatalogItemsExceptionTest() + { + $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/importCatalogItemsTest'); + $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->catalogName('[PROJECT]', '[LOCATION]', '[CATALOG]'); + $inputConfig = new InputConfig(); + $request = (new ImportCatalogItemsRequest()) + ->setParent($formattedParent) + ->setInputConfig($inputConfig); + $response = $gapicClient->importCatalogItems($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/importCatalogItemsTest'); + 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 listCatalogItemsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $catalogItemsElement = new CatalogItem(); + $catalogItems = [ + $catalogItemsElement, + ]; + $expectedResponse = new ListCatalogItemsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCatalogItems($catalogItems); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->catalogName('[PROJECT]', '[LOCATION]', '[CATALOG]'); + $request = (new ListCatalogItemsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listCatalogItems($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCatalogItems()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.recommendationengine.v1beta1.CatalogService/ListCatalogItems', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCatalogItemsExceptionTest() + { + $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->catalogName('[PROJECT]', '[LOCATION]', '[CATALOG]'); + $request = (new ListCatalogItemsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listCatalogItems($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 updateCatalogItemTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $title = 'title110371416'; + $description = 'description-1724546052'; + $languageCode = 'languageCode-412800396'; + $itemGroupId = 'itemGroupId894431879'; + $expectedResponse = new CatalogItem(); + $expectedResponse->setId($id); + $expectedResponse->setTitle($title); + $expectedResponse->setDescription($description); + $expectedResponse->setLanguageCode($languageCode); + $expectedResponse->setItemGroupId($itemGroupId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->catalogItemPathName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[CATALOG_ITEM_PATH]'); + $catalogItem = new CatalogItem(); + $catalogItemId = 'catalogItemId-1850269433'; + $catalogItem->setId($catalogItemId); + $catalogItemCategoryHierarchies = []; + $catalogItem->setCategoryHierarchies($catalogItemCategoryHierarchies); + $catalogItemTitle = 'catalogItemTitle244020972'; + $catalogItem->setTitle($catalogItemTitle); + $request = (new UpdateCatalogItemRequest()) + ->setName($formattedName) + ->setCatalogItem($catalogItem); + $response = $gapicClient->updateCatalogItem($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.recommendationengine.v1beta1.CatalogService/UpdateCatalogItem', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getCatalogItem(); + $this->assertProtobufEquals($catalogItem, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateCatalogItemExceptionTest() + { + $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->catalogItemPathName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[CATALOG_ITEM_PATH]'); + $catalogItem = new CatalogItem(); + $catalogItemId = 'catalogItemId-1850269433'; + $catalogItem->setId($catalogItemId); + $catalogItemCategoryHierarchies = []; + $catalogItem->setCategoryHierarchies($catalogItemCategoryHierarchies); + $catalogItemTitle = 'catalogItemTitle244020972'; + $catalogItem->setTitle($catalogItemTitle); + $request = (new UpdateCatalogItemRequest()) + ->setName($formattedName) + ->setCatalogItem($catalogItem); + try { + $gapicClient->updateCatalogItem($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 createCatalogItemAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $id = 'id3355'; + $title = 'title110371416'; + $description = 'description-1724546052'; + $languageCode = 'languageCode-412800396'; + $itemGroupId = 'itemGroupId894431879'; + $expectedResponse = new CatalogItem(); + $expectedResponse->setId($id); + $expectedResponse->setTitle($title); + $expectedResponse->setDescription($description); + $expectedResponse->setLanguageCode($languageCode); + $expectedResponse->setItemGroupId($itemGroupId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->catalogName('[PROJECT]', '[LOCATION]', '[CATALOG]'); + $catalogItem = new CatalogItem(); + $catalogItemId = 'catalogItemId-1850269433'; + $catalogItem->setId($catalogItemId); + $catalogItemCategoryHierarchies = []; + $catalogItem->setCategoryHierarchies($catalogItemCategoryHierarchies); + $catalogItemTitle = 'catalogItemTitle244020972'; + $catalogItem->setTitle($catalogItemTitle); + $request = (new CreateCatalogItemRequest()) + ->setParent($formattedParent) + ->setCatalogItem($catalogItem); + $response = $gapicClient->createCatalogItemAsync($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.recommendationengine.v1beta1.CatalogService/CreateCatalogItem', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getCatalogItem(); + $this->assertProtobufEquals($catalogItem, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/RecommendationEngine/tests/Unit/V1beta1/Client/PredictionApiKeyRegistryClientTest.php b/RecommendationEngine/tests/Unit/V1beta1/Client/PredictionApiKeyRegistryClientTest.php new file mode 100644 index 000000000000..9a37a160408b --- /dev/null +++ b/RecommendationEngine/tests/Unit/V1beta1/Client/PredictionApiKeyRegistryClientTest.php @@ -0,0 +1,302 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return PredictionApiKeyRegistryClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new PredictionApiKeyRegistryClient($options); + } + + /** @test */ + public function createPredictionApiKeyRegistrationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $apiKey = 'apiKey-800085318'; + $expectedResponse = new PredictionApiKeyRegistration(); + $expectedResponse->setApiKey($apiKey); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $predictionApiKeyRegistration = new PredictionApiKeyRegistration(); + $request = (new CreatePredictionApiKeyRegistrationRequest()) + ->setParent($formattedParent) + ->setPredictionApiKeyRegistration($predictionApiKeyRegistration); + $response = $gapicClient->createPredictionApiKeyRegistration($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.recommendationengine.v1beta1.PredictionApiKeyRegistry/CreatePredictionApiKeyRegistration', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPredictionApiKeyRegistration(); + $this->assertProtobufEquals($predictionApiKeyRegistration, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createPredictionApiKeyRegistrationExceptionTest() + { + $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->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $predictionApiKeyRegistration = new PredictionApiKeyRegistration(); + $request = (new CreatePredictionApiKeyRegistrationRequest()) + ->setParent($formattedParent) + ->setPredictionApiKeyRegistration($predictionApiKeyRegistration); + try { + $gapicClient->createPredictionApiKeyRegistration($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 deletePredictionApiKeyRegistrationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->predictionApiKeyRegistrationName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]', '[PREDICTION_API_KEY_REGISTRATION]'); + $request = (new DeletePredictionApiKeyRegistrationRequest()) + ->setName($formattedName); + $gapicClient->deletePredictionApiKeyRegistration($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/DeletePredictionApiKeyRegistration', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deletePredictionApiKeyRegistrationExceptionTest() + { + $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->predictionApiKeyRegistrationName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]', '[PREDICTION_API_KEY_REGISTRATION]'); + $request = (new DeletePredictionApiKeyRegistrationRequest()) + ->setName($formattedName); + try { + $gapicClient->deletePredictionApiKeyRegistration($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 listPredictionApiKeyRegistrationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $predictionApiKeyRegistrationsElement = new PredictionApiKeyRegistration(); + $predictionApiKeyRegistrations = [ + $predictionApiKeyRegistrationsElement, + ]; + $expectedResponse = new ListPredictionApiKeyRegistrationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setPredictionApiKeyRegistrations($predictionApiKeyRegistrations); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $request = (new ListPredictionApiKeyRegistrationsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listPredictionApiKeyRegistrations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getPredictionApiKeyRegistrations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/ListPredictionApiKeyRegistrations', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listPredictionApiKeyRegistrationsExceptionTest() + { + $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->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $request = (new ListPredictionApiKeyRegistrationsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listPredictionApiKeyRegistrations($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 createPredictionApiKeyRegistrationAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $apiKey = 'apiKey-800085318'; + $expectedResponse = new PredictionApiKeyRegistration(); + $expectedResponse->setApiKey($apiKey); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $predictionApiKeyRegistration = new PredictionApiKeyRegistration(); + $request = (new CreatePredictionApiKeyRegistrationRequest()) + ->setParent($formattedParent) + ->setPredictionApiKeyRegistration($predictionApiKeyRegistration); + $response = $gapicClient->createPredictionApiKeyRegistrationAsync($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.recommendationengine.v1beta1.PredictionApiKeyRegistry/CreatePredictionApiKeyRegistration', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPredictionApiKeyRegistration(); + $this->assertProtobufEquals($predictionApiKeyRegistration, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/RecommendationEngine/tests/Unit/V1beta1/Client/PredictionServiceClientTest.php b/RecommendationEngine/tests/Unit/V1beta1/Client/PredictionServiceClientTest.php new file mode 100644 index 000000000000..74db58507a65 --- /dev/null +++ b/RecommendationEngine/tests/Unit/V1beta1/Client/PredictionServiceClientTest.php @@ -0,0 +1,210 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return PredictionServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new PredictionServiceClient($options); + } + + /** @test */ + public function predictTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $recommendationToken = 'recommendationToken-1973883405'; + $dryRun2 = true; + $nextPageToken = ''; + $resultsElement = new PredictionResult(); + $results = [ + $resultsElement, + ]; + $expectedResponse = new PredictResponse(); + $expectedResponse->setRecommendationToken($recommendationToken); + $expectedResponse->setDryRun($dryRun2); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setResults($results); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->placementName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]', '[PLACEMENT]'); + $userEvent = new UserEvent(); + $userEventEventType = 'userEventEventType341658661'; + $userEvent->setEventType($userEventEventType); + $userEventUserInfo = new UserInfo(); + $userInfoVisitorId = 'userInfoVisitorId-1297088752'; + $userEventUserInfo->setVisitorId($userInfoVisitorId); + $userEvent->setUserInfo($userEventUserInfo); + $request = (new PredictRequest()) + ->setName($formattedName) + ->setUserEvent($userEvent); + $response = $gapicClient->predict($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getResults()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.recommendationengine.v1beta1.PredictionService/Predict', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getUserEvent(); + $this->assertProtobufEquals($userEvent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function predictExceptionTest() + { + $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->placementName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]', '[PLACEMENT]'); + $userEvent = new UserEvent(); + $userEventEventType = 'userEventEventType341658661'; + $userEvent->setEventType($userEventEventType); + $userEventUserInfo = new UserInfo(); + $userInfoVisitorId = 'userInfoVisitorId-1297088752'; + $userEventUserInfo->setVisitorId($userInfoVisitorId); + $userEvent->setUserInfo($userEventUserInfo); + $request = (new PredictRequest()) + ->setName($formattedName) + ->setUserEvent($userEvent); + try { + $gapicClient->predict($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 predictAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $recommendationToken = 'recommendationToken-1973883405'; + $dryRun2 = true; + $nextPageToken = ''; + $resultsElement = new PredictionResult(); + $results = [ + $resultsElement, + ]; + $expectedResponse = new PredictResponse(); + $expectedResponse->setRecommendationToken($recommendationToken); + $expectedResponse->setDryRun($dryRun2); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setResults($results); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->placementName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]', '[PLACEMENT]'); + $userEvent = new UserEvent(); + $userEventEventType = 'userEventEventType341658661'; + $userEvent->setEventType($userEventEventType); + $userEventUserInfo = new UserInfo(); + $userInfoVisitorId = 'userInfoVisitorId-1297088752'; + $userEventUserInfo->setVisitorId($userInfoVisitorId); + $userEvent->setUserInfo($userEventUserInfo); + $request = (new PredictRequest()) + ->setName($formattedName) + ->setUserEvent($userEvent); + $response = $gapicClient->predictAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getResults()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.recommendationengine.v1beta1.PredictionService/Predict', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getUserEvent(); + $this->assertProtobufEquals($userEvent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/RecommendationEngine/tests/Unit/V1beta1/Client/UserEventServiceClientTest.php b/RecommendationEngine/tests/Unit/V1beta1/Client/UserEventServiceClientTest.php new file mode 100644 index 000000000000..72f0907876f5 --- /dev/null +++ b/RecommendationEngine/tests/Unit/V1beta1/Client/UserEventServiceClientTest.php @@ -0,0 +1,593 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return UserEventServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new UserEventServiceClient($options); + } + + /** @test */ + public function collectUserEventTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $contentType = 'contentType831846208'; + $data = '-86'; + $expectedResponse = new HttpBody(); + $expectedResponse->setContentType($contentType); + $expectedResponse->setData($data); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $userEvent = 'userEvent1921940774'; + $request = (new CollectUserEventRequest()) + ->setParent($formattedParent) + ->setUserEvent($userEvent); + $response = $gapicClient->collectUserEvent($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.recommendationengine.v1beta1.UserEventService/CollectUserEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getUserEvent(); + $this->assertProtobufEquals($userEvent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function collectUserEventExceptionTest() + { + $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->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $userEvent = 'userEvent1921940774'; + $request = (new CollectUserEventRequest()) + ->setParent($formattedParent) + ->setUserEvent($userEvent); + try { + $gapicClient->collectUserEvent($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 importUserEventsTest() + { + $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/importUserEventsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new ImportUserEventsResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/importUserEventsTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $inputConfig = new InputConfig(); + $request = (new ImportUserEventsRequest()) + ->setParent($formattedParent) + ->setInputConfig($inputConfig); + $response = $gapicClient->importUserEvents($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.recommendationengine.v1beta1.UserEventService/ImportUserEvents', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInputConfig(); + $this->assertProtobufEquals($inputConfig, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/importUserEventsTest'); + $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 importUserEventsExceptionTest() + { + $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/importUserEventsTest'); + $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->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $inputConfig = new InputConfig(); + $request = (new ImportUserEventsRequest()) + ->setParent($formattedParent) + ->setInputConfig($inputConfig); + $response = $gapicClient->importUserEvents($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/importUserEventsTest'); + 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 listUserEventsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $userEventsElement = new UserEvent(); + $userEvents = [ + $userEventsElement, + ]; + $expectedResponse = new ListUserEventsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setUserEvents($userEvents); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $request = (new ListUserEventsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listUserEvents($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getUserEvents()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.recommendationengine.v1beta1.UserEventService/ListUserEvents', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listUserEventsExceptionTest() + { + $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->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $request = (new ListUserEventsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listUserEvents($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 purgeUserEventsTest() + { + $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/purgeUserEventsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $purgedEventsCount = 310774833; + $expectedResponse = new PurgeUserEventsResponse(); + $expectedResponse->setPurgedEventsCount($purgedEventsCount); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/purgeUserEventsTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $filter = 'filter-1274492040'; + $request = (new PurgeUserEventsRequest()) + ->setParent($formattedParent) + ->setFilter($filter); + $response = $gapicClient->purgeUserEvents($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.recommendationengine.v1beta1.UserEventService/PurgeUserEvents', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getFilter(); + $this->assertProtobufEquals($filter, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/purgeUserEventsTest'); + $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 purgeUserEventsExceptionTest() + { + $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/purgeUserEventsTest'); + $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->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $filter = 'filter-1274492040'; + $request = (new PurgeUserEventsRequest()) + ->setParent($formattedParent) + ->setFilter($filter); + $response = $gapicClient->purgeUserEvents($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/purgeUserEventsTest'); + 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 writeUserEventTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $eventType = 'eventType984376767'; + $expectedResponse = new UserEvent(); + $expectedResponse->setEventType($eventType); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $userEvent = new UserEvent(); + $userEventEventType = 'userEventEventType341658661'; + $userEvent->setEventType($userEventEventType); + $userEventUserInfo = new UserInfo(); + $userInfoVisitorId = 'userInfoVisitorId-1297088752'; + $userEventUserInfo->setVisitorId($userInfoVisitorId); + $userEvent->setUserInfo($userEventUserInfo); + $request = (new WriteUserEventRequest()) + ->setParent($formattedParent) + ->setUserEvent($userEvent); + $response = $gapicClient->writeUserEvent($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.recommendationengine.v1beta1.UserEventService/WriteUserEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getUserEvent(); + $this->assertProtobufEquals($userEvent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function writeUserEventExceptionTest() + { + $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->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $userEvent = new UserEvent(); + $userEventEventType = 'userEventEventType341658661'; + $userEvent->setEventType($userEventEventType); + $userEventUserInfo = new UserInfo(); + $userInfoVisitorId = 'userInfoVisitorId-1297088752'; + $userEventUserInfo->setVisitorId($userInfoVisitorId); + $userEvent->setUserInfo($userEventUserInfo); + $request = (new WriteUserEventRequest()) + ->setParent($formattedParent) + ->setUserEvent($userEvent); + try { + $gapicClient->writeUserEvent($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 collectUserEventAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $contentType = 'contentType831846208'; + $data = '-86'; + $expectedResponse = new HttpBody(); + $expectedResponse->setContentType($contentType); + $expectedResponse->setData($data); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->eventStoreName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[EVENT_STORE]'); + $userEvent = 'userEvent1921940774'; + $request = (new CollectUserEventRequest()) + ->setParent($formattedParent) + ->setUserEvent($userEvent); + $response = $gapicClient->collectUserEventAsync($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.recommendationengine.v1beta1.UserEventService/CollectUserEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getUserEvent(); + $this->assertProtobufEquals($userEvent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/Run/samples/V2/ExecutionsClient/delete_execution.php b/Run/samples/V2/ExecutionsClient/delete_execution.php index b4756561d0bc..6c286dcf93fc 100644 --- a/Run/samples/V2/ExecutionsClient/delete_execution.php +++ b/Run/samples/V2/ExecutionsClient/delete_execution.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Executions_DeleteExecution_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\ExecutionsClient; +use Google\Cloud\Run\V2\DeleteExecutionRequest; use Google\Cloud\Run\V2\Execution; -use Google\Cloud\Run\V2\ExecutionsClient; use Google\Rpc\Status; /** @@ -43,10 +44,14 @@ function delete_execution_sample(string $formattedName): void // Create a client. $executionsClient = new ExecutionsClient(); + // Prepare the request message. + $request = (new DeleteExecutionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $executionsClient->deleteExecution($formattedName); + $response = $executionsClient->deleteExecution($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/ExecutionsClient/get_execution.php b/Run/samples/V2/ExecutionsClient/get_execution.php index 0a61160ac8c5..5ffef312f8eb 100644 --- a/Run/samples/V2/ExecutionsClient/get_execution.php +++ b/Run/samples/V2/ExecutionsClient/get_execution.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Executions_GetExecution_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Run\V2\Client\ExecutionsClient; use Google\Cloud\Run\V2\Execution; -use Google\Cloud\Run\V2\ExecutionsClient; +use Google\Cloud\Run\V2\GetExecutionRequest; /** * Gets information about an Execution. @@ -41,10 +42,14 @@ function get_execution_sample(string $formattedName): void // Create a client. $executionsClient = new ExecutionsClient(); + // Prepare the request message. + $request = (new GetExecutionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Execution $response */ - $response = $executionsClient->getExecution($formattedName); + $response = $executionsClient->getExecution($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/Run/samples/V2/ExecutionsClient/list_executions.php b/Run/samples/V2/ExecutionsClient/list_executions.php index 88c3a5913db3..8f7356217e69 100644 --- a/Run/samples/V2/ExecutionsClient/list_executions.php +++ b/Run/samples/V2/ExecutionsClient/list_executions.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Executions_ListExecutions_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Run\V2\Client\ExecutionsClient; use Google\Cloud\Run\V2\Execution; -use Google\Cloud\Run\V2\ExecutionsClient; +use Google\Cloud\Run\V2\ListExecutionsRequest; /** * Lists Executions from a Job. @@ -42,10 +43,14 @@ function list_executions_sample(string $formattedParent): void // Create a client. $executionsClient = new ExecutionsClient(); + // Prepare the request message. + $request = (new ListExecutionsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $executionsClient->listExecutions($formattedParent); + $response = $executionsClient->listExecutions($request); /** @var Execution $element */ foreach ($response as $element) { diff --git a/Run/samples/V2/JobsClient/create_job.php b/Run/samples/V2/JobsClient/create_job.php index 1fb23bfc8ef3..94ed390e1fa0 100644 --- a/Run/samples/V2/JobsClient/create_job.php +++ b/Run/samples/V2/JobsClient/create_job.php @@ -25,9 +25,10 @@ // [START run_v2_generated_Jobs_CreateJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\JobsClient; +use Google\Cloud\Run\V2\CreateJobRequest; use Google\Cloud\Run\V2\ExecutionTemplate; use Google\Cloud\Run\V2\Job; -use Google\Cloud\Run\V2\JobsClient; use Google\Cloud\Run\V2\TaskTemplate; use Google\Rpc\Status; @@ -46,17 +47,21 @@ function create_job_sample(string $formattedParent, string $jobId): void // Create a client. $jobsClient = new JobsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $jobTemplateTemplate = new TaskTemplate(); $jobTemplate = (new ExecutionTemplate()) ->setTemplate($jobTemplateTemplate); $job = (new Job()) ->setTemplate($jobTemplate); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job) + ->setJobId($jobId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $jobsClient->createJob($formattedParent, $job, $jobId); + $response = $jobsClient->createJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/JobsClient/delete_job.php b/Run/samples/V2/JobsClient/delete_job.php index b881fd69d2d7..b1c2450255d9 100644 --- a/Run/samples/V2/JobsClient/delete_job.php +++ b/Run/samples/V2/JobsClient/delete_job.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Jobs_DeleteJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\JobsClient; +use Google\Cloud\Run\V2\DeleteJobRequest; use Google\Cloud\Run\V2\Job; -use Google\Cloud\Run\V2\JobsClient; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function delete_job_sample(string $formattedName): void // Create a client. $jobsClient = new JobsClient(); + // Prepare the request message. + $request = (new DeleteJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $jobsClient->deleteJob($formattedName); + $response = $jobsClient->deleteJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/JobsClient/get_iam_policy.php b/Run/samples/V2/JobsClient/get_iam_policy.php index d7a983a82913..131617d3d4b1 100644 --- a/Run/samples/V2/JobsClient/get_iam_policy.php +++ b/Run/samples/V2/JobsClient/get_iam_policy.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Jobs_GetIamPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\Run\V2\JobsClient; +use Google\Cloud\Run\V2\Client\JobsClient; /** * Gets the IAM Access Control policy currently in effect for the given Job. @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $jobsClient = new JobsClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $jobsClient->getIamPolicy($resource); + $response = $jobsClient->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/Run/samples/V2/JobsClient/get_job.php b/Run/samples/V2/JobsClient/get_job.php index 8a8832e9a5da..e7b02adf0f35 100644 --- a/Run/samples/V2/JobsClient/get_job.php +++ b/Run/samples/V2/JobsClient/get_job.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Jobs_GetJob_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Run\V2\Client\JobsClient; +use Google\Cloud\Run\V2\GetJobRequest; use Google\Cloud\Run\V2\Job; -use Google\Cloud\Run\V2\JobsClient; /** * Gets information about a Job. @@ -40,10 +41,14 @@ function get_job_sample(string $formattedName): void // Create a client. $jobsClient = new JobsClient(); + // Prepare the request message. + $request = (new GetJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $jobsClient->getJob($formattedName); + $response = $jobsClient->getJob($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/Run/samples/V2/JobsClient/list_jobs.php b/Run/samples/V2/JobsClient/list_jobs.php index 817f71d722c8..9897eb1ee02d 100644 --- a/Run/samples/V2/JobsClient/list_jobs.php +++ b/Run/samples/V2/JobsClient/list_jobs.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Jobs_ListJobs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Run\V2\Client\JobsClient; use Google\Cloud\Run\V2\Job; -use Google\Cloud\Run\V2\JobsClient; +use Google\Cloud\Run\V2\ListJobsRequest; /** * Lists Jobs. @@ -41,10 +42,14 @@ function list_jobs_sample(string $formattedParent): void // Create a client. $jobsClient = new JobsClient(); + // Prepare the request message. + $request = (new ListJobsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $jobsClient->listJobs($formattedParent); + $response = $jobsClient->listJobs($request); /** @var Job $element */ foreach ($response as $element) { diff --git a/Run/samples/V2/JobsClient/run_job.php b/Run/samples/V2/JobsClient/run_job.php index 09bac68afc78..94f692ac787c 100644 --- a/Run/samples/V2/JobsClient/run_job.php +++ b/Run/samples/V2/JobsClient/run_job.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Jobs_RunJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\JobsClient; use Google\Cloud\Run\V2\Execution; -use Google\Cloud\Run\V2\JobsClient; +use Google\Cloud\Run\V2\RunJobRequest; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function run_job_sample(string $formattedName): void // Create a client. $jobsClient = new JobsClient(); + // Prepare the request message. + $request = (new RunJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $jobsClient->runJob($formattedName); + $response = $jobsClient->runJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/JobsClient/set_iam_policy.php b/Run/samples/V2/JobsClient/set_iam_policy.php index 1053be70e23b..9e4487b14792 100644 --- a/Run/samples/V2/JobsClient/set_iam_policy.php +++ b/Run/samples/V2/JobsClient/set_iam_policy.php @@ -25,7 +25,8 @@ // [START run_v2_generated_Jobs_SetIamPolicy_sync] use Google\ApiCore\ApiException; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\Run\V2\JobsClient; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; +use Google\Cloud\Run\V2\Client\JobsClient; /** * Sets the IAM Access control policy for the specified Job. Overwrites @@ -39,13 +40,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $jobsClient = new JobsClient(); - // 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 = $jobsClient->setIamPolicy($resource, $policy); + $response = $jobsClient->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/Run/samples/V2/JobsClient/test_iam_permissions.php b/Run/samples/V2/JobsClient/test_iam_permissions.php index bbbe1675c4c4..324edaa4e134 100644 --- a/Run/samples/V2/JobsClient/test_iam_permissions.php +++ b/Run/samples/V2/JobsClient/test_iam_permissions.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Jobs_TestIamPermissions_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; -use Google\Cloud\Run\V2\JobsClient; +use Google\Cloud\Run\V2\Client\JobsClient; /** * Returns permissions that a caller has on the specified Project. @@ -44,13 +45,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $jobsClient = new JobsClient(); - // 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 = $jobsClient->testIamPermissions($resource, $permissions); + $response = $jobsClient->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/Run/samples/V2/JobsClient/update_job.php b/Run/samples/V2/JobsClient/update_job.php index 7eb2b2607d9a..bbb8c4dccdcc 100644 --- a/Run/samples/V2/JobsClient/update_job.php +++ b/Run/samples/V2/JobsClient/update_job.php @@ -25,10 +25,11 @@ // [START run_v2_generated_Jobs_UpdateJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\JobsClient; use Google\Cloud\Run\V2\ExecutionTemplate; use Google\Cloud\Run\V2\Job; -use Google\Cloud\Run\V2\JobsClient; use Google\Cloud\Run\V2\TaskTemplate; +use Google\Cloud\Run\V2\UpdateJobRequest; use Google\Rpc\Status; /** @@ -45,17 +46,19 @@ function update_job_sample(): void // Create a client. $jobsClient = new JobsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $jobTemplateTemplate = new TaskTemplate(); $jobTemplate = (new ExecutionTemplate()) ->setTemplate($jobTemplateTemplate); $job = (new Job()) ->setTemplate($jobTemplate); + $request = (new UpdateJobRequest()) + ->setJob($job); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $jobsClient->updateJob($job); + $response = $jobsClient->updateJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/RevisionsClient/delete_revision.php b/Run/samples/V2/RevisionsClient/delete_revision.php index e2532e256f44..a2e53f13fa74 100644 --- a/Run/samples/V2/RevisionsClient/delete_revision.php +++ b/Run/samples/V2/RevisionsClient/delete_revision.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Revisions_DeleteRevision_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\RevisionsClient; +use Google\Cloud\Run\V2\DeleteRevisionRequest; use Google\Cloud\Run\V2\Revision; -use Google\Cloud\Run\V2\RevisionsClient; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function delete_revision_sample(string $formattedName): void // Create a client. $revisionsClient = new RevisionsClient(); + // Prepare the request message. + $request = (new DeleteRevisionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $revisionsClient->deleteRevision($formattedName); + $response = $revisionsClient->deleteRevision($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/RevisionsClient/get_revision.php b/Run/samples/V2/RevisionsClient/get_revision.php index c76ffa667125..85da95fc0cf0 100644 --- a/Run/samples/V2/RevisionsClient/get_revision.php +++ b/Run/samples/V2/RevisionsClient/get_revision.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Revisions_GetRevision_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Run\V2\Client\RevisionsClient; +use Google\Cloud\Run\V2\GetRevisionRequest; use Google\Cloud\Run\V2\Revision; -use Google\Cloud\Run\V2\RevisionsClient; /** * Gets information about a Revision. @@ -40,10 +41,14 @@ function get_revision_sample(string $formattedName): void // Create a client. $revisionsClient = new RevisionsClient(); + // Prepare the request message. + $request = (new GetRevisionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Revision $response */ - $response = $revisionsClient->getRevision($formattedName); + $response = $revisionsClient->getRevision($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/Run/samples/V2/RevisionsClient/list_revisions.php b/Run/samples/V2/RevisionsClient/list_revisions.php index 8002542ca3c7..1c3d929a34fd 100644 --- a/Run/samples/V2/RevisionsClient/list_revisions.php +++ b/Run/samples/V2/RevisionsClient/list_revisions.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Revisions_ListRevisions_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Run\V2\Client\RevisionsClient; +use Google\Cloud\Run\V2\ListRevisionsRequest; use Google\Cloud\Run\V2\Revision; -use Google\Cloud\Run\V2\RevisionsClient; /** * Lists Revisions from a given Service, or from a given location. @@ -42,10 +43,14 @@ function list_revisions_sample(string $formattedParent): void // Create a client. $revisionsClient = new RevisionsClient(); + // Prepare the request message. + $request = (new ListRevisionsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $revisionsClient->listRevisions($formattedParent); + $response = $revisionsClient->listRevisions($request); /** @var Revision $element */ foreach ($response as $element) { diff --git a/Run/samples/V2/ServicesClient/create_service.php b/Run/samples/V2/ServicesClient/create_service.php index cbd7375994a4..0f7d3e8f6a33 100644 --- a/Run/samples/V2/ServicesClient/create_service.php +++ b/Run/samples/V2/ServicesClient/create_service.php @@ -25,9 +25,10 @@ // [START run_v2_generated_Services_CreateService_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\ServicesClient; +use Google\Cloud\Run\V2\CreateServiceRequest; use Google\Cloud\Run\V2\RevisionTemplate; use Google\Cloud\Run\V2\Service; -use Google\Cloud\Run\V2\ServicesClient; use Google\Rpc\Status; /** @@ -46,15 +47,19 @@ function create_service_sample(string $formattedParent, string $serviceId): void // Create a client. $servicesClient = new ServicesClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $serviceTemplate = new RevisionTemplate(); $service = (new Service()) ->setTemplate($serviceTemplate); + $request = (new CreateServiceRequest()) + ->setParent($formattedParent) + ->setService($service) + ->setServiceId($serviceId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $servicesClient->createService($formattedParent, $service, $serviceId); + $response = $servicesClient->createService($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/ServicesClient/delete_service.php b/Run/samples/V2/ServicesClient/delete_service.php index 388158d9ea9c..6ae7bf3e38d9 100644 --- a/Run/samples/V2/ServicesClient/delete_service.php +++ b/Run/samples/V2/ServicesClient/delete_service.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Services_DeleteService_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\ServicesClient; +use Google\Cloud\Run\V2\DeleteServiceRequest; use Google\Cloud\Run\V2\Service; -use Google\Cloud\Run\V2\ServicesClient; use Google\Rpc\Status; /** @@ -44,10 +45,14 @@ function delete_service_sample(string $formattedName): void // Create a client. $servicesClient = new ServicesClient(); + // Prepare the request message. + $request = (new DeleteServiceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $servicesClient->deleteService($formattedName); + $response = $servicesClient->deleteService($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/ServicesClient/get_iam_policy.php b/Run/samples/V2/ServicesClient/get_iam_policy.php index f3aa329dec90..b7168f514328 100644 --- a/Run/samples/V2/ServicesClient/get_iam_policy.php +++ b/Run/samples/V2/ServicesClient/get_iam_policy.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Services_GetIamPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\Run\V2\ServicesClient; +use Google\Cloud\Run\V2\Client\ServicesClient; /** * Gets the IAM Access Control policy currently in effect for the given @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $servicesClient = new ServicesClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $servicesClient->getIamPolicy($resource); + $response = $servicesClient->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/Run/samples/V2/ServicesClient/get_service.php b/Run/samples/V2/ServicesClient/get_service.php index 9ed073cf67af..1b4e11b9858e 100644 --- a/Run/samples/V2/ServicesClient/get_service.php +++ b/Run/samples/V2/ServicesClient/get_service.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Services_GetService_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Run\V2\Client\ServicesClient; +use Google\Cloud\Run\V2\GetServiceRequest; use Google\Cloud\Run\V2\Service; -use Google\Cloud\Run\V2\ServicesClient; /** * Gets information about a Service. @@ -40,10 +41,14 @@ function get_service_sample(string $formattedName): void // Create a client. $servicesClient = new ServicesClient(); + // Prepare the request message. + $request = (new GetServiceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Service $response */ - $response = $servicesClient->getService($formattedName); + $response = $servicesClient->getService($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/Run/samples/V2/ServicesClient/list_services.php b/Run/samples/V2/ServicesClient/list_services.php index d8d5eb885f87..cb3963b3b0c2 100644 --- a/Run/samples/V2/ServicesClient/list_services.php +++ b/Run/samples/V2/ServicesClient/list_services.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Services_ListServices_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Run\V2\Client\ServicesClient; +use Google\Cloud\Run\V2\ListServicesRequest; use Google\Cloud\Run\V2\Service; -use Google\Cloud\Run\V2\ServicesClient; /** * Lists Services. @@ -42,10 +43,14 @@ function list_services_sample(string $formattedParent): void // Create a client. $servicesClient = new ServicesClient(); + // Prepare the request message. + $request = (new ListServicesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $servicesClient->listServices($formattedParent); + $response = $servicesClient->listServices($request); /** @var Service $element */ foreach ($response as $element) { diff --git a/Run/samples/V2/ServicesClient/set_iam_policy.php b/Run/samples/V2/ServicesClient/set_iam_policy.php index 21f7df5389e5..45936c7d6f5c 100644 --- a/Run/samples/V2/ServicesClient/set_iam_policy.php +++ b/Run/samples/V2/ServicesClient/set_iam_policy.php @@ -25,7 +25,8 @@ // [START run_v2_generated_Services_SetIamPolicy_sync] use Google\ApiCore\ApiException; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\Run\V2\ServicesClient; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; +use Google\Cloud\Run\V2\Client\ServicesClient; /** * Sets the IAM Access control policy for the specified Service. Overwrites @@ -39,13 +40,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $servicesClient = new ServicesClient(); - // 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 = $servicesClient->setIamPolicy($resource, $policy); + $response = $servicesClient->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/Run/samples/V2/ServicesClient/test_iam_permissions.php b/Run/samples/V2/ServicesClient/test_iam_permissions.php index 7c78858ba6b7..52c9c493a60a 100644 --- a/Run/samples/V2/ServicesClient/test_iam_permissions.php +++ b/Run/samples/V2/ServicesClient/test_iam_permissions.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Services_TestIamPermissions_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; -use Google\Cloud\Run\V2\ServicesClient; +use Google\Cloud\Run\V2\Client\ServicesClient; /** * Returns permissions that a caller has on the specified Project. @@ -44,13 +45,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $servicesClient = new ServicesClient(); - // 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 = $servicesClient->testIamPermissions($resource, $permissions); + $response = $servicesClient->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/Run/samples/V2/ServicesClient/update_service.php b/Run/samples/V2/ServicesClient/update_service.php index 12fe170727f5..368b6259f080 100644 --- a/Run/samples/V2/ServicesClient/update_service.php +++ b/Run/samples/V2/ServicesClient/update_service.php @@ -25,9 +25,10 @@ // [START run_v2_generated_Services_UpdateService_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Run\V2\Client\ServicesClient; use Google\Cloud\Run\V2\RevisionTemplate; use Google\Cloud\Run\V2\Service; -use Google\Cloud\Run\V2\ServicesClient; +use Google\Cloud\Run\V2\UpdateServiceRequest; use Google\Rpc\Status; /** @@ -44,15 +45,17 @@ function update_service_sample(): void // Create a client. $servicesClient = new ServicesClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $serviceTemplate = new RevisionTemplate(); $service = (new Service()) ->setTemplate($serviceTemplate); + $request = (new UpdateServiceRequest()) + ->setService($service); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $servicesClient->updateService($service); + $response = $servicesClient->updateService($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/Run/samples/V2/TasksClient/get_task.php b/Run/samples/V2/TasksClient/get_task.php index ff4e5c435577..5d245de3edc6 100644 --- a/Run/samples/V2/TasksClient/get_task.php +++ b/Run/samples/V2/TasksClient/get_task.php @@ -24,8 +24,9 @@ // [START run_v2_generated_Tasks_GetTask_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Run\V2\Client\TasksClient; +use Google\Cloud\Run\V2\GetTaskRequest; use Google\Cloud\Run\V2\Task; -use Google\Cloud\Run\V2\TasksClient; /** * Gets information about a Task. @@ -40,10 +41,14 @@ function get_task_sample(string $formattedName): void // Create a client. $tasksClient = new TasksClient(); + // Prepare the request message. + $request = (new GetTaskRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Task $response */ - $response = $tasksClient->getTask($formattedName); + $response = $tasksClient->getTask($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/Run/samples/V2/TasksClient/list_tasks.php b/Run/samples/V2/TasksClient/list_tasks.php index 1a138ff647b1..bd9f63c97fef 100644 --- a/Run/samples/V2/TasksClient/list_tasks.php +++ b/Run/samples/V2/TasksClient/list_tasks.php @@ -25,8 +25,9 @@ // [START run_v2_generated_Tasks_ListTasks_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Run\V2\Client\TasksClient; +use Google\Cloud\Run\V2\ListTasksRequest; use Google\Cloud\Run\V2\Task; -use Google\Cloud\Run\V2\TasksClient; /** * Lists Tasks from an Execution of a Job. @@ -42,10 +43,14 @@ function list_tasks_sample(string $formattedParent): void // Create a client. $tasksClient = new TasksClient(); + // Prepare the request message. + $request = (new ListTasksRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $tasksClient->listTasks($formattedParent); + $response = $tasksClient->listTasks($request); /** @var Task $element */ foreach ($response as $element) { diff --git a/Run/src/V2/Client/BaseClient/ExecutionsBaseClient.php b/Run/src/V2/Client/BaseClient/ExecutionsBaseClient.php new file mode 100644 index 000000000000..c3c09ad3634d --- /dev/null +++ b/Run/src/V2/Client/BaseClient/ExecutionsBaseClient.php @@ -0,0 +1,346 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/executions_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/executions_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/executions_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/executions_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 execution + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * @param string $execution + * + * @return string The formatted execution resource. + */ + public static function executionName(string $project, string $location, string $job, string $execution): string + { + return self::getPathTemplate('execution')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + 'execution' => $execution, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a job + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * + * @return string The formatted job resource. + */ + public static function jobName(string $project, string $location, string $job): string + { + return self::getPathTemplate('job')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - execution: projects/{project}/locations/{location}/jobs/{job}/executions/{execution} + * - job: projects/{project}/locations/{location}/jobs/{job} + * + * 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 'run.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); + } + + /** + * Deletes an Execution. + * + * The async variant is {@see self::deleteExecutionAsync()} . + * + * @param DeleteExecutionRequest $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 deleteExecution(DeleteExecutionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteExecution', $request, $callOptions)->wait(); + } + + /** + * Gets information about an Execution. + * + * The async variant is {@see self::getExecutionAsync()} . + * + * @param GetExecutionRequest $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 Execution + * + * @throws ApiException Thrown if the API call fails. + */ + public function getExecution(GetExecutionRequest $request, array $callOptions = []): Execution + { + return $this->startApiCall('GetExecution', $request, $callOptions)->wait(); + } + + /** + * Lists Executions from a Job. + * + * The async variant is {@see self::listExecutionsAsync()} . + * + * @param ListExecutionsRequest $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 listExecutions(ListExecutionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListExecutions', $request, $callOptions); + } +} diff --git a/Run/src/V2/Client/BaseClient/JobsBaseClient.php b/Run/src/V2/Client/BaseClient/JobsBaseClient.php new file mode 100644 index 000000000000..f058d6ce777a --- /dev/null +++ b/Run/src/V2/Client/BaseClient/JobsBaseClient.php @@ -0,0 +1,607 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/jobs_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/jobs_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/jobs_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/jobs_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 connector + * resource. + * + * @param string $project + * @param string $location + * @param string $connector + * + * @return string The formatted connector resource. + */ + public static function connectorName(string $project, string $location, string $connector): string + { + return self::getPathTemplate('connector')->render([ + 'project' => $project, + 'location' => $location, + 'connector' => $connector, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a crypto_key + * resource. + * + * @param string $project + * @param string $location + * @param string $keyRing + * @param string $cryptoKey + * + * @return string The formatted crypto_key resource. + */ + public static function cryptoKeyName(string $project, string $location, string $keyRing, string $cryptoKey): string + { + return self::getPathTemplate('cryptoKey')->render([ + 'project' => $project, + 'location' => $location, + 'key_ring' => $keyRing, + 'crypto_key' => $cryptoKey, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a execution + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * @param string $execution + * + * @return string The formatted execution resource. + */ + public static function executionName(string $project, string $location, string $job, string $execution): string + { + return self::getPathTemplate('execution')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + 'execution' => $execution, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a job + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * + * @return string The formatted job resource. + */ + public static function jobName(string $project, string $location, string $job): string + { + return self::getPathTemplate('job')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a secret + * resource. + * + * @param string $project + * @param string $secret + * + * @return string The formatted secret resource. + */ + public static function secretName(string $project, string $secret): string + { + return self::getPathTemplate('secret')->render([ + 'project' => $project, + 'secret' => $secret, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * secret_version resource. + * + * @param string $project + * @param string $secret + * @param string $version + * + * @return string The formatted secret_version resource. + */ + public static function secretVersionName(string $project, string $secret, string $version): string + { + return self::getPathTemplate('secretVersion')->render([ + 'project' => $project, + 'secret' => $secret, + 'version' => $version, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - connector: projects/{project}/locations/{location}/connectors/{connector} + * - cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key} + * - execution: projects/{project}/locations/{location}/jobs/{job}/executions/{execution} + * - job: projects/{project}/locations/{location}/jobs/{job} + * - location: projects/{project}/locations/{location} + * - secret: projects/{project}/secrets/{secret} + * - secretVersion: projects/{project}/secrets/{secret}/versions/{version} + * + * 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 'run.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 Job. + * + * The async variant is {@see self::createJobAsync()} . + * + * @param CreateJobRequest $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 createJob(CreateJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateJob', $request, $callOptions)->wait(); + } + + /** + * Deletes a Job. + * + * The async variant is {@see self::deleteJobAsync()} . + * + * @param DeleteJobRequest $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 deleteJob(DeleteJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteJob', $request, $callOptions)->wait(); + } + + /** + * Gets the IAM Access Control policy currently in effect for the given Job. + * This result does not include any inherited policies. + * + * 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(); + } + + /** + * Gets information about a Job. + * + * The async variant is {@see self::getJobAsync()} . + * + * @param GetJobRequest $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 Job + * + * @throws ApiException Thrown if the API call fails. + */ + public function getJob(GetJobRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('GetJob', $request, $callOptions)->wait(); + } + + /** + * Lists Jobs. + * + * The async variant is {@see self::listJobsAsync()} . + * + * @param ListJobsRequest $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 listJobs(ListJobsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListJobs', $request, $callOptions); + } + + /** + * Triggers creation of a new Execution of this Job. + * + * The async variant is {@see self::runJobAsync()} . + * + * @param RunJobRequest $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 runJob(RunJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('RunJob', $request, $callOptions)->wait(); + } + + /** + * Sets the IAM Access control policy for the specified Job. Overwrites + * any existing policy. + * + * 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. + * + * 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 a Job. + * + * The async variant is {@see self::updateJobAsync()} . + * + * @param UpdateJobRequest $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 updateJob(UpdateJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateJob', $request, $callOptions)->wait(); + } +} diff --git a/Run/src/V2/Client/BaseClient/RevisionsBaseClient.php b/Run/src/V2/Client/BaseClient/RevisionsBaseClient.php new file mode 100644 index 000000000000..a99d50e3ebbb --- /dev/null +++ b/Run/src/V2/Client/BaseClient/RevisionsBaseClient.php @@ -0,0 +1,346 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/revisions_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/revisions_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/revisions_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/revisions_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 revision + * resource. + * + * @param string $project + * @param string $location + * @param string $service + * @param string $revision + * + * @return string The formatted revision resource. + */ + public static function revisionName(string $project, string $location, string $service, string $revision): string + { + return self::getPathTemplate('revision')->render([ + 'project' => $project, + 'location' => $location, + 'service' => $service, + 'revision' => $revision, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a service + * resource. + * + * @param string $project + * @param string $location + * @param string $service + * + * @return string The formatted service resource. + */ + public static function serviceName(string $project, string $location, string $service): string + { + return self::getPathTemplate('service')->render([ + 'project' => $project, + 'location' => $location, + 'service' => $service, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - revision: projects/{project}/locations/{location}/services/{service}/revisions/{revision} + * - service: projects/{project}/locations/{location}/services/{service} + * + * 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 'run.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); + } + + /** + * Deletes a Revision. + * + * The async variant is {@see self::deleteRevisionAsync()} . + * + * @param DeleteRevisionRequest $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 deleteRevision(DeleteRevisionRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteRevision', $request, $callOptions)->wait(); + } + + /** + * Gets information about a Revision. + * + * The async variant is {@see self::getRevisionAsync()} . + * + * @param GetRevisionRequest $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 Revision + * + * @throws ApiException Thrown if the API call fails. + */ + public function getRevision(GetRevisionRequest $request, array $callOptions = []): Revision + { + return $this->startApiCall('GetRevision', $request, $callOptions)->wait(); + } + + /** + * Lists Revisions from a given Service, or from a given location. + * + * The async variant is {@see self::listRevisionsAsync()} . + * + * @param ListRevisionsRequest $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 listRevisions(ListRevisionsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListRevisions', $request, $callOptions); + } +} diff --git a/Run/src/V2/Client/BaseClient/ServicesBaseClient.php b/Run/src/V2/Client/BaseClient/ServicesBaseClient.php new file mode 100644 index 000000000000..bf3f488caa20 --- /dev/null +++ b/Run/src/V2/Client/BaseClient/ServicesBaseClient.php @@ -0,0 +1,582 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/services_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/services_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/services_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/services_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 connector + * resource. + * + * @param string $project + * @param string $location + * @param string $connector + * + * @return string The formatted connector resource. + */ + public static function connectorName(string $project, string $location, string $connector): string + { + return self::getPathTemplate('connector')->render([ + 'project' => $project, + 'location' => $location, + 'connector' => $connector, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a crypto_key + * resource. + * + * @param string $project + * @param string $location + * @param string $keyRing + * @param string $cryptoKey + * + * @return string The formatted crypto_key resource. + */ + public static function cryptoKeyName(string $project, string $location, string $keyRing, string $cryptoKey): string + { + return self::getPathTemplate('cryptoKey')->render([ + 'project' => $project, + 'location' => $location, + 'key_ring' => $keyRing, + 'crypto_key' => $cryptoKey, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a revision + * resource. + * + * @param string $project + * @param string $location + * @param string $service + * @param string $revision + * + * @return string The formatted revision resource. + */ + public static function revisionName(string $project, string $location, string $service, string $revision): string + { + return self::getPathTemplate('revision')->render([ + 'project' => $project, + 'location' => $location, + 'service' => $service, + 'revision' => $revision, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a secret + * resource. + * + * @param string $project + * @param string $secret + * + * @return string The formatted secret resource. + */ + public static function secretName(string $project, string $secret): string + { + return self::getPathTemplate('secret')->render([ + 'project' => $project, + 'secret' => $secret, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * secret_version resource. + * + * @param string $project + * @param string $secret + * @param string $version + * + * @return string The formatted secret_version resource. + */ + public static function secretVersionName(string $project, string $secret, string $version): string + { + return self::getPathTemplate('secretVersion')->render([ + 'project' => $project, + 'secret' => $secret, + 'version' => $version, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a service + * resource. + * + * @param string $project + * @param string $location + * @param string $service + * + * @return string The formatted service resource. + */ + public static function serviceName(string $project, string $location, string $service): string + { + return self::getPathTemplate('service')->render([ + 'project' => $project, + 'location' => $location, + 'service' => $service, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - connector: projects/{project}/locations/{location}/connectors/{connector} + * - cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key} + * - location: projects/{project}/locations/{location} + * - revision: projects/{project}/locations/{location}/services/{service}/revisions/{revision} + * - secret: projects/{project}/secrets/{secret} + * - secretVersion: projects/{project}/secrets/{secret}/versions/{version} + * - service: projects/{project}/locations/{location}/services/{service} + * + * 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 'run.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 Service in a given project and location. + * + * The async variant is {@see self::createServiceAsync()} . + * + * @param CreateServiceRequest $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 createService(CreateServiceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateService', $request, $callOptions)->wait(); + } + + /** + * Deletes a Service. + * This will cause the Service to stop serving traffic and will delete all + * revisions. + * + * The async variant is {@see self::deleteServiceAsync()} . + * + * @param DeleteServiceRequest $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 deleteService(DeleteServiceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteService', $request, $callOptions)->wait(); + } + + /** + * Gets the IAM Access Control policy currently in effect for the given + * Cloud Run Service. This result does not include any inherited policies. + * + * 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(); + } + + /** + * Gets information about a Service. + * + * The async variant is {@see self::getServiceAsync()} . + * + * @param GetServiceRequest $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 Service + * + * @throws ApiException Thrown if the API call fails. + */ + public function getService(GetServiceRequest $request, array $callOptions = []): Service + { + return $this->startApiCall('GetService', $request, $callOptions)->wait(); + } + + /** + * Lists Services. + * + * The async variant is {@see self::listServicesAsync()} . + * + * @param ListServicesRequest $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 listServices(ListServicesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListServices', $request, $callOptions); + } + + /** + * Sets the IAM Access control policy for the specified Service. Overwrites + * any existing policy. + * + * 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. + * + * 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 a Service. + * + * The async variant is {@see self::updateServiceAsync()} . + * + * @param UpdateServiceRequest $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 updateService(UpdateServiceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateService', $request, $callOptions)->wait(); + } +} diff --git a/Run/src/V2/Client/BaseClient/TasksBaseClient.php b/Run/src/V2/Client/BaseClient/TasksBaseClient.php new file mode 100644 index 000000000000..1dfcbb1b55e8 --- /dev/null +++ b/Run/src/V2/Client/BaseClient/TasksBaseClient.php @@ -0,0 +1,289 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/tasks_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/tasks_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/tasks_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/tasks_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a execution + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * @param string $execution + * + * @return string The formatted execution resource. + */ + public static function executionName(string $project, string $location, string $job, string $execution): string + { + return self::getPathTemplate('execution')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + 'execution' => $execution, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a task + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * @param string $execution + * @param string $task + * + * @return string The formatted task resource. + */ + public static function taskName(string $project, string $location, string $job, string $execution, string $task): string + { + return self::getPathTemplate('task')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + 'execution' => $execution, + 'task' => $task, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - execution: projects/{project}/locations/{location}/jobs/{job}/executions/{execution} + * - task: projects/{project}/locations/{location}/jobs/{job}/executions/{execution}/tasks/{task} + * + * 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 'run.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 information about a Task. + * + * The async variant is {@see self::getTaskAsync()} . + * + * @param GetTaskRequest $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 Task + * + * @throws ApiException Thrown if the API call fails. + */ + public function getTask(GetTaskRequest $request, array $callOptions = []): Task + { + return $this->startApiCall('GetTask', $request, $callOptions)->wait(); + } + + /** + * Lists Tasks from an Execution of a Job. + * + * The async variant is {@see self::listTasksAsync()} . + * + * @param ListTasksRequest $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 listTasks(ListTasksRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTasks', $request, $callOptions); + } +} diff --git a/Run/src/V2/Client/ExecutionsClient.php b/Run/src/V2/Client/ExecutionsClient.php new file mode 100644 index 000000000000..7c1c810a6e4b --- /dev/null +++ b/Run/src/V2/Client/ExecutionsClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setJob($job) + ->setJobId($jobId); + } + /** * Constructor. * diff --git a/Run/src/V2/CreateServiceRequest.php b/Run/src/V2/CreateServiceRequest.php index 385c15f4cfe2..3b03a0c74b45 100644 --- a/Run/src/V2/CreateServiceRequest.php +++ b/Run/src/V2/CreateServiceRequest.php @@ -45,6 +45,28 @@ class CreateServiceRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $parent Required. The location and project in which this service should be created. + * Format: projects/{project}/locations/{location}, where {project} can be + * project id or number. Only lowercase characters, digits, and hyphens. Please see + * {@see ServicesClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Run\V2\Service $service Required. The Service instance to create. + * @param string $serviceId Required. The unique identifier for the Service. It must begin with letter, + * and cannot end with hyphen; must contain fewer than 50 characters. + * The name of the service becomes {parent}/services/{service_id}. + * + * @return \Google\Cloud\Run\V2\CreateServiceRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Run\V2\Service $service, string $serviceId): self + { + return (new self()) + ->setParent($parent) + ->setService($service) + ->setServiceId($serviceId); + } + /** * Constructor. * diff --git a/Run/src/V2/DeleteExecutionRequest.php b/Run/src/V2/DeleteExecutionRequest.php index 75ea0ee56f46..7e7d5102fb9d 100644 --- a/Run/src/V2/DeleteExecutionRequest.php +++ b/Run/src/V2/DeleteExecutionRequest.php @@ -39,6 +39,23 @@ class DeleteExecutionRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. The name of the Execution to delete. + * Format: + * projects/{project}/locations/{location}/jobs/{job}/executions/{execution}, + * where {project} can be project id or number. Please see + * {@see ExecutionsClient::executionName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\DeleteExecutionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/DeleteJobRequest.php b/Run/src/V2/DeleteJobRequest.php index 77ff362fbf3d..459cc1ccc66e 100644 --- a/Run/src/V2/DeleteJobRequest.php +++ b/Run/src/V2/DeleteJobRequest.php @@ -38,6 +38,22 @@ class DeleteJobRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. The full name of the Job. + * Format: projects/{project}/locations/{location}/jobs/{job}, where {project} + * can be project id or number. Please see + * {@see JobsClient::jobName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\DeleteJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/DeleteRevisionRequest.php b/Run/src/V2/DeleteRevisionRequest.php index 8090add0020e..54543d7168ee 100644 --- a/Run/src/V2/DeleteRevisionRequest.php +++ b/Run/src/V2/DeleteRevisionRequest.php @@ -40,6 +40,22 @@ class DeleteRevisionRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. The name of the Revision to delete. + * Format: + * projects/{project}/locations/{location}/services/{service}/revisions/{revision} + * Please see {@see RevisionsClient::revisionName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\DeleteRevisionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/DeleteServiceRequest.php b/Run/src/V2/DeleteServiceRequest.php index 2b0050c6d2dc..43cd4df65f86 100644 --- a/Run/src/V2/DeleteServiceRequest.php +++ b/Run/src/V2/DeleteServiceRequest.php @@ -38,6 +38,22 @@ class DeleteServiceRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. The full name of the Service. + * Format: projects/{project}/locations/{location}/services/{service}, where + * {project} can be project id or number. Please see + * {@see ServicesClient::serviceName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\DeleteServiceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/GetExecutionRequest.php b/Run/src/V2/GetExecutionRequest.php index 574423d3ecb7..766d020bed1b 100644 --- a/Run/src/V2/GetExecutionRequest.php +++ b/Run/src/V2/GetExecutionRequest.php @@ -25,6 +25,23 @@ class GetExecutionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The full name of the Execution. + * Format: + * projects/{project}/locations/{location}/jobs/{job}/executions/{execution}, + * where {project} can be project id or number. Please see + * {@see ExecutionsClient::executionName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\GetExecutionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/GetJobRequest.php b/Run/src/V2/GetJobRequest.php index f0965782741e..353fb8f0ca4a 100644 --- a/Run/src/V2/GetJobRequest.php +++ b/Run/src/V2/GetJobRequest.php @@ -24,6 +24,22 @@ class GetJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The full name of the Job. + * Format: projects/{project}/locations/{location}/jobs/{job}, where {project} + * can be project id or number. Please see + * {@see JobsClient::jobName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\GetJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/GetRevisionRequest.php b/Run/src/V2/GetRevisionRequest.php index 216bd25240a3..d599a8da02b7 100644 --- a/Run/src/V2/GetRevisionRequest.php +++ b/Run/src/V2/GetRevisionRequest.php @@ -24,6 +24,22 @@ class GetRevisionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The full name of the Revision. + * Format: + * projects/{project}/locations/{location}/services/{service}/revisions/{revision} + * Please see {@see RevisionsClient::revisionName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\GetRevisionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/GetServiceRequest.php b/Run/src/V2/GetServiceRequest.php index 265cdec47171..c0ca460670f7 100644 --- a/Run/src/V2/GetServiceRequest.php +++ b/Run/src/V2/GetServiceRequest.php @@ -24,6 +24,22 @@ class GetServiceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The full name of the Service. + * Format: projects/{project}/locations/{location}/services/{service}, where + * {project} can be project id or number. Please see + * {@see ServicesClient::serviceName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\GetServiceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/GetTaskRequest.php b/Run/src/V2/GetTaskRequest.php index 523a8946b64f..b587c8487fc6 100644 --- a/Run/src/V2/GetTaskRequest.php +++ b/Run/src/V2/GetTaskRequest.php @@ -24,6 +24,22 @@ class GetTaskRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The full name of the Task. + * Format: + * projects/{project}/locations/{location}/jobs/{job}/executions/{execution}/tasks/{task} + * Please see {@see TasksClient::taskName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\GetTaskRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/ListExecutionsRequest.php b/Run/src/V2/ListExecutionsRequest.php index 911f25e530ed..f26871d73a63 100644 --- a/Run/src/V2/ListExecutionsRequest.php +++ b/Run/src/V2/ListExecutionsRequest.php @@ -44,6 +44,23 @@ class ListExecutionsRequest extends \Google\Protobuf\Internal\Message */ private $show_deleted = false; + /** + * @param string $parent Required. The Execution from which the Executions should be listed. + * To list all Executions across Jobs, use "-" instead of Job name. + * Format: projects/{project}/locations/{location}/jobs/{job}, where {project} + * can be project id or number. Please see + * {@see ExecutionsClient::jobName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\ListExecutionsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Run/src/V2/ListJobsRequest.php b/Run/src/V2/ListJobsRequest.php index bbdaa5840712..4729fabd9d87 100644 --- a/Run/src/V2/ListJobsRequest.php +++ b/Run/src/V2/ListJobsRequest.php @@ -43,6 +43,22 @@ class ListJobsRequest extends \Google\Protobuf\Internal\Message */ private $show_deleted = false; + /** + * @param string $parent Required. The location and project to list resources on. + * Format: projects/{project}/locations/{location}, where {project} can be + * project id or number. Please see + * {@see JobsClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\ListJobsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Run/src/V2/ListRevisionsRequest.php b/Run/src/V2/ListRevisionsRequest.php index 10a7ad97f43e..2ebc3cf9638a 100644 --- a/Run/src/V2/ListRevisionsRequest.php +++ b/Run/src/V2/ListRevisionsRequest.php @@ -44,6 +44,23 @@ class ListRevisionsRequest extends \Google\Protobuf\Internal\Message */ private $show_deleted = false; + /** + * @param string $parent Required. The Service from which the Revisions should be listed. + * To list all Revisions across Services, use "-" instead of Service name. + * Format: + * projects/{project}/locations/{location}/services/{service} + * Please see {@see RevisionsClient::serviceName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\ListRevisionsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Run/src/V2/ListServicesRequest.php b/Run/src/V2/ListServicesRequest.php index c4be72321489..b0f6b04af52b 100644 --- a/Run/src/V2/ListServicesRequest.php +++ b/Run/src/V2/ListServicesRequest.php @@ -44,6 +44,23 @@ class ListServicesRequest extends \Google\Protobuf\Internal\Message */ private $show_deleted = false; + /** + * @param string $parent Required. The location and project to list resources on. + * Location must be a valid Google Cloud region, and cannot be the "-" + * wildcard. Format: projects/{project}/locations/{location}, where {project} + * can be project id or number. Please see + * {@see ServicesClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\ListServicesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Run/src/V2/ListTasksRequest.php b/Run/src/V2/ListTasksRequest.php index 38563bf60fc3..2bcd77611718 100644 --- a/Run/src/V2/ListTasksRequest.php +++ b/Run/src/V2/ListTasksRequest.php @@ -44,6 +44,23 @@ class ListTasksRequest extends \Google\Protobuf\Internal\Message */ private $show_deleted = false; + /** + * @param string $parent Required. The Execution from which the Tasks should be listed. + * To list all Tasks across Executions of a Job, use "-" instead of Execution + * name. To list all Tasks across Jobs, use "-" instead of Job name. Format: + * projects/{project}/locations/{location}/jobs/{job}/executions/{execution} + * Please see {@see TasksClient::executionName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\ListTasksRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Run/src/V2/RunJobRequest.php b/Run/src/V2/RunJobRequest.php index 698204b5394b..8624f462d5a5 100644 --- a/Run/src/V2/RunJobRequest.php +++ b/Run/src/V2/RunJobRequest.php @@ -38,6 +38,22 @@ class RunJobRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. The full name of the Job. + * Format: projects/{project}/locations/{location}/jobs/{job}, where {project} + * can be project id or number. Please see + * {@see JobsClient::jobName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\RunJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Run/src/V2/UpdateJobRequest.php b/Run/src/V2/UpdateJobRequest.php index 98fd70eab0a5..c8b9972eef69 100644 --- a/Run/src/V2/UpdateJobRequest.php +++ b/Run/src/V2/UpdateJobRequest.php @@ -37,6 +37,19 @@ class UpdateJobRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param \Google\Cloud\Run\V2\Job $job Required. The Job to be updated. + * + * @return \Google\Cloud\Run\V2\UpdateJobRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Run\V2\Job $job): self + { + return (new self()) + ->setJob($job); + } + /** * Constructor. * diff --git a/Run/src/V2/UpdateServiceRequest.php b/Run/src/V2/UpdateServiceRequest.php index 86c07da9ea15..c493075f1ac1 100644 --- a/Run/src/V2/UpdateServiceRequest.php +++ b/Run/src/V2/UpdateServiceRequest.php @@ -37,6 +37,19 @@ class UpdateServiceRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param \Google\Cloud\Run\V2\Service $service Required. The Service to be updated. + * + * @return \Google\Cloud\Run\V2\UpdateServiceRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Run\V2\Service $service): self + { + return (new self()) + ->setService($service); + } + /** * Constructor. * diff --git a/Run/src/V2/resources/executions_descriptor_config.php b/Run/src/V2/resources/executions_descriptor_config.php index f869b7d9edd5..ed33b5bd9909 100644 --- a/Run/src/V2/resources/executions_descriptor_config.php +++ b/Run/src/V2/resources/executions_descriptor_config.php @@ -12,6 +12,27 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetExecution' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Run\V2\Execution', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListExecutions' => [ 'pageStreaming' => [ @@ -22,6 +43,20 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getExecutions', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Run\V2\ListExecutionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'execution' => 'projects/{project}/locations/{location}/jobs/{job}/executions/{execution}', + 'job' => 'projects/{project}/locations/{location}/jobs/{job}', ], ], ], diff --git a/Run/src/V2/resources/jobs_descriptor_config.php b/Run/src/V2/resources/jobs_descriptor_config.php index 7b12dc0e46ab..e3451d82aa68 100644 --- a/Run/src/V2/resources/jobs_descriptor_config.php +++ b/Run/src/V2/resources/jobs_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteJob' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'RunJob' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateJob' => [ 'longRunning' => [ @@ -42,6 +69,40 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'job.name', + 'fieldAccessors' => [ + 'getJob', + 'getName', + ], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'GetJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Run\V2\Job', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListJobs' => [ 'pageStreaming' => [ @@ -52,6 +113,49 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getJobs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Run\V2\ListJobsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + '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' => [ + 'connector' => 'projects/{project}/locations/{location}/connectors/{connector}', + 'cryptoKey' => 'projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}', + 'execution' => 'projects/{project}/locations/{location}/jobs/{job}/executions/{execution}', + 'job' => 'projects/{project}/locations/{location}/jobs/{job}', + 'location' => 'projects/{project}/locations/{location}', + 'secret' => 'projects/{project}/secrets/{secret}', + 'secretVersion' => 'projects/{project}/secrets/{secret}/versions/{version}', ], ], ], diff --git a/Run/src/V2/resources/revisions_descriptor_config.php b/Run/src/V2/resources/revisions_descriptor_config.php index 1156a585026f..bea3f234a4a7 100644 --- a/Run/src/V2/resources/revisions_descriptor_config.php +++ b/Run/src/V2/resources/revisions_descriptor_config.php @@ -12,6 +12,29 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getName', + ], + 'matchers' => [], + ], + ], + ], + 'GetRevision' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Run\V2\Revision', + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getName', + ], + 'matchers' => [], + ], + ], ], 'ListRevisions' => [ 'pageStreaming' => [ @@ -22,6 +45,21 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getRevisions', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Run\V2\ListRevisionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getParent', + ], + 'matchers' => [], + ], + ], + ], + 'templateMap' => [ + 'revision' => 'projects/{project}/locations/{location}/services/{service}/revisions/{revision}', + 'service' => 'projects/{project}/locations/{location}/services/{service}', ], ], ], diff --git a/Run/src/V2/resources/services_descriptor_config.php b/Run/src/V2/resources/services_descriptor_config.php index e8cce55d24c6..df4517da0d0c 100644 --- a/Run/src/V2/resources/services_descriptor_config.php +++ b/Run/src/V2/resources/services_descriptor_config.php @@ -12,6 +12,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getParent', + ], + 'matchers' => [], + ], + ], ], 'DeleteService' => [ 'longRunning' => [ @@ -22,6 +32,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getName', + ], + 'matchers' => [], + ], + ], ], 'UpdateService' => [ 'longRunning' => [ @@ -32,6 +52,42 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getService', + 'getName', + ], + 'matchers' => [], + ], + ], + ], + 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], + ], + 'GetService' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Run\V2\Service', + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getName', + ], + 'matchers' => [], + ], + ], ], 'ListServices' => [ 'pageStreaming' => [ @@ -42,6 +98,50 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getServices', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Run\V2\ListServicesResponse', + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getParent', + ], + 'matchers' => [], + ], + ], + ], + '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' => [ + 'connector' => 'projects/{project}/locations/{location}/connectors/{connector}', + 'cryptoKey' => 'projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}', + 'location' => 'projects/{project}/locations/{location}', + 'revision' => 'projects/{project}/locations/{location}/services/{service}/revisions/{revision}', + 'secret' => 'projects/{project}/secrets/{secret}', + 'secretVersion' => 'projects/{project}/secrets/{secret}/versions/{version}', + 'service' => 'projects/{project}/locations/{location}/services/{service}', ], ], ], diff --git a/Run/src/V2/resources/tasks_descriptor_config.php b/Run/src/V2/resources/tasks_descriptor_config.php index 243c1b7eb2c4..dce4691d1ab2 100644 --- a/Run/src/V2/resources/tasks_descriptor_config.php +++ b/Run/src/V2/resources/tasks_descriptor_config.php @@ -3,6 +3,18 @@ return [ 'interfaces' => [ 'google.cloud.run.v2.Tasks' => [ + 'GetTask' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Run\V2\Task', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListTasks' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +24,20 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getTasks', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Run\V2\ListTasksResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'execution' => 'projects/{project}/locations/{location}/jobs/{job}/executions/{execution}', + 'task' => 'projects/{project}/locations/{location}/jobs/{job}/executions/{execution}/tasks/{task}', ], ], ], diff --git a/Run/tests/Unit/V2/Client/ExecutionsClientTest.php b/Run/tests/Unit/V2/Client/ExecutionsClientTest.php new file mode 100644 index 000000000000..952e67fc8e3e --- /dev/null +++ b/Run/tests/Unit/V2/Client/ExecutionsClientTest.php @@ -0,0 +1,484 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ExecutionsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ExecutionsClient($options); + } + + /** @test */ + public function deleteExecutionTest() + { + $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/deleteExecutionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $job = 'job105405'; + $parallelism = 635164956; + $taskCount = 1297805781; + $reconciling = false; + $observedGeneration = 900833007; + $runningCount = 261439119; + $succeededCount = 633694641; + $failedCount = 2013829491; + $cancelledCount = 1921113249; + $retriedCount = 1654679545; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Execution(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setJob($job); + $expectedResponse->setParallelism($parallelism); + $expectedResponse->setTaskCount($taskCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setRunningCount($runningCount); + $expectedResponse->setSucceededCount($succeededCount); + $expectedResponse->setFailedCount($failedCount); + $expectedResponse->setCancelledCount($cancelledCount); + $expectedResponse->setRetriedCount($retriedCount); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteExecutionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->executionName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]'); + $request = (new DeleteExecutionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteExecution($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.run.v2.Executions/DeleteExecution', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteExecutionTest'); + $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 deleteExecutionExceptionTest() + { + $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/deleteExecutionTest'); + $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->executionName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]'); + $request = (new DeleteExecutionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteExecution($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteExecutionTest'); + 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 getExecutionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $job = 'job105405'; + $parallelism = 635164956; + $taskCount = 1297805781; + $reconciling = false; + $observedGeneration = 900833007; + $runningCount = 261439119; + $succeededCount = 633694641; + $failedCount = 2013829491; + $cancelledCount = 1921113249; + $retriedCount = 1654679545; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $etag = 'etag3123477'; + $expectedResponse = new Execution(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setJob($job); + $expectedResponse->setParallelism($parallelism); + $expectedResponse->setTaskCount($taskCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setRunningCount($runningCount); + $expectedResponse->setSucceededCount($succeededCount); + $expectedResponse->setFailedCount($failedCount); + $expectedResponse->setCancelledCount($cancelledCount); + $expectedResponse->setRetriedCount($retriedCount); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->executionName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]'); + $request = (new GetExecutionRequest()) + ->setName($formattedName); + $response = $gapicClient->getExecution($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.run.v2.Executions/GetExecution', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getExecutionExceptionTest() + { + $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->executionName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]'); + $request = (new GetExecutionRequest()) + ->setName($formattedName); + try { + $gapicClient->getExecution($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 listExecutionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $executionsElement = new Execution(); + $executions = [ + $executionsElement, + ]; + $expectedResponse = new ListExecutionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setExecutions($executions); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new ListExecutionsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listExecutions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getExecutions()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.run.v2.Executions/ListExecutions', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listExecutionsExceptionTest() + { + $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->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new ListExecutionsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listExecutions($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 deleteExecutionAsyncTest() + { + $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/deleteExecutionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $job = 'job105405'; + $parallelism = 635164956; + $taskCount = 1297805781; + $reconciling = false; + $observedGeneration = 900833007; + $runningCount = 261439119; + $succeededCount = 633694641; + $failedCount = 2013829491; + $cancelledCount = 1921113249; + $retriedCount = 1654679545; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Execution(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setJob($job); + $expectedResponse->setParallelism($parallelism); + $expectedResponse->setTaskCount($taskCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setRunningCount($runningCount); + $expectedResponse->setSucceededCount($succeededCount); + $expectedResponse->setFailedCount($failedCount); + $expectedResponse->setCancelledCount($cancelledCount); + $expectedResponse->setRetriedCount($retriedCount); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteExecutionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->executionName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]'); + $request = (new DeleteExecutionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteExecutionAsync($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.run.v2.Executions/DeleteExecution', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteExecutionTest'); + $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/Run/tests/Unit/V2/Client/JobsClientTest.php b/Run/tests/Unit/V2/Client/JobsClientTest.php new file mode 100644 index 000000000000..87993586da78 --- /dev/null +++ b/Run/tests/Unit/V2/Client/JobsClientTest.php @@ -0,0 +1,1160 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return JobsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new JobsClient($options); + } + + /** @test */ + public function createJobTest() + { + $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/createJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $executionCount = 1646136616; + $reconciling = false; + $satisfiesPzs = false; + $etag = 'etag3123477'; + $expectedResponse = new Job(); + $expectedResponse->setName($name); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setExecutionCount($executionCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $jobTemplate = new ExecutionTemplate(); + $templateTemplate = new TaskTemplate(); + $jobTemplate->setTemplate($templateTemplate); + $job->setTemplate($jobTemplate); + $jobId = 'jobId-1154752291'; + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job) + ->setJobId($jobId); + $response = $gapicClient->createJob($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.run.v2.Jobs/CreateJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getJob(); + $this->assertProtobufEquals($job, $actualValue); + $actualValue = $actualApiRequestObject->getJobId(); + $this->assertProtobufEquals($jobId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createJobTest'); + $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 createJobExceptionTest() + { + $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/createJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $jobTemplate = new ExecutionTemplate(); + $templateTemplate = new TaskTemplate(); + $jobTemplate->setTemplate($templateTemplate); + $job->setTemplate($jobTemplate); + $jobId = 'jobId-1154752291'; + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job) + ->setJobId($jobId); + $response = $gapicClient->createJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createJobTest'); + 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 deleteJobTest() + { + $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/deleteJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $executionCount = 1646136616; + $reconciling = false; + $satisfiesPzs = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Job(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setExecutionCount($executionCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new DeleteJobRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteJob($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.run.v2.Jobs/DeleteJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteJobTest'); + $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 deleteJobExceptionTest() + { + $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/deleteJobTest'); + $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->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new DeleteJobRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteJobTest'); + 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.run.v2.Jobs/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 getJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $executionCount = 1646136616; + $reconciling = false; + $satisfiesPzs = false; + $etag = 'etag3123477'; + $expectedResponse = new Job(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setExecutionCount($executionCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new GetJobRequest()) + ->setName($formattedName); + $response = $gapicClient->getJob($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.run.v2.Jobs/GetJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobExceptionTest() + { + $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->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new GetJobRequest()) + ->setName($formattedName); + try { + $gapicClient->getJob($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 listJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobsElement = new Job(); + $jobs = [ + $jobsElement, + ]; + $expectedResponse = new ListJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobs($jobs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListJobsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listJobs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.run.v2.Jobs/ListJobs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListJobsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listJobs($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 runJobTest() + { + $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/runJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $job = 'job105405'; + $parallelism = 635164956; + $taskCount = 1297805781; + $reconciling = false; + $observedGeneration = 900833007; + $runningCount = 261439119; + $succeededCount = 633694641; + $failedCount = 2013829491; + $cancelledCount = 1921113249; + $retriedCount = 1654679545; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Execution(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setJob($job); + $expectedResponse->setParallelism($parallelism); + $expectedResponse->setTaskCount($taskCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setRunningCount($runningCount); + $expectedResponse->setSucceededCount($succeededCount); + $expectedResponse->setFailedCount($failedCount); + $expectedResponse->setCancelledCount($cancelledCount); + $expectedResponse->setRetriedCount($retriedCount); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/runJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new RunJobRequest()) + ->setName($formattedName); + $response = $gapicClient->runJob($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.run.v2.Jobs/RunJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/runJobTest'); + $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 runJobExceptionTest() + { + $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/runJobTest'); + $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->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new RunJobRequest()) + ->setName($formattedName); + $response = $gapicClient->runJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/runJobTest'); + 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 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.run.v2.Jobs/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.run.v2.Jobs/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 updateJobTest() + { + $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/updateJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $executionCount = 1646136616; + $reconciling = false; + $satisfiesPzs = false; + $etag = 'etag3123477'; + $expectedResponse = new Job(); + $expectedResponse->setName($name); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setExecutionCount($executionCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $job = new Job(); + $jobTemplate = new ExecutionTemplate(); + $templateTemplate = new TaskTemplate(); + $jobTemplate->setTemplate($templateTemplate); + $job->setTemplate($jobTemplate); + $request = (new UpdateJobRequest()) + ->setJob($job); + $response = $gapicClient->updateJob($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.run.v2.Jobs/UpdateJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getJob(); + $this->assertProtobufEquals($job, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateJobTest'); + $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 updateJobExceptionTest() + { + $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/updateJobTest'); + $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 + $job = new Job(); + $jobTemplate = new ExecutionTemplate(); + $templateTemplate = new TaskTemplate(); + $jobTemplate->setTemplate($templateTemplate); + $job->setTemplate($jobTemplate); + $request = (new UpdateJobRequest()) + ->setJob($job); + $response = $gapicClient->updateJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateJobTest'); + 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 createJobAsyncTest() + { + $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/createJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $executionCount = 1646136616; + $reconciling = false; + $satisfiesPzs = false; + $etag = 'etag3123477'; + $expectedResponse = new Job(); + $expectedResponse->setName($name); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setExecutionCount($executionCount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $jobTemplate = new ExecutionTemplate(); + $templateTemplate = new TaskTemplate(); + $jobTemplate->setTemplate($templateTemplate); + $job->setTemplate($jobTemplate); + $jobId = 'jobId-1154752291'; + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job) + ->setJobId($jobId); + $response = $gapicClient->createJobAsync($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.run.v2.Jobs/CreateJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getJob(); + $this->assertProtobufEquals($job, $actualValue); + $actualValue = $actualApiRequestObject->getJobId(); + $this->assertProtobufEquals($jobId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createJobTest'); + $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/Run/tests/Unit/V2/Client/RevisionsClientTest.php b/Run/tests/Unit/V2/Client/RevisionsClientTest.php new file mode 100644 index 000000000000..3edcccf962cc --- /dev/null +++ b/Run/tests/Unit/V2/Client/RevisionsClientTest.php @@ -0,0 +1,466 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return RevisionsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new RevisionsClient($options); + } + + /** @test */ + public function deleteRevisionTest() + { + $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/deleteRevisionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $service = 'service1984153269'; + $maxInstanceRequestConcurrency = 117250100; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $reconciling = false; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $sessionAffinity = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Revision(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setService($service); + $expectedResponse->setMaxInstanceRequestConcurrency($maxInstanceRequestConcurrency); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setSessionAffinity($sessionAffinity); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteRevisionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->revisionName('[PROJECT]', '[LOCATION]', '[SERVICE]', '[REVISION]'); + $request = (new DeleteRevisionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteRevision($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.run.v2.Revisions/DeleteRevision', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteRevisionTest'); + $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 deleteRevisionExceptionTest() + { + $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/deleteRevisionTest'); + $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->revisionName('[PROJECT]', '[LOCATION]', '[SERVICE]', '[REVISION]'); + $request = (new DeleteRevisionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteRevision($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteRevisionTest'); + 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 getRevisionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $service = 'service1984153269'; + $maxInstanceRequestConcurrency = 117250100; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $reconciling = false; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $sessionAffinity = false; + $etag = 'etag3123477'; + $expectedResponse = new Revision(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setService($service); + $expectedResponse->setMaxInstanceRequestConcurrency($maxInstanceRequestConcurrency); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setSessionAffinity($sessionAffinity); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->revisionName('[PROJECT]', '[LOCATION]', '[SERVICE]', '[REVISION]'); + $request = (new GetRevisionRequest()) + ->setName($formattedName); + $response = $gapicClient->getRevision($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.run.v2.Revisions/GetRevision', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getRevisionExceptionTest() + { + $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->revisionName('[PROJECT]', '[LOCATION]', '[SERVICE]', '[REVISION]'); + $request = (new GetRevisionRequest()) + ->setName($formattedName); + try { + $gapicClient->getRevision($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 listRevisionsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $revisionsElement = new Revision(); + $revisions = [ + $revisionsElement, + ]; + $expectedResponse = new ListRevisionsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setRevisions($revisions); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->serviceName('[PROJECT]', '[LOCATION]', '[SERVICE]'); + $request = (new ListRevisionsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listRevisions($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getRevisions()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.run.v2.Revisions/ListRevisions', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listRevisionsExceptionTest() + { + $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->serviceName('[PROJECT]', '[LOCATION]', '[SERVICE]'); + $request = (new ListRevisionsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listRevisions($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 deleteRevisionAsyncTest() + { + $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/deleteRevisionTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $service = 'service1984153269'; + $maxInstanceRequestConcurrency = 117250100; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $reconciling = false; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $sessionAffinity = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Revision(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setService($service); + $expectedResponse->setMaxInstanceRequestConcurrency($maxInstanceRequestConcurrency); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setSessionAffinity($sessionAffinity); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteRevisionTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->revisionName('[PROJECT]', '[LOCATION]', '[SERVICE]', '[REVISION]'); + $request = (new DeleteRevisionRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteRevisionAsync($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.run.v2.Revisions/DeleteRevision', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteRevisionTest'); + $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/Run/tests/Unit/V2/Client/ServicesClientTest.php b/Run/tests/Unit/V2/Client/ServicesClientTest.php new file mode 100644 index 000000000000..bd98ec1b1385 --- /dev/null +++ b/Run/tests/Unit/V2/Client/ServicesClientTest.php @@ -0,0 +1,1024 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ServicesClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ServicesClient($options); + } + + /** @test */ + public function createServiceTest() + { + $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/createServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $latestReadyRevision = 'latestReadyRevision-853854545'; + $latestCreatedRevision = 'latestCreatedRevision452370698'; + $uri = 'uri116076'; + $satisfiesPzs = false; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Service(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLatestReadyRevision($latestReadyRevision); + $expectedResponse->setLatestCreatedRevision($latestCreatedRevision); + $expectedResponse->setUri($uri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createServiceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $service = new Service(); + $serviceTemplate = new RevisionTemplate(); + $service->setTemplate($serviceTemplate); + $serviceId = 'serviceId-1724763419'; + $request = (new CreateServiceRequest()) + ->setParent($formattedParent) + ->setService($service) + ->setServiceId($serviceId); + $response = $gapicClient->createService($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.run.v2.Services/CreateService', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getService(); + $this->assertProtobufEquals($service, $actualValue); + $actualValue = $actualApiRequestObject->getServiceId(); + $this->assertProtobufEquals($serviceId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createServiceTest'); + $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 createServiceExceptionTest() + { + $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/createServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $service = new Service(); + $serviceTemplate = new RevisionTemplate(); + $service->setTemplate($serviceTemplate); + $serviceId = 'serviceId-1724763419'; + $request = (new CreateServiceRequest()) + ->setParent($formattedParent) + ->setService($service) + ->setServiceId($serviceId); + $response = $gapicClient->createService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createServiceTest'); + 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 deleteServiceTest() + { + $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/deleteServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $latestReadyRevision = 'latestReadyRevision-853854545'; + $latestCreatedRevision = 'latestCreatedRevision452370698'; + $uri = 'uri116076'; + $satisfiesPzs = false; + $reconciling = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Service(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLatestReadyRevision($latestReadyRevision); + $expectedResponse->setLatestCreatedRevision($latestCreatedRevision); + $expectedResponse->setUri($uri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteServiceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->serviceName('[PROJECT]', '[LOCATION]', '[SERVICE]'); + $request = (new DeleteServiceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteService($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.run.v2.Services/DeleteService', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteServiceTest'); + $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 deleteServiceExceptionTest() + { + $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/deleteServiceTest'); + $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->serviceName('[PROJECT]', '[LOCATION]', '[SERVICE]'); + $request = (new DeleteServiceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteServiceTest'); + 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.run.v2.Services/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 getServiceTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $latestReadyRevision = 'latestReadyRevision-853854545'; + $latestCreatedRevision = 'latestCreatedRevision452370698'; + $uri = 'uri116076'; + $satisfiesPzs = false; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Service(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLatestReadyRevision($latestReadyRevision); + $expectedResponse->setLatestCreatedRevision($latestCreatedRevision); + $expectedResponse->setUri($uri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->serviceName('[PROJECT]', '[LOCATION]', '[SERVICE]'); + $request = (new GetServiceRequest()) + ->setName($formattedName); + $response = $gapicClient->getService($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.run.v2.Services/GetService', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getServiceExceptionTest() + { + $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->serviceName('[PROJECT]', '[LOCATION]', '[SERVICE]'); + $request = (new GetServiceRequest()) + ->setName($formattedName); + try { + $gapicClient->getService($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 listServicesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $servicesElement = new Service(); + $services = [ + $servicesElement, + ]; + $expectedResponse = new ListServicesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setServices($services); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListServicesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listServices($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getServices()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.run.v2.Services/ListServices', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listServicesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListServicesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listServices($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.run.v2.Services/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.run.v2.Services/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 updateServiceTest() + { + $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/updateServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $latestReadyRevision = 'latestReadyRevision-853854545'; + $latestCreatedRevision = 'latestCreatedRevision452370698'; + $uri = 'uri116076'; + $satisfiesPzs = false; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Service(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLatestReadyRevision($latestReadyRevision); + $expectedResponse->setLatestCreatedRevision($latestCreatedRevision); + $expectedResponse->setUri($uri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateServiceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $service = new Service(); + $serviceTemplate = new RevisionTemplate(); + $service->setTemplate($serviceTemplate); + $request = (new UpdateServiceRequest()) + ->setService($service); + $response = $gapicClient->updateService($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.run.v2.Services/UpdateService', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getService(); + $this->assertProtobufEquals($service, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateServiceTest'); + $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 updateServiceExceptionTest() + { + $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/updateServiceTest'); + $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 + $service = new Service(); + $serviceTemplate = new RevisionTemplate(); + $service->setTemplate($serviceTemplate); + $request = (new UpdateServiceRequest()) + ->setService($service); + $response = $gapicClient->updateService($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateServiceTest'); + 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 createServiceAsyncTest() + { + $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/createServiceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $observedGeneration = 900833007; + $latestReadyRevision = 'latestReadyRevision-853854545'; + $latestCreatedRevision = 'latestCreatedRevision452370698'; + $uri = 'uri116076'; + $satisfiesPzs = false; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Service(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLatestReadyRevision($latestReadyRevision); + $expectedResponse->setLatestCreatedRevision($latestCreatedRevision); + $expectedResponse->setUri($uri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createServiceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $service = new Service(); + $serviceTemplate = new RevisionTemplate(); + $service->setTemplate($serviceTemplate); + $serviceId = 'serviceId-1724763419'; + $request = (new CreateServiceRequest()) + ->setParent($formattedParent) + ->setService($service) + ->setServiceId($serviceId); + $response = $gapicClient->createServiceAsync($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.run.v2.Services/CreateService', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getService(); + $this->assertProtobufEquals($service, $actualValue); + $actualValue = $actualApiRequestObject->getServiceId(); + $this->assertProtobufEquals($serviceId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createServiceTest'); + $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/Run/tests/Unit/V2/Client/TasksClientTest.php b/Run/tests/Unit/V2/Client/TasksClientTest.php new file mode 100644 index 000000000000..c4535a917a59 --- /dev/null +++ b/Run/tests/Unit/V2/Client/TasksClientTest.php @@ -0,0 +1,285 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return TasksClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new TasksClient($options); + } + + /** @test */ + public function getTaskTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $job = 'job105405'; + $execution = 'execution-1090974952'; + $maxRetries = 1129288043; + $serviceAccount = 'serviceAccount-1948028253'; + $reconciling = false; + $observedGeneration = 900833007; + $index = 100346066; + $retried = 1098377527; + $encryptionKey = 'encryptionKey-1122344029'; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $etag = 'etag3123477'; + $expectedResponse = new Task(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setJob($job); + $expectedResponse->setExecution($execution); + $expectedResponse->setMaxRetries($maxRetries); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setIndex($index); + $expectedResponse->setRetried($retried); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->taskName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]', '[TASK]'); + $request = (new GetTaskRequest()) + ->setName($formattedName); + $response = $gapicClient->getTask($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.run.v2.Tasks/GetTask', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTaskExceptionTest() + { + $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->taskName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]', '[TASK]'); + $request = (new GetTaskRequest()) + ->setName($formattedName); + try { + $gapicClient->getTask($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 listTasksTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $tasksElement = new Task(); + $tasks = [ + $tasksElement, + ]; + $expectedResponse = new ListTasksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTasks($tasks); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->executionName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]'); + $request = (new ListTasksRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listTasks($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTasks()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.run.v2.Tasks/ListTasks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTasksExceptionTest() + { + $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->executionName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]'); + $request = (new ListTasksRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listTasks($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 getTaskAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uid = 'uid115792'; + $generation = 305703192; + $job = 'job105405'; + $execution = 'execution-1090974952'; + $maxRetries = 1129288043; + $serviceAccount = 'serviceAccount-1948028253'; + $reconciling = false; + $observedGeneration = 900833007; + $index = 100346066; + $retried = 1098377527; + $encryptionKey = 'encryptionKey-1122344029'; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $etag = 'etag3123477'; + $expectedResponse = new Task(); + $expectedResponse->setName($name2); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setJob($job); + $expectedResponse->setExecution($execution); + $expectedResponse->setMaxRetries($maxRetries); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setIndex($index); + $expectedResponse->setRetried($retried); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->taskName('[PROJECT]', '[LOCATION]', '[JOB]', '[EXECUTION]', '[TASK]'); + $request = (new GetTaskRequest()) + ->setName($formattedName); + $response = $gapicClient->getTaskAsync($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.run.v2.Tasks/GetTask', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/SecurityPublicCA/samples/V1beta1/PublicCertificateAuthorityServiceClient/create_external_account_key.php b/SecurityPublicCA/samples/V1beta1/PublicCertificateAuthorityServiceClient/create_external_account_key.php index 16e6cbd1983c..928168ea76fc 100644 --- a/SecurityPublicCA/samples/V1beta1/PublicCertificateAuthorityServiceClient/create_external_account_key.php +++ b/SecurityPublicCA/samples/V1beta1/PublicCertificateAuthorityServiceClient/create_external_account_key.php @@ -24,8 +24,9 @@ // [START publicca_v1beta1_generated_PublicCertificateAuthorityService_CreateExternalAccountKey_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Security\PublicCA\V1beta1\Client\PublicCertificateAuthorityServiceClient; +use Google\Cloud\Security\PublicCA\V1beta1\CreateExternalAccountKeyRequest; use Google\Cloud\Security\PublicCA\V1beta1\ExternalAccountKey; -use Google\Cloud\Security\PublicCA\V1beta1\PublicCertificateAuthorityServiceClient; /** * Creates a new [ExternalAccountKey][google.cloud.security.publicca.v1beta1.ExternalAccountKey] bound to the project. @@ -40,16 +41,16 @@ function create_external_account_key_sample(string $formattedParent): void // Create a client. $publicCertificateAuthorityServiceClient = new PublicCertificateAuthorityServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $externalAccountKey = new ExternalAccountKey(); + $request = (new CreateExternalAccountKeyRequest()) + ->setParent($formattedParent) + ->setExternalAccountKey($externalAccountKey); // Call the API and handle any network failures. try { /** @var ExternalAccountKey $response */ - $response = $publicCertificateAuthorityServiceClient->createExternalAccountKey( - $formattedParent, - $externalAccountKey - ); + $response = $publicCertificateAuthorityServiceClient->createExternalAccountKey($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/SecurityPublicCA/src/V1beta1/Client/BaseClient/PublicCertificateAuthorityServiceBaseClient.php b/SecurityPublicCA/src/V1beta1/Client/BaseClient/PublicCertificateAuthorityServiceBaseClient.php new file mode 100644 index 000000000000..0f3e92ff9ed7 --- /dev/null +++ b/SecurityPublicCA/src/V1beta1/Client/BaseClient/PublicCertificateAuthorityServiceBaseClient.php @@ -0,0 +1,268 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/public_certificate_authority_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/public_certificate_authority_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/public_certificate_authority_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/public_certificate_authority_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a + * external_account_key resource. + * + * @param string $project + * @param string $location + * @param string $externalAccountKey + * + * @return string The formatted external_account_key resource. + * + * @experimental + */ + public static function externalAccountKeyName(string $project, string $location, string $externalAccountKey): string + { + return self::getPathTemplate('externalAccountKey')->render([ + 'project' => $project, + 'location' => $location, + 'external_account_key' => $externalAccountKey, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + * + * @experimental + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - externalAccountKey: projects/{project}/locations/{location}/externalAccountKeys/{external_account_key} + * - location: projects/{project}/locations/{location} + * + * 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. + * + * @experimental + */ + 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 'publicca.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 + * + * @experimental + */ + 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); + } + + /** + * Creates a new [ExternalAccountKey][google.cloud.security.publicca.v1beta1.ExternalAccountKey] bound to the project. + * + * The async variant is {@see self::createExternalAccountKeyAsync()} . + * + * @param CreateExternalAccountKeyRequest $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 ExternalAccountKey + * + * @throws ApiException Thrown if the API call fails. + * + * @experimental + */ + public function createExternalAccountKey(CreateExternalAccountKeyRequest $request, array $callOptions = []): ExternalAccountKey + { + return $this->startApiCall('CreateExternalAccountKey', $request, $callOptions)->wait(); + } +} diff --git a/SecurityPublicCA/src/V1beta1/Client/PublicCertificateAuthorityServiceClient.php b/SecurityPublicCA/src/V1beta1/Client/PublicCertificateAuthorityServiceClient.php new file mode 100644 index 000000000000..c9195cf2b2e1 --- /dev/null +++ b/SecurityPublicCA/src/V1beta1/Client/PublicCertificateAuthorityServiceClient.php @@ -0,0 +1,42 @@ +setParent($parent) + ->setExternalAccountKey($externalAccountKey); + } + /** * Constructor. * diff --git a/SecurityPublicCA/src/V1beta1/resources/public_certificate_authority_service_descriptor_config.php b/SecurityPublicCA/src/V1beta1/resources/public_certificate_authority_service_descriptor_config.php index 34a67e476001..5f6ea79e4908 100644 --- a/SecurityPublicCA/src/V1beta1/resources/public_certificate_authority_service_descriptor_config.php +++ b/SecurityPublicCA/src/V1beta1/resources/public_certificate_authority_service_descriptor_config.php @@ -2,6 +2,23 @@ return [ 'interfaces' => [ - 'google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService' => [], + 'google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService' => [ + 'CreateExternalAccountKey' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Security\PublicCA\V1beta1\ExternalAccountKey', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'externalAccountKey' => 'projects/{project}/locations/{location}/externalAccountKeys/{external_account_key}', + 'location' => 'projects/{project}/locations/{location}', + ], + ], ], ]; diff --git a/SecurityPublicCA/tests/Unit/V1beta1/Client/PublicCertificateAuthorityServiceClientTest.php b/SecurityPublicCA/tests/Unit/V1beta1/Client/PublicCertificateAuthorityServiceClientTest.php new file mode 100644 index 000000000000..30868041de39 --- /dev/null +++ b/SecurityPublicCA/tests/Unit/V1beta1/Client/PublicCertificateAuthorityServiceClientTest.php @@ -0,0 +1,173 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return PublicCertificateAuthorityServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new PublicCertificateAuthorityServiceClient($options); + } + + /** @test */ + public function createExternalAccountKeyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $keyId = 'keyId-1134673157'; + $b64MacKey = '-48'; + $expectedResponse = new ExternalAccountKey(); + $expectedResponse->setName($name); + $expectedResponse->setKeyId($keyId); + $expectedResponse->setB64MacKey($b64MacKey); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $externalAccountKey = new ExternalAccountKey(); + $request = (new CreateExternalAccountKeyRequest()) + ->setParent($formattedParent) + ->setExternalAccountKey($externalAccountKey); + $response = $gapicClient->createExternalAccountKey($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.security.publicca.v1beta1.PublicCertificateAuthorityService/CreateExternalAccountKey', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getExternalAccountKey(); + $this->assertProtobufEquals($externalAccountKey, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createExternalAccountKeyExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $externalAccountKey = new ExternalAccountKey(); + $request = (new CreateExternalAccountKeyRequest()) + ->setParent($formattedParent) + ->setExternalAccountKey($externalAccountKey); + try { + $gapicClient->createExternalAccountKey($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 createExternalAccountKeyAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $keyId = 'keyId-1134673157'; + $b64MacKey = '-48'; + $expectedResponse = new ExternalAccountKey(); + $expectedResponse->setName($name); + $expectedResponse->setKeyId($keyId); + $expectedResponse->setB64MacKey($b64MacKey); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $externalAccountKey = new ExternalAccountKey(); + $request = (new CreateExternalAccountKeyRequest()) + ->setParent($formattedParent) + ->setExternalAccountKey($externalAccountKey); + $response = $gapicClient->createExternalAccountKeyAsync($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.security.publicca.v1beta1.PublicCertificateAuthorityService/CreateExternalAccountKey', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getExternalAccountKey(); + $this->assertProtobufEquals($externalAccountKey, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/StorageInsights/samples/V1/StorageInsightsClient/create_report_config.php b/StorageInsights/samples/V1/StorageInsightsClient/create_report_config.php index ab55ce2c4ee4..9b224929363f 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/create_report_config.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/create_report_config.php @@ -24,8 +24,9 @@ // [START storageinsights_v1_generated_StorageInsights_CreateReportConfig_sync] use Google\ApiCore\ApiException; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\CreateReportConfigRequest; use Google\Cloud\StorageInsights\V1\ReportConfig; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; /** * Creates a new ReportConfig in a given project and location. @@ -38,13 +39,16 @@ function create_report_config_sample(string $formattedParent): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $reportConfig = new ReportConfig(); + $request = (new CreateReportConfigRequest()) + ->setParent($formattedParent) + ->setReportConfig($reportConfig); // Call the API and handle any network failures. try { /** @var ReportConfig $response */ - $response = $storageInsightsClient->createReportConfig($formattedParent, $reportConfig); + $response = $storageInsightsClient->createReportConfig($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/StorageInsights/samples/V1/StorageInsightsClient/delete_report_config.php b/StorageInsights/samples/V1/StorageInsightsClient/delete_report_config.php index f027d462d052..3f34f2c4b100 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/delete_report_config.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/delete_report_config.php @@ -24,7 +24,8 @@ // [START storageinsights_v1_generated_StorageInsights_DeleteReportConfig_sync] use Google\ApiCore\ApiException; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\DeleteReportConfigRequest; /** * Deletes a single ReportConfig. @@ -37,9 +38,13 @@ function delete_report_config_sample(string $formattedName): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); + // Prepare the request message. + $request = (new DeleteReportConfigRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $storageInsightsClient->deleteReportConfig($formattedName); + $storageInsightsClient->deleteReportConfig($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/StorageInsights/samples/V1/StorageInsightsClient/get_location.php b/StorageInsights/samples/V1/StorageInsightsClient/get_location.php index d3bd8c1683da..9c254dcf5374 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/get_location.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/get_location.php @@ -24,8 +24,9 @@ // [START storageinsights_v1_generated_StorageInsights_GetLocation_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; /** * Gets information about a location. @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $storageInsightsClient->getLocation(); + $response = $storageInsightsClient->getLocation($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/StorageInsights/samples/V1/StorageInsightsClient/get_report_config.php b/StorageInsights/samples/V1/StorageInsightsClient/get_report_config.php index abec01b1380b..3ec0ac9a6d45 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/get_report_config.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/get_report_config.php @@ -24,8 +24,9 @@ // [START storageinsights_v1_generated_StorageInsights_GetReportConfig_sync] use Google\ApiCore\ApiException; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\GetReportConfigRequest; use Google\Cloud\StorageInsights\V1\ReportConfig; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; /** * Gets details of a single ReportConfig. @@ -38,10 +39,14 @@ function get_report_config_sample(string $formattedName): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); + // Prepare the request message. + $request = (new GetReportConfigRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ReportConfig $response */ - $response = $storageInsightsClient->getReportConfig($formattedName); + $response = $storageInsightsClient->getReportConfig($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/StorageInsights/samples/V1/StorageInsightsClient/get_report_detail.php b/StorageInsights/samples/V1/StorageInsightsClient/get_report_detail.php index 7fe534a8ee81..387a09d0886a 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/get_report_detail.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/get_report_detail.php @@ -24,8 +24,9 @@ // [START storageinsights_v1_generated_StorageInsights_GetReportDetail_sync] use Google\ApiCore\ApiException; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\GetReportDetailRequest; use Google\Cloud\StorageInsights\V1\ReportDetail; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; /** * Gets details of a single ReportDetail. @@ -38,10 +39,14 @@ function get_report_detail_sample(string $formattedName): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); + // Prepare the request message. + $request = (new GetReportDetailRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ReportDetail $response */ - $response = $storageInsightsClient->getReportDetail($formattedName); + $response = $storageInsightsClient->getReportDetail($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/StorageInsights/samples/V1/StorageInsightsClient/list_locations.php b/StorageInsights/samples/V1/StorageInsightsClient/list_locations.php index 4261fedf98d0..6ed9f1d96347 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/list_locations.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/list_locations.php @@ -25,8 +25,9 @@ // [START storageinsights_v1_generated_StorageInsights_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; /** * Lists information about the supported locations for this service. @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $storageInsightsClient->listLocations(); + $response = $storageInsightsClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/StorageInsights/samples/V1/StorageInsightsClient/list_report_configs.php b/StorageInsights/samples/V1/StorageInsightsClient/list_report_configs.php index 665199522a82..8ca550df6727 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/list_report_configs.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/list_report_configs.php @@ -25,8 +25,9 @@ // [START storageinsights_v1_generated_StorageInsights_ListReportConfigs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\ListReportConfigsRequest; use Google\Cloud\StorageInsights\V1\ReportConfig; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; /** * Lists ReportConfigs in a given project and location. @@ -39,10 +40,14 @@ function list_report_configs_sample(string $formattedParent): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); + // Prepare the request message. + $request = (new ListReportConfigsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $storageInsightsClient->listReportConfigs($formattedParent); + $response = $storageInsightsClient->listReportConfigs($request); /** @var ReportConfig $element */ foreach ($response as $element) { diff --git a/StorageInsights/samples/V1/StorageInsightsClient/list_report_details.php b/StorageInsights/samples/V1/StorageInsightsClient/list_report_details.php index 5233e677d4ac..dcc1746a6b17 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/list_report_details.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/list_report_details.php @@ -25,8 +25,9 @@ // [START storageinsights_v1_generated_StorageInsights_ListReportDetails_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\ListReportDetailsRequest; use Google\Cloud\StorageInsights\V1\ReportDetail; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; /** * Lists ReportDetails in a given project and location. @@ -39,10 +40,14 @@ function list_report_details_sample(string $formattedParent): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); + // Prepare the request message. + $request = (new ListReportDetailsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $storageInsightsClient->listReportDetails($formattedParent); + $response = $storageInsightsClient->listReportDetails($request); /** @var ReportDetail $element */ foreach ($response as $element) { diff --git a/StorageInsights/samples/V1/StorageInsightsClient/update_report_config.php b/StorageInsights/samples/V1/StorageInsightsClient/update_report_config.php index c5f745489b81..e167f9d66ef1 100644 --- a/StorageInsights/samples/V1/StorageInsightsClient/update_report_config.php +++ b/StorageInsights/samples/V1/StorageInsightsClient/update_report_config.php @@ -24,8 +24,9 @@ // [START storageinsights_v1_generated_StorageInsights_UpdateReportConfig_sync] use Google\ApiCore\ApiException; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; use Google\Cloud\StorageInsights\V1\ReportConfig; -use Google\Cloud\StorageInsights\V1\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\UpdateReportConfigRequest; use Google\Protobuf\FieldMask; /** @@ -42,14 +43,17 @@ function update_report_config_sample(): void // Create a client. $storageInsightsClient = new StorageInsightsClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $reportConfig = new ReportConfig(); + $request = (new UpdateReportConfigRequest()) + ->setUpdateMask($updateMask) + ->setReportConfig($reportConfig); // Call the API and handle any network failures. try { /** @var ReportConfig $response */ - $response = $storageInsightsClient->updateReportConfig($updateMask, $reportConfig); + $response = $storageInsightsClient->updateReportConfig($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/StorageInsights/src/V1/Client/BaseClient/StorageInsightsBaseClient.php b/StorageInsights/src/V1/Client/BaseClient/StorageInsightsBaseClient.php new file mode 100644 index 000000000000..83088d2d9522 --- /dev/null +++ b/StorageInsights/src/V1/Client/BaseClient/StorageInsightsBaseClient.php @@ -0,0 +1,485 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/storage_insights_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/storage_insights_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/storage_insights_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/storage_insights_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * report_config resource. + * + * @param string $project + * @param string $location + * @param string $reportConfig + * + * @return string The formatted report_config resource. + */ + public static function reportConfigName(string $project, string $location, string $reportConfig): string + { + return self::getPathTemplate('reportConfig')->render([ + 'project' => $project, + 'location' => $location, + 'report_config' => $reportConfig, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * report_detail resource. + * + * @param string $project + * @param string $location + * @param string $reportConfig + * @param string $reportDetail + * + * @return string The formatted report_detail resource. + */ + public static function reportDetailName(string $project, string $location, string $reportConfig, string $reportDetail): string + { + return self::getPathTemplate('reportDetail')->render([ + 'project' => $project, + 'location' => $location, + 'report_config' => $reportConfig, + 'report_detail' => $reportDetail, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - location: projects/{project}/locations/{location} + * - reportConfig: projects/{project}/locations/{location}/reportConfigs/{report_config} + * - reportDetail: projects/{project}/locations/{location}/reportConfigs/{report_config}/reportDetails/{report_detail} + * + * 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 'storageinsights.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); + } + + /** + * Creates a new ReportConfig in a given project and location. + * + * The async variant is {@see self::createReportConfigAsync()} . + * + * @param CreateReportConfigRequest $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 ReportConfig + * + * @throws ApiException Thrown if the API call fails. + */ + public function createReportConfig(CreateReportConfigRequest $request, array $callOptions = []): ReportConfig + { + return $this->startApiCall('CreateReportConfig', $request, $callOptions)->wait(); + } + + /** + * Deletes a single ReportConfig. + * + * The async variant is {@see self::deleteReportConfigAsync()} . + * + * @param DeleteReportConfigRequest $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. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteReportConfig(DeleteReportConfigRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteReportConfig', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single ReportConfig. + * + * The async variant is {@see self::getReportConfigAsync()} . + * + * @param GetReportConfigRequest $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 ReportConfig + * + * @throws ApiException Thrown if the API call fails. + */ + public function getReportConfig(GetReportConfigRequest $request, array $callOptions = []): ReportConfig + { + return $this->startApiCall('GetReportConfig', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single ReportDetail. + * + * The async variant is {@see self::getReportDetailAsync()} . + * + * @param GetReportDetailRequest $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 ReportDetail + * + * @throws ApiException Thrown if the API call fails. + */ + public function getReportDetail(GetReportDetailRequest $request, array $callOptions = []): ReportDetail + { + return $this->startApiCall('GetReportDetail', $request, $callOptions)->wait(); + } + + /** + * Lists ReportConfigs in a given project and location. + * + * The async variant is {@see self::listReportConfigsAsync()} . + * + * @param ListReportConfigsRequest $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 listReportConfigs(ListReportConfigsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListReportConfigs', $request, $callOptions); + } + + /** + * Lists ReportDetails in a given project and location. + * + * The async variant is {@see self::listReportDetailsAsync()} . + * + * @param ListReportDetailsRequest $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 listReportDetails(ListReportDetailsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListReportDetails', $request, $callOptions); + } + + /** + * Updates the parameters of a single ReportConfig. + * + * The async variant is {@see self::updateReportConfigAsync()} . + * + * @param UpdateReportConfigRequest $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 ReportConfig + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateReportConfig(UpdateReportConfigRequest $request, array $callOptions = []): ReportConfig + { + return $this->startApiCall('UpdateReportConfig', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $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 Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $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 listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } +} diff --git a/StorageInsights/src/V1/Client/StorageInsightsClient.php b/StorageInsights/src/V1/Client/StorageInsightsClient.php new file mode 100644 index 000000000000..cd71ddc66d8e --- /dev/null +++ b/StorageInsights/src/V1/Client/StorageInsightsClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setReportConfig($reportConfig); + } + /** * Constructor. * diff --git a/StorageInsights/src/V1/DeleteReportConfigRequest.php b/StorageInsights/src/V1/DeleteReportConfigRequest.php index 51a51ebaa6c5..4fea2e9560c1 100644 --- a/StorageInsights/src/V1/DeleteReportConfigRequest.php +++ b/StorageInsights/src/V1/DeleteReportConfigRequest.php @@ -44,6 +44,20 @@ class DeleteReportConfigRequest extends \Google\Protobuf\Internal\Message */ protected $request_id = ''; + /** + * @param string $name Required. Name of the resource + * Please see {@see StorageInsightsClient::reportConfigName()} for help formatting this field. + * + * @return \Google\Cloud\StorageInsights\V1\DeleteReportConfigRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/StorageInsights/src/V1/GetReportConfigRequest.php b/StorageInsights/src/V1/GetReportConfigRequest.php index 58163e616bff..8158367d9ded 100644 --- a/StorageInsights/src/V1/GetReportConfigRequest.php +++ b/StorageInsights/src/V1/GetReportConfigRequest.php @@ -22,6 +22,20 @@ class GetReportConfigRequest extends \Google\Protobuf\Internal\Message */ protected $name = ''; + /** + * @param string $name Required. Name of the resource + * Please see {@see StorageInsightsClient::reportConfigName()} for help formatting this field. + * + * @return \Google\Cloud\StorageInsights\V1\GetReportConfigRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/StorageInsights/src/V1/GetReportDetailRequest.php b/StorageInsights/src/V1/GetReportDetailRequest.php index 70350ea17296..c0798c466611 100644 --- a/StorageInsights/src/V1/GetReportDetailRequest.php +++ b/StorageInsights/src/V1/GetReportDetailRequest.php @@ -22,6 +22,20 @@ class GetReportDetailRequest extends \Google\Protobuf\Internal\Message */ protected $name = ''; + /** + * @param string $name Required. Name of the resource + * Please see {@see StorageInsightsClient::reportDetailName()} for help formatting this field. + * + * @return \Google\Cloud\StorageInsights\V1\GetReportDetailRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/StorageInsights/src/V1/ListReportConfigsRequest.php b/StorageInsights/src/V1/ListReportConfigsRequest.php index 33eb2c4b3397..0b81255d3d05 100644 --- a/StorageInsights/src/V1/ListReportConfigsRequest.php +++ b/StorageInsights/src/V1/ListReportConfigsRequest.php @@ -47,6 +47,20 @@ class ListReportConfigsRequest extends \Google\Protobuf\Internal\Message */ protected $order_by = ''; + /** + * @param string $parent Required. Parent value for ListReportConfigsRequest + * Please see {@see StorageInsightsClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\StorageInsights\V1\ListReportConfigsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/StorageInsights/src/V1/ListReportDetailsRequest.php b/StorageInsights/src/V1/ListReportDetailsRequest.php index 511fc902da1c..1822f972ee85 100644 --- a/StorageInsights/src/V1/ListReportDetailsRequest.php +++ b/StorageInsights/src/V1/ListReportDetailsRequest.php @@ -47,6 +47,20 @@ class ListReportDetailsRequest extends \Google\Protobuf\Internal\Message */ protected $order_by = ''; + /** + * @param string $parent Required. Parent value for ListReportDetailsRequest + * Please see {@see StorageInsightsClient::reportConfigName()} for help formatting this field. + * + * @return \Google\Cloud\StorageInsights\V1\ListReportDetailsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/StorageInsights/src/V1/UpdateReportConfigRequest.php b/StorageInsights/src/V1/UpdateReportConfigRequest.php index a043d7d85dd0..f71297f950de 100644 --- a/StorageInsights/src/V1/UpdateReportConfigRequest.php +++ b/StorageInsights/src/V1/UpdateReportConfigRequest.php @@ -48,6 +48,25 @@ class UpdateReportConfigRequest extends \Google\Protobuf\Internal\Message */ protected $request_id = ''; + /** + * @param \Google\Cloud\StorageInsights\V1\ReportConfig $reportConfig Required. The resource being updated + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask is used to specify the fields to be overwritten in the + * ReportConfig resource by the update. + * The fields specified in the update_mask are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. If the + * user does not provide a mask then all fields will be overwritten. + * + * @return \Google\Cloud\StorageInsights\V1\UpdateReportConfigRequest + * + * @experimental + */ + public static function build(\Google\Cloud\StorageInsights\V1\ReportConfig $reportConfig, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setReportConfig($reportConfig) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/StorageInsights/src/V1/resources/storage_insights_descriptor_config.php b/StorageInsights/src/V1/resources/storage_insights_descriptor_config.php index b1d0c6f1a586..eebdad743e95 100644 --- a/StorageInsights/src/V1/resources/storage_insights_descriptor_config.php +++ b/StorageInsights/src/V1/resources/storage_insights_descriptor_config.php @@ -3,6 +3,54 @@ return [ 'interfaces' => [ 'google.cloud.storageinsights.v1.StorageInsights' => [ + 'CreateReportConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\StorageInsights\V1\ReportConfig', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteReportConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetReportConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\StorageInsights\V1\ReportConfig', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetReportDetail' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\StorageInsights\V1\ReportDetail', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListReportConfigs' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +60,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getReportConfigs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\StorageInsights\V1\ListReportConfigsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListReportDetails' => [ 'pageStreaming' => [ @@ -22,8 +80,41 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getReportDetails', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\StorageInsights\V1\ListReportDetailsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'UpdateReportConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\StorageInsights\V1\ReportConfig', + 'headerParams' => [ + [ + 'keyName' => 'report_config.name', + 'fieldAccessors' => [ + 'getReportConfig', + 'getName', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -35,8 +126,23 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], + 'templateMap' => [ + 'location' => 'projects/{project}/locations/{location}', + 'reportConfig' => 'projects/{project}/locations/{location}/reportConfigs/{report_config}', + 'reportDetail' => 'projects/{project}/locations/{location}/reportConfigs/{report_config}/reportDetails/{report_detail}', + ], ], ], ]; diff --git a/StorageInsights/tests/Unit/V1/Client/StorageInsightsClientTest.php b/StorageInsights/tests/Unit/V1/Client/StorageInsightsClientTest.php new file mode 100644 index 000000000000..6e6693372a19 --- /dev/null +++ b/StorageInsights/tests/Unit/V1/Client/StorageInsightsClientTest.php @@ -0,0 +1,719 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return StorageInsightsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new StorageInsightsClient($options); + } + + /** @test */ + public function createReportConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ReportConfig(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $reportConfig = new ReportConfig(); + $request = (new CreateReportConfigRequest()) + ->setParent($formattedParent) + ->setReportConfig($reportConfig); + $response = $gapicClient->createReportConfig($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.storageinsights.v1.StorageInsights/CreateReportConfig', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getReportConfig(); + $this->assertProtobufEquals($reportConfig, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createReportConfigExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $reportConfig = new ReportConfig(); + $request = (new CreateReportConfigRequest()) + ->setParent($formattedParent) + ->setReportConfig($reportConfig); + try { + $gapicClient->createReportConfig($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 deleteReportConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->reportConfigName('[PROJECT]', '[LOCATION]', '[REPORT_CONFIG]'); + $request = (new DeleteReportConfigRequest()) + ->setName($formattedName); + $gapicClient->deleteReportConfig($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.storageinsights.v1.StorageInsights/DeleteReportConfig', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteReportConfigExceptionTest() + { + $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->reportConfigName('[PROJECT]', '[LOCATION]', '[REPORT_CONFIG]'); + $request = (new DeleteReportConfigRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteReportConfig($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 getReportConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ReportConfig(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->reportConfigName('[PROJECT]', '[LOCATION]', '[REPORT_CONFIG]'); + $request = (new GetReportConfigRequest()) + ->setName($formattedName); + $response = $gapicClient->getReportConfig($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.storageinsights.v1.StorageInsights/GetReportConfig', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getReportConfigExceptionTest() + { + $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->reportConfigName('[PROJECT]', '[LOCATION]', '[REPORT_CONFIG]'); + $request = (new GetReportConfigRequest()) + ->setName($formattedName); + try { + $gapicClient->getReportConfig($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 getReportDetailTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $reportPathPrefix = 'reportPathPrefix39964001'; + $shardsCount = 2027352923; + $expectedResponse = new ReportDetail(); + $expectedResponse->setName($name2); + $expectedResponse->setReportPathPrefix($reportPathPrefix); + $expectedResponse->setShardsCount($shardsCount); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->reportDetailName('[PROJECT]', '[LOCATION]', '[REPORT_CONFIG]', '[REPORT_DETAIL]'); + $request = (new GetReportDetailRequest()) + ->setName($formattedName); + $response = $gapicClient->getReportDetail($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.storageinsights.v1.StorageInsights/GetReportDetail', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getReportDetailExceptionTest() + { + $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->reportDetailName('[PROJECT]', '[LOCATION]', '[REPORT_CONFIG]', '[REPORT_DETAIL]'); + $request = (new GetReportDetailRequest()) + ->setName($formattedName); + try { + $gapicClient->getReportDetail($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 listReportConfigsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $reportConfigsElement = new ReportConfig(); + $reportConfigs = [ + $reportConfigsElement, + ]; + $expectedResponse = new ListReportConfigsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setReportConfigs($reportConfigs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListReportConfigsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listReportConfigs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getReportConfigs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.storageinsights.v1.StorageInsights/ListReportConfigs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listReportConfigsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListReportConfigsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listReportConfigs($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 listReportDetailsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $reportDetailsElement = new ReportDetail(); + $reportDetails = [ + $reportDetailsElement, + ]; + $expectedResponse = new ListReportDetailsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setReportDetails($reportDetails); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->reportConfigName('[PROJECT]', '[LOCATION]', '[REPORT_CONFIG]'); + $request = (new ListReportDetailsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listReportDetails($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getReportDetails()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.storageinsights.v1.StorageInsights/ListReportDetails', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listReportDetailsExceptionTest() + { + $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->reportConfigName('[PROJECT]', '[LOCATION]', '[REPORT_CONFIG]'); + $request = (new ListReportDetailsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listReportDetails($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 updateReportConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ReportConfig(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $updateMask = new FieldMask(); + $reportConfig = new ReportConfig(); + $request = (new UpdateReportConfigRequest()) + ->setUpdateMask($updateMask) + ->setReportConfig($reportConfig); + $response = $gapicClient->updateReportConfig($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.storageinsights.v1.StorageInsights/UpdateReportConfig', $actualFuncCall); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualRequestObject->getReportConfig(); + $this->assertProtobufEquals($reportConfig, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateReportConfigExceptionTest() + { + $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 + $updateMask = new FieldMask(); + $reportConfig = new ReportConfig(); + $request = (new UpdateReportConfigRequest()) + ->setUpdateMask($updateMask) + ->setReportConfig($reportConfig); + try { + $gapicClient->updateReportConfig($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 getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($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.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $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 GetLocationRequest(); + try { + $gapicClient->getLocation($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 listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $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 ListLocationsRequest(); + try { + $gapicClient->listLocations($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 createReportConfigAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ReportConfig(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $reportConfig = new ReportConfig(); + $request = (new CreateReportConfigRequest()) + ->setParent($formattedParent) + ->setReportConfig($reportConfig); + $response = $gapicClient->createReportConfigAsync($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.storageinsights.v1.StorageInsights/CreateReportConfig', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getReportConfig(); + $this->assertProtobufEquals($reportConfig, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/create_channel.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/create_channel.php index 2dd4d1bdb607..836e9ba71e00 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/create_channel.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/create_channel.php @@ -27,7 +27,8 @@ use Google\ApiCore\OperationResponse; use Google\Cloud\Video\LiveStream\V1\Channel; use Google\Cloud\Video\LiveStream\V1\Channel\Output; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\CreateChannelRequest; use Google\Rpc\Status; /** @@ -46,15 +47,19 @@ function create_channel_sample(string $formattedParent, string $channelId): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $channelOutput = new Output(); $channel = (new Channel()) ->setOutput($channelOutput); + $request = (new CreateChannelRequest()) + ->setParent($formattedParent) + ->setChannel($channel) + ->setChannelId($channelId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $livestreamServiceClient->createChannel($formattedParent, $channel, $channelId); + $response = $livestreamServiceClient->createChannel($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/create_event.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/create_event.php index 3c0e0cdabba8..3439827de557 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/create_event.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/create_event.php @@ -24,9 +24,10 @@ // [START livestream_v1_generated_LivestreamService_CreateEvent_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\CreateEventRequest; use Google\Cloud\Video\LiveStream\V1\Event; use Google\Cloud\Video\LiveStream\V1\Event\InputSwitchTask; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; /** * Creates an event with the provided unique ID in the specified channel. @@ -43,15 +44,19 @@ function create_event_sample(string $formattedParent, string $eventId): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $eventInputSwitch = new InputSwitchTask(); $event = (new Event()) ->setInputSwitch($eventInputSwitch); + $request = (new CreateEventRequest()) + ->setParent($formattedParent) + ->setEvent($event) + ->setEventId($eventId); // Call the API and handle any network failures. try { /** @var Event $response */ - $response = $livestreamServiceClient->createEvent($formattedParent, $event, $eventId); + $response = $livestreamServiceClient->createEvent($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/VideoLiveStream/samples/V1/LivestreamServiceClient/create_input.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/create_input.php index 507676e2ec99..2d244266722c 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/create_input.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/create_input.php @@ -25,8 +25,9 @@ // [START livestream_v1_generated_LivestreamService_CreateInput_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\CreateInputRequest; use Google\Cloud\Video\LiveStream\V1\Input; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; use Google\Rpc\Status; /** @@ -44,13 +45,17 @@ function create_input_sample(string $formattedParent, string $inputId): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $input = new Input(); + $request = (new CreateInputRequest()) + ->setParent($formattedParent) + ->setInput($input) + ->setInputId($inputId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $livestreamServiceClient->createInput($formattedParent, $input, $inputId); + $response = $livestreamServiceClient->createInput($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_channel.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_channel.php index be9260b7a6bf..924d586e79eb 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_channel.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_channel.php @@ -25,7 +25,8 @@ // [START livestream_v1_generated_LivestreamService_DeleteChannel_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\DeleteChannelRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_channel_sample(string $formattedName): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new DeleteChannelRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $livestreamServiceClient->deleteChannel($formattedName); + $response = $livestreamServiceClient->deleteChannel($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_event.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_event.php index 2c7342b77dfc..240d25ba37d4 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_event.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_event.php @@ -24,7 +24,8 @@ // [START livestream_v1_generated_LivestreamService_DeleteEvent_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\DeleteEventRequest; /** * Deletes the specified event. @@ -38,9 +39,13 @@ function delete_event_sample(string $formattedName): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new DeleteEventRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $livestreamServiceClient->deleteEvent($formattedName); + $livestreamServiceClient->deleteEvent($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_input.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_input.php index 53a028f7c7b7..8e172d6ece9a 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_input.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/delete_input.php @@ -25,7 +25,8 @@ // [START livestream_v1_generated_LivestreamService_DeleteInput_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\DeleteInputRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_input_sample(string $formattedName): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new DeleteInputRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $livestreamServiceClient->deleteInput($formattedName); + $response = $livestreamServiceClient->deleteInput($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/get_channel.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/get_channel.php index 37ecf9a75030..c2b490773cd0 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/get_channel.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/get_channel.php @@ -25,7 +25,8 @@ // [START livestream_v1_generated_LivestreamService_GetChannel_sync] use Google\ApiCore\ApiException; use Google\Cloud\Video\LiveStream\V1\Channel; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\GetChannelRequest; /** * Returns the specified channel. @@ -39,10 +40,14 @@ function get_channel_sample(string $formattedName): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new GetChannelRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Channel $response */ - $response = $livestreamServiceClient->getChannel($formattedName); + $response = $livestreamServiceClient->getChannel($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/VideoLiveStream/samples/V1/LivestreamServiceClient/get_event.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/get_event.php index cfaddb26df80..60ea30d5b5b1 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/get_event.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/get_event.php @@ -24,8 +24,9 @@ // [START livestream_v1_generated_LivestreamService_GetEvent_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; use Google\Cloud\Video\LiveStream\V1\Event; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\GetEventRequest; /** * Returns the specified event. @@ -39,10 +40,14 @@ function get_event_sample(string $formattedName): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new GetEventRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Event $response */ - $response = $livestreamServiceClient->getEvent($formattedName); + $response = $livestreamServiceClient->getEvent($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/VideoLiveStream/samples/V1/LivestreamServiceClient/get_input.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/get_input.php index a2881bf6aea3..1881f3669bba 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/get_input.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/get_input.php @@ -24,8 +24,9 @@ // [START livestream_v1_generated_LivestreamService_GetInput_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\GetInputRequest; use Google\Cloud\Video\LiveStream\V1\Input; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; /** * Returns the specified input. @@ -39,10 +40,14 @@ function get_input_sample(string $formattedName): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new GetInputRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Input $response */ - $response = $livestreamServiceClient->getInput($formattedName); + $response = $livestreamServiceClient->getInput($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/VideoLiveStream/samples/V1/LivestreamServiceClient/get_location.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/get_location.php index 875c398c2ffb..a3b885a9de6b 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/get_location.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/get_location.php @@ -24,8 +24,9 @@ // [START livestream_v1_generated_LivestreamService_GetLocation_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; /** * Gets information about a location. @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $livestreamServiceClient->getLocation(); + $response = $livestreamServiceClient->getLocation($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/VideoLiveStream/samples/V1/LivestreamServiceClient/list_channels.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/list_channels.php index 2bcf39de50d6..5337d49bb3cd 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/list_channels.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/list_channels.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\Video\LiveStream\V1\Channel; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\ListChannelsRequest; /** * Returns a list of all channels in the specified region. @@ -40,10 +41,14 @@ function list_channels_sample(string $formattedParent): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new ListChannelsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $livestreamServiceClient->listChannels($formattedParent); + $response = $livestreamServiceClient->listChannels($request); /** @var Channel $element */ foreach ($response as $element) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/list_events.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/list_events.php index 10436624bc73..d81556803099 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/list_events.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/list_events.php @@ -25,8 +25,9 @@ // [START livestream_v1_generated_LivestreamService_ListEvents_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; use Google\Cloud\Video\LiveStream\V1\Event; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\ListEventsRequest; /** * Returns a list of all events in the specified channel. @@ -40,10 +41,14 @@ function list_events_sample(string $formattedParent): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new ListEventsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $livestreamServiceClient->listEvents($formattedParent); + $response = $livestreamServiceClient->listEvents($request); /** @var Event $element */ foreach ($response as $element) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/list_inputs.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/list_inputs.php index 89230bf006b2..a8ad5f1258a8 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/list_inputs.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/list_inputs.php @@ -25,8 +25,9 @@ // [START livestream_v1_generated_LivestreamService_ListInputs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; use Google\Cloud\Video\LiveStream\V1\Input; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\ListInputsRequest; /** * Returns a list of all inputs in the specified region. @@ -40,10 +41,14 @@ function list_inputs_sample(string $formattedParent): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new ListInputsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $livestreamServiceClient->listInputs($formattedParent); + $response = $livestreamServiceClient->listInputs($request); /** @var Input $element */ foreach ($response as $element) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/list_locations.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/list_locations.php index 651fafa24f24..5a16f54d9602 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/list_locations.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/list_locations.php @@ -25,8 +25,9 @@ // [START livestream_v1_generated_LivestreamService_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; /** * Lists information about the supported locations for this service. @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $livestreamServiceClient->listLocations(); + $response = $livestreamServiceClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/start_channel.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/start_channel.php index 11ccdd52acb1..941b8ce45439 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/start_channel.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/start_channel.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\Video\LiveStream\V1\ChannelOperationResponse; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\StartChannelRequest; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function start_channel_sample(string $formattedName): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new StartChannelRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $livestreamServiceClient->startChannel($formattedName); + $response = $livestreamServiceClient->startChannel($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/stop_channel.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/stop_channel.php index fd4d103d9bef..9c2c592c6d61 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/stop_channel.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/stop_channel.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\Video\LiveStream\V1\ChannelOperationResponse; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\StopChannelRequest; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function stop_channel_sample(string $formattedName): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); + // Prepare the request message. + $request = (new StopChannelRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $livestreamServiceClient->stopChannel($formattedName); + $response = $livestreamServiceClient->stopChannel($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/update_channel.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/update_channel.php index f1cb665a8d1e..43b3523f3f85 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/update_channel.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/update_channel.php @@ -27,7 +27,8 @@ use Google\ApiCore\OperationResponse; use Google\Cloud\Video\LiveStream\V1\Channel; use Google\Cloud\Video\LiveStream\V1\Channel\Output; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\UpdateChannelRequest; use Google\Rpc\Status; /** @@ -44,15 +45,17 @@ function update_channel_sample(): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $channelOutput = new Output(); $channel = (new Channel()) ->setOutput($channelOutput); + $request = (new UpdateChannelRequest()) + ->setChannel($channel); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $livestreamServiceClient->updateChannel($channel); + $response = $livestreamServiceClient->updateChannel($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoLiveStream/samples/V1/LivestreamServiceClient/update_input.php b/VideoLiveStream/samples/V1/LivestreamServiceClient/update_input.php index bb67e62e231d..403ab50e47d5 100644 --- a/VideoLiveStream/samples/V1/LivestreamServiceClient/update_input.php +++ b/VideoLiveStream/samples/V1/LivestreamServiceClient/update_input.php @@ -25,8 +25,9 @@ // [START livestream_v1_generated_LivestreamService_UpdateInput_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; use Google\Cloud\Video\LiveStream\V1\Input; -use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\UpdateInputRequest; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function update_input_sample(): void // Create a client. $livestreamServiceClient = new LivestreamServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $input = new Input(); + $request = (new UpdateInputRequest()) + ->setInput($input); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $livestreamServiceClient->updateInput($input); + $response = $livestreamServiceClient->updateInput($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoLiveStream/src/V1/Client/BaseClient/LivestreamServiceBaseClient.php b/VideoLiveStream/src/V1/Client/BaseClient/LivestreamServiceBaseClient.php new file mode 100644 index 000000000000..5db98580b409 --- /dev/null +++ b/VideoLiveStream/src/V1/Client/BaseClient/LivestreamServiceBaseClient.php @@ -0,0 +1,802 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/livestream_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/livestream_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/livestream_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/livestream_service_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 channel + * resource. + * + * @param string $project + * @param string $location + * @param string $channel + * + * @return string The formatted channel resource. + */ + public static function channelName(string $project, string $location, string $channel): string + { + return self::getPathTemplate('channel')->render([ + 'project' => $project, + 'location' => $location, + 'channel' => $channel, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a event + * resource. + * + * @param string $project + * @param string $location + * @param string $channel + * @param string $event + * + * @return string The formatted event resource. + */ + public static function eventName(string $project, string $location, string $channel, string $event): string + { + return self::getPathTemplate('event')->render([ + 'project' => $project, + 'location' => $location, + 'channel' => $channel, + 'event' => $event, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a input + * resource. + * + * @param string $project + * @param string $location + * @param string $input + * + * @return string The formatted input resource. + */ + public static function inputName(string $project, string $location, string $input): string + { + return self::getPathTemplate('input')->render([ + 'project' => $project, + 'location' => $location, + 'input' => $input, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * secret_version resource. + * + * @param string $project + * @param string $secret + * @param string $version + * + * @return string The formatted secret_version resource. + */ + public static function secretVersionName(string $project, string $secret, string $version): string + { + return self::getPathTemplate('secretVersion')->render([ + 'project' => $project, + 'secret' => $secret, + 'version' => $version, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - channel: projects/{project}/locations/{location}/channels/{channel} + * - event: projects/{project}/locations/{location}/channels/{channel}/events/{event} + * - input: projects/{project}/locations/{location}/inputs/{input} + * - location: projects/{project}/locations/{location} + * - secretVersion: projects/{project}/secrets/{secret}/versions/{version} + * + * 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 'livestream.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 channel with the provided unique ID in the specified + * region. + * + * The async variant is {@see self::createChannelAsync()} . + * + * @param CreateChannelRequest $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 createChannel(CreateChannelRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateChannel', $request, $callOptions)->wait(); + } + + /** + * Creates an event with the provided unique ID in the specified channel. + * + * The async variant is {@see self::createEventAsync()} . + * + * @param CreateEventRequest $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 Event + * + * @throws ApiException Thrown if the API call fails. + */ + public function createEvent(CreateEventRequest $request, array $callOptions = []): Event + { + return $this->startApiCall('CreateEvent', $request, $callOptions)->wait(); + } + + /** + * Creates an input with the provided unique ID in the specified region. + * + * The async variant is {@see self::createInputAsync()} . + * + * @param CreateInputRequest $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 createInput(CreateInputRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateInput', $request, $callOptions)->wait(); + } + + /** + * Deletes the specified channel. + * + * The async variant is {@see self::deleteChannelAsync()} . + * + * @param DeleteChannelRequest $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 deleteChannel(DeleteChannelRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteChannel', $request, $callOptions)->wait(); + } + + /** + * Deletes the specified event. + * + * The async variant is {@see self::deleteEventAsync()} . + * + * @param DeleteEventRequest $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. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteEvent(DeleteEventRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteEvent', $request, $callOptions)->wait(); + } + + /** + * Deletes the specified input. + * + * The async variant is {@see self::deleteInputAsync()} . + * + * @param DeleteInputRequest $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 deleteInput(DeleteInputRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteInput', $request, $callOptions)->wait(); + } + + /** + * Returns the specified channel. + * + * The async variant is {@see self::getChannelAsync()} . + * + * @param GetChannelRequest $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 Channel + * + * @throws ApiException Thrown if the API call fails. + */ + public function getChannel(GetChannelRequest $request, array $callOptions = []): Channel + { + return $this->startApiCall('GetChannel', $request, $callOptions)->wait(); + } + + /** + * Returns the specified event. + * + * The async variant is {@see self::getEventAsync()} . + * + * @param GetEventRequest $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 Event + * + * @throws ApiException Thrown if the API call fails. + */ + public function getEvent(GetEventRequest $request, array $callOptions = []): Event + { + return $this->startApiCall('GetEvent', $request, $callOptions)->wait(); + } + + /** + * Returns the specified input. + * + * The async variant is {@see self::getInputAsync()} . + * + * @param GetInputRequest $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 Input + * + * @throws ApiException Thrown if the API call fails. + */ + public function getInput(GetInputRequest $request, array $callOptions = []): Input + { + return $this->startApiCall('GetInput', $request, $callOptions)->wait(); + } + + /** + * Returns a list of all channels in the specified region. + * + * The async variant is {@see self::listChannelsAsync()} . + * + * @param ListChannelsRequest $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 listChannels(ListChannelsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListChannels', $request, $callOptions); + } + + /** + * Returns a list of all events in the specified channel. + * + * The async variant is {@see self::listEventsAsync()} . + * + * @param ListEventsRequest $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 listEvents(ListEventsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListEvents', $request, $callOptions); + } + + /** + * Returns a list of all inputs in the specified region. + * + * The async variant is {@see self::listInputsAsync()} . + * + * @param ListInputsRequest $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 listInputs(ListInputsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListInputs', $request, $callOptions); + } + + /** + * Starts the specified channel. Part of the video pipeline will be created + * only when the StartChannel request is received by the server. + * + * The async variant is {@see self::startChannelAsync()} . + * + * @param StartChannelRequest $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 startChannel(StartChannelRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('StartChannel', $request, $callOptions)->wait(); + } + + /** + * Stops the specified channel. Part of the video pipeline will be released + * when the StopChannel request is received by the server. + * + * The async variant is {@see self::stopChannelAsync()} . + * + * @param StopChannelRequest $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 stopChannel(StopChannelRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('StopChannel', $request, $callOptions)->wait(); + } + + /** + * Updates the specified channel. + * + * The async variant is {@see self::updateChannelAsync()} . + * + * @param UpdateChannelRequest $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 updateChannel(UpdateChannelRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateChannel', $request, $callOptions)->wait(); + } + + /** + * Updates the specified input. + * + * The async variant is {@see self::updateInputAsync()} . + * + * @param UpdateInputRequest $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 updateInput(UpdateInputRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateInput', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $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 Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $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 listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } +} diff --git a/VideoLiveStream/src/V1/Client/LivestreamServiceClient.php b/VideoLiveStream/src/V1/Client/LivestreamServiceClient.php new file mode 100644 index 000000000000..055a92e9d6ce --- /dev/null +++ b/VideoLiveStream/src/V1/Client/LivestreamServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setChannel($channel) + ->setChannelId($channelId); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/CreateEventRequest.php b/VideoLiveStream/src/V1/CreateEventRequest.php index f6899ed34f24..6a4fda27569c 100644 --- a/VideoLiveStream/src/V1/CreateEventRequest.php +++ b/VideoLiveStream/src/V1/CreateEventRequest.php @@ -53,6 +53,27 @@ class CreateEventRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The parent channel for the resource, in the form of: + * `projects/{project}/locations/{location}/channels/{channelId}`. Please see + * {@see LivestreamServiceClient::channelName()} for help formatting this field. + * @param \Google\Cloud\Video\LiveStream\V1\Event $event Required. The event resource to be created. + * @param string $eventId Required. The ID of the event resource to be created. + * This value must be 1-63 characters, begin and end with `[a-z0-9]`, + * could contain dashes (-) in between. + * + * @return \Google\Cloud\Video\LiveStream\V1\CreateEventRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Video\LiveStream\V1\Event $event, string $eventId): self + { + return (new self()) + ->setParent($parent) + ->setEvent($event) + ->setEventId($eventId); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/CreateInputRequest.php b/VideoLiveStream/src/V1/CreateInputRequest.php index 374dd9a58db7..ea1cbbd40e29 100644 --- a/VideoLiveStream/src/V1/CreateInputRequest.php +++ b/VideoLiveStream/src/V1/CreateInputRequest.php @@ -53,6 +53,27 @@ class CreateInputRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The parent location for the resource, in the form of: + * `projects/{project}/locations/{location}`. Please see + * {@see LivestreamServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Video\LiveStream\V1\Input $input Required. The input resource to be created. + * @param string $inputId Required. The ID of the input resource to be created. + * This value must be 1-63 characters, begin and end with `[a-z0-9]`, + * could contain dashes (-) in between. + * + * @return \Google\Cloud\Video\LiveStream\V1\CreateInputRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Video\LiveStream\V1\Input $input, string $inputId): self + { + return (new self()) + ->setParent($parent) + ->setInput($input) + ->setInputId($inputId); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/DeleteChannelRequest.php b/VideoLiveStream/src/V1/DeleteChannelRequest.php index 393357ecd61f..c58e5e68da80 100644 --- a/VideoLiveStream/src/V1/DeleteChannelRequest.php +++ b/VideoLiveStream/src/V1/DeleteChannelRequest.php @@ -48,6 +48,21 @@ class DeleteChannelRequest extends \Google\Protobuf\Internal\Message */ private $force = false; + /** + * @param string $name Required. The name of the channel resource, in the form of: + * `projects/{project}/locations/{location}/channels/{channelId}`. Please see + * {@see LivestreamServiceClient::channelName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\DeleteChannelRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/DeleteEventRequest.php b/VideoLiveStream/src/V1/DeleteEventRequest.php index ab46e203a9da..c075bfda6f69 100644 --- a/VideoLiveStream/src/V1/DeleteEventRequest.php +++ b/VideoLiveStream/src/V1/DeleteEventRequest.php @@ -39,6 +39,21 @@ class DeleteEventRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The name of the event resource, in the form of: + * `projects/{project}/locations/{location}/channels/{channelId}/events/{eventId}`. Please see + * {@see LivestreamServiceClient::eventName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\DeleteEventRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/DeleteInputRequest.php b/VideoLiveStream/src/V1/DeleteInputRequest.php index 0e23601fff08..5b867332d62d 100644 --- a/VideoLiveStream/src/V1/DeleteInputRequest.php +++ b/VideoLiveStream/src/V1/DeleteInputRequest.php @@ -39,6 +39,21 @@ class DeleteInputRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The name of the input resource, in the form of: + * `projects/{project}/locations/{location}/inputs/{inputId}`. Please see + * {@see LivestreamServiceClient::inputName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\DeleteInputRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/GetChannelRequest.php b/VideoLiveStream/src/V1/GetChannelRequest.php index 5767c32eea39..7eddcf3775e3 100644 --- a/VideoLiveStream/src/V1/GetChannelRequest.php +++ b/VideoLiveStream/src/V1/GetChannelRequest.php @@ -23,6 +23,21 @@ class GetChannelRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the channel resource, in the form of: + * `projects/{project}/locations/{location}/channels/{channelId}`. Please see + * {@see LivestreamServiceClient::channelName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\GetChannelRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/GetEventRequest.php b/VideoLiveStream/src/V1/GetEventRequest.php index 8051b904c8e9..3944a24ea858 100644 --- a/VideoLiveStream/src/V1/GetEventRequest.php +++ b/VideoLiveStream/src/V1/GetEventRequest.php @@ -23,6 +23,21 @@ class GetEventRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the event resource, in the form of: + * `projects/{project}/locations/{location}/channels/{channelId}/events/{eventId}`. Please see + * {@see LivestreamServiceClient::eventName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\GetEventRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/GetInputRequest.php b/VideoLiveStream/src/V1/GetInputRequest.php index 400305b4f76f..bfb040293676 100644 --- a/VideoLiveStream/src/V1/GetInputRequest.php +++ b/VideoLiveStream/src/V1/GetInputRequest.php @@ -23,6 +23,21 @@ class GetInputRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the input resource, in the form of: + * `projects/{project}/locations/{location}/inputs/{inputId}`. Please see + * {@see LivestreamServiceClient::inputName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\GetInputRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/ListChannelsRequest.php b/VideoLiveStream/src/V1/ListChannelsRequest.php index f8de1adebe9f..19397ddf8eff 100644 --- a/VideoLiveStream/src/V1/ListChannelsRequest.php +++ b/VideoLiveStream/src/V1/ListChannelsRequest.php @@ -52,6 +52,21 @@ class ListChannelsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent location for the resource, in the form of: + * `projects/{project}/locations/{location}`. Please see + * {@see LivestreamServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\ListChannelsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/ListEventsRequest.php b/VideoLiveStream/src/V1/ListEventsRequest.php index fc63e0924332..91c18ba52b96 100644 --- a/VideoLiveStream/src/V1/ListEventsRequest.php +++ b/VideoLiveStream/src/V1/ListEventsRequest.php @@ -52,6 +52,21 @@ class ListEventsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent channel for the resource, in the form of: + * `projects/{project}/locations/{location}/channels/{channelId}`. Please see + * {@see LivestreamServiceClient::channelName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\ListEventsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/ListInputsRequest.php b/VideoLiveStream/src/V1/ListInputsRequest.php index 8735e785b54c..d1afb5171aea 100644 --- a/VideoLiveStream/src/V1/ListInputsRequest.php +++ b/VideoLiveStream/src/V1/ListInputsRequest.php @@ -52,6 +52,21 @@ class ListInputsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent location for the resource, in the form of: + * `projects/{project}/locations/{location}`. Please see + * {@see LivestreamServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\ListInputsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/StartChannelRequest.php b/VideoLiveStream/src/V1/StartChannelRequest.php index 229143673e95..f58d66497b36 100644 --- a/VideoLiveStream/src/V1/StartChannelRequest.php +++ b/VideoLiveStream/src/V1/StartChannelRequest.php @@ -39,6 +39,21 @@ class StartChannelRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The name of the channel resource, in the form of: + * `projects/{project}/locations/{location}/channels/{channelId}`. Please see + * {@see LivestreamServiceClient::channelName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\StartChannelRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/StopChannelRequest.php b/VideoLiveStream/src/V1/StopChannelRequest.php index 382736cec8c5..deb3da56c69f 100644 --- a/VideoLiveStream/src/V1/StopChannelRequest.php +++ b/VideoLiveStream/src/V1/StopChannelRequest.php @@ -39,6 +39,21 @@ class StopChannelRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The name of the channel resource, in the form of: + * `projects/{project}/locations/{location}/channels/{channelId}`. Please see + * {@see LivestreamServiceClient::channelName()} for help formatting this field. + * + * @return \Google\Cloud\Video\LiveStream\V1\StopChannelRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/UpdateChannelRequest.php b/VideoLiveStream/src/V1/UpdateChannelRequest.php index ad8aa133e56b..717d755f7ab9 100644 --- a/VideoLiveStream/src/V1/UpdateChannelRequest.php +++ b/VideoLiveStream/src/V1/UpdateChannelRequest.php @@ -60,6 +60,40 @@ class UpdateChannelRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\Video\LiveStream\V1\Channel $channel Required. The channel resource to be updated. + * @param \Google\Protobuf\FieldMask $updateMask Field mask is used to specify the fields to be overwritten in the Channel + * resource by the update. You can only update the following fields: + * + * * [`inputAttachments`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#inputattachment) + * * [`inputConfig`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#inputconfig) + * * [`output`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#output) + * * [`elementaryStreams`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#elementarystream) + * * [`muxStreams`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#muxstream) + * * [`manifests`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#manifest) + * * [`spriteSheets`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#spritesheet) + * * [`logConfig`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#logconfig) + * * [`timecodeConfig`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#timecodeconfig) + * * [`encryptions`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.channels#encryption) + * + * The fields specified in the update_mask are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. + * + * If the mask is not present, then each field from the list above is updated + * if the field appears in the request payload. To unset a field, add the + * field to the update mask and remove it from the request payload. + * + * @return \Google\Cloud\Video\LiveStream\V1\UpdateChannelRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Video\LiveStream\V1\Channel $channel, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setChannel($channel) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/UpdateInputRequest.php b/VideoLiveStream/src/V1/UpdateInputRequest.php index c5b9d452c989..581399e3f3e6 100644 --- a/VideoLiveStream/src/V1/UpdateInputRequest.php +++ b/VideoLiveStream/src/V1/UpdateInputRequest.php @@ -52,6 +52,32 @@ class UpdateInputRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\Video\LiveStream\V1\Input $input Required. The input resource to be updated. + * @param \Google\Protobuf\FieldMask $updateMask Field mask is used to specify the fields to be overwritten in the Input + * resource by the update. You can only update the following fields: + * + * * [`preprocessingConfig`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.inputs#PreprocessingConfig) + * * [`securityRules`](https://cloud.google.com/livestream/docs/reference/rest/v1/projects.locations.inputs#SecurityRule) + * + * The fields specified in the update_mask are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. + * + * If the mask is not present, then each field from the list above is updated + * if the field appears in the request payload. To unset a field, add the + * field to the update mask and remove it from the request payload. + * + * @return \Google\Cloud\Video\LiveStream\V1\UpdateInputRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Video\LiveStream\V1\Input $input, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setInput($input) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VideoLiveStream/src/V1/resources/livestream_service_descriptor_config.php b/VideoLiveStream/src/V1/resources/livestream_service_descriptor_config.php index 466780ff1e1e..3f79b06e28d9 100644 --- a/VideoLiveStream/src/V1/resources/livestream_service_descriptor_config.php +++ b/VideoLiveStream/src/V1/resources/livestream_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateInput' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteChannel' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteInput' => [ 'longRunning' => [ @@ -42,6 +69,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'StartChannel' => [ 'longRunning' => [ @@ -52,6 +88,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'StopChannel' => [ 'longRunning' => [ @@ -62,6 +107,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateChannel' => [ 'longRunning' => [ @@ -72,6 +126,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'channel.name', + 'fieldAccessors' => [ + 'getChannel', + 'getName', + ], + ], + ], ], 'UpdateInput' => [ 'longRunning' => [ @@ -82,6 +146,76 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'input.name', + 'fieldAccessors' => [ + 'getInput', + 'getName', + ], + ], + ], + ], + 'CreateEvent' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\LiveStream\V1\Event', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteEvent' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetChannel' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\LiveStream\V1\Channel', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetEvent' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\LiveStream\V1\Event', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetInput' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\LiveStream\V1\Input', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListChannels' => [ 'pageStreaming' => [ @@ -92,6 +226,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getChannels', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\LiveStream\V1\ListChannelsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListEvents' => [ 'pageStreaming' => [ @@ -102,6 +246,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getEvents', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\LiveStream\V1\ListEventsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListInputs' => [ 'pageStreaming' => [ @@ -112,8 +266,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getInputs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\LiveStream\V1\ListInputsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -125,8 +299,25 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], + 'templateMap' => [ + 'channel' => 'projects/{project}/locations/{location}/channels/{channel}', + 'event' => 'projects/{project}/locations/{location}/channels/{channel}/events/{event}', + 'input' => 'projects/{project}/locations/{location}/inputs/{input}', + 'location' => 'projects/{project}/locations/{location}', + 'secretVersion' => 'projects/{project}/secrets/{secret}/versions/{version}', + ], ], ], ]; diff --git a/VideoLiveStream/tests/Unit/V1/Client/LivestreamServiceClientTest.php b/VideoLiveStream/tests/Unit/V1/Client/LivestreamServiceClientTest.php new file mode 100644 index 000000000000..1d5c31b5f615 --- /dev/null +++ b/VideoLiveStream/tests/Unit/V1/Client/LivestreamServiceClientTest.php @@ -0,0 +1,1869 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return LivestreamServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new LivestreamServiceClient($options); + } + + /** @test */ + public function createChannelTest() + { + $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/createChannelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $activeInput = 'activeInput1758551377'; + $expectedResponse = new Channel(); + $expectedResponse->setName($name); + $expectedResponse->setActiveInput($activeInput); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createChannelTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $channel = new Channel(); + $channelOutput = new Output(); + $channel->setOutput($channelOutput); + $channelId = 'channelId-1930808873'; + $request = (new CreateChannelRequest()) + ->setParent($formattedParent) + ->setChannel($channel) + ->setChannelId($channelId); + $response = $gapicClient->createChannel($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.video.livestream.v1.LivestreamService/CreateChannel', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getChannel(); + $this->assertProtobufEquals($channel, $actualValue); + $actualValue = $actualApiRequestObject->getChannelId(); + $this->assertProtobufEquals($channelId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createChannelTest'); + $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 createChannelExceptionTest() + { + $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/createChannelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $channel = new Channel(); + $channelOutput = new Output(); + $channel->setOutput($channelOutput); + $channelId = 'channelId-1930808873'; + $request = (new CreateChannelRequest()) + ->setParent($formattedParent) + ->setChannel($channel) + ->setChannelId($channelId); + $response = $gapicClient->createChannel($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createChannelTest'); + 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 createEventTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $executeNow = true; + $expectedResponse = new Event(); + $expectedResponse->setName($name); + $expectedResponse->setExecuteNow($executeNow); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $event = new Event(); + $eventInputSwitch = new InputSwitchTask(); + $event->setInputSwitch($eventInputSwitch); + $eventId = 'eventId278118624'; + $request = (new CreateEventRequest()) + ->setParent($formattedParent) + ->setEvent($event) + ->setEventId($eventId); + $response = $gapicClient->createEvent($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.video.livestream.v1.LivestreamService/CreateEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getEvent(); + $this->assertProtobufEquals($event, $actualValue); + $actualValue = $actualRequestObject->getEventId(); + $this->assertProtobufEquals($eventId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createEventExceptionTest() + { + $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->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $event = new Event(); + $eventInputSwitch = new InputSwitchTask(); + $event->setInputSwitch($eventInputSwitch); + $eventId = 'eventId278118624'; + $request = (new CreateEventRequest()) + ->setParent($formattedParent) + ->setEvent($event) + ->setEventId($eventId); + try { + $gapicClient->createEvent($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 createInputTest() + { + $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/createInputTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uri = 'uri116076'; + $expectedResponse = new Input(); + $expectedResponse->setName($name); + $expectedResponse->setUri($uri); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createInputTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $input = new Input(); + $inputId = 'inputId470715824'; + $request = (new CreateInputRequest()) + ->setParent($formattedParent) + ->setInput($input) + ->setInputId($inputId); + $response = $gapicClient->createInput($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.video.livestream.v1.LivestreamService/CreateInput', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInput(); + $this->assertProtobufEquals($input, $actualValue); + $actualValue = $actualApiRequestObject->getInputId(); + $this->assertProtobufEquals($inputId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInputTest'); + $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 createInputExceptionTest() + { + $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/createInputTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $input = new Input(); + $inputId = 'inputId470715824'; + $request = (new CreateInputRequest()) + ->setParent($formattedParent) + ->setInput($input) + ->setInputId($inputId); + $response = $gapicClient->createInput($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInputTest'); + 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 deleteChannelTest() + { + $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/deleteChannelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteChannelTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new DeleteChannelRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteChannel($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.video.livestream.v1.LivestreamService/DeleteChannel', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteChannelTest'); + $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 deleteChannelExceptionTest() + { + $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/deleteChannelTest'); + $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->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new DeleteChannelRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteChannel($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteChannelTest'); + 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 deleteEventTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->eventName('[PROJECT]', '[LOCATION]', '[CHANNEL]', '[EVENT]'); + $request = (new DeleteEventRequest()) + ->setName($formattedName); + $gapicClient->deleteEvent($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.livestream.v1.LivestreamService/DeleteEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteEventExceptionTest() + { + $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->eventName('[PROJECT]', '[LOCATION]', '[CHANNEL]', '[EVENT]'); + $request = (new DeleteEventRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteEvent($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 deleteInputTest() + { + $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/deleteInputTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteInputTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->inputName('[PROJECT]', '[LOCATION]', '[INPUT]'); + $request = (new DeleteInputRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteInput($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.video.livestream.v1.LivestreamService/DeleteInput', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteInputTest'); + $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 deleteInputExceptionTest() + { + $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/deleteInputTest'); + $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->inputName('[PROJECT]', '[LOCATION]', '[INPUT]'); + $request = (new DeleteInputRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteInput($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteInputTest'); + 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 getChannelTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $activeInput = 'activeInput1758551377'; + $expectedResponse = new Channel(); + $expectedResponse->setName($name2); + $expectedResponse->setActiveInput($activeInput); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new GetChannelRequest()) + ->setName($formattedName); + $response = $gapicClient->getChannel($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.video.livestream.v1.LivestreamService/GetChannel', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getChannelExceptionTest() + { + $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->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new GetChannelRequest()) + ->setName($formattedName); + try { + $gapicClient->getChannel($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 getEventTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $executeNow = true; + $expectedResponse = new Event(); + $expectedResponse->setName($name2); + $expectedResponse->setExecuteNow($executeNow); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->eventName('[PROJECT]', '[LOCATION]', '[CHANNEL]', '[EVENT]'); + $request = (new GetEventRequest()) + ->setName($formattedName); + $response = $gapicClient->getEvent($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.video.livestream.v1.LivestreamService/GetEvent', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getEventExceptionTest() + { + $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->eventName('[PROJECT]', '[LOCATION]', '[CHANNEL]', '[EVENT]'); + $request = (new GetEventRequest()) + ->setName($formattedName); + try { + $gapicClient->getEvent($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 getInputTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uri = 'uri116076'; + $expectedResponse = new Input(); + $expectedResponse->setName($name2); + $expectedResponse->setUri($uri); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->inputName('[PROJECT]', '[LOCATION]', '[INPUT]'); + $request = (new GetInputRequest()) + ->setName($formattedName); + $response = $gapicClient->getInput($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.video.livestream.v1.LivestreamService/GetInput', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getInputExceptionTest() + { + $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->inputName('[PROJECT]', '[LOCATION]', '[INPUT]'); + $request = (new GetInputRequest()) + ->setName($formattedName); + try { + $gapicClient->getInput($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 listChannelsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $channelsElement = new Channel(); + $channels = [ + $channelsElement, + ]; + $expectedResponse = new ListChannelsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setChannels($channels); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListChannelsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listChannels($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getChannels()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.livestream.v1.LivestreamService/ListChannels', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listChannelsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListChannelsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listChannels($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 listEventsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $eventsElement = new Event(); + $events = [ + $eventsElement, + ]; + $expectedResponse = new ListEventsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setEvents($events); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new ListEventsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listEvents($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getEvents()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.livestream.v1.LivestreamService/ListEvents', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listEventsExceptionTest() + { + $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->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new ListEventsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listEvents($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 listInputsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $inputsElement = new Input(); + $inputs = [ + $inputsElement, + ]; + $expectedResponse = new ListInputsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setInputs($inputs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListInputsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listInputs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getInputs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.livestream.v1.LivestreamService/ListInputs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listInputsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListInputsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listInputs($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 startChannelTest() + { + $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/startChannelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new ChannelOperationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/startChannelTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new StartChannelRequest()) + ->setName($formattedName); + $response = $gapicClient->startChannel($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.video.livestream.v1.LivestreamService/StartChannel', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/startChannelTest'); + $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 startChannelExceptionTest() + { + $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/startChannelTest'); + $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->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new StartChannelRequest()) + ->setName($formattedName); + $response = $gapicClient->startChannel($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/startChannelTest'); + 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 stopChannelTest() + { + $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/stopChannelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new ChannelOperationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/stopChannelTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new StopChannelRequest()) + ->setName($formattedName); + $response = $gapicClient->stopChannel($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.video.livestream.v1.LivestreamService/StopChannel', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/stopChannelTest'); + $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 stopChannelExceptionTest() + { + $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/stopChannelTest'); + $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->channelName('[PROJECT]', '[LOCATION]', '[CHANNEL]'); + $request = (new StopChannelRequest()) + ->setName($formattedName); + $response = $gapicClient->stopChannel($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/stopChannelTest'); + 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 updateChannelTest() + { + $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/updateChannelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $activeInput = 'activeInput1758551377'; + $expectedResponse = new Channel(); + $expectedResponse->setName($name); + $expectedResponse->setActiveInput($activeInput); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateChannelTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $channel = new Channel(); + $channelOutput = new Output(); + $channel->setOutput($channelOutput); + $request = (new UpdateChannelRequest()) + ->setChannel($channel); + $response = $gapicClient->updateChannel($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.video.livestream.v1.LivestreamService/UpdateChannel', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getChannel(); + $this->assertProtobufEquals($channel, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateChannelTest'); + $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 updateChannelExceptionTest() + { + $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/updateChannelTest'); + $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 + $channel = new Channel(); + $channelOutput = new Output(); + $channel->setOutput($channelOutput); + $request = (new UpdateChannelRequest()) + ->setChannel($channel); + $response = $gapicClient->updateChannel($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateChannelTest'); + 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 updateInputTest() + { + $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/updateInputTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uri = 'uri116076'; + $expectedResponse = new Input(); + $expectedResponse->setName($name); + $expectedResponse->setUri($uri); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateInputTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $input = new Input(); + $request = (new UpdateInputRequest()) + ->setInput($input); + $response = $gapicClient->updateInput($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.video.livestream.v1.LivestreamService/UpdateInput', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getInput(); + $this->assertProtobufEquals($input, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateInputTest'); + $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 updateInputExceptionTest() + { + $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/updateInputTest'); + $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 + $input = new Input(); + $request = (new UpdateInputRequest()) + ->setInput($input); + $response = $gapicClient->updateInput($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateInputTest'); + 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 getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($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.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $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 GetLocationRequest(); + try { + $gapicClient->getLocation($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 listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $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 ListLocationsRequest(); + try { + $gapicClient->listLocations($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 createChannelAsyncTest() + { + $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/createChannelTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $activeInput = 'activeInput1758551377'; + $expectedResponse = new Channel(); + $expectedResponse->setName($name); + $expectedResponse->setActiveInput($activeInput); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createChannelTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $channel = new Channel(); + $channelOutput = new Output(); + $channel->setOutput($channelOutput); + $channelId = 'channelId-1930808873'; + $request = (new CreateChannelRequest()) + ->setParent($formattedParent) + ->setChannel($channel) + ->setChannelId($channelId); + $response = $gapicClient->createChannelAsync($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.video.livestream.v1.LivestreamService/CreateChannel', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getChannel(); + $this->assertProtobufEquals($channel, $actualValue); + $actualValue = $actualApiRequestObject->getChannelId(); + $this->assertProtobufEquals($channelId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createChannelTest'); + $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/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_cdn_key.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_cdn_key.php index be91ccc209ed..3e267a8c6872 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_cdn_key.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_cdn_key.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\Video\Stitcher\V1\CdnKey; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\CreateCdnKeyRequest; use Google\Rpc\Status; /** @@ -47,13 +48,17 @@ function create_cdn_key_sample(string $formattedParent, string $cdnKeyId): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $cdnKey = new CdnKey(); + $request = (new CreateCdnKeyRequest()) + ->setParent($formattedParent) + ->setCdnKey($cdnKey) + ->setCdnKeyId($cdnKeyId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $videoStitcherServiceClient->createCdnKey($formattedParent, $cdnKey, $cdnKeyId); + $response = $videoStitcherServiceClient->createCdnKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_live_config.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_live_config.php index f3aa900bc763..a6b9a87a31f1 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_live_config.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_live_config.php @@ -26,8 +26,9 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\Video\Stitcher\V1\AdTracking; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\CreateLiveConfigRequest; use Google\Cloud\Video\Stitcher\V1\LiveConfig; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; use Google\Rpc\Status; /** @@ -52,19 +53,19 @@ function create_live_config_sample( // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $liveConfig = (new LiveConfig()) ->setSourceUri($liveConfigSourceUri) ->setAdTracking($liveConfigAdTracking); + $request = (new CreateLiveConfigRequest()) + ->setParent($formattedParent) + ->setLiveConfigId($liveConfigId) + ->setLiveConfig($liveConfig); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $videoStitcherServiceClient->createLiveConfig( - $formattedParent, - $liveConfigId, - $liveConfig - ); + $response = $videoStitcherServiceClient->createLiveConfig($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_live_session.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_live_session.php index 739fb50cfe43..508472025c67 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_live_session.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_live_session.php @@ -24,8 +24,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_CreateLiveSession_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\CreateLiveSessionRequest; use Google\Cloud\Video\Stitcher\V1\LiveSession; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; /** * Creates a new live session. @@ -44,14 +45,17 @@ function create_live_session_sample( // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $liveSession = (new LiveSession()) ->setLiveConfig($formattedLiveSessionLiveConfig); + $request = (new CreateLiveSessionRequest()) + ->setParent($formattedParent) + ->setLiveSession($liveSession); // Call the API and handle any network failures. try { /** @var LiveSession $response */ - $response = $videoStitcherServiceClient->createLiveSession($formattedParent, $liveSession); + $response = $videoStitcherServiceClient->createLiveSession($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_slate.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_slate.php index 4d8af138aa48..55d58624fc03 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_slate.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_slate.php @@ -25,8 +25,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_CreateSlate_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\CreateSlateRequest; use Google\Cloud\Video\Stitcher\V1\Slate; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; use Google\Rpc\Status; /** @@ -45,13 +46,17 @@ function create_slate_sample(string $formattedParent, string $slateId): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $slate = new Slate(); + $request = (new CreateSlateRequest()) + ->setParent($formattedParent) + ->setSlateId($slateId) + ->setSlate($slate); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $videoStitcherServiceClient->createSlate($formattedParent, $slateId, $slate); + $response = $videoStitcherServiceClient->createSlate($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_vod_session.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_vod_session.php index bfc8b0e8cae2..ebfea24aa549 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_vod_session.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/create_vod_session.php @@ -25,7 +25,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_CreateVodSession_sync] use Google\ApiCore\ApiException; use Google\Cloud\Video\Stitcher\V1\AdTracking; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\CreateVodSessionRequest; use Google\Cloud\Video\Stitcher\V1\VodSession; /** @@ -50,16 +51,19 @@ function create_vod_session_sample( // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $vodSession = (new VodSession()) ->setSourceUri($vodSessionSourceUri) ->setAdTagUri($vodSessionAdTagUri) ->setAdTracking($vodSessionAdTracking); + $request = (new CreateVodSessionRequest()) + ->setParent($formattedParent) + ->setVodSession($vodSession); // Call the API and handle any network failures. try { /** @var VodSession $response */ - $response = $videoStitcherServiceClient->createVodSession($formattedParent, $vodSession); + $response = $videoStitcherServiceClient->createVodSession($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_cdn_key.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_cdn_key.php index 601a8a30f1e3..65ac186c2db7 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_cdn_key.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_cdn_key.php @@ -25,7 +25,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_DeleteCdnKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\DeleteCdnKeyRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_cdn_key_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new DeleteCdnKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $videoStitcherServiceClient->deleteCdnKey($formattedName); + $response = $videoStitcherServiceClient->deleteCdnKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_live_config.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_live_config.php index 2eaecda73950..143782006eee 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_live_config.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_live_config.php @@ -25,7 +25,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_DeleteLiveConfig_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\DeleteLiveConfigRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_live_config_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new DeleteLiveConfigRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $videoStitcherServiceClient->deleteLiveConfig($formattedName); + $response = $videoStitcherServiceClient->deleteLiveConfig($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_slate.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_slate.php index ffe2d475f540..dd47ad9eb371 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_slate.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/delete_slate.php @@ -25,7 +25,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_DeleteSlate_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\DeleteSlateRequest; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function delete_slate_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new DeleteSlateRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $videoStitcherServiceClient->deleteSlate($formattedName); + $response = $videoStitcherServiceClient->deleteSlate($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_cdn_key.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_cdn_key.php index 7b859510cef4..b0d6a1412bb7 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_cdn_key.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_cdn_key.php @@ -25,7 +25,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_GetCdnKey_sync] use Google\ApiCore\ApiException; use Google\Cloud\Video\Stitcher\V1\CdnKey; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetCdnKeyRequest; /** * Returns the specified CDN key. @@ -39,10 +40,14 @@ function get_cdn_key_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new GetCdnKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var CdnKey $response */ - $response = $videoStitcherServiceClient->getCdnKey($formattedName); + $response = $videoStitcherServiceClient->getCdnKey($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_ad_tag_detail.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_ad_tag_detail.php index 91b3c5ae9862..47973de8261f 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_ad_tag_detail.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_ad_tag_detail.php @@ -24,8 +24,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_GetLiveAdTagDetail_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetLiveAdTagDetailRequest; use Google\Cloud\Video\Stitcher\V1\LiveAdTagDetail; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; /** * Returns the specified ad tag detail for the specified live session. @@ -39,10 +40,14 @@ function get_live_ad_tag_detail_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new GetLiveAdTagDetailRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var LiveAdTagDetail $response */ - $response = $videoStitcherServiceClient->getLiveAdTagDetail($formattedName); + $response = $videoStitcherServiceClient->getLiveAdTagDetail($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_config.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_config.php index 20bda5f67f4b..dafdbfc5d412 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_config.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_config.php @@ -24,8 +24,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_GetLiveConfig_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetLiveConfigRequest; use Google\Cloud\Video\Stitcher\V1\LiveConfig; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; /** * Returns the specified live config managed by the Video @@ -41,10 +42,14 @@ function get_live_config_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new GetLiveConfigRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var LiveConfig $response */ - $response = $videoStitcherServiceClient->getLiveConfig($formattedName); + $response = $videoStitcherServiceClient->getLiveConfig($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_session.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_session.php index fa5d04aa3b75..af1c4107d1bb 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_session.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_live_session.php @@ -24,8 +24,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_GetLiveSession_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetLiveSessionRequest; use Google\Cloud\Video\Stitcher\V1\LiveSession; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; /** * Returns the details for the specified live session. @@ -39,10 +40,14 @@ function get_live_session_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new GetLiveSessionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var LiveSession $response */ - $response = $videoStitcherServiceClient->getLiveSession($formattedName); + $response = $videoStitcherServiceClient->getLiveSession($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_slate.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_slate.php index 3a64f751c444..e2ce964a97ed 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_slate.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_slate.php @@ -24,8 +24,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_GetSlate_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetSlateRequest; use Google\Cloud\Video\Stitcher\V1\Slate; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; /** * Returns the specified slate. @@ -39,10 +40,14 @@ function get_slate_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new GetSlateRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Slate $response */ - $response = $videoStitcherServiceClient->getSlate($formattedName); + $response = $videoStitcherServiceClient->getSlate($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_ad_tag_detail.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_ad_tag_detail.php index d28ac6c5dfa6..f6792cfb8d20 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_ad_tag_detail.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_ad_tag_detail.php @@ -24,7 +24,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_GetVodAdTagDetail_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetVodAdTagDetailRequest; use Google\Cloud\Video\Stitcher\V1\VodAdTagDetail; /** @@ -40,10 +41,14 @@ function get_vod_ad_tag_detail_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new GetVodAdTagDetailRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var VodAdTagDetail $response */ - $response = $videoStitcherServiceClient->getVodAdTagDetail($formattedName); + $response = $videoStitcherServiceClient->getVodAdTagDetail($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_session.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_session.php index 8f4ca6d138ff..686eddbc9153 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_session.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_session.php @@ -24,7 +24,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_GetVodSession_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetVodSessionRequest; use Google\Cloud\Video\Stitcher\V1\VodSession; /** @@ -40,10 +41,14 @@ function get_vod_session_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new GetVodSessionRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var VodSession $response */ - $response = $videoStitcherServiceClient->getVodSession($formattedName); + $response = $videoStitcherServiceClient->getVodSession($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_stitch_detail.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_stitch_detail.php index d850e7f70348..9a8d1e2e1398 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_stitch_detail.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/get_vod_stitch_detail.php @@ -24,7 +24,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_GetVodStitchDetail_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetVodStitchDetailRequest; use Google\Cloud\Video\Stitcher\V1\VodStitchDetail; /** @@ -40,10 +41,14 @@ function get_vod_stitch_detail_sample(string $formattedName): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new GetVodStitchDetailRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var VodStitchDetail $response */ - $response = $videoStitcherServiceClient->getVodStitchDetail($formattedName); + $response = $videoStitcherServiceClient->getVodStitchDetail($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/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_cdn_keys.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_cdn_keys.php index 6910d9c3e4a4..d0b3865a5a9c 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_cdn_keys.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_cdn_keys.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; use Google\Cloud\Video\Stitcher\V1\CdnKey; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\ListCdnKeysRequest; /** * Lists all CDN keys in the specified project and location. @@ -40,10 +41,14 @@ function list_cdn_keys_sample(string $formattedParent): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new ListCdnKeysRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $videoStitcherServiceClient->listCdnKeys($formattedParent); + $response = $videoStitcherServiceClient->listCdnKeys($request); /** @var CdnKey $element */ foreach ($response as $element) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_live_ad_tag_details.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_live_ad_tag_details.php index efd99171c1eb..ef44d8db8c0b 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_live_ad_tag_details.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_live_ad_tag_details.php @@ -25,8 +25,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_ListLiveAdTagDetails_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\ListLiveAdTagDetailsRequest; use Google\Cloud\Video\Stitcher\V1\LiveAdTagDetail; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; /** * Return the list of ad tag details for the specified live session. @@ -40,10 +41,14 @@ function list_live_ad_tag_details_sample(string $formattedParent): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new ListLiveAdTagDetailsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $videoStitcherServiceClient->listLiveAdTagDetails($formattedParent); + $response = $videoStitcherServiceClient->listLiveAdTagDetails($request); /** @var LiveAdTagDetail $element */ foreach ($response as $element) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_live_configs.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_live_configs.php index d0d67bc3f409..d0429815bf4b 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_live_configs.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_live_configs.php @@ -25,8 +25,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_ListLiveConfigs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\ListLiveConfigsRequest; use Google\Cloud\Video\Stitcher\V1\LiveConfig; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; /** * Lists all live configs managed by the Video Stitcher that @@ -41,10 +42,14 @@ function list_live_configs_sample(string $formattedParent): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new ListLiveConfigsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $videoStitcherServiceClient->listLiveConfigs($formattedParent); + $response = $videoStitcherServiceClient->listLiveConfigs($request); /** @var LiveConfig $element */ foreach ($response as $element) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_slates.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_slates.php index fcd9bfaf9e56..76d16281b7ff 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_slates.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_slates.php @@ -25,8 +25,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_ListSlates_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\ListSlatesRequest; use Google\Cloud\Video\Stitcher\V1\Slate; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; /** * Lists all slates in the specified project and location. @@ -40,10 +41,14 @@ function list_slates_sample(string $formattedParent): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new ListSlatesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $videoStitcherServiceClient->listSlates($formattedParent); + $response = $videoStitcherServiceClient->listSlates($request); /** @var Slate $element */ foreach ($response as $element) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_vod_ad_tag_details.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_vod_ad_tag_details.php index cf01422ed62a..46209f887a61 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_vod_ad_tag_details.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_vod_ad_tag_details.php @@ -25,7 +25,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_ListVodAdTagDetails_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\ListVodAdTagDetailsRequest; use Google\Cloud\Video\Stitcher\V1\VodAdTagDetail; /** @@ -40,10 +41,14 @@ function list_vod_ad_tag_details_sample(string $formattedParent): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new ListVodAdTagDetailsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $videoStitcherServiceClient->listVodAdTagDetails($formattedParent); + $response = $videoStitcherServiceClient->listVodAdTagDetails($request); /** @var VodAdTagDetail $element */ foreach ($response as $element) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_vod_stitch_details.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_vod_stitch_details.php index 6e09b474af54..f7daf5c5342f 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_vod_stitch_details.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/list_vod_stitch_details.php @@ -25,7 +25,8 @@ // [START videostitcher_v1_generated_VideoStitcherService_ListVodStitchDetails_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\ListVodStitchDetailsRequest; use Google\Cloud\Video\Stitcher\V1\VodStitchDetail; /** @@ -41,10 +42,14 @@ function list_vod_stitch_details_sample(string $formattedParent): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); + // Prepare the request message. + $request = (new ListVodStitchDetailsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $videoStitcherServiceClient->listVodStitchDetails($formattedParent); + $response = $videoStitcherServiceClient->listVodStitchDetails($request); /** @var VodStitchDetail $element */ foreach ($response as $element) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/update_cdn_key.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/update_cdn_key.php index 0bcdadd3bd73..53da153f4d44 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/update_cdn_key.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/update_cdn_key.php @@ -26,7 +26,8 @@ use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; use Google\Cloud\Video\Stitcher\V1\CdnKey; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\UpdateCdnKeyRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -45,14 +46,17 @@ function update_cdn_key_sample(): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $cdnKey = new CdnKey(); $updateMask = new FieldMask(); + $request = (new UpdateCdnKeyRequest()) + ->setCdnKey($cdnKey) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $videoStitcherServiceClient->updateCdnKey($cdnKey, $updateMask); + $response = $videoStitcherServiceClient->updateCdnKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoStitcher/samples/V1/VideoStitcherServiceClient/update_slate.php b/VideoStitcher/samples/V1/VideoStitcherServiceClient/update_slate.php index f087df9914a2..2719f2f2bfe7 100644 --- a/VideoStitcher/samples/V1/VideoStitcherServiceClient/update_slate.php +++ b/VideoStitcher/samples/V1/VideoStitcherServiceClient/update_slate.php @@ -25,8 +25,9 @@ // [START videostitcher_v1_generated_VideoStitcherService_UpdateSlate_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; use Google\Cloud\Video\Stitcher\V1\Slate; -use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\UpdateSlateRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -44,14 +45,17 @@ function update_slate_sample(): void // Create a client. $videoStitcherServiceClient = new VideoStitcherServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $slate = new Slate(); $updateMask = new FieldMask(); + $request = (new UpdateSlateRequest()) + ->setSlate($slate) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $videoStitcherServiceClient->updateSlate($slate, $updateMask); + $response = $videoStitcherServiceClient->updateSlate($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VideoStitcher/src/V1/Client/BaseClient/VideoStitcherServiceBaseClient.php b/VideoStitcher/src/V1/Client/BaseClient/VideoStitcherServiceBaseClient.php new file mode 100644 index 000000000000..d2727fa68c36 --- /dev/null +++ b/VideoStitcher/src/V1/Client/BaseClient/VideoStitcherServiceBaseClient.php @@ -0,0 +1,1052 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/video_stitcher_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/video_stitcher_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/video_stitcher_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/video_stitcher_service_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 cdn_key + * resource. + * + * @param string $project + * @param string $location + * @param string $cdnKey + * + * @return string The formatted cdn_key resource. + */ + public static function cdnKeyName(string $project, string $location, string $cdnKey): string + { + return self::getPathTemplate('cdnKey')->render([ + 'project' => $project, + 'location' => $location, + 'cdn_key' => $cdnKey, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * live_ad_tag_detail resource. + * + * @param string $project + * @param string $location + * @param string $liveSession + * @param string $liveAdTagDetail + * + * @return string The formatted live_ad_tag_detail resource. + */ + public static function liveAdTagDetailName(string $project, string $location, string $liveSession, string $liveAdTagDetail): string + { + return self::getPathTemplate('liveAdTagDetail')->render([ + 'project' => $project, + 'location' => $location, + 'live_session' => $liveSession, + 'live_ad_tag_detail' => $liveAdTagDetail, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a live_config + * resource. + * + * @param string $project + * @param string $location + * @param string $liveConfig + * + * @return string The formatted live_config resource. + */ + public static function liveConfigName(string $project, string $location, string $liveConfig): string + { + return self::getPathTemplate('liveConfig')->render([ + 'project' => $project, + 'location' => $location, + 'live_config' => $liveConfig, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a live_session + * resource. + * + * @param string $project + * @param string $location + * @param string $liveSession + * + * @return string The formatted live_session resource. + */ + public static function liveSessionName(string $project, string $location, string $liveSession): string + { + return self::getPathTemplate('liveSession')->render([ + 'project' => $project, + 'location' => $location, + 'live_session' => $liveSession, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a slate + * resource. + * + * @param string $project + * @param string $location + * @param string $slate + * + * @return string The formatted slate resource. + */ + public static function slateName(string $project, string $location, string $slate): string + { + return self::getPathTemplate('slate')->render([ + 'project' => $project, + 'location' => $location, + 'slate' => $slate, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * vod_ad_tag_detail resource. + * + * @param string $project + * @param string $location + * @param string $vodSession + * @param string $vodAdTagDetail + * + * @return string The formatted vod_ad_tag_detail resource. + */ + public static function vodAdTagDetailName(string $project, string $location, string $vodSession, string $vodAdTagDetail): string + { + return self::getPathTemplate('vodAdTagDetail')->render([ + 'project' => $project, + 'location' => $location, + 'vod_session' => $vodSession, + 'vod_ad_tag_detail' => $vodAdTagDetail, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a vod_session + * resource. + * + * @param string $project + * @param string $location + * @param string $vodSession + * + * @return string The formatted vod_session resource. + */ + public static function vodSessionName(string $project, string $location, string $vodSession): string + { + return self::getPathTemplate('vodSession')->render([ + 'project' => $project, + 'location' => $location, + 'vod_session' => $vodSession, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * vod_stitch_detail resource. + * + * @param string $project + * @param string $location + * @param string $vodSession + * @param string $vodStitchDetail + * + * @return string The formatted vod_stitch_detail resource. + */ + public static function vodStitchDetailName(string $project, string $location, string $vodSession, string $vodStitchDetail): string + { + return self::getPathTemplate('vodStitchDetail')->render([ + 'project' => $project, + 'location' => $location, + 'vod_session' => $vodSession, + 'vod_stitch_detail' => $vodStitchDetail, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - cdnKey: projects/{project}/locations/{location}/cdnKeys/{cdn_key} + * - liveAdTagDetail: projects/{project}/locations/{location}/liveSessions/{live_session}/liveAdTagDetails/{live_ad_tag_detail} + * - liveConfig: projects/{project}/locations/{location}/liveConfigs/{live_config} + * - liveSession: projects/{project}/locations/{location}/liveSessions/{live_session} + * - location: projects/{project}/locations/{location} + * - slate: projects/{project}/locations/{location}/slates/{slate} + * - vodAdTagDetail: projects/{project}/locations/{location}/vodSessions/{vod_session}/vodAdTagDetails/{vod_ad_tag_detail} + * - vodSession: projects/{project}/locations/{location}/vodSessions/{vod_session} + * - vodStitchDetail: projects/{project}/locations/{location}/vodSessions/{vod_session}/vodStitchDetails/{vod_stitch_detail} + * + * 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 'videostitcher.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 CDN key. + * + * The async variant is {@see self::createCdnKeyAsync()} . + * + * @param CreateCdnKeyRequest $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 createCdnKey(CreateCdnKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateCdnKey', $request, $callOptions)->wait(); + } + + /** + * Registers the live config with the provided unique ID in + * the specified region. + * + * The async variant is {@see self::createLiveConfigAsync()} . + * + * @param CreateLiveConfigRequest $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 createLiveConfig(CreateLiveConfigRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateLiveConfig', $request, $callOptions)->wait(); + } + + /** + * Creates a new live session. + * + * The async variant is {@see self::createLiveSessionAsync()} . + * + * @param CreateLiveSessionRequest $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 LiveSession + * + * @throws ApiException Thrown if the API call fails. + */ + public function createLiveSession(CreateLiveSessionRequest $request, array $callOptions = []): LiveSession + { + return $this->startApiCall('CreateLiveSession', $request, $callOptions)->wait(); + } + + /** + * Creates a slate. + * + * The async variant is {@see self::createSlateAsync()} . + * + * @param CreateSlateRequest $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 createSlate(CreateSlateRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateSlate', $request, $callOptions)->wait(); + } + + /** + * Creates a client side playback VOD session and returns the full + * tracking and playback metadata of the session. + * + * The async variant is {@see self::createVodSessionAsync()} . + * + * @param CreateVodSessionRequest $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 VodSession + * + * @throws ApiException Thrown if the API call fails. + */ + public function createVodSession(CreateVodSessionRequest $request, array $callOptions = []): VodSession + { + return $this->startApiCall('CreateVodSession', $request, $callOptions)->wait(); + } + + /** + * Deletes the specified CDN key. + * + * The async variant is {@see self::deleteCdnKeyAsync()} . + * + * @param DeleteCdnKeyRequest $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 deleteCdnKey(DeleteCdnKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteCdnKey', $request, $callOptions)->wait(); + } + + /** + * Deletes the specified live config. + * + * The async variant is {@see self::deleteLiveConfigAsync()} . + * + * @param DeleteLiveConfigRequest $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 deleteLiveConfig(DeleteLiveConfigRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteLiveConfig', $request, $callOptions)->wait(); + } + + /** + * Deletes the specified slate. + * + * The async variant is {@see self::deleteSlateAsync()} . + * + * @param DeleteSlateRequest $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 deleteSlate(DeleteSlateRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteSlate', $request, $callOptions)->wait(); + } + + /** + * Returns the specified CDN key. + * + * The async variant is {@see self::getCdnKeyAsync()} . + * + * @param GetCdnKeyRequest $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 CdnKey + * + * @throws ApiException Thrown if the API call fails. + */ + public function getCdnKey(GetCdnKeyRequest $request, array $callOptions = []): CdnKey + { + return $this->startApiCall('GetCdnKey', $request, $callOptions)->wait(); + } + + /** + * Returns the specified ad tag detail for the specified live session. + * + * The async variant is {@see self::getLiveAdTagDetailAsync()} . + * + * @param GetLiveAdTagDetailRequest $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 LiveAdTagDetail + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLiveAdTagDetail(GetLiveAdTagDetailRequest $request, array $callOptions = []): LiveAdTagDetail + { + return $this->startApiCall('GetLiveAdTagDetail', $request, $callOptions)->wait(); + } + + /** + * Returns the specified live config managed by the Video + * Stitcher service. + * + * The async variant is {@see self::getLiveConfigAsync()} . + * + * @param GetLiveConfigRequest $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 LiveConfig + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLiveConfig(GetLiveConfigRequest $request, array $callOptions = []): LiveConfig + { + return $this->startApiCall('GetLiveConfig', $request, $callOptions)->wait(); + } + + /** + * Returns the details for the specified live session. + * + * The async variant is {@see self::getLiveSessionAsync()} . + * + * @param GetLiveSessionRequest $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 LiveSession + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLiveSession(GetLiveSessionRequest $request, array $callOptions = []): LiveSession + { + return $this->startApiCall('GetLiveSession', $request, $callOptions)->wait(); + } + + /** + * Returns the specified slate. + * + * The async variant is {@see self::getSlateAsync()} . + * + * @param GetSlateRequest $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 Slate + * + * @throws ApiException Thrown if the API call fails. + */ + public function getSlate(GetSlateRequest $request, array $callOptions = []): Slate + { + return $this->startApiCall('GetSlate', $request, $callOptions)->wait(); + } + + /** + * Returns the specified ad tag detail for the specified VOD session. + * + * The async variant is {@see self::getVodAdTagDetailAsync()} . + * + * @param GetVodAdTagDetailRequest $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 VodAdTagDetail + * + * @throws ApiException Thrown if the API call fails. + */ + public function getVodAdTagDetail(GetVodAdTagDetailRequest $request, array $callOptions = []): VodAdTagDetail + { + return $this->startApiCall('GetVodAdTagDetail', $request, $callOptions)->wait(); + } + + /** + * Returns the full tracking, playback metadata, and relevant ad-ops + * logs for the specified VOD session. + * + * The async variant is {@see self::getVodSessionAsync()} . + * + * @param GetVodSessionRequest $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 VodSession + * + * @throws ApiException Thrown if the API call fails. + */ + public function getVodSession(GetVodSessionRequest $request, array $callOptions = []): VodSession + { + return $this->startApiCall('GetVodSession', $request, $callOptions)->wait(); + } + + /** + * Returns the specified stitching information for the specified VOD session. + * + * The async variant is {@see self::getVodStitchDetailAsync()} . + * + * @param GetVodStitchDetailRequest $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 VodStitchDetail + * + * @throws ApiException Thrown if the API call fails. + */ + public function getVodStitchDetail(GetVodStitchDetailRequest $request, array $callOptions = []): VodStitchDetail + { + return $this->startApiCall('GetVodStitchDetail', $request, $callOptions)->wait(); + } + + /** + * Lists all CDN keys in the specified project and location. + * + * The async variant is {@see self::listCdnKeysAsync()} . + * + * @param ListCdnKeysRequest $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 listCdnKeys(ListCdnKeysRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCdnKeys', $request, $callOptions); + } + + /** + * Return the list of ad tag details for the specified live session. + * + * The async variant is {@see self::listLiveAdTagDetailsAsync()} . + * + * @param ListLiveAdTagDetailsRequest $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 listLiveAdTagDetails(ListLiveAdTagDetailsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLiveAdTagDetails', $request, $callOptions); + } + + /** + * Lists all live configs managed by the Video Stitcher that + * belong to the specified project and region. + * + * The async variant is {@see self::listLiveConfigsAsync()} . + * + * @param ListLiveConfigsRequest $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 listLiveConfigs(ListLiveConfigsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLiveConfigs', $request, $callOptions); + } + + /** + * Lists all slates in the specified project and location. + * + * The async variant is {@see self::listSlatesAsync()} . + * + * @param ListSlatesRequest $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 listSlates(ListSlatesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListSlates', $request, $callOptions); + } + + /** + * Return the list of ad tag details for the specified VOD session. + * + * The async variant is {@see self::listVodAdTagDetailsAsync()} . + * + * @param ListVodAdTagDetailsRequest $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 listVodAdTagDetails(ListVodAdTagDetailsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListVodAdTagDetails', $request, $callOptions); + } + + /** + * Returns a list of detailed stitching information of the specified VOD + * session. + * + * The async variant is {@see self::listVodStitchDetailsAsync()} . + * + * @param ListVodStitchDetailsRequest $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 listVodStitchDetails(ListVodStitchDetailsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListVodStitchDetails', $request, $callOptions); + } + + /** + * Updates the specified CDN key. Only update fields specified + * in the call method body. + * + * The async variant is {@see self::updateCdnKeyAsync()} . + * + * @param UpdateCdnKeyRequest $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 updateCdnKey(UpdateCdnKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateCdnKey', $request, $callOptions)->wait(); + } + + /** + * Updates the specified slate. + * + * The async variant is {@see self::updateSlateAsync()} . + * + * @param UpdateSlateRequest $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 updateSlate(UpdateSlateRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateSlate', $request, $callOptions)->wait(); + } +} diff --git a/VideoStitcher/src/V1/Client/VideoStitcherServiceClient.php b/VideoStitcher/src/V1/Client/VideoStitcherServiceClient.php new file mode 100644 index 000000000000..214ff555e8fc --- /dev/null +++ b/VideoStitcher/src/V1/Client/VideoStitcherServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setCdnKey($cdnKey) + ->setCdnKeyId($cdnKeyId); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/CreateLiveConfigRequest.php b/VideoStitcher/src/V1/CreateLiveConfigRequest.php index 388981f3c104..e671a7c3b2b8 100644 --- a/VideoStitcher/src/V1/CreateLiveConfigRequest.php +++ b/VideoStitcher/src/V1/CreateLiveConfigRequest.php @@ -51,6 +51,25 @@ class CreateLiveConfigRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The project in which the live config should be created, in + * the form of `projects/{project_number}/locations/{location}`. Please see + * {@see VideoStitcherServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Video\Stitcher\V1\LiveConfig $liveConfig Required. The live config resource to create. + * @param string $liveConfigId Required. The unique identifier ID to use for the live config. + * + * @return \Google\Cloud\Video\Stitcher\V1\CreateLiveConfigRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Video\Stitcher\V1\LiveConfig $liveConfig, string $liveConfigId): self + { + return (new self()) + ->setParent($parent) + ->setLiveConfig($liveConfig) + ->setLiveConfigId($liveConfigId); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/CreateLiveSessionRequest.php b/VideoStitcher/src/V1/CreateLiveSessionRequest.php index 022884962630..45e9728e284b 100644 --- a/VideoStitcher/src/V1/CreateLiveSessionRequest.php +++ b/VideoStitcher/src/V1/CreateLiveSessionRequest.php @@ -29,6 +29,23 @@ class CreateLiveSessionRequest extends \Google\Protobuf\Internal\Message */ private $live_session = null; + /** + * @param string $parent Required. The project and location in which the live session should be + * created, in the form of `projects/{project_number}/locations/{location}`. Please see + * {@see VideoStitcherServiceClient::liveSessionName()} for help formatting this field. + * @param \Google\Cloud\Video\Stitcher\V1\LiveSession $liveSession Required. Parameters for creating a live session. + * + * @return \Google\Cloud\Video\Stitcher\V1\CreateLiveSessionRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Video\Stitcher\V1\LiveSession $liveSession): self + { + return (new self()) + ->setParent($parent) + ->setLiveSession($liveSession); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/CreateSlateRequest.php b/VideoStitcher/src/V1/CreateSlateRequest.php index 7390a6cb510a..845a3b79ddb2 100644 --- a/VideoStitcher/src/V1/CreateSlateRequest.php +++ b/VideoStitcher/src/V1/CreateSlateRequest.php @@ -54,6 +54,28 @@ class CreateSlateRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The project in which the slate should be created, in the form of + * `projects/{project_number}/locations/{location}`. Please see + * {@see VideoStitcherServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Video\Stitcher\V1\Slate $slate Required. The slate to create. + * @param string $slateId Required. The unique identifier for the slate. + * This value should conform to RFC-1034, which restricts to + * lower-case letters, numbers, and hyphen, with the first character a + * letter, the last a letter or a number, and a 63 character maximum. + * + * @return \Google\Cloud\Video\Stitcher\V1\CreateSlateRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Video\Stitcher\V1\Slate $slate, string $slateId): self + { + return (new self()) + ->setParent($parent) + ->setSlate($slate) + ->setSlateId($slateId); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/CreateVodSessionRequest.php b/VideoStitcher/src/V1/CreateVodSessionRequest.php index da245761764a..58359f704c24 100644 --- a/VideoStitcher/src/V1/CreateVodSessionRequest.php +++ b/VideoStitcher/src/V1/CreateVodSessionRequest.php @@ -29,6 +29,23 @@ class CreateVodSessionRequest extends \Google\Protobuf\Internal\Message */ private $vod_session = null; + /** + * @param string $parent Required. The project and location in which the VOD session should be + * created, in the form of `projects/{project_number}/locations/{location}`. Please see + * {@see VideoStitcherServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Video\Stitcher\V1\VodSession $vodSession Required. Parameters for creating a session. + * + * @return \Google\Cloud\Video\Stitcher\V1\CreateVodSessionRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Video\Stitcher\V1\VodSession $vodSession): self + { + return (new self()) + ->setParent($parent) + ->setVodSession($vodSession); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/DeleteCdnKeyRequest.php b/VideoStitcher/src/V1/DeleteCdnKeyRequest.php index 5b55c4e683c9..04ac205dd751 100644 --- a/VideoStitcher/src/V1/DeleteCdnKeyRequest.php +++ b/VideoStitcher/src/V1/DeleteCdnKeyRequest.php @@ -23,6 +23,21 @@ class DeleteCdnKeyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the CDN key to be deleted, in the form of + * `projects/{project_number}/locations/{location}/cdnKeys/{id}`. Please see + * {@see VideoStitcherServiceClient::cdnKeyName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\DeleteCdnKeyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/DeleteLiveConfigRequest.php b/VideoStitcher/src/V1/DeleteLiveConfigRequest.php index c8ee068204b7..0f7bdbb7cb85 100644 --- a/VideoStitcher/src/V1/DeleteLiveConfigRequest.php +++ b/VideoStitcher/src/V1/DeleteLiveConfigRequest.php @@ -23,6 +23,21 @@ class DeleteLiveConfigRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the live config to be deleted, in the form of + * `projects/{project_number}/locations/{location}/liveConfigs/{id}`. Please see + * {@see VideoStitcherServiceClient::liveConfigName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\DeleteLiveConfigRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/DeleteSlateRequest.php b/VideoStitcher/src/V1/DeleteSlateRequest.php index 1dcf21111b5a..437df519ed4f 100644 --- a/VideoStitcher/src/V1/DeleteSlateRequest.php +++ b/VideoStitcher/src/V1/DeleteSlateRequest.php @@ -23,6 +23,21 @@ class DeleteSlateRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the slate to be deleted, in the form of + * `projects/{project_number}/locations/{location}/slates/{id}`. Please see + * {@see VideoStitcherServiceClient::slateName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\DeleteSlateRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/GetCdnKeyRequest.php b/VideoStitcher/src/V1/GetCdnKeyRequest.php index 68b97e09d375..f78de1642919 100644 --- a/VideoStitcher/src/V1/GetCdnKeyRequest.php +++ b/VideoStitcher/src/V1/GetCdnKeyRequest.php @@ -23,6 +23,21 @@ class GetCdnKeyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the CDN key to be retrieved, in the form of + * `projects/{project}/locations/{location}/cdnKeys/{id}`. Please see + * {@see VideoStitcherServiceClient::cdnKeyName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\GetCdnKeyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/GetLiveAdTagDetailRequest.php b/VideoStitcher/src/V1/GetLiveAdTagDetailRequest.php index b1ce1baa454c..5bd3a1300331 100644 --- a/VideoStitcher/src/V1/GetLiveAdTagDetailRequest.php +++ b/VideoStitcher/src/V1/GetLiveAdTagDetailRequest.php @@ -23,6 +23,21 @@ class GetLiveAdTagDetailRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name in the form of + * `projects/{project}/locations/{location}/liveSessions/{live_session}/liveAdTagDetails/{live_ad_tag_detail}`. Please see + * {@see VideoStitcherServiceClient::liveAdTagDetailName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\GetLiveAdTagDetailRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/GetLiveConfigRequest.php b/VideoStitcher/src/V1/GetLiveConfigRequest.php index 6f627987d681..7dbf9566b48e 100644 --- a/VideoStitcher/src/V1/GetLiveConfigRequest.php +++ b/VideoStitcher/src/V1/GetLiveConfigRequest.php @@ -24,6 +24,22 @@ class GetLiveConfigRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the live config to be retrieved, in the form + * of + * `projects/{project_number}/locations/{location}/liveConfigs/{id}`. Please see + * {@see VideoStitcherServiceClient::liveConfigName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\GetLiveConfigRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/GetLiveSessionRequest.php b/VideoStitcher/src/V1/GetLiveSessionRequest.php index 9e4bf9bfff86..d88b2d2e390e 100644 --- a/VideoStitcher/src/V1/GetLiveSessionRequest.php +++ b/VideoStitcher/src/V1/GetLiveSessionRequest.php @@ -23,6 +23,21 @@ class GetLiveSessionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the live session, in the form of + * `projects/{project_number}/locations/{location}/liveSessions/{id}`. Please see + * {@see VideoStitcherServiceClient::liveSessionName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\GetLiveSessionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/GetSlateRequest.php b/VideoStitcher/src/V1/GetSlateRequest.php index 06d635327f90..d5957f235281 100644 --- a/VideoStitcher/src/V1/GetSlateRequest.php +++ b/VideoStitcher/src/V1/GetSlateRequest.php @@ -23,6 +23,21 @@ class GetSlateRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the slate to be retrieved, of the slate, in the form + * of `projects/{project_number}/locations/{location}/slates/{id}`. Please see + * {@see VideoStitcherServiceClient::slateName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\GetSlateRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/GetVodAdTagDetailRequest.php b/VideoStitcher/src/V1/GetVodAdTagDetailRequest.php index ccba25b0e9c2..3aa557f76085 100644 --- a/VideoStitcher/src/V1/GetVodAdTagDetailRequest.php +++ b/VideoStitcher/src/V1/GetVodAdTagDetailRequest.php @@ -24,6 +24,22 @@ class GetVodAdTagDetailRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the ad tag detail for the specified VOD session, in + * the form of + * `projects/{project}/locations/{location}/vodSessions/{vod_session_id}/vodAdTagDetails/{vod_ad_tag_detail}`. Please see + * {@see VideoStitcherServiceClient::vodAdTagDetailName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\GetVodAdTagDetailRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/GetVodSessionRequest.php b/VideoStitcher/src/V1/GetVodSessionRequest.php index b65578927658..16f44a83b203 100644 --- a/VideoStitcher/src/V1/GetVodSessionRequest.php +++ b/VideoStitcher/src/V1/GetVodSessionRequest.php @@ -23,6 +23,21 @@ class GetVodSessionRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the VOD session to be retrieved, in the form of + * `projects/{project_number}/locations/{location}/vodSessions/{id}`. Please see + * {@see VideoStitcherServiceClient::vodSessionName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\GetVodSessionRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/GetVodStitchDetailRequest.php b/VideoStitcher/src/V1/GetVodStitchDetailRequest.php index df418877aa51..0c9eeaf552e0 100644 --- a/VideoStitcher/src/V1/GetVodStitchDetailRequest.php +++ b/VideoStitcher/src/V1/GetVodStitchDetailRequest.php @@ -24,6 +24,22 @@ class GetVodStitchDetailRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the stitch detail in the specified VOD session, in + * the form of + * `projects/{project}/locations/{location}/vodSessions/{vod_session_id}/vodStitchDetails/{id}`. Please see + * {@see VideoStitcherServiceClient::vodStitchDetailName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\GetVodStitchDetailRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/ListCdnKeysRequest.php b/VideoStitcher/src/V1/ListCdnKeysRequest.php index 17081a6fe6c0..4c7932ca3de9 100644 --- a/VideoStitcher/src/V1/ListCdnKeysRequest.php +++ b/VideoStitcher/src/V1/ListCdnKeysRequest.php @@ -48,6 +48,21 @@ class ListCdnKeysRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The project that contains the list of CDN keys, in the form of + * `projects/{project_number}/locations/{location}`. Please see + * {@see VideoStitcherServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\ListCdnKeysRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/ListLiveAdTagDetailsRequest.php b/VideoStitcher/src/V1/ListLiveAdTagDetailsRequest.php index 233c430e7a6f..f96388f33907 100644 --- a/VideoStitcher/src/V1/ListLiveAdTagDetailsRequest.php +++ b/VideoStitcher/src/V1/ListLiveAdTagDetailsRequest.php @@ -35,6 +35,21 @@ class ListLiveAdTagDetailsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The resource parent in the form of + * `projects/{project}/locations/{location}/liveSessions/{live_session}`. Please see + * {@see VideoStitcherServiceClient::liveSessionName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\ListLiveAdTagDetailsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/ListLiveConfigsRequest.php b/VideoStitcher/src/V1/ListLiveConfigsRequest.php index 899ad31adfb1..0ce2387ce32f 100644 --- a/VideoStitcher/src/V1/ListLiveConfigsRequest.php +++ b/VideoStitcher/src/V1/ListLiveConfigsRequest.php @@ -50,6 +50,21 @@ class ListLiveConfigsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The project that contains the list of live configs, in the + * form of `projects/{project_number}/locations/{location}`. Please see + * {@see VideoStitcherServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\ListLiveConfigsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/ListSlatesRequest.php b/VideoStitcher/src/V1/ListSlatesRequest.php index 0d43d4935e6e..95f26c7b6eca 100644 --- a/VideoStitcher/src/V1/ListSlatesRequest.php +++ b/VideoStitcher/src/V1/ListSlatesRequest.php @@ -48,6 +48,21 @@ class ListSlatesRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The project to list slates, in the form of + * `projects/{project_number}/locations/{location}`. Please see + * {@see VideoStitcherServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\ListSlatesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/ListVodAdTagDetailsRequest.php b/VideoStitcher/src/V1/ListVodAdTagDetailsRequest.php index c5b89683c781..0374515917d0 100644 --- a/VideoStitcher/src/V1/ListVodAdTagDetailsRequest.php +++ b/VideoStitcher/src/V1/ListVodAdTagDetailsRequest.php @@ -35,6 +35,21 @@ class ListVodAdTagDetailsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The VOD session which the ad tag details belong to, in the form + * of `projects/{project}/locations/{location}/vodSessions/{vod_session_id}`. Please see + * {@see VideoStitcherServiceClient::vodSessionName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\ListVodAdTagDetailsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/ListVodStitchDetailsRequest.php b/VideoStitcher/src/V1/ListVodStitchDetailsRequest.php index dff54ff368a8..02607583ec59 100644 --- a/VideoStitcher/src/V1/ListVodStitchDetailsRequest.php +++ b/VideoStitcher/src/V1/ListVodStitchDetailsRequest.php @@ -35,6 +35,21 @@ class ListVodStitchDetailsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The VOD session where the stitch details belong to, in the form + * of `projects/{project}/locations/{location}/vodSessions/{id}`. Please see + * {@see VideoStitcherServiceClient::vodSessionName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Stitcher\V1\ListVodStitchDetailsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/UpdateCdnKeyRequest.php b/VideoStitcher/src/V1/UpdateCdnKeyRequest.php index 40d92c6522cd..cc9ebd244576 100644 --- a/VideoStitcher/src/V1/UpdateCdnKeyRequest.php +++ b/VideoStitcher/src/V1/UpdateCdnKeyRequest.php @@ -30,6 +30,23 @@ class UpdateCdnKeyRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\Video\Stitcher\V1\CdnKey $cdnKey Required. The CDN key resource which replaces the resource on the server. + * @param \Google\Protobuf\FieldMask $updateMask Required. The update mask applies to the resource. + * For the `FieldMask` definition, see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + * + * @return \Google\Cloud\Video\Stitcher\V1\UpdateCdnKeyRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Video\Stitcher\V1\CdnKey $cdnKey, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setCdnKey($cdnKey) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/UpdateSlateRequest.php b/VideoStitcher/src/V1/UpdateSlateRequest.php index e9f80ac4d090..e773dd07452a 100644 --- a/VideoStitcher/src/V1/UpdateSlateRequest.php +++ b/VideoStitcher/src/V1/UpdateSlateRequest.php @@ -28,6 +28,21 @@ class UpdateSlateRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\Video\Stitcher\V1\Slate $slate Required. The resource with updated fields. + * @param \Google\Protobuf\FieldMask $updateMask Required. The update mask which specifies fields which should be updated. + * + * @return \Google\Cloud\Video\Stitcher\V1\UpdateSlateRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Video\Stitcher\V1\Slate $slate, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setSlate($slate) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VideoStitcher/src/V1/resources/video_stitcher_service_descriptor_config.php b/VideoStitcher/src/V1/resources/video_stitcher_service_descriptor_config.php index dfd442554541..a971c38ff6d0 100644 --- a/VideoStitcher/src/V1/resources/video_stitcher_service_descriptor_config.php +++ b/VideoStitcher/src/V1/resources/video_stitcher_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateLiveConfig' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateSlate' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteCdnKey' => [ 'longRunning' => [ @@ -42,6 +69,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteLiveConfig' => [ 'longRunning' => [ @@ -52,6 +88,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteSlate' => [ 'longRunning' => [ @@ -62,6 +107,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateCdnKey' => [ 'longRunning' => [ @@ -72,6 +126,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'cdn_key.name', + 'fieldAccessors' => [ + 'getCdnKey', + 'getName', + ], + ], + ], ], 'UpdateSlate' => [ 'longRunning' => [ @@ -82,6 +146,136 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'slate.name', + 'fieldAccessors' => [ + 'getSlate', + 'getName', + ], + ], + ], + ], + 'CreateLiveSession' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\LiveSession', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateVodSession' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\VodSession', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'GetCdnKey' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\CdnKey', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetLiveAdTagDetail' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\LiveAdTagDetail', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetLiveConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\LiveConfig', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetLiveSession' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\LiveSession', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetSlate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\Slate', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetVodAdTagDetail' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\VodAdTagDetail', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetVodSession' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\VodSession', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetVodStitchDetail' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\VodStitchDetail', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListCdnKeys' => [ 'pageStreaming' => [ @@ -92,6 +286,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getCdnKeys', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\ListCdnKeysResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListLiveAdTagDetails' => [ 'pageStreaming' => [ @@ -102,6 +306,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLiveAdTagDetails', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\ListLiveAdTagDetailsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListLiveConfigs' => [ 'pageStreaming' => [ @@ -112,6 +326,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLiveConfigs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\ListLiveConfigsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListSlates' => [ 'pageStreaming' => [ @@ -122,6 +346,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSlates', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\ListSlatesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListVodAdTagDetails' => [ 'pageStreaming' => [ @@ -132,6 +366,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getVodAdTagDetails', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\ListVodAdTagDetailsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListVodStitchDetails' => [ 'pageStreaming' => [ @@ -142,6 +386,27 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getVodStitchDetails', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\Stitcher\V1\ListVodStitchDetailsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'cdnKey' => 'projects/{project}/locations/{location}/cdnKeys/{cdn_key}', + 'liveAdTagDetail' => 'projects/{project}/locations/{location}/liveSessions/{live_session}/liveAdTagDetails/{live_ad_tag_detail}', + 'liveConfig' => 'projects/{project}/locations/{location}/liveConfigs/{live_config}', + 'liveSession' => 'projects/{project}/locations/{location}/liveSessions/{live_session}', + 'location' => 'projects/{project}/locations/{location}', + 'slate' => 'projects/{project}/locations/{location}/slates/{slate}', + 'vodAdTagDetail' => 'projects/{project}/locations/{location}/vodSessions/{vod_session}/vodAdTagDetails/{vod_ad_tag_detail}', + 'vodSession' => 'projects/{project}/locations/{location}/vodSessions/{vod_session}', + 'vodStitchDetail' => 'projects/{project}/locations/{location}/vodSessions/{vod_session}/vodStitchDetails/{vod_stitch_detail}', ], ], ], diff --git a/VideoStitcher/tests/Unit/V1/Client/VideoStitcherServiceClientTest.php b/VideoStitcher/tests/Unit/V1/Client/VideoStitcherServiceClientTest.php new file mode 100644 index 000000000000..d9f52614ce1e --- /dev/null +++ b/VideoStitcher/tests/Unit/V1/Client/VideoStitcherServiceClientTest.php @@ -0,0 +1,2363 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return VideoStitcherServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new VideoStitcherServiceClient($options); + } + + /** @test */ + public function createCdnKeyTest() + { + $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/createCdnKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $hostname = 'hostname-299803597'; + $expectedResponse = new CdnKey(); + $expectedResponse->setName($name); + $expectedResponse->setHostname($hostname); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCdnKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $cdnKey = new CdnKey(); + $cdnKeyId = 'cdnKeyId1672586061'; + $request = (new CreateCdnKeyRequest()) + ->setParent($formattedParent) + ->setCdnKey($cdnKey) + ->setCdnKeyId($cdnKeyId); + $response = $gapicClient->createCdnKey($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.video.stitcher.v1.VideoStitcherService/CreateCdnKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCdnKey(); + $this->assertProtobufEquals($cdnKey, $actualValue); + $actualValue = $actualApiRequestObject->getCdnKeyId(); + $this->assertProtobufEquals($cdnKeyId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCdnKeyTest'); + $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 createCdnKeyExceptionTest() + { + $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/createCdnKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $cdnKey = new CdnKey(); + $cdnKeyId = 'cdnKeyId1672586061'; + $request = (new CreateCdnKeyRequest()) + ->setParent($formattedParent) + ->setCdnKey($cdnKey) + ->setCdnKeyId($cdnKeyId); + $response = $gapicClient->createCdnKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCdnKeyTest'); + 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 createLiveConfigTest() + { + $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/createLiveConfigTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $sourceUri = 'sourceUri-1111107768'; + $adTagUri = 'adTagUri-1429194965'; + $defaultSlate = 'defaultSlate1316218395'; + $expectedResponse = new LiveConfig(); + $expectedResponse->setName($name); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setAdTagUri($adTagUri); + $expectedResponse->setDefaultSlate($defaultSlate); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createLiveConfigTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $liveConfigId = 'liveConfigId-558267483'; + $liveConfig = new LiveConfig(); + $liveConfigSourceUri = 'liveConfigSourceUri-20192349'; + $liveConfig->setSourceUri($liveConfigSourceUri); + $liveConfigAdTracking = AdTracking::AD_TRACKING_UNSPECIFIED; + $liveConfig->setAdTracking($liveConfigAdTracking); + $request = (new CreateLiveConfigRequest()) + ->setParent($formattedParent) + ->setLiveConfigId($liveConfigId) + ->setLiveConfig($liveConfig); + $response = $gapicClient->createLiveConfig($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.video.stitcher.v1.VideoStitcherService/CreateLiveConfig', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getLiveConfigId(); + $this->assertProtobufEquals($liveConfigId, $actualValue); + $actualValue = $actualApiRequestObject->getLiveConfig(); + $this->assertProtobufEquals($liveConfig, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createLiveConfigTest'); + $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 createLiveConfigExceptionTest() + { + $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/createLiveConfigTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $liveConfigId = 'liveConfigId-558267483'; + $liveConfig = new LiveConfig(); + $liveConfigSourceUri = 'liveConfigSourceUri-20192349'; + $liveConfig->setSourceUri($liveConfigSourceUri); + $liveConfigAdTracking = AdTracking::AD_TRACKING_UNSPECIFIED; + $liveConfig->setAdTracking($liveConfigAdTracking); + $request = (new CreateLiveConfigRequest()) + ->setParent($formattedParent) + ->setLiveConfigId($liveConfigId) + ->setLiveConfig($liveConfig); + $response = $gapicClient->createLiveConfig($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createLiveConfigTest'); + 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 createLiveSessionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $playUri = 'playUri1879098849'; + $liveConfig = 'liveConfig-1498665483'; + $expectedResponse = new LiveSession(); + $expectedResponse->setName($name); + $expectedResponse->setPlayUri($playUri); + $expectedResponse->setLiveConfig($liveConfig); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->liveSessionName('[PROJECT]', '[LOCATION]', '[LIVE_SESSION]'); + $liveSession = new LiveSession(); + $liveSessionLiveConfig = $gapicClient->liveConfigName('[PROJECT]', '[LOCATION]', '[LIVE_CONFIG]'); + $liveSession->setLiveConfig($liveSessionLiveConfig); + $request = (new CreateLiveSessionRequest()) + ->setParent($formattedParent) + ->setLiveSession($liveSession); + $response = $gapicClient->createLiveSession($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.video.stitcher.v1.VideoStitcherService/CreateLiveSession', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getLiveSession(); + $this->assertProtobufEquals($liveSession, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createLiveSessionExceptionTest() + { + $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->liveSessionName('[PROJECT]', '[LOCATION]', '[LIVE_SESSION]'); + $liveSession = new LiveSession(); + $liveSessionLiveConfig = $gapicClient->liveConfigName('[PROJECT]', '[LOCATION]', '[LIVE_CONFIG]'); + $liveSession->setLiveConfig($liveSessionLiveConfig); + $request = (new CreateLiveSessionRequest()) + ->setParent($formattedParent) + ->setLiveSession($liveSession); + try { + $gapicClient->createLiveSession($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 createSlateTest() + { + $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/createSlateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uri = 'uri116076'; + $expectedResponse = new Slate(); + $expectedResponse->setName($name); + $expectedResponse->setUri($uri); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createSlateTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $slateId = 'slateId-1486865023'; + $slate = new Slate(); + $request = (new CreateSlateRequest()) + ->setParent($formattedParent) + ->setSlateId($slateId) + ->setSlate($slate); + $response = $gapicClient->createSlate($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.video.stitcher.v1.VideoStitcherService/CreateSlate', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getSlateId(); + $this->assertProtobufEquals($slateId, $actualValue); + $actualValue = $actualApiRequestObject->getSlate(); + $this->assertProtobufEquals($slate, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createSlateTest'); + $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 createSlateExceptionTest() + { + $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/createSlateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $slateId = 'slateId-1486865023'; + $slate = new Slate(); + $request = (new CreateSlateRequest()) + ->setParent($formattedParent) + ->setSlateId($slateId) + ->setSlate($slate); + $response = $gapicClient->createSlate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createSlateTest'); + 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 createVodSessionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $playUri = 'playUri1879098849'; + $sourceUri = 'sourceUri-1111107768'; + $adTagUri = 'adTagUri-1429194965'; + $assetId = 'assetId-373202742'; + $expectedResponse = new VodSession(); + $expectedResponse->setName($name); + $expectedResponse->setPlayUri($playUri); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setAdTagUri($adTagUri); + $expectedResponse->setAssetId($assetId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $vodSession = new VodSession(); + $vodSessionSourceUri = 'vodSessionSourceUri2085185606'; + $vodSession->setSourceUri($vodSessionSourceUri); + $vodSessionAdTagUri = 'vodSessionAdTagUri-600567328'; + $vodSession->setAdTagUri($vodSessionAdTagUri); + $vodSessionAdTracking = AdTracking::AD_TRACKING_UNSPECIFIED; + $vodSession->setAdTracking($vodSessionAdTracking); + $request = (new CreateVodSessionRequest()) + ->setParent($formattedParent) + ->setVodSession($vodSession); + $response = $gapicClient->createVodSession($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.video.stitcher.v1.VideoStitcherService/CreateVodSession', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getVodSession(); + $this->assertProtobufEquals($vodSession, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createVodSessionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $vodSession = new VodSession(); + $vodSessionSourceUri = 'vodSessionSourceUri2085185606'; + $vodSession->setSourceUri($vodSessionSourceUri); + $vodSessionAdTagUri = 'vodSessionAdTagUri-600567328'; + $vodSession->setAdTagUri($vodSessionAdTagUri); + $vodSessionAdTracking = AdTracking::AD_TRACKING_UNSPECIFIED; + $vodSession->setAdTracking($vodSessionAdTracking); + $request = (new CreateVodSessionRequest()) + ->setParent($formattedParent) + ->setVodSession($vodSession); + try { + $gapicClient->createVodSession($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 deleteCdnKeyTest() + { + $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/deleteCdnKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteCdnKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->cdnKeyName('[PROJECT]', '[LOCATION]', '[CDN_KEY]'); + $request = (new DeleteCdnKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCdnKey($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.video.stitcher.v1.VideoStitcherService/DeleteCdnKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCdnKeyTest'); + $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 deleteCdnKeyExceptionTest() + { + $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/deleteCdnKeyTest'); + $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->cdnKeyName('[PROJECT]', '[LOCATION]', '[CDN_KEY]'); + $request = (new DeleteCdnKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCdnKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteCdnKeyTest'); + 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 deleteLiveConfigTest() + { + $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/deleteLiveConfigTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteLiveConfigTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->liveConfigName('[PROJECT]', '[LOCATION]', '[LIVE_CONFIG]'); + $request = (new DeleteLiveConfigRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteLiveConfig($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.video.stitcher.v1.VideoStitcherService/DeleteLiveConfig', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteLiveConfigTest'); + $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 deleteLiveConfigExceptionTest() + { + $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/deleteLiveConfigTest'); + $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->liveConfigName('[PROJECT]', '[LOCATION]', '[LIVE_CONFIG]'); + $request = (new DeleteLiveConfigRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteLiveConfig($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteLiveConfigTest'); + 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 deleteSlateTest() + { + $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/deleteSlateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteSlateTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->slateName('[PROJECT]', '[LOCATION]', '[SLATE]'); + $request = (new DeleteSlateRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteSlate($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.video.stitcher.v1.VideoStitcherService/DeleteSlate', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteSlateTest'); + $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 deleteSlateExceptionTest() + { + $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/deleteSlateTest'); + $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->slateName('[PROJECT]', '[LOCATION]', '[SLATE]'); + $request = (new DeleteSlateRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteSlate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteSlateTest'); + 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 getCdnKeyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $hostname = 'hostname-299803597'; + $expectedResponse = new CdnKey(); + $expectedResponse->setName($name2); + $expectedResponse->setHostname($hostname); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->cdnKeyName('[PROJECT]', '[LOCATION]', '[CDN_KEY]'); + $request = (new GetCdnKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->getCdnKey($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.video.stitcher.v1.VideoStitcherService/GetCdnKey', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCdnKeyExceptionTest() + { + $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->cdnKeyName('[PROJECT]', '[LOCATION]', '[CDN_KEY]'); + $request = (new GetCdnKeyRequest()) + ->setName($formattedName); + try { + $gapicClient->getCdnKey($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 getLiveAdTagDetailTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new LiveAdTagDetail(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->liveAdTagDetailName('[PROJECT]', '[LOCATION]', '[LIVE_SESSION]', '[LIVE_AD_TAG_DETAIL]'); + $request = (new GetLiveAdTagDetailRequest()) + ->setName($formattedName); + $response = $gapicClient->getLiveAdTagDetail($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.video.stitcher.v1.VideoStitcherService/GetLiveAdTagDetail', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLiveAdTagDetailExceptionTest() + { + $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->liveAdTagDetailName('[PROJECT]', '[LOCATION]', '[LIVE_SESSION]', '[LIVE_AD_TAG_DETAIL]'); + $request = (new GetLiveAdTagDetailRequest()) + ->setName($formattedName); + try { + $gapicClient->getLiveAdTagDetail($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 getLiveConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $sourceUri = 'sourceUri-1111107768'; + $adTagUri = 'adTagUri-1429194965'; + $defaultSlate = 'defaultSlate1316218395'; + $expectedResponse = new LiveConfig(); + $expectedResponse->setName($name2); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setAdTagUri($adTagUri); + $expectedResponse->setDefaultSlate($defaultSlate); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->liveConfigName('[PROJECT]', '[LOCATION]', '[LIVE_CONFIG]'); + $request = (new GetLiveConfigRequest()) + ->setName($formattedName); + $response = $gapicClient->getLiveConfig($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.video.stitcher.v1.VideoStitcherService/GetLiveConfig', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLiveConfigExceptionTest() + { + $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->liveConfigName('[PROJECT]', '[LOCATION]', '[LIVE_CONFIG]'); + $request = (new GetLiveConfigRequest()) + ->setName($formattedName); + try { + $gapicClient->getLiveConfig($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 getLiveSessionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $playUri = 'playUri1879098849'; + $liveConfig = 'liveConfig-1498665483'; + $expectedResponse = new LiveSession(); + $expectedResponse->setName($name2); + $expectedResponse->setPlayUri($playUri); + $expectedResponse->setLiveConfig($liveConfig); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->liveSessionName('[PROJECT]', '[LOCATION]', '[LIVE_SESSION]'); + $request = (new GetLiveSessionRequest()) + ->setName($formattedName); + $response = $gapicClient->getLiveSession($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.video.stitcher.v1.VideoStitcherService/GetLiveSession', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLiveSessionExceptionTest() + { + $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->liveSessionName('[PROJECT]', '[LOCATION]', '[LIVE_SESSION]'); + $request = (new GetLiveSessionRequest()) + ->setName($formattedName); + try { + $gapicClient->getLiveSession($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 getSlateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uri = 'uri116076'; + $expectedResponse = new Slate(); + $expectedResponse->setName($name2); + $expectedResponse->setUri($uri); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->slateName('[PROJECT]', '[LOCATION]', '[SLATE]'); + $request = (new GetSlateRequest()) + ->setName($formattedName); + $response = $gapicClient->getSlate($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.video.stitcher.v1.VideoStitcherService/GetSlate', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSlateExceptionTest() + { + $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->slateName('[PROJECT]', '[LOCATION]', '[SLATE]'); + $request = (new GetSlateRequest()) + ->setName($formattedName); + try { + $gapicClient->getSlate($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 getVodAdTagDetailTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new VodAdTagDetail(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->vodAdTagDetailName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]', '[VOD_AD_TAG_DETAIL]'); + $request = (new GetVodAdTagDetailRequest()) + ->setName($formattedName); + $response = $gapicClient->getVodAdTagDetail($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.video.stitcher.v1.VideoStitcherService/GetVodAdTagDetail', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getVodAdTagDetailExceptionTest() + { + $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->vodAdTagDetailName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]', '[VOD_AD_TAG_DETAIL]'); + $request = (new GetVodAdTagDetailRequest()) + ->setName($formattedName); + try { + $gapicClient->getVodAdTagDetail($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 getVodSessionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $playUri = 'playUri1879098849'; + $sourceUri = 'sourceUri-1111107768'; + $adTagUri = 'adTagUri-1429194965'; + $assetId = 'assetId-373202742'; + $expectedResponse = new VodSession(); + $expectedResponse->setName($name2); + $expectedResponse->setPlayUri($playUri); + $expectedResponse->setSourceUri($sourceUri); + $expectedResponse->setAdTagUri($adTagUri); + $expectedResponse->setAssetId($assetId); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->vodSessionName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]'); + $request = (new GetVodSessionRequest()) + ->setName($formattedName); + $response = $gapicClient->getVodSession($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.video.stitcher.v1.VideoStitcherService/GetVodSession', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getVodSessionExceptionTest() + { + $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->vodSessionName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]'); + $request = (new GetVodSessionRequest()) + ->setName($formattedName); + try { + $gapicClient->getVodSession($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 getVodStitchDetailTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new VodStitchDetail(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->vodStitchDetailName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]', '[VOD_STITCH_DETAIL]'); + $request = (new GetVodStitchDetailRequest()) + ->setName($formattedName); + $response = $gapicClient->getVodStitchDetail($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.video.stitcher.v1.VideoStitcherService/GetVodStitchDetail', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getVodStitchDetailExceptionTest() + { + $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->vodStitchDetailName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]', '[VOD_STITCH_DETAIL]'); + $request = (new GetVodStitchDetailRequest()) + ->setName($formattedName); + try { + $gapicClient->getVodStitchDetail($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 listCdnKeysTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $cdnKeysElement = new CdnKey(); + $cdnKeys = [ + $cdnKeysElement, + ]; + $expectedResponse = new ListCdnKeysResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCdnKeys($cdnKeys); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListCdnKeysRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listCdnKeys($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCdnKeys()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.stitcher.v1.VideoStitcherService/ListCdnKeys', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCdnKeysExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListCdnKeysRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listCdnKeys($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 listLiveAdTagDetailsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $liveAdTagDetailsElement = new LiveAdTagDetail(); + $liveAdTagDetails = [ + $liveAdTagDetailsElement, + ]; + $expectedResponse = new ListLiveAdTagDetailsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLiveAdTagDetails($liveAdTagDetails); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->liveSessionName('[PROJECT]', '[LOCATION]', '[LIVE_SESSION]'); + $request = (new ListLiveAdTagDetailsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listLiveAdTagDetails($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLiveAdTagDetails()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.stitcher.v1.VideoStitcherService/ListLiveAdTagDetails', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLiveAdTagDetailsExceptionTest() + { + $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->liveSessionName('[PROJECT]', '[LOCATION]', '[LIVE_SESSION]'); + $request = (new ListLiveAdTagDetailsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listLiveAdTagDetails($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 listLiveConfigsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $liveConfigsElement = new LiveConfig(); + $liveConfigs = [ + $liveConfigsElement, + ]; + $expectedResponse = new ListLiveConfigsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLiveConfigs($liveConfigs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListLiveConfigsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listLiveConfigs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLiveConfigs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.stitcher.v1.VideoStitcherService/ListLiveConfigs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLiveConfigsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListLiveConfigsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listLiveConfigs($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 listSlatesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $slatesElement = new Slate(); + $slates = [ + $slatesElement, + ]; + $expectedResponse = new ListSlatesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSlates($slates); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListSlatesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listSlates($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSlates()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.stitcher.v1.VideoStitcherService/ListSlates', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSlatesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListSlatesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listSlates($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 listVodAdTagDetailsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $vodAdTagDetailsElement = new VodAdTagDetail(); + $vodAdTagDetails = [ + $vodAdTagDetailsElement, + ]; + $expectedResponse = new ListVodAdTagDetailsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setVodAdTagDetails($vodAdTagDetails); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->vodSessionName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]'); + $request = (new ListVodAdTagDetailsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listVodAdTagDetails($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getVodAdTagDetails()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.stitcher.v1.VideoStitcherService/ListVodAdTagDetails', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listVodAdTagDetailsExceptionTest() + { + $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->vodSessionName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]'); + $request = (new ListVodAdTagDetailsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listVodAdTagDetails($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 listVodStitchDetailsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $vodStitchDetailsElement = new VodStitchDetail(); + $vodStitchDetails = [ + $vodStitchDetailsElement, + ]; + $expectedResponse = new ListVodStitchDetailsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setVodStitchDetails($vodStitchDetails); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->vodSessionName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]'); + $request = (new ListVodStitchDetailsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listVodStitchDetails($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getVodStitchDetails()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.stitcher.v1.VideoStitcherService/ListVodStitchDetails', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listVodStitchDetailsExceptionTest() + { + $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->vodSessionName('[PROJECT]', '[LOCATION]', '[VOD_SESSION]'); + $request = (new ListVodStitchDetailsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listVodStitchDetails($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 updateCdnKeyTest() + { + $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/updateCdnKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $hostname = 'hostname-299803597'; + $expectedResponse = new CdnKey(); + $expectedResponse->setName($name); + $expectedResponse->setHostname($hostname); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateCdnKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $cdnKey = new CdnKey(); + $updateMask = new FieldMask(); + $request = (new UpdateCdnKeyRequest()) + ->setCdnKey($cdnKey) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateCdnKey($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.video.stitcher.v1.VideoStitcherService/UpdateCdnKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getCdnKey(); + $this->assertProtobufEquals($cdnKey, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateCdnKeyTest'); + $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 updateCdnKeyExceptionTest() + { + $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/updateCdnKeyTest'); + $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 + $cdnKey = new CdnKey(); + $updateMask = new FieldMask(); + $request = (new UpdateCdnKeyRequest()) + ->setCdnKey($cdnKey) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateCdnKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateCdnKeyTest'); + 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 updateSlateTest() + { + $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/updateSlateTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $uri = 'uri116076'; + $expectedResponse = new Slate(); + $expectedResponse->setName($name); + $expectedResponse->setUri($uri); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateSlateTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $slate = new Slate(); + $updateMask = new FieldMask(); + $request = (new UpdateSlateRequest()) + ->setSlate($slate) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateSlate($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.video.stitcher.v1.VideoStitcherService/UpdateSlate', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getSlate(); + $this->assertProtobufEquals($slate, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateSlateTest'); + $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 updateSlateExceptionTest() + { + $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/updateSlateTest'); + $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 + $slate = new Slate(); + $updateMask = new FieldMask(); + $request = (new UpdateSlateRequest()) + ->setSlate($slate) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateSlate($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateSlateTest'); + 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 createCdnKeyAsyncTest() + { + $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/createCdnKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $hostname = 'hostname-299803597'; + $expectedResponse = new CdnKey(); + $expectedResponse->setName($name); + $expectedResponse->setHostname($hostname); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCdnKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $cdnKey = new CdnKey(); + $cdnKeyId = 'cdnKeyId1672586061'; + $request = (new CreateCdnKeyRequest()) + ->setParent($formattedParent) + ->setCdnKey($cdnKey) + ->setCdnKeyId($cdnKeyId); + $response = $gapicClient->createCdnKeyAsync($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.video.stitcher.v1.VideoStitcherService/CreateCdnKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCdnKey(); + $this->assertProtobufEquals($cdnKey, $actualValue); + $actualValue = $actualApiRequestObject->getCdnKeyId(); + $this->assertProtobufEquals($cdnKeyId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCdnKeyTest'); + $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/VideoTranscoder/samples/V1/TranscoderServiceClient/create_job.php b/VideoTranscoder/samples/V1/TranscoderServiceClient/create_job.php index b4d66797c092..c03c971ea0da 100644 --- a/VideoTranscoder/samples/V1/TranscoderServiceClient/create_job.php +++ b/VideoTranscoder/samples/V1/TranscoderServiceClient/create_job.php @@ -24,8 +24,9 @@ // [START transcoder_v1_generated_TranscoderService_CreateJob_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\CreateJobRequest; use Google\Cloud\Video\Transcoder\V1\Job; -use Google\Cloud\Video\Transcoder\V1\TranscoderServiceClient; /** * Creates a job in the specified region. @@ -39,13 +40,16 @@ function create_job_sample(string $formattedParent): void // Create a client. $transcoderServiceClient = new TranscoderServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $job = new Job(); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job); // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $transcoderServiceClient->createJob($formattedParent, $job); + $response = $transcoderServiceClient->createJob($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/VideoTranscoder/samples/V1/TranscoderServiceClient/create_job_template.php b/VideoTranscoder/samples/V1/TranscoderServiceClient/create_job_template.php index e86632a53337..375ea9e07f7f 100644 --- a/VideoTranscoder/samples/V1/TranscoderServiceClient/create_job_template.php +++ b/VideoTranscoder/samples/V1/TranscoderServiceClient/create_job_template.php @@ -24,8 +24,9 @@ // [START transcoder_v1_generated_TranscoderService_CreateJobTemplate_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\CreateJobTemplateRequest; use Google\Cloud\Video\Transcoder\V1\JobTemplate; -use Google\Cloud\Video\Transcoder\V1\TranscoderServiceClient; /** * Creates a job template in the specified region. @@ -44,17 +45,17 @@ function create_job_template_sample(string $formattedParent, string $jobTemplate // Create a client. $transcoderServiceClient = new TranscoderServiceClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $jobTemplate = new JobTemplate(); + $request = (new CreateJobTemplateRequest()) + ->setParent($formattedParent) + ->setJobTemplate($jobTemplate) + ->setJobTemplateId($jobTemplateId); // Call the API and handle any network failures. try { /** @var JobTemplate $response */ - $response = $transcoderServiceClient->createJobTemplate( - $formattedParent, - $jobTemplate, - $jobTemplateId - ); + $response = $transcoderServiceClient->createJobTemplate($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/VideoTranscoder/samples/V1/TranscoderServiceClient/delete_job.php b/VideoTranscoder/samples/V1/TranscoderServiceClient/delete_job.php index 9742b300e81f..bc9d13be9d8c 100644 --- a/VideoTranscoder/samples/V1/TranscoderServiceClient/delete_job.php +++ b/VideoTranscoder/samples/V1/TranscoderServiceClient/delete_job.php @@ -24,7 +24,8 @@ // [START transcoder_v1_generated_TranscoderService_DeleteJob_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Video\Transcoder\V1\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\DeleteJobRequest; /** * Deletes a job. @@ -38,9 +39,13 @@ function delete_job_sample(string $formattedName): void // Create a client. $transcoderServiceClient = new TranscoderServiceClient(); + // Prepare the request message. + $request = (new DeleteJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $transcoderServiceClient->deleteJob($formattedName); + $transcoderServiceClient->deleteJob($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/VideoTranscoder/samples/V1/TranscoderServiceClient/delete_job_template.php b/VideoTranscoder/samples/V1/TranscoderServiceClient/delete_job_template.php index 5c67192a72a7..4f1f17da3a19 100644 --- a/VideoTranscoder/samples/V1/TranscoderServiceClient/delete_job_template.php +++ b/VideoTranscoder/samples/V1/TranscoderServiceClient/delete_job_template.php @@ -24,7 +24,8 @@ // [START transcoder_v1_generated_TranscoderService_DeleteJobTemplate_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Video\Transcoder\V1\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\DeleteJobTemplateRequest; /** * Deletes a job template. @@ -38,9 +39,13 @@ function delete_job_template_sample(string $formattedName): void // Create a client. $transcoderServiceClient = new TranscoderServiceClient(); + // Prepare the request message. + $request = (new DeleteJobTemplateRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { - $transcoderServiceClient->deleteJobTemplate($formattedName); + $transcoderServiceClient->deleteJobTemplate($request); printf('Call completed successfully.' . PHP_EOL); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/VideoTranscoder/samples/V1/TranscoderServiceClient/get_job.php b/VideoTranscoder/samples/V1/TranscoderServiceClient/get_job.php index 00ac4ff001af..aad5f588dd8f 100644 --- a/VideoTranscoder/samples/V1/TranscoderServiceClient/get_job.php +++ b/VideoTranscoder/samples/V1/TranscoderServiceClient/get_job.php @@ -24,8 +24,9 @@ // [START transcoder_v1_generated_TranscoderService_GetJob_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\GetJobRequest; use Google\Cloud\Video\Transcoder\V1\Job; -use Google\Cloud\Video\Transcoder\V1\TranscoderServiceClient; /** * Returns the job data. @@ -39,10 +40,14 @@ function get_job_sample(string $formattedName): void // Create a client. $transcoderServiceClient = new TranscoderServiceClient(); + // Prepare the request message. + $request = (new GetJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Job $response */ - $response = $transcoderServiceClient->getJob($formattedName); + $response = $transcoderServiceClient->getJob($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/VideoTranscoder/samples/V1/TranscoderServiceClient/get_job_template.php b/VideoTranscoder/samples/V1/TranscoderServiceClient/get_job_template.php index ab0f886b9b99..94e6c420d8e0 100644 --- a/VideoTranscoder/samples/V1/TranscoderServiceClient/get_job_template.php +++ b/VideoTranscoder/samples/V1/TranscoderServiceClient/get_job_template.php @@ -24,8 +24,9 @@ // [START transcoder_v1_generated_TranscoderService_GetJobTemplate_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\GetJobTemplateRequest; use Google\Cloud\Video\Transcoder\V1\JobTemplate; -use Google\Cloud\Video\Transcoder\V1\TranscoderServiceClient; /** * Returns the job template data. @@ -40,10 +41,14 @@ function get_job_template_sample(string $formattedName): void // Create a client. $transcoderServiceClient = new TranscoderServiceClient(); + // Prepare the request message. + $request = (new GetJobTemplateRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var JobTemplate $response */ - $response = $transcoderServiceClient->getJobTemplate($formattedName); + $response = $transcoderServiceClient->getJobTemplate($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/VideoTranscoder/samples/V1/TranscoderServiceClient/list_job_templates.php b/VideoTranscoder/samples/V1/TranscoderServiceClient/list_job_templates.php index 2b02ddd19dd0..e047c1fe4407 100644 --- a/VideoTranscoder/samples/V1/TranscoderServiceClient/list_job_templates.php +++ b/VideoTranscoder/samples/V1/TranscoderServiceClient/list_job_templates.php @@ -25,8 +25,9 @@ // [START transcoder_v1_generated_TranscoderService_ListJobTemplates_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; use Google\Cloud\Video\Transcoder\V1\JobTemplate; -use Google\Cloud\Video\Transcoder\V1\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\ListJobTemplatesRequest; /** * Lists job templates in the specified region. @@ -40,10 +41,14 @@ function list_job_templates_sample(string $formattedParent): void // Create a client. $transcoderServiceClient = new TranscoderServiceClient(); + // Prepare the request message. + $request = (new ListJobTemplatesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $transcoderServiceClient->listJobTemplates($formattedParent); + $response = $transcoderServiceClient->listJobTemplates($request); /** @var JobTemplate $element */ foreach ($response as $element) { diff --git a/VideoTranscoder/samples/V1/TranscoderServiceClient/list_jobs.php b/VideoTranscoder/samples/V1/TranscoderServiceClient/list_jobs.php index 98e4b365646f..356e2abde352 100644 --- a/VideoTranscoder/samples/V1/TranscoderServiceClient/list_jobs.php +++ b/VideoTranscoder/samples/V1/TranscoderServiceClient/list_jobs.php @@ -25,8 +25,9 @@ // [START transcoder_v1_generated_TranscoderService_ListJobs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; use Google\Cloud\Video\Transcoder\V1\Job; -use Google\Cloud\Video\Transcoder\V1\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\ListJobsRequest; /** * Lists jobs in the specified region. @@ -39,10 +40,14 @@ function list_jobs_sample(string $formattedParent): void // Create a client. $transcoderServiceClient = new TranscoderServiceClient(); + // Prepare the request message. + $request = (new ListJobsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $transcoderServiceClient->listJobs($formattedParent); + $response = $transcoderServiceClient->listJobs($request); /** @var Job $element */ foreach ($response as $element) { diff --git a/VideoTranscoder/src/V1/Client/BaseClient/TranscoderServiceBaseClient.php b/VideoTranscoder/src/V1/Client/BaseClient/TranscoderServiceBaseClient.php new file mode 100644 index 000000000000..5e0591ea4bea --- /dev/null +++ b/VideoTranscoder/src/V1/Client/BaseClient/TranscoderServiceBaseClient.php @@ -0,0 +1,459 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/transcoder_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/transcoder_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/transcoder_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/transcoder_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a job + * resource. + * + * @param string $project + * @param string $location + * @param string $job + * + * @return string The formatted job resource. + */ + public static function jobName(string $project, string $location, string $job): string + { + return self::getPathTemplate('job')->render([ + 'project' => $project, + 'location' => $location, + 'job' => $job, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a job_template + * resource. + * + * @param string $project + * @param string $location + * @param string $jobTemplate + * + * @return string The formatted job_template resource. + */ + public static function jobTemplateName(string $project, string $location, string $jobTemplate): string + { + return self::getPathTemplate('jobTemplate')->render([ + 'project' => $project, + 'location' => $location, + 'job_template' => $jobTemplate, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - job: projects/{project}/locations/{location}/jobs/{job} + * - jobTemplate: projects/{project}/locations/{location}/jobTemplates/{job_template} + * - location: projects/{project}/locations/{location} + * + * 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 'transcoder.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); + } + + /** + * Creates a job in the specified region. + * + * The async variant is {@see self::createJobAsync()} . + * + * @param CreateJobRequest $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 Job + * + * @throws ApiException Thrown if the API call fails. + */ + public function createJob(CreateJobRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('CreateJob', $request, $callOptions)->wait(); + } + + /** + * Creates a job template in the specified region. + * + * The async variant is {@see self::createJobTemplateAsync()} . + * + * @param CreateJobTemplateRequest $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 JobTemplate + * + * @throws ApiException Thrown if the API call fails. + */ + public function createJobTemplate(CreateJobTemplateRequest $request, array $callOptions = []): JobTemplate + { + return $this->startApiCall('CreateJobTemplate', $request, $callOptions)->wait(); + } + + /** + * Deletes a job. + * + * The async variant is {@see self::deleteJobAsync()} . + * + * @param DeleteJobRequest $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. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteJob(DeleteJobRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteJob', $request, $callOptions)->wait(); + } + + /** + * Deletes a job template. + * + * The async variant is {@see self::deleteJobTemplateAsync()} . + * + * @param DeleteJobTemplateRequest $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. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteJobTemplate(DeleteJobTemplateRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteJobTemplate', $request, $callOptions)->wait(); + } + + /** + * Returns the job data. + * + * The async variant is {@see self::getJobAsync()} . + * + * @param GetJobRequest $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 Job + * + * @throws ApiException Thrown if the API call fails. + */ + public function getJob(GetJobRequest $request, array $callOptions = []): Job + { + return $this->startApiCall('GetJob', $request, $callOptions)->wait(); + } + + /** + * Returns the job template data. + * + * The async variant is {@see self::getJobTemplateAsync()} . + * + * @param GetJobTemplateRequest $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 JobTemplate + * + * @throws ApiException Thrown if the API call fails. + */ + public function getJobTemplate(GetJobTemplateRequest $request, array $callOptions = []): JobTemplate + { + return $this->startApiCall('GetJobTemplate', $request, $callOptions)->wait(); + } + + /** + * Lists job templates in the specified region. + * + * The async variant is {@see self::listJobTemplatesAsync()} . + * + * @param ListJobTemplatesRequest $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 listJobTemplates(ListJobTemplatesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListJobTemplates', $request, $callOptions); + } + + /** + * Lists jobs in the specified region. + * + * The async variant is {@see self::listJobsAsync()} . + * + * @param ListJobsRequest $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 listJobs(ListJobsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListJobs', $request, $callOptions); + } +} diff --git a/VideoTranscoder/src/V1/Client/TranscoderServiceClient.php b/VideoTranscoder/src/V1/Client/TranscoderServiceClient.php new file mode 100644 index 000000000000..5052e44f31e2 --- /dev/null +++ b/VideoTranscoder/src/V1/Client/TranscoderServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setJob($job); + } + /** * Constructor. * diff --git a/VideoTranscoder/src/V1/CreateJobTemplateRequest.php b/VideoTranscoder/src/V1/CreateJobTemplateRequest.php index bf735c95d65f..1676eac5c0c7 100644 --- a/VideoTranscoder/src/V1/CreateJobTemplateRequest.php +++ b/VideoTranscoder/src/V1/CreateJobTemplateRequest.php @@ -38,6 +38,29 @@ class CreateJobTemplateRequest extends \Google\Protobuf\Internal\Message */ private $job_template_id = ''; + /** + * @param string $parent Required. The parent location to create this job template. + * Format: `projects/{project}/locations/{location}` + * Please see {@see TranscoderServiceClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Video\Transcoder\V1\JobTemplate $jobTemplate Required. Parameters for creating job template. + * @param string $jobTemplateId Required. The ID to use for the job template, which will become the final + * component of the job template's resource name. + * + * This value should be 4-63 characters, and valid characters must match the + * regular expression `[a-zA-Z][a-zA-Z0-9_-]*`. + * + * @return \Google\Cloud\Video\Transcoder\V1\CreateJobTemplateRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Video\Transcoder\V1\JobTemplate $jobTemplate, string $jobTemplateId): self + { + return (new self()) + ->setParent($parent) + ->setJobTemplate($jobTemplate) + ->setJobTemplateId($jobTemplateId); + } + /** * Constructor. * diff --git a/VideoTranscoder/src/V1/DeleteJobRequest.php b/VideoTranscoder/src/V1/DeleteJobRequest.php index 20d4939a24bd..1602e061a1ea 100644 --- a/VideoTranscoder/src/V1/DeleteJobRequest.php +++ b/VideoTranscoder/src/V1/DeleteJobRequest.php @@ -30,6 +30,21 @@ class DeleteJobRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param string $name Required. The name of the job to delete. + * Format: `projects/{project}/locations/{location}/jobs/{job}` + * Please see {@see TranscoderServiceClient::jobName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Transcoder\V1\DeleteJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoTranscoder/src/V1/DeleteJobTemplateRequest.php b/VideoTranscoder/src/V1/DeleteJobTemplateRequest.php index 3475b87603f6..f73cfa6d8021 100644 --- a/VideoTranscoder/src/V1/DeleteJobTemplateRequest.php +++ b/VideoTranscoder/src/V1/DeleteJobTemplateRequest.php @@ -30,6 +30,21 @@ class DeleteJobTemplateRequest extends \Google\Protobuf\Internal\Message */ private $allow_missing = false; + /** + * @param string $name Required. The name of the job template to delete. + * `projects/{project}/locations/{location}/jobTemplates/{job_template}` + * Please see {@see TranscoderServiceClient::jobTemplateName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Transcoder\V1\DeleteJobTemplateRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoTranscoder/src/V1/GetJobRequest.php b/VideoTranscoder/src/V1/GetJobRequest.php index a42e8e7ccccd..215587d12147 100644 --- a/VideoTranscoder/src/V1/GetJobRequest.php +++ b/VideoTranscoder/src/V1/GetJobRequest.php @@ -23,6 +23,21 @@ class GetJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the job to retrieve. + * Format: `projects/{project}/locations/{location}/jobs/{job}` + * Please see {@see TranscoderServiceClient::jobName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Transcoder\V1\GetJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoTranscoder/src/V1/GetJobTemplateRequest.php b/VideoTranscoder/src/V1/GetJobTemplateRequest.php index 57c072a283d3..ea6d0765a69e 100644 --- a/VideoTranscoder/src/V1/GetJobTemplateRequest.php +++ b/VideoTranscoder/src/V1/GetJobTemplateRequest.php @@ -24,6 +24,22 @@ class GetJobTemplateRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the job template to retrieve. + * Format: + * `projects/{project}/locations/{location}/jobTemplates/{job_template}` + * Please see {@see TranscoderServiceClient::jobTemplateName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Transcoder\V1\GetJobTemplateRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VideoTranscoder/src/V1/ListJobTemplatesRequest.php b/VideoTranscoder/src/V1/ListJobTemplatesRequest.php index 36c08b55b5b2..50c1cf3efe33 100644 --- a/VideoTranscoder/src/V1/ListJobTemplatesRequest.php +++ b/VideoTranscoder/src/V1/ListJobTemplatesRequest.php @@ -50,6 +50,21 @@ class ListJobTemplatesRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent location from which to retrieve the collection of job + * templates. Format: `projects/{project}/locations/{location}` + * Please see {@see TranscoderServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Transcoder\V1\ListJobTemplatesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoTranscoder/src/V1/ListJobsRequest.php b/VideoTranscoder/src/V1/ListJobsRequest.php index 113be21c7e97..7911664a0f21 100644 --- a/VideoTranscoder/src/V1/ListJobsRequest.php +++ b/VideoTranscoder/src/V1/ListJobsRequest.php @@ -50,6 +50,20 @@ class ListJobsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. Format: `projects/{project}/locations/{location}` + * Please see {@see TranscoderServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Video\Transcoder\V1\ListJobsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VideoTranscoder/src/V1/resources/transcoder_service_descriptor_config.php b/VideoTranscoder/src/V1/resources/transcoder_service_descriptor_config.php index dc847b62ab92..acc7edd295ae 100644 --- a/VideoTranscoder/src/V1/resources/transcoder_service_descriptor_config.php +++ b/VideoTranscoder/src/V1/resources/transcoder_service_descriptor_config.php @@ -3,6 +3,78 @@ return [ 'interfaces' => [ 'google.cloud.video.transcoder.v1.TranscoderService' => [ + 'CreateJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Transcoder\V1\Job', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateJobTemplate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Transcoder\V1\JobTemplate', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteJobTemplate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Transcoder\V1\Job', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetJobTemplate' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Video\Transcoder\V1\JobTemplate', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'ListJobTemplates' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -12,6 +84,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getJobTemplates', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\Transcoder\V1\ListJobTemplatesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListJobs' => [ 'pageStreaming' => [ @@ -22,6 +104,21 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getJobs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Video\Transcoder\V1\ListJobsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'job' => 'projects/{project}/locations/{location}/jobs/{job}', + 'jobTemplate' => 'projects/{project}/locations/{location}/jobTemplates/{job_template}', + 'location' => 'projects/{project}/locations/{location}', ], ], ], diff --git a/VideoTranscoder/tests/Unit/V1/Client/TranscoderServiceClientTest.php b/VideoTranscoder/tests/Unit/V1/Client/TranscoderServiceClientTest.php new file mode 100644 index 000000000000..548cd320c092 --- /dev/null +++ b/VideoTranscoder/tests/Unit/V1/Client/TranscoderServiceClientTest.php @@ -0,0 +1,670 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return TranscoderServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new TranscoderServiceClient($options); + } + + /** @test */ + public function createJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $inputUri = 'inputUri1707300727'; + $outputUri = 'outputUri-1273518802'; + $templateId = 'templateId1769642752'; + $ttlAfterCompletionDays = 107576420; + $expectedResponse = new Job(); + $expectedResponse->setName($name); + $expectedResponse->setInputUri($inputUri); + $expectedResponse->setOutputUri($outputUri); + $expectedResponse->setTemplateId($templateId); + $expectedResponse->setTtlAfterCompletionDays($ttlAfterCompletionDays); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job); + $response = $gapicClient->createJob($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.video.transcoder.v1.TranscoderService/CreateJob', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getJob(); + $this->assertProtobufEquals($job, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createJobExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job); + try { + $gapicClient->createJob($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 createJobTemplateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $expectedResponse = new JobTemplate(); + $expectedResponse->setName($name); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $jobTemplate = new JobTemplate(); + $jobTemplateId = 'jobTemplateId-1231822466'; + $request = (new CreateJobTemplateRequest()) + ->setParent($formattedParent) + ->setJobTemplate($jobTemplate) + ->setJobTemplateId($jobTemplateId); + $response = $gapicClient->createJobTemplate($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.video.transcoder.v1.TranscoderService/CreateJobTemplate', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getJobTemplate(); + $this->assertProtobufEquals($jobTemplate, $actualValue); + $actualValue = $actualRequestObject->getJobTemplateId(); + $this->assertProtobufEquals($jobTemplateId, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createJobTemplateExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $jobTemplate = new JobTemplate(); + $jobTemplateId = 'jobTemplateId-1231822466'; + $request = (new CreateJobTemplateRequest()) + ->setParent($formattedParent) + ->setJobTemplate($jobTemplate) + ->setJobTemplateId($jobTemplateId); + try { + $gapicClient->createJobTemplate($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 deleteJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new DeleteJobRequest()) + ->setName($formattedName); + $gapicClient->deleteJob($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.transcoder.v1.TranscoderService/DeleteJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteJobExceptionTest() + { + $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->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new DeleteJobRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteJob($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 deleteJobTemplateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->jobTemplateName('[PROJECT]', '[LOCATION]', '[JOB_TEMPLATE]'); + $request = (new DeleteJobTemplateRequest()) + ->setName($formattedName); + $gapicClient->deleteJobTemplate($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.transcoder.v1.TranscoderService/DeleteJobTemplate', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteJobTemplateExceptionTest() + { + $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->jobTemplateName('[PROJECT]', '[LOCATION]', '[JOB_TEMPLATE]'); + $request = (new DeleteJobTemplateRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteJobTemplate($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 getJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $inputUri = 'inputUri1707300727'; + $outputUri = 'outputUri-1273518802'; + $templateId = 'templateId1769642752'; + $ttlAfterCompletionDays = 107576420; + $expectedResponse = new Job(); + $expectedResponse->setName($name2); + $expectedResponse->setInputUri($inputUri); + $expectedResponse->setOutputUri($outputUri); + $expectedResponse->setTemplateId($templateId); + $expectedResponse->setTtlAfterCompletionDays($ttlAfterCompletionDays); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new GetJobRequest()) + ->setName($formattedName); + $response = $gapicClient->getJob($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.video.transcoder.v1.TranscoderService/GetJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobExceptionTest() + { + $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->jobName('[PROJECT]', '[LOCATION]', '[JOB]'); + $request = (new GetJobRequest()) + ->setName($formattedName); + try { + $gapicClient->getJob($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 getJobTemplateTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new JobTemplate(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->jobTemplateName('[PROJECT]', '[LOCATION]', '[JOB_TEMPLATE]'); + $request = (new GetJobTemplateRequest()) + ->setName($formattedName); + $response = $gapicClient->getJobTemplate($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.video.transcoder.v1.TranscoderService/GetJobTemplate', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getJobTemplateExceptionTest() + { + $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->jobTemplateName('[PROJECT]', '[LOCATION]', '[JOB_TEMPLATE]'); + $request = (new GetJobTemplateRequest()) + ->setName($formattedName); + try { + $gapicClient->getJobTemplate($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 listJobTemplatesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobTemplatesElement = new JobTemplate(); + $jobTemplates = [ + $jobTemplatesElement, + ]; + $expectedResponse = new ListJobTemplatesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobTemplates($jobTemplates); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListJobTemplatesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listJobTemplates($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobTemplates()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.transcoder.v1.TranscoderService/ListJobTemplates', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobTemplatesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListJobTemplatesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listJobTemplates($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 listJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $jobsElement = new Job(); + $jobs = [ + $jobsElement, + ]; + $expectedResponse = new ListJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setJobs($jobs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListJobsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listJobs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.video.transcoder.v1.TranscoderService/ListJobs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listJobsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListJobsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listJobs($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 createJobAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $inputUri = 'inputUri1707300727'; + $outputUri = 'outputUri-1273518802'; + $templateId = 'templateId1769642752'; + $ttlAfterCompletionDays = 107576420; + $expectedResponse = new Job(); + $expectedResponse->setName($name); + $expectedResponse->setInputUri($inputUri); + $expectedResponse->setOutputUri($outputUri); + $expectedResponse->setTemplateId($templateId); + $expectedResponse->setTtlAfterCompletionDays($ttlAfterCompletionDays); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $job = new Job(); + $request = (new CreateJobRequest()) + ->setParent($formattedParent) + ->setJob($job); + $response = $gapicClient->createJobAsync($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.video.transcoder.v1.TranscoderService/CreateJob', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getJob(); + $this->assertProtobufEquals($job, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/VmMigration/samples/V1/VmMigrationClient/add_group_migration.php b/VmMigration/samples/V1/VmMigrationClient/add_group_migration.php index f566f7661fbd..cdd9824a8afa 100644 --- a/VmMigration/samples/V1/VmMigrationClient/add_group_migration.php +++ b/VmMigration/samples/V1/VmMigrationClient/add_group_migration.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_AddGroupMigration_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\AddGroupMigrationRequest; use Google\Cloud\VMMigration\V1\AddGroupMigrationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function add_group_migration_sample(string $formattedGroup): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new AddGroupMigrationRequest()) + ->setGroup($formattedGroup); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->addGroupMigration($formattedGroup); + $response = $vmMigrationClient->addGroupMigration($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/cancel_clone_job.php b/VmMigration/samples/V1/VmMigrationClient/cancel_clone_job.php index 8bd9569ffa4f..b7f3d205d94f 100644 --- a/VmMigration/samples/V1/VmMigrationClient/cancel_clone_job.php +++ b/VmMigration/samples/V1/VmMigrationClient/cancel_clone_job.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CancelCloneJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\CancelCloneJobRequest; use Google\Cloud\VMMigration\V1\CancelCloneJobResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function cancel_clone_job_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new CancelCloneJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->cancelCloneJob($formattedName); + $response = $vmMigrationClient->cancelCloneJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/cancel_cutover_job.php b/VmMigration/samples/V1/VmMigrationClient/cancel_cutover_job.php index 559cbacf324e..e463f9e23c6b 100644 --- a/VmMigration/samples/V1/VmMigrationClient/cancel_cutover_job.php +++ b/VmMigration/samples/V1/VmMigrationClient/cancel_cutover_job.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CancelCutoverJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\CancelCutoverJobRequest; use Google\Cloud\VMMigration\V1\CancelCutoverJobResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function cancel_cutover_job_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new CancelCutoverJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->cancelCutoverJob($formattedName); + $response = $vmMigrationClient->cancelCutoverJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/create_clone_job.php b/VmMigration/samples/V1/VmMigrationClient/create_clone_job.php index a62598f93815..6044f76543a9 100644 --- a/VmMigration/samples/V1/VmMigrationClient/create_clone_job.php +++ b/VmMigration/samples/V1/VmMigrationClient/create_clone_job.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CreateCloneJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\CloneJob; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CreateCloneJobRequest; use Google\Rpc\Status; /** @@ -41,13 +42,17 @@ function create_clone_job_sample(string $formattedParent, string $cloneJobId): v // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $cloneJob = new CloneJob(); + $request = (new CreateCloneJobRequest()) + ->setParent($formattedParent) + ->setCloneJobId($cloneJobId) + ->setCloneJob($cloneJob); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->createCloneJob($formattedParent, $cloneJobId, $cloneJob); + $response = $vmMigrationClient->createCloneJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/create_cutover_job.php b/VmMigration/samples/V1/VmMigrationClient/create_cutover_job.php index bc9b86de7ff6..cc182e873915 100644 --- a/VmMigration/samples/V1/VmMigrationClient/create_cutover_job.php +++ b/VmMigration/samples/V1/VmMigrationClient/create_cutover_job.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CreateCutoverJob_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CreateCutoverJobRequest; use Google\Cloud\VMMigration\V1\CutoverJob; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -43,13 +44,17 @@ function create_cutover_job_sample(string $formattedParent, string $cutoverJobId // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $cutoverJob = new CutoverJob(); + $request = (new CreateCutoverJobRequest()) + ->setParent($formattedParent) + ->setCutoverJobId($cutoverJobId) + ->setCutoverJob($cutoverJob); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->createCutoverJob($formattedParent, $cutoverJobId, $cutoverJob); + $response = $vmMigrationClient->createCutoverJob($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/create_datacenter_connector.php b/VmMigration/samples/V1/VmMigrationClient/create_datacenter_connector.php index d8c8d303f733..bdfb438798a4 100644 --- a/VmMigration/samples/V1/VmMigrationClient/create_datacenter_connector.php +++ b/VmMigration/samples/V1/VmMigrationClient/create_datacenter_connector.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CreateDatacenterConnector_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CreateDatacenterConnectorRequest; use Google\Cloud\VMMigration\V1\DatacenterConnector; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -46,17 +47,17 @@ function create_datacenter_connector_sample( // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $datacenterConnector = new DatacenterConnector(); + $request = (new CreateDatacenterConnectorRequest()) + ->setParent($formattedParent) + ->setDatacenterConnectorId($datacenterConnectorId) + ->setDatacenterConnector($datacenterConnector); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->createDatacenterConnector( - $formattedParent, - $datacenterConnectorId, - $datacenterConnector - ); + $response = $vmMigrationClient->createDatacenterConnector($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/create_group.php b/VmMigration/samples/V1/VmMigrationClient/create_group.php index 1c6131780f80..ddf83186f95e 100644 --- a/VmMigration/samples/V1/VmMigrationClient/create_group.php +++ b/VmMigration/samples/V1/VmMigrationClient/create_group.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CreateGroup_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CreateGroupRequest; use Google\Cloud\VMMigration\V1\Group; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -41,13 +42,17 @@ function create_group_sample(string $formattedParent, string $groupId): void // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $group = new Group(); + $request = (new CreateGroupRequest()) + ->setParent($formattedParent) + ->setGroupId($groupId) + ->setGroup($group); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->createGroup($formattedParent, $groupId, $group); + $response = $vmMigrationClient->createGroup($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/create_migrating_vm.php b/VmMigration/samples/V1/VmMigrationClient/create_migrating_vm.php index c1ad9f2253ac..0b01aceb0f74 100644 --- a/VmMigration/samples/V1/VmMigrationClient/create_migrating_vm.php +++ b/VmMigration/samples/V1/VmMigrationClient/create_migrating_vm.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CreateMigratingVm_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CreateMigratingVmRequest; use Google\Cloud\VMMigration\V1\MigratingVm; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -41,13 +42,17 @@ function create_migrating_vm_sample(string $formattedParent, string $migratingVm // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $migratingVm = new MigratingVm(); + $request = (new CreateMigratingVmRequest()) + ->setParent($formattedParent) + ->setMigratingVmId($migratingVmId) + ->setMigratingVm($migratingVm); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->createMigratingVm($formattedParent, $migratingVmId, $migratingVm); + $response = $vmMigrationClient->createMigratingVm($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/create_source.php b/VmMigration/samples/V1/VmMigrationClient/create_source.php index 683a477f3b28..4acbe2f93d71 100644 --- a/VmMigration/samples/V1/VmMigrationClient/create_source.php +++ b/VmMigration/samples/V1/VmMigrationClient/create_source.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CreateSource_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CreateSourceRequest; use Google\Cloud\VMMigration\V1\Source; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -41,13 +42,17 @@ function create_source_sample(string $formattedParent, string $sourceId): void // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $source = new Source(); + $request = (new CreateSourceRequest()) + ->setParent($formattedParent) + ->setSourceId($sourceId) + ->setSource($source); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->createSource($formattedParent, $sourceId, $source); + $response = $vmMigrationClient->createSource($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/create_target_project.php b/VmMigration/samples/V1/VmMigrationClient/create_target_project.php index 6bf792d475ca..7b290dc3d393 100644 --- a/VmMigration/samples/V1/VmMigrationClient/create_target_project.php +++ b/VmMigration/samples/V1/VmMigrationClient/create_target_project.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CreateTargetProject_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CreateTargetProjectRequest; use Google\Cloud\VMMigration\V1\TargetProject; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -44,17 +45,17 @@ function create_target_project_sample(string $formattedParent, string $targetPro // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $targetProject = new TargetProject(); + $request = (new CreateTargetProjectRequest()) + ->setParent($formattedParent) + ->setTargetProjectId($targetProjectId) + ->setTargetProject($targetProject); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->createTargetProject( - $formattedParent, - $targetProjectId, - $targetProject - ); + $response = $vmMigrationClient->createTargetProject($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/create_utilization_report.php b/VmMigration/samples/V1/VmMigrationClient/create_utilization_report.php index e1ea80297d80..4e1d315d20dd 100644 --- a/VmMigration/samples/V1/VmMigrationClient/create_utilization_report.php +++ b/VmMigration/samples/V1/VmMigrationClient/create_utilization_report.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_CreateUtilizationReport_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CreateUtilizationReportRequest; use Google\Cloud\VMMigration\V1\UtilizationReport; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -48,17 +49,17 @@ function create_utilization_report_sample( // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $utilizationReport = new UtilizationReport(); + $request = (new CreateUtilizationReportRequest()) + ->setParent($formattedParent) + ->setUtilizationReport($utilizationReport) + ->setUtilizationReportId($utilizationReportId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->createUtilizationReport( - $formattedParent, - $utilizationReport, - $utilizationReportId - ); + $response = $vmMigrationClient->createUtilizationReport($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/delete_datacenter_connector.php b/VmMigration/samples/V1/VmMigrationClient/delete_datacenter_connector.php index 931bcc462e10..63e2b1fbce48 100644 --- a/VmMigration/samples/V1/VmMigrationClient/delete_datacenter_connector.php +++ b/VmMigration/samples/V1/VmMigrationClient/delete_datacenter_connector.php @@ -25,7 +25,8 @@ // [START vmmigration_v1_generated_VmMigration_DeleteDatacenterConnector_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\DeleteDatacenterConnectorRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_datacenter_connector_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new DeleteDatacenterConnectorRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->deleteDatacenterConnector($formattedName); + $response = $vmMigrationClient->deleteDatacenterConnector($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/delete_group.php b/VmMigration/samples/V1/VmMigrationClient/delete_group.php index 1ed149c8269e..c0ee667528bd 100644 --- a/VmMigration/samples/V1/VmMigrationClient/delete_group.php +++ b/VmMigration/samples/V1/VmMigrationClient/delete_group.php @@ -25,7 +25,8 @@ // [START vmmigration_v1_generated_VmMigration_DeleteGroup_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\DeleteGroupRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_group_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new DeleteGroupRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->deleteGroup($formattedName); + $response = $vmMigrationClient->deleteGroup($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/delete_migrating_vm.php b/VmMigration/samples/V1/VmMigrationClient/delete_migrating_vm.php index e863dce65cb7..811aa8b9ce1b 100644 --- a/VmMigration/samples/V1/VmMigrationClient/delete_migrating_vm.php +++ b/VmMigration/samples/V1/VmMigrationClient/delete_migrating_vm.php @@ -25,7 +25,8 @@ // [START vmmigration_v1_generated_VmMigration_DeleteMigratingVm_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\DeleteMigratingVmRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_migrating_vm_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new DeleteMigratingVmRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->deleteMigratingVm($formattedName); + $response = $vmMigrationClient->deleteMigratingVm($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/delete_source.php b/VmMigration/samples/V1/VmMigrationClient/delete_source.php index 0650a00643e4..ba057f0ed1c6 100644 --- a/VmMigration/samples/V1/VmMigrationClient/delete_source.php +++ b/VmMigration/samples/V1/VmMigrationClient/delete_source.php @@ -25,7 +25,8 @@ // [START vmmigration_v1_generated_VmMigration_DeleteSource_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\DeleteSourceRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_source_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new DeleteSourceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->deleteSource($formattedName); + $response = $vmMigrationClient->deleteSource($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/delete_target_project.php b/VmMigration/samples/V1/VmMigrationClient/delete_target_project.php index 2e05d0b7b227..0de5a6e7b61e 100644 --- a/VmMigration/samples/V1/VmMigrationClient/delete_target_project.php +++ b/VmMigration/samples/V1/VmMigrationClient/delete_target_project.php @@ -25,7 +25,8 @@ // [START vmmigration_v1_generated_VmMigration_DeleteTargetProject_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\DeleteTargetProjectRequest; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function delete_target_project_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new DeleteTargetProjectRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->deleteTargetProject($formattedName); + $response = $vmMigrationClient->deleteTargetProject($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/delete_utilization_report.php b/VmMigration/samples/V1/VmMigrationClient/delete_utilization_report.php index a3aebce72a0f..a84ab0d75462 100644 --- a/VmMigration/samples/V1/VmMigrationClient/delete_utilization_report.php +++ b/VmMigration/samples/V1/VmMigrationClient/delete_utilization_report.php @@ -25,7 +25,8 @@ // [START vmmigration_v1_generated_VmMigration_DeleteUtilizationReport_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\DeleteUtilizationReportRequest; use Google\Rpc\Status; /** @@ -39,10 +40,14 @@ function delete_utilization_report_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new DeleteUtilizationReportRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->deleteUtilizationReport($formattedName); + $response = $vmMigrationClient->deleteUtilizationReport($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/fetch_inventory.php b/VmMigration/samples/V1/VmMigrationClient/fetch_inventory.php index 3968418cd244..6968eaaa7177 100644 --- a/VmMigration/samples/V1/VmMigrationClient/fetch_inventory.php +++ b/VmMigration/samples/V1/VmMigrationClient/fetch_inventory.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_FetchInventory_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\FetchInventoryRequest; use Google\Cloud\VMMigration\V1\FetchInventoryResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * List remote source's inventory of VMs. @@ -42,10 +43,14 @@ function fetch_inventory_sample(string $formattedSource): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new FetchInventoryRequest()) + ->setSource($formattedSource); + // Call the API and handle any network failures. try { /** @var FetchInventoryResponse $response */ - $response = $vmMigrationClient->fetchInventory($formattedSource); + $response = $vmMigrationClient->fetchInventory($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/VmMigration/samples/V1/VmMigrationClient/finalize_migration.php b/VmMigration/samples/V1/VmMigrationClient/finalize_migration.php index f33369e4f411..a923fb1eca1b 100644 --- a/VmMigration/samples/V1/VmMigrationClient/finalize_migration.php +++ b/VmMigration/samples/V1/VmMigrationClient/finalize_migration.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_FinalizeMigration_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\FinalizeMigrationRequest; use Google\Cloud\VMMigration\V1\FinalizeMigrationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -41,10 +42,14 @@ function finalize_migration_sample(string $formattedMigratingVm): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new FinalizeMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->finalizeMigration($formattedMigratingVm); + $response = $vmMigrationClient->finalizeMigration($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/get_clone_job.php b/VmMigration/samples/V1/VmMigrationClient/get_clone_job.php index d5e8d06e2b9a..ed7ede76068a 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_clone_job.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_clone_job.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetCloneJob_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\CloneJob; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetCloneJobRequest; /** * Gets details of a single CloneJob. @@ -38,10 +39,14 @@ function get_clone_job_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetCloneJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var CloneJob $response */ - $response = $vmMigrationClient->getCloneJob($formattedName); + $response = $vmMigrationClient->getCloneJob($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/VmMigration/samples/V1/VmMigrationClient/get_cutover_job.php b/VmMigration/samples/V1/VmMigrationClient/get_cutover_job.php index 82f62ac5eca0..494666059e6f 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_cutover_job.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_cutover_job.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetCutoverJob_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\CutoverJob; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetCutoverJobRequest; /** * Gets details of a single CutoverJob. @@ -38,10 +39,14 @@ function get_cutover_job_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetCutoverJobRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var CutoverJob $response */ - $response = $vmMigrationClient->getCutoverJob($formattedName); + $response = $vmMigrationClient->getCutoverJob($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/VmMigration/samples/V1/VmMigrationClient/get_datacenter_connector.php b/VmMigration/samples/V1/VmMigrationClient/get_datacenter_connector.php index 83f01557a111..c57b931d10c2 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_datacenter_connector.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_datacenter_connector.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetDatacenterConnector_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\DatacenterConnector; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetDatacenterConnectorRequest; /** * Gets details of a single DatacenterConnector. @@ -38,10 +39,14 @@ function get_datacenter_connector_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetDatacenterConnectorRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var DatacenterConnector $response */ - $response = $vmMigrationClient->getDatacenterConnector($formattedName); + $response = $vmMigrationClient->getDatacenterConnector($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/VmMigration/samples/V1/VmMigrationClient/get_group.php b/VmMigration/samples/V1/VmMigrationClient/get_group.php index 90b84a0d6b9d..dcbb5095cfb0 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_group.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_group.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetGroup_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetGroupRequest; use Google\Cloud\VMMigration\V1\Group; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Gets details of a single Group. @@ -38,10 +39,14 @@ function get_group_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetGroupRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Group $response */ - $response = $vmMigrationClient->getGroup($formattedName); + $response = $vmMigrationClient->getGroup($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/VmMigration/samples/V1/VmMigrationClient/get_location.php b/VmMigration/samples/V1/VmMigrationClient/get_location.php index c4d0b301529f..95a44e7266d7 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_location.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_location.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetLocation_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; /** * Gets information about a location. @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $vmMigrationClient->getLocation(); + $response = $vmMigrationClient->getLocation($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/VmMigration/samples/V1/VmMigrationClient/get_migrating_vm.php b/VmMigration/samples/V1/VmMigrationClient/get_migrating_vm.php index 01a1ec556b43..8b9004a3fa03 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_migrating_vm.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_migrating_vm.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetMigratingVm_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetMigratingVmRequest; use Google\Cloud\VMMigration\V1\MigratingVm; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Gets details of a single MigratingVm. @@ -38,10 +39,14 @@ function get_migrating_vm_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetMigratingVmRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var MigratingVm $response */ - $response = $vmMigrationClient->getMigratingVm($formattedName); + $response = $vmMigrationClient->getMigratingVm($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/VmMigration/samples/V1/VmMigrationClient/get_replication_cycle.php b/VmMigration/samples/V1/VmMigrationClient/get_replication_cycle.php index 3ce81b637555..819a1a61da08 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_replication_cycle.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_replication_cycle.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetReplicationCycle_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetReplicationCycleRequest; use Google\Cloud\VMMigration\V1\ReplicationCycle; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Gets details of a single ReplicationCycle. @@ -38,10 +39,14 @@ function get_replication_cycle_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetReplicationCycleRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var ReplicationCycle $response */ - $response = $vmMigrationClient->getReplicationCycle($formattedName); + $response = $vmMigrationClient->getReplicationCycle($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/VmMigration/samples/V1/VmMigrationClient/get_source.php b/VmMigration/samples/V1/VmMigrationClient/get_source.php index ec8b7f86ef33..98a3e37ca652 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_source.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_source.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetSource_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetSourceRequest; use Google\Cloud\VMMigration\V1\Source; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Gets details of a single Source. @@ -38,10 +39,14 @@ function get_source_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetSourceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Source $response */ - $response = $vmMigrationClient->getSource($formattedName); + $response = $vmMigrationClient->getSource($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/VmMigration/samples/V1/VmMigrationClient/get_target_project.php b/VmMigration/samples/V1/VmMigrationClient/get_target_project.php index 4657e5537b0a..75a1456fe996 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_target_project.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_target_project.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetTargetProject_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetTargetProjectRequest; use Google\Cloud\VMMigration\V1\TargetProject; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Gets details of a single TargetProject. @@ -41,10 +42,14 @@ function get_target_project_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetTargetProjectRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var TargetProject $response */ - $response = $vmMigrationClient->getTargetProject($formattedName); + $response = $vmMigrationClient->getTargetProject($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/VmMigration/samples/V1/VmMigrationClient/get_utilization_report.php b/VmMigration/samples/V1/VmMigrationClient/get_utilization_report.php index fdf9584599f4..6de881a1495c 100644 --- a/VmMigration/samples/V1/VmMigrationClient/get_utilization_report.php +++ b/VmMigration/samples/V1/VmMigrationClient/get_utilization_report.php @@ -24,8 +24,9 @@ // [START vmmigration_v1_generated_VmMigration_GetUtilizationReport_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\GetUtilizationReportRequest; use Google\Cloud\VMMigration\V1\UtilizationReport; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Gets a single Utilization Report. @@ -38,10 +39,14 @@ function get_utilization_report_sample(string $formattedName): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new GetUtilizationReportRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var UtilizationReport $response */ - $response = $vmMigrationClient->getUtilizationReport($formattedName); + $response = $vmMigrationClient->getUtilizationReport($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/VmMigration/samples/V1/VmMigrationClient/list_clone_jobs.php b/VmMigration/samples/V1/VmMigrationClient/list_clone_jobs.php index a7fa66963d4b..78172d4e1e1a 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_clone_jobs.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_clone_jobs.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListCloneJobs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\CloneJob; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListCloneJobsRequest; /** * Lists CloneJobs of a given migrating VM. @@ -43,10 +44,15 @@ function list_clone_jobs_sample(string $formattedParent, string $pageToken): voi // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListCloneJobsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listCloneJobs($formattedParent, $pageToken); + $response = $vmMigrationClient->listCloneJobs($request); /** @var CloneJob $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_cutover_jobs.php b/VmMigration/samples/V1/VmMigrationClient/list_cutover_jobs.php index eca45ad8a195..1eb3ebbd189d 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_cutover_jobs.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_cutover_jobs.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListCutoverJobs_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\CutoverJob; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListCutoverJobsRequest; /** * Lists CutoverJobs of a given migrating VM. @@ -43,10 +44,15 @@ function list_cutover_jobs_sample(string $formattedParent, string $pageToken): v // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListCutoverJobsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listCutoverJobs($formattedParent, $pageToken); + $response = $vmMigrationClient->listCutoverJobs($request); /** @var CutoverJob $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_datacenter_connectors.php b/VmMigration/samples/V1/VmMigrationClient/list_datacenter_connectors.php index 5cbae14bf38e..73a5c3f7647b 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_datacenter_connectors.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_datacenter_connectors.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListDatacenterConnectors_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\DatacenterConnector; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListDatacenterConnectorsRequest; /** * Lists DatacenterConnectors in a given Source. @@ -43,10 +44,15 @@ function list_datacenter_connectors_sample(string $formattedParent, string $page // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListDatacenterConnectorsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listDatacenterConnectors($formattedParent, $pageToken); + $response = $vmMigrationClient->listDatacenterConnectors($request); /** @var DatacenterConnector $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_groups.php b/VmMigration/samples/V1/VmMigrationClient/list_groups.php index ce4ea9bf038e..95c67456e8fe 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_groups.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_groups.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListGroups_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\Group; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListGroupsRequest; /** * Lists Groups in a given project and location. @@ -43,10 +44,15 @@ function list_groups_sample(string $formattedParent, string $pageToken): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListGroupsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listGroups($formattedParent, $pageToken); + $response = $vmMigrationClient->listGroups($request); /** @var Group $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_locations.php b/VmMigration/samples/V1/VmMigrationClient/list_locations.php index d51209d54612..5c4c202109a8 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_locations.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_locations.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; /** * Lists information about the supported locations for this service. @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listLocations(); + $response = $vmMigrationClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_migrating_vms.php b/VmMigration/samples/V1/VmMigrationClient/list_migrating_vms.php index 11a62faece70..acfd8373c61d 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_migrating_vms.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_migrating_vms.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListMigratingVms_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListMigratingVmsRequest; use Google\Cloud\VMMigration\V1\MigratingVm; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Lists MigratingVms in a given Source. @@ -43,10 +44,15 @@ function list_migrating_vms_sample(string $formattedParent, string $pageToken): // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListMigratingVmsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listMigratingVms($formattedParent, $pageToken); + $response = $vmMigrationClient->listMigratingVms($request); /** @var MigratingVm $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_replication_cycles.php b/VmMigration/samples/V1/VmMigrationClient/list_replication_cycles.php index d552cdd12ad1..19f44cce5f68 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_replication_cycles.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_replication_cycles.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListReplicationCycles_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListReplicationCyclesRequest; use Google\Cloud\VMMigration\V1\ReplicationCycle; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Lists ReplicationCycles in a given MigratingVM. @@ -43,10 +44,15 @@ function list_replication_cycles_sample(string $formattedParent, string $pageTok // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListReplicationCyclesRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listReplicationCycles($formattedParent, $pageToken); + $response = $vmMigrationClient->listReplicationCycles($request); /** @var ReplicationCycle $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_sources.php b/VmMigration/samples/V1/VmMigrationClient/list_sources.php index f7ce9ca134fe..29d22a9400bf 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_sources.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_sources.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListSources_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListSourcesRequest; use Google\Cloud\VMMigration\V1\Source; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Lists Sources in a given project and location. @@ -43,10 +44,15 @@ function list_sources_sample(string $formattedParent, string $pageToken): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListSourcesRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listSources($formattedParent, $pageToken); + $response = $vmMigrationClient->listSources($request); /** @var Source $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_target_projects.php b/VmMigration/samples/V1/VmMigrationClient/list_target_projects.php index 37a26cfdb260..47aee58280ca 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_target_projects.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_target_projects.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListTargetProjects_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListTargetProjectsRequest; use Google\Cloud\VMMigration\V1\TargetProject; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Lists TargetProjects in a given project. @@ -46,10 +47,15 @@ function list_target_projects_sample(string $formattedParent, string $pageToken) // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListTargetProjectsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listTargetProjects($formattedParent, $pageToken); + $response = $vmMigrationClient->listTargetProjects($request); /** @var TargetProject $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/list_utilization_reports.php b/VmMigration/samples/V1/VmMigrationClient/list_utilization_reports.php index 63a3ed590a1f..0e8b92bd0dec 100644 --- a/VmMigration/samples/V1/VmMigrationClient/list_utilization_reports.php +++ b/VmMigration/samples/V1/VmMigrationClient/list_utilization_reports.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ListUtilizationReports_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ListUtilizationReportsRequest; use Google\Cloud\VMMigration\V1\UtilizationReport; -use Google\Cloud\VMMigration\V1\VmMigrationClient; /** * Lists Utilization Reports of the given Source. @@ -43,10 +44,15 @@ function list_utilization_reports_sample(string $formattedParent, string $pageTo // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ListUtilizationReportsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmMigrationClient->listUtilizationReports($formattedParent, $pageToken); + $response = $vmMigrationClient->listUtilizationReports($request); /** @var UtilizationReport $element */ foreach ($response as $element) { diff --git a/VmMigration/samples/V1/VmMigrationClient/pause_migration.php b/VmMigration/samples/V1/VmMigrationClient/pause_migration.php index c567a678b582..166c90056af4 100644 --- a/VmMigration/samples/V1/VmMigrationClient/pause_migration.php +++ b/VmMigration/samples/V1/VmMigrationClient/pause_migration.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_PauseMigration_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\PauseMigrationRequest; use Google\Cloud\VMMigration\V1\PauseMigrationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function pause_migration_sample(string $formattedMigratingVm): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new PauseMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->pauseMigration($formattedMigratingVm); + $response = $vmMigrationClient->pauseMigration($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/remove_group_migration.php b/VmMigration/samples/V1/VmMigrationClient/remove_group_migration.php index 60e4ec185323..2e1e7a7afea4 100644 --- a/VmMigration/samples/V1/VmMigrationClient/remove_group_migration.php +++ b/VmMigration/samples/V1/VmMigrationClient/remove_group_migration.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_RemoveGroupMigration_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\RemoveGroupMigrationRequest; use Google\Cloud\VMMigration\V1\RemoveGroupMigrationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -40,10 +41,14 @@ function remove_group_migration_sample(string $formattedGroup): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new RemoveGroupMigrationRequest()) + ->setGroup($formattedGroup); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->removeGroupMigration($formattedGroup); + $response = $vmMigrationClient->removeGroupMigration($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/resume_migration.php b/VmMigration/samples/V1/VmMigrationClient/resume_migration.php index 4bf041b7f60e..f6fcffc319cb 100644 --- a/VmMigration/samples/V1/VmMigrationClient/resume_migration.php +++ b/VmMigration/samples/V1/VmMigrationClient/resume_migration.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_ResumeMigration_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\ResumeMigrationRequest; use Google\Cloud\VMMigration\V1\ResumeMigrationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -43,10 +44,14 @@ function resume_migration_sample(string $formattedMigratingVm): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new ResumeMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->resumeMigration($formattedMigratingVm); + $response = $vmMigrationClient->resumeMigration($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/start_migration.php b/VmMigration/samples/V1/VmMigrationClient/start_migration.php index 92b25f7ac3a1..27e93109a358 100644 --- a/VmMigration/samples/V1/VmMigrationClient/start_migration.php +++ b/VmMigration/samples/V1/VmMigrationClient/start_migration.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_StartMigration_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\StartMigrationRequest; use Google\Cloud\VMMigration\V1\StartMigrationResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -41,10 +42,14 @@ function start_migration_sample(string $formattedMigratingVm): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new StartMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->startMigration($formattedMigratingVm); + $response = $vmMigrationClient->startMigration($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/update_group.php b/VmMigration/samples/V1/VmMigrationClient/update_group.php index e76561231ceb..a9db35ae6fd2 100644 --- a/VmMigration/samples/V1/VmMigrationClient/update_group.php +++ b/VmMigration/samples/V1/VmMigrationClient/update_group.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_UpdateGroup_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\Group; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\UpdateGroupRequest; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function update_group_sample(): void // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $group = new Group(); + $request = (new UpdateGroupRequest()) + ->setGroup($group); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->updateGroup($group); + $response = $vmMigrationClient->updateGroup($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/update_migrating_vm.php b/VmMigration/samples/V1/VmMigrationClient/update_migrating_vm.php index 6bbd1bf64a2a..45b1716a7036 100644 --- a/VmMigration/samples/V1/VmMigrationClient/update_migrating_vm.php +++ b/VmMigration/samples/V1/VmMigrationClient/update_migrating_vm.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_UpdateMigratingVm_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\MigratingVm; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\UpdateMigratingVmRequest; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function update_migrating_vm_sample(): void // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $migratingVm = new MigratingVm(); + $request = (new UpdateMigratingVmRequest()) + ->setMigratingVm($migratingVm); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->updateMigratingVm($migratingVm); + $response = $vmMigrationClient->updateMigratingVm($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/update_source.php b/VmMigration/samples/V1/VmMigrationClient/update_source.php index 3be6015cab59..322eda0377c8 100644 --- a/VmMigration/samples/V1/VmMigrationClient/update_source.php +++ b/VmMigration/samples/V1/VmMigrationClient/update_source.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_UpdateSource_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\Source; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\UpdateSourceRequest; use Google\Rpc\Status; /** @@ -43,13 +44,15 @@ function update_source_sample(): void // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $source = new Source(); + $request = (new UpdateSourceRequest()) + ->setSource($source); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->updateSource($source); + $response = $vmMigrationClient->updateSource($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/update_target_project.php b/VmMigration/samples/V1/VmMigrationClient/update_target_project.php index 2c6253356198..28f20a611404 100644 --- a/VmMigration/samples/V1/VmMigrationClient/update_target_project.php +++ b/VmMigration/samples/V1/VmMigrationClient/update_target_project.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_UpdateTargetProject_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; use Google\Cloud\VMMigration\V1\TargetProject; -use Google\Cloud\VMMigration\V1\VmMigrationClient; +use Google\Cloud\VMMigration\V1\UpdateTargetProjectRequest; use Google\Rpc\Status; /** @@ -46,13 +47,15 @@ function update_target_project_sample(): void // Create a client. $vmMigrationClient = new VmMigrationClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $targetProject = new TargetProject(); + $request = (new UpdateTargetProjectRequest()) + ->setTargetProject($targetProject); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->updateTargetProject($targetProject); + $response = $vmMigrationClient->updateTargetProject($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/samples/V1/VmMigrationClient/upgrade_appliance.php b/VmMigration/samples/V1/VmMigrationClient/upgrade_appliance.php index c97cdecd812d..52f87bb9c1c1 100644 --- a/VmMigration/samples/V1/VmMigrationClient/upgrade_appliance.php +++ b/VmMigration/samples/V1/VmMigrationClient/upgrade_appliance.php @@ -25,8 +25,9 @@ // [START vmmigration_v1_generated_VmMigration_UpgradeAppliance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\UpgradeApplianceRequest; use Google\Cloud\VMMigration\V1\UpgradeApplianceResponse; -use Google\Cloud\VMMigration\V1\VmMigrationClient; use Google\Rpc\Status; /** @@ -41,10 +42,14 @@ function upgrade_appliance_sample(string $formattedDatacenterConnector): void // Create a client. $vmMigrationClient = new VmMigrationClient(); + // Prepare the request message. + $request = (new UpgradeApplianceRequest()) + ->setDatacenterConnector($formattedDatacenterConnector); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmMigrationClient->upgradeAppliance($formattedDatacenterConnector); + $response = $vmMigrationClient->upgradeAppliance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmMigration/src/V1/AddGroupMigrationRequest.php b/VmMigration/src/V1/AddGroupMigrationRequest.php index 7d4c1984e09d..5d5a21fd908e 100644 --- a/VmMigration/src/V1/AddGroupMigrationRequest.php +++ b/VmMigration/src/V1/AddGroupMigrationRequest.php @@ -28,6 +28,20 @@ class AddGroupMigrationRequest extends \Google\Protobuf\Internal\Message */ private $migrating_vm = ''; + /** + * @param string $group Required. The full path name of the Group to add to. Please see + * {@see VmMigrationClient::groupName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\AddGroupMigrationRequest + * + * @experimental + */ + public static function build(string $group): self + { + return (new self()) + ->setGroup($group); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CancelCloneJobRequest.php b/VmMigration/src/V1/CancelCloneJobRequest.php index 0c017bf0ef66..cde00ce199f4 100644 --- a/VmMigration/src/V1/CancelCloneJobRequest.php +++ b/VmMigration/src/V1/CancelCloneJobRequest.php @@ -22,6 +22,20 @@ class CancelCloneJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The clone job id + * Please see {@see VmMigrationClient::cloneJobName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\CancelCloneJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CancelCutoverJobRequest.php b/VmMigration/src/V1/CancelCutoverJobRequest.php index 86e3ef455d7b..cd03359e11cf 100644 --- a/VmMigration/src/V1/CancelCutoverJobRequest.php +++ b/VmMigration/src/V1/CancelCutoverJobRequest.php @@ -22,6 +22,20 @@ class CancelCutoverJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The cutover job id + * Please see {@see VmMigrationClient::cutoverJobName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\CancelCutoverJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/Client/BaseClient/VmMigrationBaseClient.php b/VmMigration/src/V1/Client/BaseClient/VmMigrationBaseClient.php new file mode 100644 index 000000000000..a9d8ce66cc8c --- /dev/null +++ b/VmMigration/src/V1/Client/BaseClient/VmMigrationBaseClient.php @@ -0,0 +1,1729 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/vm_migration_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/vm_migration_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/vm_migration_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/vm_migration_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 clone_job + * resource. + * + * @param string $project + * @param string $location + * @param string $source + * @param string $migratingVm + * @param string $cloneJob + * + * @return string The formatted clone_job resource. + */ + public static function cloneJobName(string $project, string $location, string $source, string $migratingVm, string $cloneJob): string + { + return self::getPathTemplate('cloneJob')->render([ + 'project' => $project, + 'location' => $location, + 'source' => $source, + 'migrating_vm' => $migratingVm, + 'clone_job' => $cloneJob, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a cutover_job + * resource. + * + * @param string $project + * @param string $location + * @param string $source + * @param string $migratingVm + * @param string $cutoverJob + * + * @return string The formatted cutover_job resource. + */ + public static function cutoverJobName(string $project, string $location, string $source, string $migratingVm, string $cutoverJob): string + { + return self::getPathTemplate('cutoverJob')->render([ + 'project' => $project, + 'location' => $location, + 'source' => $source, + 'migrating_vm' => $migratingVm, + 'cutover_job' => $cutoverJob, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * datacenter_connector resource. + * + * @param string $project + * @param string $location + * @param string $source + * @param string $datacenterConnector + * + * @return string The formatted datacenter_connector resource. + */ + public static function datacenterConnectorName(string $project, string $location, string $source, string $datacenterConnector): string + { + return self::getPathTemplate('datacenterConnector')->render([ + 'project' => $project, + 'location' => $location, + 'source' => $source, + 'datacenter_connector' => $datacenterConnector, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a group + * resource. + * + * @param string $project + * @param string $location + * @param string $group + * + * @return string The formatted group resource. + */ + public static function groupName(string $project, string $location, string $group): string + { + return self::getPathTemplate('group')->render([ + 'project' => $project, + 'location' => $location, + 'group' => $group, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a migrating_vm + * resource. + * + * @param string $project + * @param string $location + * @param string $source + * @param string $migratingVm + * + * @return string The formatted migrating_vm resource. + */ + public static function migratingVmName(string $project, string $location, string $source, string $migratingVm): string + { + return self::getPathTemplate('migratingVm')->render([ + 'project' => $project, + 'location' => $location, + 'source' => $source, + 'migrating_vm' => $migratingVm, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * replication_cycle resource. + * + * @param string $project + * @param string $location + * @param string $source + * @param string $migratingVm + * @param string $replicationCycle + * + * @return string The formatted replication_cycle resource. + */ + public static function replicationCycleName(string $project, string $location, string $source, string $migratingVm, string $replicationCycle): string + { + return self::getPathTemplate('replicationCycle')->render([ + 'project' => $project, + 'location' => $location, + 'source' => $source, + 'migrating_vm' => $migratingVm, + 'replication_cycle' => $replicationCycle, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a source + * resource. + * + * @param string $project + * @param string $location + * @param string $source + * + * @return string The formatted source resource. + */ + public static function sourceName(string $project, string $location, string $source): string + { + return self::getPathTemplate('source')->render([ + 'project' => $project, + 'location' => $location, + 'source' => $source, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * target_project resource. + * + * @param string $project + * @param string $location + * @param string $targetProject + * + * @return string The formatted target_project resource. + */ + public static function targetProjectName(string $project, string $location, string $targetProject): string + { + return self::getPathTemplate('targetProject')->render([ + 'project' => $project, + 'location' => $location, + 'target_project' => $targetProject, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * utilization_report resource. + * + * @param string $project + * @param string $location + * @param string $source + * @param string $utilizationReport + * + * @return string The formatted utilization_report resource. + */ + public static function utilizationReportName(string $project, string $location, string $source, string $utilizationReport): string + { + return self::getPathTemplate('utilizationReport')->render([ + 'project' => $project, + 'location' => $location, + 'source' => $source, + 'utilization_report' => $utilizationReport, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - cloneJob: projects/{project}/locations/{location}/sources/{source}/migratingVms/{migrating_vm}/cloneJobs/{clone_job} + * - cutoverJob: projects/{project}/locations/{location}/sources/{source}/migratingVms/{migrating_vm}/cutoverJobs/{cutover_job} + * - datacenterConnector: projects/{project}/locations/{location}/sources/{source}/datacenterConnectors/{datacenter_connector} + * - group: projects/{project}/locations/{location}/groups/{group} + * - location: projects/{project}/locations/{location} + * - migratingVm: projects/{project}/locations/{location}/sources/{source}/migratingVms/{migrating_vm} + * - replicationCycle: projects/{project}/locations/{location}/sources/{source}/migratingVms/{migrating_vm}/replicationCycles/{replication_cycle} + * - source: projects/{project}/locations/{location}/sources/{source} + * - targetProject: projects/{project}/locations/{location}/targetProjects/{target_project} + * - utilizationReport: projects/{project}/locations/{location}/sources/{source}/utilizationReports/{utilization_report} + * + * 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 'vmmigration.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); + } + + /** + * Adds a MigratingVm to a Group. + * + * The async variant is {@see self::addGroupMigrationAsync()} . + * + * @param AddGroupMigrationRequest $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 addGroupMigration(AddGroupMigrationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('AddGroupMigration', $request, $callOptions)->wait(); + } + + /** + * Initiates the cancellation of a running clone job. + * + * The async variant is {@see self::cancelCloneJobAsync()} . + * + * @param CancelCloneJobRequest $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 cancelCloneJob(CancelCloneJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CancelCloneJob', $request, $callOptions)->wait(); + } + + /** + * Initiates the cancellation of a running cutover job. + * + * The async variant is {@see self::cancelCutoverJobAsync()} . + * + * @param CancelCutoverJobRequest $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 cancelCutoverJob(CancelCutoverJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CancelCutoverJob', $request, $callOptions)->wait(); + } + + /** + * Initiates a Clone of a specific migrating VM. + * + * The async variant is {@see self::createCloneJobAsync()} . + * + * @param CreateCloneJobRequest $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 createCloneJob(CreateCloneJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateCloneJob', $request, $callOptions)->wait(); + } + + /** + * Initiates a Cutover of a specific migrating VM. + * The returned LRO is completed when the cutover job resource is created + * and the job is initiated. + * + * The async variant is {@see self::createCutoverJobAsync()} . + * + * @param CreateCutoverJobRequest $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 createCutoverJob(CreateCutoverJobRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateCutoverJob', $request, $callOptions)->wait(); + } + + /** + * Creates a new DatacenterConnector in a given Source. + * + * The async variant is {@see self::createDatacenterConnectorAsync()} . + * + * @param CreateDatacenterConnectorRequest $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 createDatacenterConnector(CreateDatacenterConnectorRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateDatacenterConnector', $request, $callOptions)->wait(); + } + + /** + * Creates a new Group in a given project and location. + * + * The async variant is {@see self::createGroupAsync()} . + * + * @param CreateGroupRequest $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 createGroup(CreateGroupRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateGroup', $request, $callOptions)->wait(); + } + + /** + * Creates a new MigratingVm in a given Source. + * + * The async variant is {@see self::createMigratingVmAsync()} . + * + * @param CreateMigratingVmRequest $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 createMigratingVm(CreateMigratingVmRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateMigratingVm', $request, $callOptions)->wait(); + } + + /** + * Creates a new Source in a given project and location. + * + * The async variant is {@see self::createSourceAsync()} . + * + * @param CreateSourceRequest $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 createSource(CreateSourceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateSource', $request, $callOptions)->wait(); + } + + /** + * Creates a new TargetProject in a given project. + * + * NOTE: TargetProject is a global resource; hence the only supported value + * for location is `global`. + * + * The async variant is {@see self::createTargetProjectAsync()} . + * + * @param CreateTargetProjectRequest $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 createTargetProject(CreateTargetProjectRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateTargetProject', $request, $callOptions)->wait(); + } + + /** + * Creates a new UtilizationReport. + * + * The async variant is {@see self::createUtilizationReportAsync()} . + * + * @param CreateUtilizationReportRequest $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 createUtilizationReport(CreateUtilizationReportRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateUtilizationReport', $request, $callOptions)->wait(); + } + + /** + * Deletes a single DatacenterConnector. + * + * The async variant is {@see self::deleteDatacenterConnectorAsync()} . + * + * @param DeleteDatacenterConnectorRequest $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 deleteDatacenterConnector(DeleteDatacenterConnectorRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteDatacenterConnector', $request, $callOptions)->wait(); + } + + /** + * Deletes a single Group. + * + * The async variant is {@see self::deleteGroupAsync()} . + * + * @param DeleteGroupRequest $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 deleteGroup(DeleteGroupRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteGroup', $request, $callOptions)->wait(); + } + + /** + * Deletes a single MigratingVm. + * + * The async variant is {@see self::deleteMigratingVmAsync()} . + * + * @param DeleteMigratingVmRequest $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 deleteMigratingVm(DeleteMigratingVmRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteMigratingVm', $request, $callOptions)->wait(); + } + + /** + * Deletes a single Source. + * + * The async variant is {@see self::deleteSourceAsync()} . + * + * @param DeleteSourceRequest $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 deleteSource(DeleteSourceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteSource', $request, $callOptions)->wait(); + } + + /** + * Deletes a single TargetProject. + * + * NOTE: TargetProject is a global resource; hence the only supported value + * for location is `global`. + * + * The async variant is {@see self::deleteTargetProjectAsync()} . + * + * @param DeleteTargetProjectRequest $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 deleteTargetProject(DeleteTargetProjectRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteTargetProject', $request, $callOptions)->wait(); + } + + /** + * Deletes a single Utilization Report. + * + * The async variant is {@see self::deleteUtilizationReportAsync()} . + * + * @param DeleteUtilizationReportRequest $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 deleteUtilizationReport(DeleteUtilizationReportRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteUtilizationReport', $request, $callOptions)->wait(); + } + + /** + * List remote source's inventory of VMs. + * The remote source is the onprem vCenter (remote in the sense it's not in + * Compute Engine). The inventory describes the list of existing VMs in that + * source. Note that this operation lists the VMs on the remote source, as + * opposed to listing the MigratingVms resources in the vmmigration service. + * + * The async variant is {@see self::fetchInventoryAsync()} . + * + * @param FetchInventoryRequest $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 FetchInventoryResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function fetchInventory(FetchInventoryRequest $request, array $callOptions = []): FetchInventoryResponse + { + return $this->startApiCall('FetchInventory', $request, $callOptions)->wait(); + } + + /** + * Marks a migration as completed, deleting migration resources that are no + * longer being used. Only applicable after cutover is done. + * + * The async variant is {@see self::finalizeMigrationAsync()} . + * + * @param FinalizeMigrationRequest $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 finalizeMigration(FinalizeMigrationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('FinalizeMigration', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single CloneJob. + * + * The async variant is {@see self::getCloneJobAsync()} . + * + * @param GetCloneJobRequest $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 CloneJob + * + * @throws ApiException Thrown if the API call fails. + */ + public function getCloneJob(GetCloneJobRequest $request, array $callOptions = []): CloneJob + { + return $this->startApiCall('GetCloneJob', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single CutoverJob. + * + * The async variant is {@see self::getCutoverJobAsync()} . + * + * @param GetCutoverJobRequest $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 CutoverJob + * + * @throws ApiException Thrown if the API call fails. + */ + public function getCutoverJob(GetCutoverJobRequest $request, array $callOptions = []): CutoverJob + { + return $this->startApiCall('GetCutoverJob', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single DatacenterConnector. + * + * The async variant is {@see self::getDatacenterConnectorAsync()} . + * + * @param GetDatacenterConnectorRequest $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 DatacenterConnector + * + * @throws ApiException Thrown if the API call fails. + */ + public function getDatacenterConnector(GetDatacenterConnectorRequest $request, array $callOptions = []): DatacenterConnector + { + return $this->startApiCall('GetDatacenterConnector', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single Group. + * + * The async variant is {@see self::getGroupAsync()} . + * + * @param GetGroupRequest $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 Group + * + * @throws ApiException Thrown if the API call fails. + */ + public function getGroup(GetGroupRequest $request, array $callOptions = []): Group + { + return $this->startApiCall('GetGroup', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single MigratingVm. + * + * The async variant is {@see self::getMigratingVmAsync()} . + * + * @param GetMigratingVmRequest $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 MigratingVm + * + * @throws ApiException Thrown if the API call fails. + */ + public function getMigratingVm(GetMigratingVmRequest $request, array $callOptions = []): MigratingVm + { + return $this->startApiCall('GetMigratingVm', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single ReplicationCycle. + * + * The async variant is {@see self::getReplicationCycleAsync()} . + * + * @param GetReplicationCycleRequest $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 ReplicationCycle + * + * @throws ApiException Thrown if the API call fails. + */ + public function getReplicationCycle(GetReplicationCycleRequest $request, array $callOptions = []): ReplicationCycle + { + return $this->startApiCall('GetReplicationCycle', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single Source. + * + * The async variant is {@see self::getSourceAsync()} . + * + * @param GetSourceRequest $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 Source + * + * @throws ApiException Thrown if the API call fails. + */ + public function getSource(GetSourceRequest $request, array $callOptions = []): Source + { + return $this->startApiCall('GetSource', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single TargetProject. + * + * NOTE: TargetProject is a global resource; hence the only supported value + * for location is `global`. + * + * The async variant is {@see self::getTargetProjectAsync()} . + * + * @param GetTargetProjectRequest $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 TargetProject + * + * @throws ApiException Thrown if the API call fails. + */ + public function getTargetProject(GetTargetProjectRequest $request, array $callOptions = []): TargetProject + { + return $this->startApiCall('GetTargetProject', $request, $callOptions)->wait(); + } + + /** + * Gets a single Utilization Report. + * + * The async variant is {@see self::getUtilizationReportAsync()} . + * + * @param GetUtilizationReportRequest $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 UtilizationReport + * + * @throws ApiException Thrown if the API call fails. + */ + public function getUtilizationReport(GetUtilizationReportRequest $request, array $callOptions = []): UtilizationReport + { + return $this->startApiCall('GetUtilizationReport', $request, $callOptions)->wait(); + } + + /** + * Lists CloneJobs of a given migrating VM. + * + * The async variant is {@see self::listCloneJobsAsync()} . + * + * @param ListCloneJobsRequest $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 listCloneJobs(ListCloneJobsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCloneJobs', $request, $callOptions); + } + + /** + * Lists CutoverJobs of a given migrating VM. + * + * The async variant is {@see self::listCutoverJobsAsync()} . + * + * @param ListCutoverJobsRequest $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 listCutoverJobs(ListCutoverJobsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCutoverJobs', $request, $callOptions); + } + + /** + * Lists DatacenterConnectors in a given Source. + * + * The async variant is {@see self::listDatacenterConnectorsAsync()} . + * + * @param ListDatacenterConnectorsRequest $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 listDatacenterConnectors(ListDatacenterConnectorsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListDatacenterConnectors', $request, $callOptions); + } + + /** + * Lists Groups in a given project and location. + * + * The async variant is {@see self::listGroupsAsync()} . + * + * @param ListGroupsRequest $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 listGroups(ListGroupsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListGroups', $request, $callOptions); + } + + /** + * Lists MigratingVms in a given Source. + * + * The async variant is {@see self::listMigratingVmsAsync()} . + * + * @param ListMigratingVmsRequest $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 listMigratingVms(ListMigratingVmsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListMigratingVms', $request, $callOptions); + } + + /** + * Lists ReplicationCycles in a given MigratingVM. + * + * The async variant is {@see self::listReplicationCyclesAsync()} . + * + * @param ListReplicationCyclesRequest $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 listReplicationCycles(ListReplicationCyclesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListReplicationCycles', $request, $callOptions); + } + + /** + * Lists Sources in a given project and location. + * + * The async variant is {@see self::listSourcesAsync()} . + * + * @param ListSourcesRequest $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 listSources(ListSourcesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListSources', $request, $callOptions); + } + + /** + * Lists TargetProjects in a given project. + * + * NOTE: TargetProject is a global resource; hence the only supported value + * for location is `global`. + * + * The async variant is {@see self::listTargetProjectsAsync()} . + * + * @param ListTargetProjectsRequest $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 listTargetProjects(ListTargetProjectsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListTargetProjects', $request, $callOptions); + } + + /** + * Lists Utilization Reports of the given Source. + * + * The async variant is {@see self::listUtilizationReportsAsync()} . + * + * @param ListUtilizationReportsRequest $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 listUtilizationReports(ListUtilizationReportsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListUtilizationReports', $request, $callOptions); + } + + /** + * Pauses a migration for a VM. If cycle tasks are running they will be + * cancelled, preserving source task data. Further replication cycles will not + * be triggered while the VM is paused. + * + * The async variant is {@see self::pauseMigrationAsync()} . + * + * @param PauseMigrationRequest $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 pauseMigration(PauseMigrationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('PauseMigration', $request, $callOptions)->wait(); + } + + /** + * Removes a MigratingVm from a Group. + * + * The async variant is {@see self::removeGroupMigrationAsync()} . + * + * @param RemoveGroupMigrationRequest $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 removeGroupMigration(RemoveGroupMigrationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('RemoveGroupMigration', $request, $callOptions)->wait(); + } + + /** + * Resumes a migration for a VM. When called on a paused migration, will start + * the process of uploading data and creating snapshots; when called on a + * completed cut-over migration, will update the migration to active state and + * start the process of uploading data and creating snapshots. + * + * The async variant is {@see self::resumeMigrationAsync()} . + * + * @param ResumeMigrationRequest $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 resumeMigration(ResumeMigrationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ResumeMigration', $request, $callOptions)->wait(); + } + + /** + * Starts migration for a VM. Starts the process of uploading + * data and creating snapshots, in replication cycles scheduled by the policy. + * + * The async variant is {@see self::startMigrationAsync()} . + * + * @param StartMigrationRequest $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 startMigration(StartMigrationRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('StartMigration', $request, $callOptions)->wait(); + } + + /** + * Updates the parameters of a single Group. + * + * The async variant is {@see self::updateGroupAsync()} . + * + * @param UpdateGroupRequest $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 updateGroup(UpdateGroupRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateGroup', $request, $callOptions)->wait(); + } + + /** + * Updates the parameters of a single MigratingVm. + * + * The async variant is {@see self::updateMigratingVmAsync()} . + * + * @param UpdateMigratingVmRequest $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 updateMigratingVm(UpdateMigratingVmRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateMigratingVm', $request, $callOptions)->wait(); + } + + /** + * Updates the parameters of a single Source. + * + * The async variant is {@see self::updateSourceAsync()} . + * + * @param UpdateSourceRequest $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 updateSource(UpdateSourceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateSource', $request, $callOptions)->wait(); + } + + /** + * Updates the parameters of a single TargetProject. + * + * NOTE: TargetProject is a global resource; hence the only supported value + * for location is `global`. + * + * The async variant is {@see self::updateTargetProjectAsync()} . + * + * @param UpdateTargetProjectRequest $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 updateTargetProject(UpdateTargetProjectRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateTargetProject', $request, $callOptions)->wait(); + } + + /** + * Upgrades the appliance relate to this DatacenterConnector to the in-place + * updateable version. + * + * The async variant is {@see self::upgradeApplianceAsync()} . + * + * @param UpgradeApplianceRequest $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 upgradeAppliance(UpgradeApplianceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpgradeAppliance', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $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 Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $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 listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } +} diff --git a/VmMigration/src/V1/Client/VmMigrationClient.php b/VmMigration/src/V1/Client/VmMigrationClient.php new file mode 100644 index 000000000000..bb4815e7acdb --- /dev/null +++ b/VmMigration/src/V1/Client/VmMigrationClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setCloneJob($cloneJob) + ->setCloneJobId($cloneJobId); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CreateCutoverJobRequest.php b/VmMigration/src/V1/CreateCutoverJobRequest.php index a800aa89bd6e..2932f98f357a 100644 --- a/VmMigration/src/V1/CreateCutoverJobRequest.php +++ b/VmMigration/src/V1/CreateCutoverJobRequest.php @@ -50,6 +50,24 @@ class CreateCutoverJobRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The Cutover's parent. Please see + * {@see VmMigrationClient::migratingVmName()} for help formatting this field. + * @param \Google\Cloud\VMMigration\V1\CutoverJob $cutoverJob Required. The cutover request body. + * @param string $cutoverJobId Required. The cutover job identifier. + * + * @return \Google\Cloud\VMMigration\V1\CreateCutoverJobRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VMMigration\V1\CutoverJob $cutoverJob, string $cutoverJobId): self + { + return (new self()) + ->setParent($parent) + ->setCutoverJob($cutoverJob) + ->setCutoverJobId($cutoverJobId); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CreateDatacenterConnectorRequest.php b/VmMigration/src/V1/CreateDatacenterConnectorRequest.php index fa34ab2ef46e..66acc831cb58 100644 --- a/VmMigration/src/V1/CreateDatacenterConnectorRequest.php +++ b/VmMigration/src/V1/CreateDatacenterConnectorRequest.php @@ -53,6 +53,27 @@ class CreateDatacenterConnectorRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The DatacenterConnector's parent. + * Required. The Source in where the new DatacenterConnector will be created. + * For example: + * `projects/my-project/locations/us-central1/sources/my-source` + * Please see {@see VmMigrationClient::sourceName()} for help formatting this field. + * @param \Google\Cloud\VMMigration\V1\DatacenterConnector $datacenterConnector Required. The create request body. + * @param string $datacenterConnectorId Required. The datacenterConnector identifier. + * + * @return \Google\Cloud\VMMigration\V1\CreateDatacenterConnectorRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VMMigration\V1\DatacenterConnector $datacenterConnector, string $datacenterConnectorId): self + { + return (new self()) + ->setParent($parent) + ->setDatacenterConnector($datacenterConnector) + ->setDatacenterConnectorId($datacenterConnectorId); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CreateGroupRequest.php b/VmMigration/src/V1/CreateGroupRequest.php index 8644c0352546..20cd3bddc46e 100644 --- a/VmMigration/src/V1/CreateGroupRequest.php +++ b/VmMigration/src/V1/CreateGroupRequest.php @@ -50,6 +50,24 @@ class CreateGroupRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The Group's parent. Please see + * {@see VmMigrationClient::locationName()} for help formatting this field. + * @param \Google\Cloud\VMMigration\V1\Group $group Required. The create request body. + * @param string $groupId Required. The group identifier. + * + * @return \Google\Cloud\VMMigration\V1\CreateGroupRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VMMigration\V1\Group $group, string $groupId): self + { + return (new self()) + ->setParent($parent) + ->setGroup($group) + ->setGroupId($groupId); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CreateMigratingVmRequest.php b/VmMigration/src/V1/CreateMigratingVmRequest.php index e18d30623777..8f74f5c97229 100644 --- a/VmMigration/src/V1/CreateMigratingVmRequest.php +++ b/VmMigration/src/V1/CreateMigratingVmRequest.php @@ -50,6 +50,24 @@ class CreateMigratingVmRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The MigratingVm's parent. Please see + * {@see VmMigrationClient::sourceName()} for help formatting this field. + * @param \Google\Cloud\VMMigration\V1\MigratingVm $migratingVm Required. The create request body. + * @param string $migratingVmId Required. The migratingVm identifier. + * + * @return \Google\Cloud\VMMigration\V1\CreateMigratingVmRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VMMigration\V1\MigratingVm $migratingVm, string $migratingVmId): self + { + return (new self()) + ->setParent($parent) + ->setMigratingVm($migratingVm) + ->setMigratingVmId($migratingVmId); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CreateSourceRequest.php b/VmMigration/src/V1/CreateSourceRequest.php index 96271260a47e..5b7c694d8316 100644 --- a/VmMigration/src/V1/CreateSourceRequest.php +++ b/VmMigration/src/V1/CreateSourceRequest.php @@ -50,6 +50,24 @@ class CreateSourceRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The Source's parent. Please see + * {@see VmMigrationClient::locationName()} for help formatting this field. + * @param \Google\Cloud\VMMigration\V1\Source $source Required. The create request body. + * @param string $sourceId Required. The source identifier. + * + * @return \Google\Cloud\VMMigration\V1\CreateSourceRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VMMigration\V1\Source $source, string $sourceId): self + { + return (new self()) + ->setParent($parent) + ->setSource($source) + ->setSourceId($sourceId); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CreateTargetProjectRequest.php b/VmMigration/src/V1/CreateTargetProjectRequest.php index 26256cf64148..da4d182c1d35 100644 --- a/VmMigration/src/V1/CreateTargetProjectRequest.php +++ b/VmMigration/src/V1/CreateTargetProjectRequest.php @@ -50,6 +50,24 @@ class CreateTargetProjectRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The TargetProject's parent. Please see + * {@see VmMigrationClient::locationName()} for help formatting this field. + * @param \Google\Cloud\VMMigration\V1\TargetProject $targetProject Required. The create request body. + * @param string $targetProjectId Required. The target_project identifier. + * + * @return \Google\Cloud\VMMigration\V1\CreateTargetProjectRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VMMigration\V1\TargetProject $targetProject, string $targetProjectId): self + { + return (new self()) + ->setParent($parent) + ->setTargetProject($targetProject) + ->setTargetProjectId($targetProjectId); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/CreateUtilizationReportRequest.php b/VmMigration/src/V1/CreateUtilizationReportRequest.php index 948486507c0f..d0c3fb4249d0 100644 --- a/VmMigration/src/V1/CreateUtilizationReportRequest.php +++ b/VmMigration/src/V1/CreateUtilizationReportRequest.php @@ -54,6 +54,29 @@ class CreateUtilizationReportRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The Utilization Report's parent. Please see + * {@see VmMigrationClient::sourceName()} for help formatting this field. + * @param \Google\Cloud\VMMigration\V1\UtilizationReport $utilizationReport Required. The report to create. + * @param string $utilizationReportId Required. The ID to use for the report, which will become the final + * component of the reports's resource name. + * + * This value maximum length is 63 characters, and valid characters + * are /[a-z][0-9]-/. It must start with an english letter and must not + * end with a hyphen. + * + * @return \Google\Cloud\VMMigration\V1\CreateUtilizationReportRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VMMigration\V1\UtilizationReport $utilizationReport, string $utilizationReportId): self + { + return (new self()) + ->setParent($parent) + ->setUtilizationReport($utilizationReport) + ->setUtilizationReportId($utilizationReportId); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/DeleteDatacenterConnectorRequest.php b/VmMigration/src/V1/DeleteDatacenterConnectorRequest.php index 1adccd41f433..187c82be34e6 100644 --- a/VmMigration/src/V1/DeleteDatacenterConnectorRequest.php +++ b/VmMigration/src/V1/DeleteDatacenterConnectorRequest.php @@ -38,6 +38,20 @@ class DeleteDatacenterConnectorRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The DatacenterConnector name. Please see + * {@see VmMigrationClient::datacenterConnectorName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\DeleteDatacenterConnectorRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/DeleteGroupRequest.php b/VmMigration/src/V1/DeleteGroupRequest.php index 087604e40ebb..cb8a9990a470 100644 --- a/VmMigration/src/V1/DeleteGroupRequest.php +++ b/VmMigration/src/V1/DeleteGroupRequest.php @@ -38,6 +38,20 @@ class DeleteGroupRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The Group name. Please see + * {@see VmMigrationClient::groupName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\DeleteGroupRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/DeleteMigratingVmRequest.php b/VmMigration/src/V1/DeleteMigratingVmRequest.php index 7c572c63c7ae..56862dfda748 100644 --- a/VmMigration/src/V1/DeleteMigratingVmRequest.php +++ b/VmMigration/src/V1/DeleteMigratingVmRequest.php @@ -22,6 +22,20 @@ class DeleteMigratingVmRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the MigratingVm. Please see + * {@see VmMigrationClient::migratingVmName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\DeleteMigratingVmRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/DeleteSourceRequest.php b/VmMigration/src/V1/DeleteSourceRequest.php index 7495e254bbd7..c4f438fd2d7d 100644 --- a/VmMigration/src/V1/DeleteSourceRequest.php +++ b/VmMigration/src/V1/DeleteSourceRequest.php @@ -38,6 +38,20 @@ class DeleteSourceRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The Source name. Please see + * {@see VmMigrationClient::sourceName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\DeleteSourceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/DeleteTargetProjectRequest.php b/VmMigration/src/V1/DeleteTargetProjectRequest.php index 0d992bbc57d1..00c148d89868 100644 --- a/VmMigration/src/V1/DeleteTargetProjectRequest.php +++ b/VmMigration/src/V1/DeleteTargetProjectRequest.php @@ -38,6 +38,20 @@ class DeleteTargetProjectRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The TargetProject name. Please see + * {@see VmMigrationClient::targetProjectName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\DeleteTargetProjectRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/DeleteUtilizationReportRequest.php b/VmMigration/src/V1/DeleteUtilizationReportRequest.php index d201302b56e1..ec9ca7c1def7 100644 --- a/VmMigration/src/V1/DeleteUtilizationReportRequest.php +++ b/VmMigration/src/V1/DeleteUtilizationReportRequest.php @@ -38,6 +38,20 @@ class DeleteUtilizationReportRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The Utilization Report name. Please see + * {@see VmMigrationClient::utilizationReportName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\DeleteUtilizationReportRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/FetchInventoryRequest.php b/VmMigration/src/V1/FetchInventoryRequest.php index 2661958bfb37..c2ae20898169 100644 --- a/VmMigration/src/V1/FetchInventoryRequest.php +++ b/VmMigration/src/V1/FetchInventoryRequest.php @@ -30,6 +30,20 @@ class FetchInventoryRequest extends \Google\Protobuf\Internal\Message */ private $force_refresh = false; + /** + * @param string $source Required. The name of the Source. Please see + * {@see VmMigrationClient::sourceName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\FetchInventoryRequest + * + * @experimental + */ + public static function build(string $source): self + { + return (new self()) + ->setSource($source); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/FinalizeMigrationRequest.php b/VmMigration/src/V1/FinalizeMigrationRequest.php index 69df41da47c9..8e13177e319e 100644 --- a/VmMigration/src/V1/FinalizeMigrationRequest.php +++ b/VmMigration/src/V1/FinalizeMigrationRequest.php @@ -22,6 +22,20 @@ class FinalizeMigrationRequest extends \Google\Protobuf\Internal\Message */ private $migrating_vm = ''; + /** + * @param string $migratingVm Required. The name of the MigratingVm. Please see + * {@see VmMigrationClient::migratingVmName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\FinalizeMigrationRequest + * + * @experimental + */ + public static function build(string $migratingVm): self + { + return (new self()) + ->setMigratingVm($migratingVm); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetCloneJobRequest.php b/VmMigration/src/V1/GetCloneJobRequest.php index 0616da97662c..927068bd8e6a 100644 --- a/VmMigration/src/V1/GetCloneJobRequest.php +++ b/VmMigration/src/V1/GetCloneJobRequest.php @@ -22,6 +22,20 @@ class GetCloneJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the CloneJob. Please see + * {@see VmMigrationClient::cloneJobName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetCloneJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetCutoverJobRequest.php b/VmMigration/src/V1/GetCutoverJobRequest.php index dff14bfe09cd..b764f18396b0 100644 --- a/VmMigration/src/V1/GetCutoverJobRequest.php +++ b/VmMigration/src/V1/GetCutoverJobRequest.php @@ -22,6 +22,20 @@ class GetCutoverJobRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the CutoverJob. Please see + * {@see VmMigrationClient::cutoverJobName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetCutoverJobRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetDatacenterConnectorRequest.php b/VmMigration/src/V1/GetDatacenterConnectorRequest.php index 0c495f063e8b..1ade9a21dfea 100644 --- a/VmMigration/src/V1/GetDatacenterConnectorRequest.php +++ b/VmMigration/src/V1/GetDatacenterConnectorRequest.php @@ -22,6 +22,20 @@ class GetDatacenterConnectorRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the DatacenterConnector. Please see + * {@see VmMigrationClient::datacenterConnectorName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetDatacenterConnectorRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetGroupRequest.php b/VmMigration/src/V1/GetGroupRequest.php index 135c74f397ea..ed1bbcf3f4be 100644 --- a/VmMigration/src/V1/GetGroupRequest.php +++ b/VmMigration/src/V1/GetGroupRequest.php @@ -22,6 +22,20 @@ class GetGroupRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The group name. Please see + * {@see VmMigrationClient::groupName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetGroupRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetMigratingVmRequest.php b/VmMigration/src/V1/GetMigratingVmRequest.php index 1bb43dbc126b..3095d7fd2686 100644 --- a/VmMigration/src/V1/GetMigratingVmRequest.php +++ b/VmMigration/src/V1/GetMigratingVmRequest.php @@ -28,6 +28,20 @@ class GetMigratingVmRequest extends \Google\Protobuf\Internal\Message */ private $view = 0; + /** + * @param string $name Required. The name of the MigratingVm. Please see + * {@see VmMigrationClient::migratingVmName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetMigratingVmRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetReplicationCycleRequest.php b/VmMigration/src/V1/GetReplicationCycleRequest.php index f8e71d7bc5e0..5178bd2d71a0 100644 --- a/VmMigration/src/V1/GetReplicationCycleRequest.php +++ b/VmMigration/src/V1/GetReplicationCycleRequest.php @@ -22,6 +22,20 @@ class GetReplicationCycleRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The name of the ReplicationCycle. Please see + * {@see VmMigrationClient::replicationCycleName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetReplicationCycleRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetSourceRequest.php b/VmMigration/src/V1/GetSourceRequest.php index 065553b76e0e..f5535afc1488 100644 --- a/VmMigration/src/V1/GetSourceRequest.php +++ b/VmMigration/src/V1/GetSourceRequest.php @@ -22,6 +22,20 @@ class GetSourceRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The Source name. Please see + * {@see VmMigrationClient::sourceName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetSourceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetTargetProjectRequest.php b/VmMigration/src/V1/GetTargetProjectRequest.php index 22078ff57fc5..0c08359ae4ed 100644 --- a/VmMigration/src/V1/GetTargetProjectRequest.php +++ b/VmMigration/src/V1/GetTargetProjectRequest.php @@ -22,6 +22,20 @@ class GetTargetProjectRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The TargetProject name. Please see + * {@see VmMigrationClient::targetProjectName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetTargetProjectRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/GetUtilizationReportRequest.php b/VmMigration/src/V1/GetUtilizationReportRequest.php index e0ceeb341acf..b821061e5d0a 100644 --- a/VmMigration/src/V1/GetUtilizationReportRequest.php +++ b/VmMigration/src/V1/GetUtilizationReportRequest.php @@ -29,6 +29,20 @@ class GetUtilizationReportRequest extends \Google\Protobuf\Internal\Message */ private $view = 0; + /** + * @param string $name Required. The Utilization Report name. Please see + * {@see VmMigrationClient::utilizationReportName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\GetUtilizationReportRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListCloneJobsRequest.php b/VmMigration/src/V1/ListCloneJobsRequest.php index e1271708ae8a..ebd6e1e24df9 100644 --- a/VmMigration/src/V1/ListCloneJobsRequest.php +++ b/VmMigration/src/V1/ListCloneJobsRequest.php @@ -52,6 +52,20 @@ class ListCloneJobsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent, which owns this collection of source VMs. Please see + * {@see VmMigrationClient::migratingVmName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListCloneJobsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListCutoverJobsRequest.php b/VmMigration/src/V1/ListCutoverJobsRequest.php index 7a076e4e5c05..42fc0a599092 100644 --- a/VmMigration/src/V1/ListCutoverJobsRequest.php +++ b/VmMigration/src/V1/ListCutoverJobsRequest.php @@ -52,6 +52,20 @@ class ListCutoverJobsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent, which owns this collection of migrating VMs. Please see + * {@see VmMigrationClient::migratingVmName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListCutoverJobsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListDatacenterConnectorsRequest.php b/VmMigration/src/V1/ListDatacenterConnectorsRequest.php index 34ba356e0c83..dc5d07f8ea40 100644 --- a/VmMigration/src/V1/ListDatacenterConnectorsRequest.php +++ b/VmMigration/src/V1/ListDatacenterConnectorsRequest.php @@ -53,6 +53,20 @@ class ListDatacenterConnectorsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent, which owns this collection of connectors. Please see + * {@see VmMigrationClient::sourceName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListDatacenterConnectorsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListGroupsRequest.php b/VmMigration/src/V1/ListGroupsRequest.php index 76fc61a940c9..d9c8e417cc19 100644 --- a/VmMigration/src/V1/ListGroupsRequest.php +++ b/VmMigration/src/V1/ListGroupsRequest.php @@ -52,6 +52,20 @@ class ListGroupsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent, which owns this collection of groups. Please see + * {@see VmMigrationClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListGroupsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListMigratingVmsRequest.php b/VmMigration/src/V1/ListMigratingVmsRequest.php index e8fe04507ff0..290c029bd0e5 100644 --- a/VmMigration/src/V1/ListMigratingVmsRequest.php +++ b/VmMigration/src/V1/ListMigratingVmsRequest.php @@ -58,6 +58,20 @@ class ListMigratingVmsRequest extends \Google\Protobuf\Internal\Message */ private $view = 0; + /** + * @param string $parent Required. The parent, which owns this collection of MigratingVms. Please see + * {@see VmMigrationClient::sourceName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListMigratingVmsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListReplicationCyclesRequest.php b/VmMigration/src/V1/ListReplicationCyclesRequest.php index d23b308908ee..f48770d1c01c 100644 --- a/VmMigration/src/V1/ListReplicationCyclesRequest.php +++ b/VmMigration/src/V1/ListReplicationCyclesRequest.php @@ -52,6 +52,20 @@ class ListReplicationCyclesRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent, which owns this collection of ReplicationCycles. Please see + * {@see VmMigrationClient::migratingVmName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListReplicationCyclesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListSourcesRequest.php b/VmMigration/src/V1/ListSourcesRequest.php index 4c2e96831f99..94cf659ca378 100644 --- a/VmMigration/src/V1/ListSourcesRequest.php +++ b/VmMigration/src/V1/ListSourcesRequest.php @@ -52,6 +52,20 @@ class ListSourcesRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent, which owns this collection of sources. Please see + * {@see VmMigrationClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListSourcesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListTargetProjectsRequest.php b/VmMigration/src/V1/ListTargetProjectsRequest.php index eec604294d48..82fcf0072007 100644 --- a/VmMigration/src/V1/ListTargetProjectsRequest.php +++ b/VmMigration/src/V1/ListTargetProjectsRequest.php @@ -52,6 +52,20 @@ class ListTargetProjectsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The parent, which owns this collection of targets. Please see + * {@see VmMigrationClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListTargetProjectsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/ListUtilizationReportsRequest.php b/VmMigration/src/V1/ListUtilizationReportsRequest.php index 1bbda587e914..b24548cbe33a 100644 --- a/VmMigration/src/V1/ListUtilizationReportsRequest.php +++ b/VmMigration/src/V1/ListUtilizationReportsRequest.php @@ -59,6 +59,20 @@ class ListUtilizationReportsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The Utilization Reports parent. Please see + * {@see VmMigrationClient::sourceName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\ListUtilizationReportsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/RemoveGroupMigrationRequest.php b/VmMigration/src/V1/RemoveGroupMigrationRequest.php index 88a37d1a7c94..aa1a961c387e 100644 --- a/VmMigration/src/V1/RemoveGroupMigrationRequest.php +++ b/VmMigration/src/V1/RemoveGroupMigrationRequest.php @@ -28,6 +28,20 @@ class RemoveGroupMigrationRequest extends \Google\Protobuf\Internal\Message */ private $migrating_vm = ''; + /** + * @param string $group Required. The name of the Group. Please see + * {@see VmMigrationClient::groupName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\RemoveGroupMigrationRequest + * + * @experimental + */ + public static function build(string $group): self + { + return (new self()) + ->setGroup($group); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/StartMigrationRequest.php b/VmMigration/src/V1/StartMigrationRequest.php index 684cfc6fa254..5788a100b433 100644 --- a/VmMigration/src/V1/StartMigrationRequest.php +++ b/VmMigration/src/V1/StartMigrationRequest.php @@ -22,6 +22,20 @@ class StartMigrationRequest extends \Google\Protobuf\Internal\Message */ private $migrating_vm = ''; + /** + * @param string $migratingVm Required. The name of the MigratingVm. Please see + * {@see VmMigrationClient::migratingVmName()} for help formatting this field. + * + * @return \Google\Cloud\VMMigration\V1\StartMigrationRequest + * + * @experimental + */ + public static function build(string $migratingVm): self + { + return (new self()) + ->setMigratingVm($migratingVm); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/UpdateGroupRequest.php b/VmMigration/src/V1/UpdateGroupRequest.php index c46a140d7a71..ec9d77d28412 100644 --- a/VmMigration/src/V1/UpdateGroupRequest.php +++ b/VmMigration/src/V1/UpdateGroupRequest.php @@ -48,6 +48,25 @@ class UpdateGroupRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\VMMigration\V1\Group $group Required. The update request body. + * @param \Google\Protobuf\FieldMask $updateMask Field mask is used to specify the fields to be overwritten in the + * Group resource by the update. + * The fields specified in the update_mask are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. If the + * user does not provide a mask then all fields will be overwritten. + * + * @return \Google\Cloud\VMMigration\V1\UpdateGroupRequest + * + * @experimental + */ + public static function build(\Google\Cloud\VMMigration\V1\Group $group, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setGroup($group) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/UpdateMigratingVmRequest.php b/VmMigration/src/V1/UpdateMigratingVmRequest.php index 94ba9a709538..6b86ccc9c162 100644 --- a/VmMigration/src/V1/UpdateMigratingVmRequest.php +++ b/VmMigration/src/V1/UpdateMigratingVmRequest.php @@ -48,6 +48,25 @@ class UpdateMigratingVmRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\VMMigration\V1\MigratingVm $migratingVm Required. The update request body. + * @param \Google\Protobuf\FieldMask $updateMask Field mask is used to specify the fields to be overwritten in the + * MigratingVm resource by the update. + * The fields specified in the update_mask are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. If the + * user does not provide a mask then all fields will be overwritten. + * + * @return \Google\Cloud\VMMigration\V1\UpdateMigratingVmRequest + * + * @experimental + */ + public static function build(\Google\Cloud\VMMigration\V1\MigratingVm $migratingVm, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setMigratingVm($migratingVm) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/UpdateSourceRequest.php b/VmMigration/src/V1/UpdateSourceRequest.php index 7f7d6337bbcc..fa1e2a4d5d83 100644 --- a/VmMigration/src/V1/UpdateSourceRequest.php +++ b/VmMigration/src/V1/UpdateSourceRequest.php @@ -48,6 +48,25 @@ class UpdateSourceRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\VMMigration\V1\Source $source Required. The update request body. + * @param \Google\Protobuf\FieldMask $updateMask Field mask is used to specify the fields to be overwritten in the + * Source resource by the update. + * The fields specified in the update_mask are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. If the + * user does not provide a mask then all fields will be overwritten. + * + * @return \Google\Cloud\VMMigration\V1\UpdateSourceRequest + * + * @experimental + */ + public static function build(\Google\Cloud\VMMigration\V1\Source $source, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setSource($source) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/UpdateTargetProjectRequest.php b/VmMigration/src/V1/UpdateTargetProjectRequest.php index c688d07e65bf..503c88793186 100644 --- a/VmMigration/src/V1/UpdateTargetProjectRequest.php +++ b/VmMigration/src/V1/UpdateTargetProjectRequest.php @@ -48,6 +48,25 @@ class UpdateTargetProjectRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\VMMigration\V1\TargetProject $targetProject Required. The update request body. + * @param \Google\Protobuf\FieldMask $updateMask Field mask is used to specify the fields to be overwritten in the + * TargetProject resource by the update. + * The fields specified in the update_mask are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. If the + * user does not provide a mask then all fields will be overwritten. + * + * @return \Google\Cloud\VMMigration\V1\UpdateTargetProjectRequest + * + * @experimental + */ + public static function build(\Google\Cloud\VMMigration\V1\TargetProject $targetProject, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setTargetProject($targetProject) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VmMigration/src/V1/resources/vm_migration_descriptor_config.php b/VmMigration/src/V1/resources/vm_migration_descriptor_config.php index a39e68cabc0b..e8dffa2de52a 100644 --- a/VmMigration/src/V1/resources/vm_migration_descriptor_config.php +++ b/VmMigration/src/V1/resources/vm_migration_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'group', + 'fieldAccessors' => [ + 'getGroup', + ], + ], + ], ], 'CancelCloneJob' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'CancelCutoverJob' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'CreateCloneJob' => [ 'longRunning' => [ @@ -42,6 +69,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateCutoverJob' => [ 'longRunning' => [ @@ -52,6 +88,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateDatacenterConnector' => [ 'longRunning' => [ @@ -62,6 +107,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateGroup' => [ 'longRunning' => [ @@ -72,6 +126,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateMigratingVm' => [ 'longRunning' => [ @@ -82,6 +145,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateSource' => [ 'longRunning' => [ @@ -92,6 +164,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateTargetProject' => [ 'longRunning' => [ @@ -102,6 +183,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateUtilizationReport' => [ 'longRunning' => [ @@ -112,6 +202,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteDatacenterConnector' => [ 'longRunning' => [ @@ -122,6 +221,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteGroup' => [ 'longRunning' => [ @@ -132,6 +240,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteMigratingVm' => [ 'longRunning' => [ @@ -142,6 +259,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteSource' => [ 'longRunning' => [ @@ -152,6 +278,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteTargetProject' => [ 'longRunning' => [ @@ -162,6 +297,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteUtilizationReport' => [ 'longRunning' => [ @@ -172,6 +316,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'FinalizeMigration' => [ 'longRunning' => [ @@ -182,6 +335,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'migrating_vm', + 'fieldAccessors' => [ + 'getMigratingVm', + ], + ], + ], ], 'PauseMigration' => [ 'longRunning' => [ @@ -192,6 +354,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'migrating_vm', + 'fieldAccessors' => [ + 'getMigratingVm', + ], + ], + ], ], 'RemoveGroupMigration' => [ 'longRunning' => [ @@ -202,6 +373,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'group', + 'fieldAccessors' => [ + 'getGroup', + ], + ], + ], ], 'ResumeMigration' => [ 'longRunning' => [ @@ -212,6 +392,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'migrating_vm', + 'fieldAccessors' => [ + 'getMigratingVm', + ], + ], + ], ], 'StartMigration' => [ 'longRunning' => [ @@ -222,6 +411,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'migrating_vm', + 'fieldAccessors' => [ + 'getMigratingVm', + ], + ], + ], ], 'UpdateGroup' => [ 'longRunning' => [ @@ -232,6 +430,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'group.name', + 'fieldAccessors' => [ + 'getGroup', + 'getName', + ], + ], + ], ], 'UpdateMigratingVm' => [ 'longRunning' => [ @@ -242,6 +450,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'migrating_vm.name', + 'fieldAccessors' => [ + 'getMigratingVm', + 'getName', + ], + ], + ], ], 'UpdateSource' => [ 'longRunning' => [ @@ -252,6 +470,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'source.name', + 'fieldAccessors' => [ + 'getSource', + 'getName', + ], + ], + ], ], 'UpdateTargetProject' => [ 'longRunning' => [ @@ -262,6 +490,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'target_project.name', + 'fieldAccessors' => [ + 'getTargetProject', + 'getName', + ], + ], + ], ], 'UpgradeAppliance' => [ 'longRunning' => [ @@ -272,6 +510,135 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'datacenter_connector', + 'fieldAccessors' => [ + 'getDatacenterConnector', + ], + ], + ], + ], + 'FetchInventory' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\FetchInventoryResponse', + 'headerParams' => [ + [ + 'keyName' => 'source', + 'fieldAccessors' => [ + 'getSource', + ], + ], + ], + ], + 'GetCloneJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\CloneJob', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetCutoverJob' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\CutoverJob', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetDatacenterConnector' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\DatacenterConnector', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetGroup' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\Group', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetMigratingVm' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\MigratingVm', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetReplicationCycle' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ReplicationCycle', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetSource' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\Source', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetTargetProject' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\TargetProject', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetUtilizationReport' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\UtilizationReport', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListCloneJobs' => [ 'pageStreaming' => [ @@ -282,6 +649,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getCloneJobs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListCloneJobsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListCutoverJobs' => [ 'pageStreaming' => [ @@ -292,6 +669,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getCutoverJobs', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListCutoverJobsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListDatacenterConnectors' => [ 'pageStreaming' => [ @@ -302,6 +689,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getDatacenterConnectors', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListDatacenterConnectorsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListGroups' => [ 'pageStreaming' => [ @@ -312,6 +709,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getGroups', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListGroupsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListMigratingVms' => [ 'pageStreaming' => [ @@ -322,6 +729,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getMigratingVms', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListMigratingVmsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListReplicationCycles' => [ 'pageStreaming' => [ @@ -332,6 +749,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getReplicationCycles', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListReplicationCyclesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListSources' => [ 'pageStreaming' => [ @@ -342,6 +769,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSources', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListSourcesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListTargetProjects' => [ 'pageStreaming' => [ @@ -352,6 +789,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getTargetProjects', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListTargetProjectsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListUtilizationReports' => [ 'pageStreaming' => [ @@ -362,8 +809,28 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getUtilizationReports', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VMMigration\V1\ListUtilizationReportsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -375,8 +842,30 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], + 'templateMap' => [ + 'cloneJob' => 'projects/{project}/locations/{location}/sources/{source}/migratingVms/{migrating_vm}/cloneJobs/{clone_job}', + 'cutoverJob' => 'projects/{project}/locations/{location}/sources/{source}/migratingVms/{migrating_vm}/cutoverJobs/{cutover_job}', + 'datacenterConnector' => 'projects/{project}/locations/{location}/sources/{source}/datacenterConnectors/{datacenter_connector}', + 'group' => 'projects/{project}/locations/{location}/groups/{group}', + 'location' => 'projects/{project}/locations/{location}', + 'migratingVm' => 'projects/{project}/locations/{location}/sources/{source}/migratingVms/{migrating_vm}', + 'replicationCycle' => 'projects/{project}/locations/{location}/sources/{source}/migratingVms/{migrating_vm}/replicationCycles/{replication_cycle}', + 'source' => 'projects/{project}/locations/{location}/sources/{source}', + 'targetProject' => 'projects/{project}/locations/{location}/targetProjects/{target_project}', + 'utilizationReport' => 'projects/{project}/locations/{location}/sources/{source}/utilizationReports/{utilization_report}', + ], ], ], ]; diff --git a/VmMigration/tests/Unit/V1/Client/VmMigrationClientTest.php b/VmMigration/tests/Unit/V1/Client/VmMigrationClientTest.php new file mode 100644 index 000000000000..ec429bc784e9 --- /dev/null +++ b/VmMigration/tests/Unit/V1/Client/VmMigrationClientTest.php @@ -0,0 +1,5156 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return VmMigrationClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new VmMigrationClient($options); + } + + /** @test */ + public function addGroupMigrationTest() + { + $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/addGroupMigrationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new AddGroupMigrationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/addGroupMigrationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedGroup = $gapicClient->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new AddGroupMigrationRequest()) + ->setGroup($formattedGroup); + $response = $gapicClient->addGroupMigration($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.vmmigration.v1.VmMigration/AddGroupMigration', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getGroup(); + $this->assertProtobufEquals($formattedGroup, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/addGroupMigrationTest'); + $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 addGroupMigrationExceptionTest() + { + $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/addGroupMigrationTest'); + $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 + $formattedGroup = $gapicClient->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new AddGroupMigrationRequest()) + ->setGroup($formattedGroup); + $response = $gapicClient->addGroupMigration($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/addGroupMigrationTest'); + 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 cancelCloneJobTest() + { + $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/cancelCloneJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new CancelCloneJobResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/cancelCloneJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->cloneJobName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[CLONE_JOB]'); + $request = (new CancelCloneJobRequest()) + ->setName($formattedName); + $response = $gapicClient->cancelCloneJob($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.vmmigration.v1.VmMigration/CancelCloneJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/cancelCloneJobTest'); + $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 cancelCloneJobExceptionTest() + { + $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/cancelCloneJobTest'); + $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->cloneJobName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[CLONE_JOB]'); + $request = (new CancelCloneJobRequest()) + ->setName($formattedName); + $response = $gapicClient->cancelCloneJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/cancelCloneJobTest'); + 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 cancelCutoverJobTest() + { + $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/cancelCutoverJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new CancelCutoverJobResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/cancelCutoverJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->cutoverJobName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[CUTOVER_JOB]'); + $request = (new CancelCutoverJobRequest()) + ->setName($formattedName); + $response = $gapicClient->cancelCutoverJob($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.vmmigration.v1.VmMigration/CancelCutoverJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/cancelCutoverJobTest'); + $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 cancelCutoverJobExceptionTest() + { + $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/cancelCutoverJobTest'); + $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->cutoverJobName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[CUTOVER_JOB]'); + $request = (new CancelCutoverJobRequest()) + ->setName($formattedName); + $response = $gapicClient->cancelCutoverJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/cancelCutoverJobTest'); + 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 createCloneJobTest() + { + $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/createCloneJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $expectedResponse = new CloneJob(); + $expectedResponse->setName($name); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCloneJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $cloneJobId = 'cloneJobId-1008685569'; + $cloneJob = new CloneJob(); + $request = (new CreateCloneJobRequest()) + ->setParent($formattedParent) + ->setCloneJobId($cloneJobId) + ->setCloneJob($cloneJob); + $response = $gapicClient->createCloneJob($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.vmmigration.v1.VmMigration/CreateCloneJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCloneJobId(); + $this->assertProtobufEquals($cloneJobId, $actualValue); + $actualValue = $actualApiRequestObject->getCloneJob(); + $this->assertProtobufEquals($cloneJob, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCloneJobTest'); + $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 createCloneJobExceptionTest() + { + $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/createCloneJobTest'); + $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->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $cloneJobId = 'cloneJobId-1008685569'; + $cloneJob = new CloneJob(); + $request = (new CreateCloneJobRequest()) + ->setParent($formattedParent) + ->setCloneJobId($cloneJobId) + ->setCloneJob($cloneJob); + $response = $gapicClient->createCloneJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCloneJobTest'); + 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 createCutoverJobTest() + { + $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/createCutoverJobTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $progressPercent = 2137894861; + $stateMessage = 'stateMessage29641305'; + $expectedResponse = new CutoverJob(); + $expectedResponse->setName($name); + $expectedResponse->setProgressPercent($progressPercent); + $expectedResponse->setStateMessage($stateMessage); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createCutoverJobTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $cutoverJobId = 'cutoverJobId504048422'; + $cutoverJob = new CutoverJob(); + $request = (new CreateCutoverJobRequest()) + ->setParent($formattedParent) + ->setCutoverJobId($cutoverJobId) + ->setCutoverJob($cutoverJob); + $response = $gapicClient->createCutoverJob($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.vmmigration.v1.VmMigration/CreateCutoverJob', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getCutoverJobId(); + $this->assertProtobufEquals($cutoverJobId, $actualValue); + $actualValue = $actualApiRequestObject->getCutoverJob(); + $this->assertProtobufEquals($cutoverJob, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCutoverJobTest'); + $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 createCutoverJobExceptionTest() + { + $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/createCutoverJobTest'); + $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->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $cutoverJobId = 'cutoverJobId504048422'; + $cutoverJob = new CutoverJob(); + $request = (new CreateCutoverJobRequest()) + ->setParent($formattedParent) + ->setCutoverJobId($cutoverJobId) + ->setCutoverJob($cutoverJob); + $response = $gapicClient->createCutoverJob($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createCutoverJobTest'); + 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 createDatacenterConnectorTest() + { + $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/createDatacenterConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $registrationId = 'registrationId-412573087'; + $serviceAccount = 'serviceAccount-1948028253'; + $version = 'version351608024'; + $bucket = 'bucket-1378203158'; + $applianceInfrastructureVersion = 'applianceInfrastructureVersion662625550'; + $applianceSoftwareVersion = 'applianceSoftwareVersion-641402222'; + $expectedResponse = new DatacenterConnector(); + $expectedResponse->setName($name); + $expectedResponse->setRegistrationId($registrationId); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setVersion($version); + $expectedResponse->setBucket($bucket); + $expectedResponse->setApplianceInfrastructureVersion($applianceInfrastructureVersion); + $expectedResponse->setApplianceSoftwareVersion($applianceSoftwareVersion); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createDatacenterConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $datacenterConnectorId = 'datacenterConnectorId1629428237'; + $datacenterConnector = new DatacenterConnector(); + $request = (new CreateDatacenterConnectorRequest()) + ->setParent($formattedParent) + ->setDatacenterConnectorId($datacenterConnectorId) + ->setDatacenterConnector($datacenterConnector); + $response = $gapicClient->createDatacenterConnector($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.vmmigration.v1.VmMigration/CreateDatacenterConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getDatacenterConnectorId(); + $this->assertProtobufEquals($datacenterConnectorId, $actualValue); + $actualValue = $actualApiRequestObject->getDatacenterConnector(); + $this->assertProtobufEquals($datacenterConnector, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createDatacenterConnectorTest'); + $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 createDatacenterConnectorExceptionTest() + { + $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/createDatacenterConnectorTest'); + $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->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $datacenterConnectorId = 'datacenterConnectorId1629428237'; + $datacenterConnector = new DatacenterConnector(); + $request = (new CreateDatacenterConnectorRequest()) + ->setParent($formattedParent) + ->setDatacenterConnectorId($datacenterConnectorId) + ->setDatacenterConnector($datacenterConnector); + $response = $gapicClient->createDatacenterConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createDatacenterConnectorTest'); + 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 createGroupTest() + { + $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/createGroupTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Group(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setDisplayName($displayName); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createGroupTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $groupId = 'groupId506361563'; + $group = new Group(); + $request = (new CreateGroupRequest()) + ->setParent($formattedParent) + ->setGroupId($groupId) + ->setGroup($group); + $response = $gapicClient->createGroup($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.vmmigration.v1.VmMigration/CreateGroup', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getGroupId(); + $this->assertProtobufEquals($groupId, $actualValue); + $actualValue = $actualApiRequestObject->getGroup(); + $this->assertProtobufEquals($group, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createGroupTest'); + $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 createGroupExceptionTest() + { + $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/createGroupTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $groupId = 'groupId506361563'; + $group = new Group(); + $request = (new CreateGroupRequest()) + ->setParent($formattedParent) + ->setGroupId($groupId) + ->setGroup($group); + $response = $gapicClient->createGroup($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createGroupTest'); + 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 createMigratingVmTest() + { + $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/createMigratingVmTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $sourceVmId = 'sourceVmId1673059967'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $group = 'group98629247'; + $expectedResponse = new MigratingVm(); + $expectedResponse->setName($name); + $expectedResponse->setSourceVmId($sourceVmId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setGroup($group); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createMigratingVmTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $migratingVmId = 'migratingVmId-899085236'; + $migratingVm = new MigratingVm(); + $request = (new CreateMigratingVmRequest()) + ->setParent($formattedParent) + ->setMigratingVmId($migratingVmId) + ->setMigratingVm($migratingVm); + $response = $gapicClient->createMigratingVm($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.vmmigration.v1.VmMigration/CreateMigratingVm', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getMigratingVmId(); + $this->assertProtobufEquals($migratingVmId, $actualValue); + $actualValue = $actualApiRequestObject->getMigratingVm(); + $this->assertProtobufEquals($migratingVm, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createMigratingVmTest'); + $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 createMigratingVmExceptionTest() + { + $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/createMigratingVmTest'); + $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->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $migratingVmId = 'migratingVmId-899085236'; + $migratingVm = new MigratingVm(); + $request = (new CreateMigratingVmRequest()) + ->setParent($formattedParent) + ->setMigratingVmId($migratingVmId) + ->setMigratingVm($migratingVm); + $response = $gapicClient->createMigratingVm($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createMigratingVmTest'); + 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 createSourceTest() + { + $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/createSourceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $expectedResponse = new Source(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createSourceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $sourceId = 'sourceId-1698410561'; + $source = new Source(); + $request = (new CreateSourceRequest()) + ->setParent($formattedParent) + ->setSourceId($sourceId) + ->setSource($source); + $response = $gapicClient->createSource($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.vmmigration.v1.VmMigration/CreateSource', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getSourceId(); + $this->assertProtobufEquals($sourceId, $actualValue); + $actualValue = $actualApiRequestObject->getSource(); + $this->assertProtobufEquals($source, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createSourceTest'); + $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 createSourceExceptionTest() + { + $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/createSourceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $sourceId = 'sourceId-1698410561'; + $source = new Source(); + $request = (new CreateSourceRequest()) + ->setParent($formattedParent) + ->setSourceId($sourceId) + ->setSource($source); + $response = $gapicClient->createSource($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createSourceTest'); + 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 createTargetProjectTest() + { + $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/createTargetProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $project = 'project-309310695'; + $description = 'description-1724546052'; + $expectedResponse = new TargetProject(); + $expectedResponse->setName($name); + $expectedResponse->setProject($project); + $expectedResponse->setDescription($description); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createTargetProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $targetProjectId = 'targetProjectId1255314287'; + $targetProject = new TargetProject(); + $request = (new CreateTargetProjectRequest()) + ->setParent($formattedParent) + ->setTargetProjectId($targetProjectId) + ->setTargetProject($targetProject); + $response = $gapicClient->createTargetProject($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.vmmigration.v1.VmMigration/CreateTargetProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getTargetProjectId(); + $this->assertProtobufEquals($targetProjectId, $actualValue); + $actualValue = $actualApiRequestObject->getTargetProject(); + $this->assertProtobufEquals($targetProject, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTargetProjectTest'); + $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 createTargetProjectExceptionTest() + { + $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/createTargetProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $targetProjectId = 'targetProjectId1255314287'; + $targetProject = new TargetProject(); + $request = (new CreateTargetProjectRequest()) + ->setParent($formattedParent) + ->setTargetProjectId($targetProjectId) + ->setTargetProject($targetProject); + $response = $gapicClient->createTargetProject($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createTargetProjectTest'); + 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 createUtilizationReportTest() + { + $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/createUtilizationReportTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $vmCount = 261463431; + $expectedResponse = new UtilizationReport(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setVmCount($vmCount); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createUtilizationReportTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $utilizationReport = new UtilizationReport(); + $utilizationReportId = 'utilizationReportId-1346894295'; + $request = (new CreateUtilizationReportRequest()) + ->setParent($formattedParent) + ->setUtilizationReport($utilizationReport) + ->setUtilizationReportId($utilizationReportId); + $response = $gapicClient->createUtilizationReport($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.vmmigration.v1.VmMigration/CreateUtilizationReport', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getUtilizationReport(); + $this->assertProtobufEquals($utilizationReport, $actualValue); + $actualValue = $actualApiRequestObject->getUtilizationReportId(); + $this->assertProtobufEquals($utilizationReportId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createUtilizationReportTest'); + $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 createUtilizationReportExceptionTest() + { + $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/createUtilizationReportTest'); + $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->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $utilizationReport = new UtilizationReport(); + $utilizationReportId = 'utilizationReportId-1346894295'; + $request = (new CreateUtilizationReportRequest()) + ->setParent($formattedParent) + ->setUtilizationReport($utilizationReport) + ->setUtilizationReportId($utilizationReportId); + $response = $gapicClient->createUtilizationReport($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createUtilizationReportTest'); + 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 deleteDatacenterConnectorTest() + { + $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/deleteDatacenterConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteDatacenterConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->datacenterConnectorName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[DATACENTER_CONNECTOR]'); + $request = (new DeleteDatacenterConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteDatacenterConnector($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.vmmigration.v1.VmMigration/DeleteDatacenterConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteDatacenterConnectorTest'); + $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 deleteDatacenterConnectorExceptionTest() + { + $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/deleteDatacenterConnectorTest'); + $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->datacenterConnectorName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[DATACENTER_CONNECTOR]'); + $request = (new DeleteDatacenterConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteDatacenterConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteDatacenterConnectorTest'); + 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 deleteGroupTest() + { + $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/deleteGroupTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteGroupTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new DeleteGroupRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteGroup($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.vmmigration.v1.VmMigration/DeleteGroup', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteGroupTest'); + $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 deleteGroupExceptionTest() + { + $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/deleteGroupTest'); + $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->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new DeleteGroupRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteGroup($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteGroupTest'); + 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 deleteMigratingVmTest() + { + $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/deleteMigratingVmTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteMigratingVmTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new DeleteMigratingVmRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteMigratingVm($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.vmmigration.v1.VmMigration/DeleteMigratingVm', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteMigratingVmTest'); + $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 deleteMigratingVmExceptionTest() + { + $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/deleteMigratingVmTest'); + $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->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new DeleteMigratingVmRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteMigratingVm($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteMigratingVmTest'); + 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 deleteSourceTest() + { + $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/deleteSourceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteSourceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $request = (new DeleteSourceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteSource($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.vmmigration.v1.VmMigration/DeleteSource', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteSourceTest'); + $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 deleteSourceExceptionTest() + { + $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/deleteSourceTest'); + $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->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $request = (new DeleteSourceRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteSource($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteSourceTest'); + 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 deleteTargetProjectTest() + { + $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/deleteTargetProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteTargetProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->targetProjectName('[PROJECT]', '[LOCATION]', '[TARGET_PROJECT]'); + $request = (new DeleteTargetProjectRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTargetProject($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.vmmigration.v1.VmMigration/DeleteTargetProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTargetProjectTest'); + $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 deleteTargetProjectExceptionTest() + { + $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/deleteTargetProjectTest'); + $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->targetProjectName('[PROJECT]', '[LOCATION]', '[TARGET_PROJECT]'); + $request = (new DeleteTargetProjectRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteTargetProject($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteTargetProjectTest'); + 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 deleteUtilizationReportTest() + { + $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/deleteUtilizationReportTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteUtilizationReportTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->utilizationReportName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[UTILIZATION_REPORT]'); + $request = (new DeleteUtilizationReportRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteUtilizationReport($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.vmmigration.v1.VmMigration/DeleteUtilizationReport', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteUtilizationReportTest'); + $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 deleteUtilizationReportExceptionTest() + { + $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/deleteUtilizationReportTest'); + $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->utilizationReportName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[UTILIZATION_REPORT]'); + $request = (new DeleteUtilizationReportRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteUtilizationReport($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteUtilizationReportTest'); + 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 fetchInventoryTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new FetchInventoryResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedSource = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $request = (new FetchInventoryRequest()) + ->setSource($formattedSource); + $response = $gapicClient->fetchInventory($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.vmmigration.v1.VmMigration/FetchInventory', $actualFuncCall); + $actualValue = $actualRequestObject->getSource(); + $this->assertProtobufEquals($formattedSource, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function fetchInventoryExceptionTest() + { + $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 + $formattedSource = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $request = (new FetchInventoryRequest()) + ->setSource($formattedSource); + try { + $gapicClient->fetchInventory($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 finalizeMigrationTest() + { + $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/finalizeMigrationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new FinalizeMigrationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/finalizeMigrationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedMigratingVm = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new FinalizeMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + $response = $gapicClient->finalizeMigration($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.vmmigration.v1.VmMigration/FinalizeMigration', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getMigratingVm(); + $this->assertProtobufEquals($formattedMigratingVm, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/finalizeMigrationTest'); + $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 finalizeMigrationExceptionTest() + { + $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/finalizeMigrationTest'); + $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 + $formattedMigratingVm = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new FinalizeMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + $response = $gapicClient->finalizeMigration($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/finalizeMigrationTest'); + 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 getCloneJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new CloneJob(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->cloneJobName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[CLONE_JOB]'); + $request = (new GetCloneJobRequest()) + ->setName($formattedName); + $response = $gapicClient->getCloneJob($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.vmmigration.v1.VmMigration/GetCloneJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCloneJobExceptionTest() + { + $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->cloneJobName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[CLONE_JOB]'); + $request = (new GetCloneJobRequest()) + ->setName($formattedName); + try { + $gapicClient->getCloneJob($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 getCutoverJobTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $progressPercent = 2137894861; + $stateMessage = 'stateMessage29641305'; + $expectedResponse = new CutoverJob(); + $expectedResponse->setName($name2); + $expectedResponse->setProgressPercent($progressPercent); + $expectedResponse->setStateMessage($stateMessage); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->cutoverJobName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[CUTOVER_JOB]'); + $request = (new GetCutoverJobRequest()) + ->setName($formattedName); + $response = $gapicClient->getCutoverJob($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.vmmigration.v1.VmMigration/GetCutoverJob', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getCutoverJobExceptionTest() + { + $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->cutoverJobName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[CUTOVER_JOB]'); + $request = (new GetCutoverJobRequest()) + ->setName($formattedName); + try { + $gapicClient->getCutoverJob($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 getDatacenterConnectorTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $registrationId = 'registrationId-412573087'; + $serviceAccount = 'serviceAccount-1948028253'; + $version = 'version351608024'; + $bucket = 'bucket-1378203158'; + $applianceInfrastructureVersion = 'applianceInfrastructureVersion662625550'; + $applianceSoftwareVersion = 'applianceSoftwareVersion-641402222'; + $expectedResponse = new DatacenterConnector(); + $expectedResponse->setName($name2); + $expectedResponse->setRegistrationId($registrationId); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setVersion($version); + $expectedResponse->setBucket($bucket); + $expectedResponse->setApplianceInfrastructureVersion($applianceInfrastructureVersion); + $expectedResponse->setApplianceSoftwareVersion($applianceSoftwareVersion); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->datacenterConnectorName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[DATACENTER_CONNECTOR]'); + $request = (new GetDatacenterConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->getDatacenterConnector($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.vmmigration.v1.VmMigration/GetDatacenterConnector', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDatacenterConnectorExceptionTest() + { + $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->datacenterConnectorName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[DATACENTER_CONNECTOR]'); + $request = (new GetDatacenterConnectorRequest()) + ->setName($formattedName); + try { + $gapicClient->getDatacenterConnector($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 getGroupTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Group(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new GetGroupRequest()) + ->setName($formattedName); + $response = $gapicClient->getGroup($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.vmmigration.v1.VmMigration/GetGroup', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getGroupExceptionTest() + { + $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->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new GetGroupRequest()) + ->setName($formattedName); + try { + $gapicClient->getGroup($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 getMigratingVmTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $sourceVmId = 'sourceVmId1673059967'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $group = 'group98629247'; + $expectedResponse = new MigratingVm(); + $expectedResponse->setName($name2); + $expectedResponse->setSourceVmId($sourceVmId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setGroup($group); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new GetMigratingVmRequest()) + ->setName($formattedName); + $response = $gapicClient->getMigratingVm($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.vmmigration.v1.VmMigration/GetMigratingVm', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getMigratingVmExceptionTest() + { + $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->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new GetMigratingVmRequest()) + ->setName($formattedName); + try { + $gapicClient->getMigratingVm($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 getReplicationCycleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $cycleNumber = 1095724862; + $progressPercent = 2137894861; + $expectedResponse = new ReplicationCycle(); + $expectedResponse->setName($name2); + $expectedResponse->setCycleNumber($cycleNumber); + $expectedResponse->setProgressPercent($progressPercent); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->replicationCycleName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[REPLICATION_CYCLE]'); + $request = (new GetReplicationCycleRequest()) + ->setName($formattedName); + $response = $gapicClient->getReplicationCycle($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.vmmigration.v1.VmMigration/GetReplicationCycle', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getReplicationCycleExceptionTest() + { + $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->replicationCycleName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]', '[REPLICATION_CYCLE]'); + $request = (new GetReplicationCycleRequest()) + ->setName($formattedName); + try { + $gapicClient->getReplicationCycle($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 getSourceTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $expectedResponse = new Source(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $request = (new GetSourceRequest()) + ->setName($formattedName); + $response = $gapicClient->getSource($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.vmmigration.v1.VmMigration/GetSource', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getSourceExceptionTest() + { + $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->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $request = (new GetSourceRequest()) + ->setName($formattedName); + try { + $gapicClient->getSource($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 getTargetProjectTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $project = 'project-309310695'; + $description = 'description-1724546052'; + $expectedResponse = new TargetProject(); + $expectedResponse->setName($name2); + $expectedResponse->setProject($project); + $expectedResponse->setDescription($description); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->targetProjectName('[PROJECT]', '[LOCATION]', '[TARGET_PROJECT]'); + $request = (new GetTargetProjectRequest()) + ->setName($formattedName); + $response = $gapicClient->getTargetProject($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.vmmigration.v1.VmMigration/GetTargetProject', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getTargetProjectExceptionTest() + { + $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->targetProjectName('[PROJECT]', '[LOCATION]', '[TARGET_PROJECT]'); + $request = (new GetTargetProjectRequest()) + ->setName($formattedName); + try { + $gapicClient->getTargetProject($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 getUtilizationReportTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $vmCount = 261463431; + $expectedResponse = new UtilizationReport(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setVmCount($vmCount); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->utilizationReportName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[UTILIZATION_REPORT]'); + $request = (new GetUtilizationReportRequest()) + ->setName($formattedName); + $response = $gapicClient->getUtilizationReport($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.vmmigration.v1.VmMigration/GetUtilizationReport', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getUtilizationReportExceptionTest() + { + $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->utilizationReportName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[UTILIZATION_REPORT]'); + $request = (new GetUtilizationReportRequest()) + ->setName($formattedName); + try { + $gapicClient->getUtilizationReport($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 listCloneJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $cloneJobsElement = new CloneJob(); + $cloneJobs = [ + $cloneJobsElement, + ]; + $expectedResponse = new ListCloneJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCloneJobs($cloneJobs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListCloneJobsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listCloneJobs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCloneJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListCloneJobs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCloneJobsExceptionTest() + { + $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->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListCloneJobsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listCloneJobs($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 listCutoverJobsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $cutoverJobsElement = new CutoverJob(); + $cutoverJobs = [ + $cutoverJobsElement, + ]; + $expectedResponse = new ListCutoverJobsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCutoverJobs($cutoverJobs); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListCutoverJobsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listCutoverJobs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCutoverJobs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListCutoverJobs', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCutoverJobsExceptionTest() + { + $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->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListCutoverJobsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listCutoverJobs($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 listDatacenterConnectorsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $datacenterConnectorsElement = new DatacenterConnector(); + $datacenterConnectors = [ + $datacenterConnectorsElement, + ]; + $expectedResponse = new ListDatacenterConnectorsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setDatacenterConnectors($datacenterConnectors); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListDatacenterConnectorsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listDatacenterConnectors($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getDatacenterConnectors()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListDatacenterConnectors', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listDatacenterConnectorsExceptionTest() + { + $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->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListDatacenterConnectorsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listDatacenterConnectors($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 listGroupsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $groupsElement = new Group(); + $groups = [ + $groupsElement, + ]; + $expectedResponse = new ListGroupsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setGroups($groups); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListGroupsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listGroups($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getGroups()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListGroups', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listGroupsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListGroupsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listGroups($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 listMigratingVmsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $migratingVmsElement = new MigratingVm(); + $migratingVms = [ + $migratingVmsElement, + ]; + $expectedResponse = new ListMigratingVmsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setMigratingVms($migratingVms); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListMigratingVmsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listMigratingVms($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getMigratingVms()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListMigratingVms', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listMigratingVmsExceptionTest() + { + $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->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListMigratingVmsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listMigratingVms($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 listReplicationCyclesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $replicationCyclesElement = new ReplicationCycle(); + $replicationCycles = [ + $replicationCyclesElement, + ]; + $expectedResponse = new ListReplicationCyclesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setReplicationCycles($replicationCycles); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListReplicationCyclesRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listReplicationCycles($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getReplicationCycles()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListReplicationCycles', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listReplicationCyclesExceptionTest() + { + $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->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListReplicationCyclesRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listReplicationCycles($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 listSourcesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $sourcesElement = new Source(); + $sources = [ + $sourcesElement, + ]; + $expectedResponse = new ListSourcesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSources($sources); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListSourcesRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listSources($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSources()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListSources', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSourcesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListSourcesRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listSources($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 listTargetProjectsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $targetProjectsElement = new TargetProject(); + $targetProjects = [ + $targetProjectsElement, + ]; + $expectedResponse = new ListTargetProjectsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setTargetProjects($targetProjects); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListTargetProjectsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listTargetProjects($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getTargetProjects()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListTargetProjects', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listTargetProjectsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListTargetProjectsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listTargetProjects($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 listUtilizationReportsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $utilizationReportsElement = new UtilizationReport(); + $utilizationReports = [ + $utilizationReportsElement, + ]; + $expectedResponse = new ListUtilizationReportsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setUtilizationReports($utilizationReports); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListUtilizationReportsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + $response = $gapicClient->listUtilizationReports($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getUtilizationReports()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmmigration.v1.VmMigration/ListUtilizationReports', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getPageToken(); + $this->assertProtobufEquals($pageToken, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listUtilizationReportsExceptionTest() + { + $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->sourceName('[PROJECT]', '[LOCATION]', '[SOURCE]'); + $pageToken = 'pageToken1630607433'; + $request = (new ListUtilizationReportsRequest()) + ->setParent($formattedParent) + ->setPageToken($pageToken); + try { + $gapicClient->listUtilizationReports($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 pauseMigrationTest() + { + $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/pauseMigrationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new PauseMigrationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/pauseMigrationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedMigratingVm = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new PauseMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + $response = $gapicClient->pauseMigration($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.vmmigration.v1.VmMigration/PauseMigration', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getMigratingVm(); + $this->assertProtobufEquals($formattedMigratingVm, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/pauseMigrationTest'); + $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 pauseMigrationExceptionTest() + { + $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/pauseMigrationTest'); + $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 + $formattedMigratingVm = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new PauseMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + $response = $gapicClient->pauseMigration($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/pauseMigrationTest'); + 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 removeGroupMigrationTest() + { + $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/removeGroupMigrationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new RemoveGroupMigrationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/removeGroupMigrationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedGroup = $gapicClient->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new RemoveGroupMigrationRequest()) + ->setGroup($formattedGroup); + $response = $gapicClient->removeGroupMigration($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.vmmigration.v1.VmMigration/RemoveGroupMigration', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getGroup(); + $this->assertProtobufEquals($formattedGroup, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/removeGroupMigrationTest'); + $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 removeGroupMigrationExceptionTest() + { + $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/removeGroupMigrationTest'); + $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 + $formattedGroup = $gapicClient->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new RemoveGroupMigrationRequest()) + ->setGroup($formattedGroup); + $response = $gapicClient->removeGroupMigration($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/removeGroupMigrationTest'); + 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 resumeMigrationTest() + { + $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/resumeMigrationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new ResumeMigrationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/resumeMigrationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedMigratingVm = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new ResumeMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + $response = $gapicClient->resumeMigration($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.vmmigration.v1.VmMigration/ResumeMigration', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getMigratingVm(); + $this->assertProtobufEquals($formattedMigratingVm, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resumeMigrationTest'); + $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 resumeMigrationExceptionTest() + { + $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/resumeMigrationTest'); + $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 + $formattedMigratingVm = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new ResumeMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + $response = $gapicClient->resumeMigration($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resumeMigrationTest'); + 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 startMigrationTest() + { + $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/startMigrationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new StartMigrationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/startMigrationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedMigratingVm = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new StartMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + $response = $gapicClient->startMigration($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.vmmigration.v1.VmMigration/StartMigration', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getMigratingVm(); + $this->assertProtobufEquals($formattedMigratingVm, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/startMigrationTest'); + $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 startMigrationExceptionTest() + { + $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/startMigrationTest'); + $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 + $formattedMigratingVm = $gapicClient->migratingVmName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[MIGRATING_VM]'); + $request = (new StartMigrationRequest()) + ->setMigratingVm($formattedMigratingVm); + $response = $gapicClient->startMigration($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/startMigrationTest'); + 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 updateGroupTest() + { + $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/updateGroupTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Group(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setDisplayName($displayName); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateGroupTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $group = new Group(); + $request = (new UpdateGroupRequest()) + ->setGroup($group); + $response = $gapicClient->updateGroup($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.vmmigration.v1.VmMigration/UpdateGroup', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getGroup(); + $this->assertProtobufEquals($group, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateGroupTest'); + $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 updateGroupExceptionTest() + { + $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/updateGroupTest'); + $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 + $group = new Group(); + $request = (new UpdateGroupRequest()) + ->setGroup($group); + $response = $gapicClient->updateGroup($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateGroupTest'); + 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 updateMigratingVmTest() + { + $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/updateMigratingVmTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $sourceVmId = 'sourceVmId1673059967'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $group = 'group98629247'; + $expectedResponse = new MigratingVm(); + $expectedResponse->setName($name); + $expectedResponse->setSourceVmId($sourceVmId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setGroup($group); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateMigratingVmTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $migratingVm = new MigratingVm(); + $request = (new UpdateMigratingVmRequest()) + ->setMigratingVm($migratingVm); + $response = $gapicClient->updateMigratingVm($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.vmmigration.v1.VmMigration/UpdateMigratingVm', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getMigratingVm(); + $this->assertProtobufEquals($migratingVm, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateMigratingVmTest'); + $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 updateMigratingVmExceptionTest() + { + $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/updateMigratingVmTest'); + $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 + $migratingVm = new MigratingVm(); + $request = (new UpdateMigratingVmRequest()) + ->setMigratingVm($migratingVm); + $response = $gapicClient->updateMigratingVm($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateMigratingVmTest'); + 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 updateSourceTest() + { + $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/updateSourceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $expectedResponse = new Source(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateSourceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $source = new Source(); + $request = (new UpdateSourceRequest()) + ->setSource($source); + $response = $gapicClient->updateSource($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.vmmigration.v1.VmMigration/UpdateSource', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getSource(); + $this->assertProtobufEquals($source, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateSourceTest'); + $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 updateSourceExceptionTest() + { + $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/updateSourceTest'); + $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 + $source = new Source(); + $request = (new UpdateSourceRequest()) + ->setSource($source); + $response = $gapicClient->updateSource($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateSourceTest'); + 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 updateTargetProjectTest() + { + $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/updateTargetProjectTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $project = 'project-309310695'; + $description = 'description-1724546052'; + $expectedResponse = new TargetProject(); + $expectedResponse->setName($name); + $expectedResponse->setProject($project); + $expectedResponse->setDescription($description); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateTargetProjectTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $targetProject = new TargetProject(); + $request = (new UpdateTargetProjectRequest()) + ->setTargetProject($targetProject); + $response = $gapicClient->updateTargetProject($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.vmmigration.v1.VmMigration/UpdateTargetProject', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getTargetProject(); + $this->assertProtobufEquals($targetProject, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateTargetProjectTest'); + $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 updateTargetProjectExceptionTest() + { + $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/updateTargetProjectTest'); + $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 + $targetProject = new TargetProject(); + $request = (new UpdateTargetProjectRequest()) + ->setTargetProject($targetProject); + $response = $gapicClient->updateTargetProject($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateTargetProjectTest'); + 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 upgradeApplianceTest() + { + $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/upgradeApplianceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new UpgradeApplianceResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/upgradeApplianceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedDatacenterConnector = $gapicClient->datacenterConnectorName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[DATACENTER_CONNECTOR]'); + $request = (new UpgradeApplianceRequest()) + ->setDatacenterConnector($formattedDatacenterConnector); + $response = $gapicClient->upgradeAppliance($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.vmmigration.v1.VmMigration/UpgradeAppliance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getDatacenterConnector(); + $this->assertProtobufEquals($formattedDatacenterConnector, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/upgradeApplianceTest'); + $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 upgradeApplianceExceptionTest() + { + $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/upgradeApplianceTest'); + $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 + $formattedDatacenterConnector = $gapicClient->datacenterConnectorName('[PROJECT]', '[LOCATION]', '[SOURCE]', '[DATACENTER_CONNECTOR]'); + $request = (new UpgradeApplianceRequest()) + ->setDatacenterConnector($formattedDatacenterConnector); + $response = $gapicClient->upgradeAppliance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/upgradeApplianceTest'); + 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 getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($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.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $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 GetLocationRequest(); + try { + $gapicClient->getLocation($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 listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $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 ListLocationsRequest(); + try { + $gapicClient->listLocations($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 addGroupMigrationAsyncTest() + { + $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/addGroupMigrationTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new AddGroupMigrationResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/addGroupMigrationTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedGroup = $gapicClient->groupName('[PROJECT]', '[LOCATION]', '[GROUP]'); + $request = (new AddGroupMigrationRequest()) + ->setGroup($formattedGroup); + $response = $gapicClient->addGroupMigrationAsync($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.vmmigration.v1.VmMigration/AddGroupMigration', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getGroup(); + $this->assertProtobufEquals($formattedGroup, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/addGroupMigrationTest'); + $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/VmwareEngine/samples/V1/VmwareEngineClient/create_cluster.php b/VmwareEngine/samples/V1/VmwareEngineClient/create_cluster.php index 8df2342cab3b..ef37e7dc84d6 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/create_cluster.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/create_cluster.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_CreateCluster_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\Cluster; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\CreateClusterRequest; use Google\Rpc\Status; /** @@ -58,15 +59,19 @@ function create_cluster_sample(string $formattedParent, string $clusterId): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $clusterNodeTypeConfigs = []; $cluster = (new Cluster()) ->setNodeTypeConfigs($clusterNodeTypeConfigs); + $request = (new CreateClusterRequest()) + ->setParent($formattedParent) + ->setClusterId($clusterId) + ->setCluster($cluster); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->createCluster($formattedParent, $clusterId, $cluster); + $response = $vmwareEngineClient->createCluster($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/create_hcx_activation_key.php b/VmwareEngine/samples/V1/VmwareEngineClient/create_hcx_activation_key.php index cdb66f5911ea..5c7b0bdd31ce 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/create_hcx_activation_key.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/create_hcx_activation_key.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_CreateHcxActivationKey_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\CreateHcxActivationKeyRequest; use Google\Cloud\VmwareEngine\V1\HcxActivationKey; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; use Google\Rpc\Status; /** @@ -57,17 +58,17 @@ function create_hcx_activation_key_sample( // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $hcxActivationKey = new HcxActivationKey(); + $request = (new CreateHcxActivationKeyRequest()) + ->setParent($formattedParent) + ->setHcxActivationKey($hcxActivationKey) + ->setHcxActivationKeyId($hcxActivationKeyId); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->createHcxActivationKey( - $formattedParent, - $hcxActivationKey, - $hcxActivationKeyId - ); + $response = $vmwareEngineClient->createHcxActivationKey($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/create_network_policy.php b/VmwareEngine/samples/V1/VmwareEngineClient/create_network_policy.php index af0016149e57..412970f7a6df 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/create_network_policy.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/create_network_policy.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_CreateNetworkPolicy_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\CreateNetworkPolicyRequest; use Google\Cloud\VmwareEngine\V1\NetworkPolicy; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; use Google\Rpc\Status; /** @@ -66,18 +67,18 @@ function create_network_policy_sample( // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $networkPolicy = (new NetworkPolicy()) ->setEdgeServicesCidr($networkPolicyEdgeServicesCidr); + $request = (new CreateNetworkPolicyRequest()) + ->setParent($formattedParent) + ->setNetworkPolicyId($networkPolicyId) + ->setNetworkPolicy($networkPolicy); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->createNetworkPolicy( - $formattedParent, - $networkPolicyId, - $networkPolicy - ); + $response = $vmwareEngineClient->createNetworkPolicy($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/create_private_cloud.php b/VmwareEngine/samples/V1/VmwareEngineClient/create_private_cloud.php index ba7be385c6f3..6e54422a6aa3 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/create_private_cloud.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/create_private_cloud.php @@ -25,10 +25,11 @@ // [START vmwareengine_v1_generated_VmwareEngine_CreatePrivateCloud_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\CreatePrivateCloudRequest; use Google\Cloud\VmwareEngine\V1\NetworkConfig; use Google\Cloud\VmwareEngine\V1\PrivateCloud; use Google\Cloud\VmwareEngine\V1\PrivateCloud\ManagementCluster; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; use Google\Rpc\Status; /** @@ -77,7 +78,7 @@ function create_private_cloud_sample( // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $privateCloudNetworkConfig = (new NetworkConfig()) ->setManagementCidr($privateCloudNetworkConfigManagementCidr); $privateCloudManagementClusterNodeTypeConfigs = []; @@ -87,15 +88,15 @@ function create_private_cloud_sample( $privateCloud = (new PrivateCloud()) ->setNetworkConfig($privateCloudNetworkConfig) ->setManagementCluster($privateCloudManagementCluster); + $request = (new CreatePrivateCloudRequest()) + ->setParent($formattedParent) + ->setPrivateCloudId($privateCloudId) + ->setPrivateCloud($privateCloud); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->createPrivateCloud( - $formattedParent, - $privateCloudId, - $privateCloud - ); + $response = $vmwareEngineClient->createPrivateCloud($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/create_vmware_engine_network.php b/VmwareEngine/samples/V1/VmwareEngineClient/create_vmware_engine_network.php index 681500ad0bc0..4c2d2346d29b 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/create_vmware_engine_network.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/create_vmware_engine_network.php @@ -25,7 +25,8 @@ // [START vmwareengine_v1_generated_VmwareEngine_CreateVmwareEngineNetwork_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\CreateVmwareEngineNetworkRequest; use Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork; use Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork\Type; use Google\Rpc\Status; @@ -65,18 +66,18 @@ function create_vmware_engine_network_sample( // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $vmwareEngineNetwork = (new VmwareEngineNetwork()) ->setType($vmwareEngineNetworkType); + $request = (new CreateVmwareEngineNetworkRequest()) + ->setParent($formattedParent) + ->setVmwareEngineNetworkId($vmwareEngineNetworkId) + ->setVmwareEngineNetwork($vmwareEngineNetwork); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->createVmwareEngineNetwork( - $formattedParent, - $vmwareEngineNetworkId, - $vmwareEngineNetwork - ); + $response = $vmwareEngineClient->createVmwareEngineNetwork($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/delete_cluster.php b/VmwareEngine/samples/V1/VmwareEngineClient/delete_cluster.php index ee1fe50c02f0..330c95b5568c 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/delete_cluster.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/delete_cluster.php @@ -25,7 +25,8 @@ // [START vmwareengine_v1_generated_VmwareEngine_DeleteCluster_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\DeleteClusterRequest; use Google\Rpc\Status; /** @@ -46,10 +47,14 @@ function delete_cluster_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new DeleteClusterRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->deleteCluster($formattedName); + $response = $vmwareEngineClient->deleteCluster($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/delete_network_policy.php b/VmwareEngine/samples/V1/VmwareEngineClient/delete_network_policy.php index 4766b861ea0d..e892edde1400 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/delete_network_policy.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/delete_network_policy.php @@ -25,7 +25,8 @@ // [START vmwareengine_v1_generated_VmwareEngine_DeleteNetworkPolicy_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\DeleteNetworkPolicyRequest; use Google\Rpc\Status; /** @@ -45,10 +46,14 @@ function delete_network_policy_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new DeleteNetworkPolicyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->deleteNetworkPolicy($formattedName); + $response = $vmwareEngineClient->deleteNetworkPolicy($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/delete_private_cloud.php b/VmwareEngine/samples/V1/VmwareEngineClient/delete_private_cloud.php index 905b7cd86a6e..656fb4ace7d7 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/delete_private_cloud.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/delete_private_cloud.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_DeletePrivateCloud_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\DeletePrivateCloudRequest; use Google\Cloud\VmwareEngine\V1\PrivateCloud; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; use Google\Rpc\Status; /** @@ -58,10 +59,14 @@ function delete_private_cloud_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new DeletePrivateCloudRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->deletePrivateCloud($formattedName); + $response = $vmwareEngineClient->deletePrivateCloud($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/delete_vmware_engine_network.php b/VmwareEngine/samples/V1/VmwareEngineClient/delete_vmware_engine_network.php index e0d52c25fb06..2f00190ed1fe 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/delete_vmware_engine_network.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/delete_vmware_engine_network.php @@ -25,7 +25,8 @@ // [START vmwareengine_v1_generated_VmwareEngine_DeleteVmwareEngineNetwork_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\DeleteVmwareEngineNetworkRequest; use Google\Rpc\Status; /** @@ -46,10 +47,14 @@ function delete_vmware_engine_network_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new DeleteVmwareEngineNetworkRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->deleteVmwareEngineNetwork($formattedName); + $response = $vmwareEngineClient->deleteVmwareEngineNetwork($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/get_cluster.php b/VmwareEngine/samples/V1/VmwareEngineClient/get_cluster.php index 5aaafa62e82a..872c4f3aa66d 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/get_cluster.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/get_cluster.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_GetCluster_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\Cluster; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\GetClusterRequest; /** * Retrieves a `Cluster` resource by its resource name. @@ -42,10 +43,14 @@ function get_cluster_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new GetClusterRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Cluster $response */ - $response = $vmwareEngineClient->getCluster($formattedName); + $response = $vmwareEngineClient->getCluster($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/VmwareEngine/samples/V1/VmwareEngineClient/get_hcx_activation_key.php b/VmwareEngine/samples/V1/VmwareEngineClient/get_hcx_activation_key.php index 1e31369494bc..d572ec12d695 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/get_hcx_activation_key.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/get_hcx_activation_key.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_GetHcxActivationKey_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\GetHcxActivationKeyRequest; use Google\Cloud\VmwareEngine\V1\HcxActivationKey; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; /** * Retrieves a `HcxActivationKey` resource by its resource name. @@ -42,10 +43,14 @@ function get_hcx_activation_key_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new GetHcxActivationKeyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var HcxActivationKey $response */ - $response = $vmwareEngineClient->getHcxActivationKey($formattedName); + $response = $vmwareEngineClient->getHcxActivationKey($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/VmwareEngine/samples/V1/VmwareEngineClient/get_iam_policy.php b/VmwareEngine/samples/V1/VmwareEngineClient/get_iam_policy.php index 2276b68ffffa..e41c3bc434d7 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/get_iam_policy.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/get_iam_policy.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_GetIamPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\GetIamPolicyRequest; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; /** * Gets the access control policy for a resource. Returns an empty policy @@ -39,10 +40,14 @@ function get_iam_policy_sample(string $resource): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new GetIamPolicyRequest()) + ->setResource($resource); + // Call the API and handle any network failures. try { /** @var Policy $response */ - $response = $vmwareEngineClient->getIamPolicy($resource); + $response = $vmwareEngineClient->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/VmwareEngine/samples/V1/VmwareEngineClient/get_location.php b/VmwareEngine/samples/V1/VmwareEngineClient/get_location.php index 78ee27c8298d..37f2166d65f6 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/get_location.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/get_location.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_GetLocation_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; /** * Gets information about a location. @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $vmwareEngineClient->getLocation(); + $response = $vmwareEngineClient->getLocation($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/VmwareEngine/samples/V1/VmwareEngineClient/get_network_policy.php b/VmwareEngine/samples/V1/VmwareEngineClient/get_network_policy.php index 29994bcd597e..cfc37fa477c5 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/get_network_policy.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/get_network_policy.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_GetNetworkPolicy_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\GetNetworkPolicyRequest; use Google\Cloud\VmwareEngine\V1\NetworkPolicy; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; /** * Retrieves a `NetworkPolicy` resource by its resource name. @@ -42,10 +43,14 @@ function get_network_policy_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new GetNetworkPolicyRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var NetworkPolicy $response */ - $response = $vmwareEngineClient->getNetworkPolicy($formattedName); + $response = $vmwareEngineClient->getNetworkPolicy($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/VmwareEngine/samples/V1/VmwareEngineClient/get_node_type.php b/VmwareEngine/samples/V1/VmwareEngineClient/get_node_type.php index c180a99b0b67..1366e36b5591 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/get_node_type.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/get_node_type.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_GetNodeType_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\GetNodeTypeRequest; use Google\Cloud\VmwareEngine\V1\NodeType; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; /** * Gets details of a single `NodeType`. @@ -42,10 +43,14 @@ function get_node_type_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new GetNodeTypeRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var NodeType $response */ - $response = $vmwareEngineClient->getNodeType($formattedName); + $response = $vmwareEngineClient->getNodeType($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/VmwareEngine/samples/V1/VmwareEngineClient/get_private_cloud.php b/VmwareEngine/samples/V1/VmwareEngineClient/get_private_cloud.php index 2da1fcebbe6e..4a72a92c92f6 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/get_private_cloud.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/get_private_cloud.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_GetPrivateCloud_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\GetPrivateCloudRequest; use Google\Cloud\VmwareEngine\V1\PrivateCloud; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; /** * Retrieves a `PrivateCloud` resource by its resource name. @@ -42,10 +43,14 @@ function get_private_cloud_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new GetPrivateCloudRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var PrivateCloud $response */ - $response = $vmwareEngineClient->getPrivateCloud($formattedName); + $response = $vmwareEngineClient->getPrivateCloud($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/VmwareEngine/samples/V1/VmwareEngineClient/get_vmware_engine_network.php b/VmwareEngine/samples/V1/VmwareEngineClient/get_vmware_engine_network.php index 2fb2e109f486..3dca688eb791 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/get_vmware_engine_network.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/get_vmware_engine_network.php @@ -24,7 +24,8 @@ // [START vmwareengine_v1_generated_VmwareEngine_GetVmwareEngineNetwork_sync] use Google\ApiCore\ApiException; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\GetVmwareEngineNetworkRequest; use Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork; /** @@ -45,10 +46,14 @@ function get_vmware_engine_network_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new GetVmwareEngineNetworkRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var VmwareEngineNetwork $response */ - $response = $vmwareEngineClient->getVmwareEngineNetwork($formattedName); + $response = $vmwareEngineClient->getVmwareEngineNetwork($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/VmwareEngine/samples/V1/VmwareEngineClient/list_clusters.php b/VmwareEngine/samples/V1/VmwareEngineClient/list_clusters.php index c73bb56c517d..ca6bd7b7b20c 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/list_clusters.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/list_clusters.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ListClusters_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\Cluster; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ListClustersRequest; /** * Lists `Cluster` resources in a given private cloud. @@ -43,10 +44,14 @@ function list_clusters_sample(string $formattedParent): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ListClustersRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmwareEngineClient->listClusters($formattedParent); + $response = $vmwareEngineClient->listClusters($request); /** @var Cluster $element */ foreach ($response as $element) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/list_hcx_activation_keys.php b/VmwareEngine/samples/V1/VmwareEngineClient/list_hcx_activation_keys.php index 95b2b9f99283..9cd6774ea81d 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/list_hcx_activation_keys.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/list_hcx_activation_keys.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ListHcxActivationKeys_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\HcxActivationKey; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ListHcxActivationKeysRequest; /** * Lists `HcxActivationKey` resources in a given private cloud. @@ -44,10 +45,14 @@ function list_hcx_activation_keys_sample(string $formattedParent): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ListHcxActivationKeysRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmwareEngineClient->listHcxActivationKeys($formattedParent); + $response = $vmwareEngineClient->listHcxActivationKeys($request); /** @var HcxActivationKey $element */ foreach ($response as $element) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/list_locations.php b/VmwareEngine/samples/V1/VmwareEngineClient/list_locations.php index 59070e40ee52..5f8dc5c6c0f4 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/list_locations.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/list_locations.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; /** * Lists information about the supported locations for this service. @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmwareEngineClient->listLocations(); + $response = $vmwareEngineClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/list_network_policies.php b/VmwareEngine/samples/V1/VmwareEngineClient/list_network_policies.php index b2f755bfe305..cfa4338cff21 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/list_network_policies.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/list_network_policies.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ListNetworkPolicies_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ListNetworkPoliciesRequest; use Google\Cloud\VmwareEngine\V1\NetworkPolicy; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; /** * Lists `NetworkPolicy` resources in a specified project and location. @@ -42,10 +43,14 @@ function list_network_policies_sample(string $formattedParent): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ListNetworkPoliciesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmwareEngineClient->listNetworkPolicies($formattedParent); + $response = $vmwareEngineClient->listNetworkPolicies($request); /** @var NetworkPolicy $element */ foreach ($response as $element) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/list_node_types.php b/VmwareEngine/samples/V1/VmwareEngineClient/list_node_types.php index 2c7f71f7272e..4b7c98df8b0a 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/list_node_types.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/list_node_types.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ListNodeTypes_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ListNodeTypesRequest; use Google\Cloud\VmwareEngine\V1\NodeType; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; /** * Lists node types @@ -43,10 +44,14 @@ function list_node_types_sample(string $formattedParent): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ListNodeTypesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmwareEngineClient->listNodeTypes($formattedParent); + $response = $vmwareEngineClient->listNodeTypes($request); /** @var NodeType $element */ foreach ($response as $element) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/list_private_clouds.php b/VmwareEngine/samples/V1/VmwareEngineClient/list_private_clouds.php index daa3e936b987..a71973024551 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/list_private_clouds.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/list_private_clouds.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ListPrivateClouds_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ListPrivateCloudsRequest; use Google\Cloud\VmwareEngine\V1\PrivateCloud; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; /** * Lists `PrivateCloud` resources in a given project and location. @@ -43,10 +44,14 @@ function list_private_clouds_sample(string $formattedParent): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ListPrivateCloudsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmwareEngineClient->listPrivateClouds($formattedParent); + $response = $vmwareEngineClient->listPrivateClouds($request); /** @var PrivateCloud $element */ foreach ($response as $element) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/list_subnets.php b/VmwareEngine/samples/V1/VmwareEngineClient/list_subnets.php index 3dbf292d8995..6cf8dfec1e93 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/list_subnets.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/list_subnets.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ListSubnets_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ListSubnetsRequest; use Google\Cloud\VmwareEngine\V1\Subnet; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; /** * Lists subnets in a given private cloud. @@ -44,10 +45,14 @@ function list_subnets_sample(string $formattedParent): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ListSubnetsRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmwareEngineClient->listSubnets($formattedParent); + $response = $vmwareEngineClient->listSubnets($request); /** @var Subnet $element */ foreach ($response as $element) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/list_vmware_engine_networks.php b/VmwareEngine/samples/V1/VmwareEngineClient/list_vmware_engine_networks.php index 63fc42402436..e11a6faa3665 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/list_vmware_engine_networks.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/list_vmware_engine_networks.php @@ -25,7 +25,8 @@ // [START vmwareengine_v1_generated_VmwareEngine_ListVmwareEngineNetworks_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ListVmwareEngineNetworksRequest; use Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork; /** @@ -42,10 +43,14 @@ function list_vmware_engine_networks_sample(string $formattedParent): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ListVmwareEngineNetworksRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $vmwareEngineClient->listVmwareEngineNetworks($formattedParent); + $response = $vmwareEngineClient->listVmwareEngineNetworks($request); /** @var VmwareEngineNetwork $element */ foreach ($response as $element) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/reset_nsx_credentials.php b/VmwareEngine/samples/V1/VmwareEngineClient/reset_nsx_credentials.php index 1d50d4d26f86..61b9cffae7f6 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/reset_nsx_credentials.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/reset_nsx_credentials.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ResetNsxCredentials_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\PrivateCloud; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ResetNsxCredentialsRequest; use Google\Rpc\Status; /** @@ -45,10 +46,14 @@ function reset_nsx_credentials_sample(string $formattedPrivateCloud): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ResetNsxCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->resetNsxCredentials($formattedPrivateCloud); + $response = $vmwareEngineClient->resetNsxCredentials($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/reset_vcenter_credentials.php b/VmwareEngine/samples/V1/VmwareEngineClient/reset_vcenter_credentials.php index cf1f32225211..2452dc2d0362 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/reset_vcenter_credentials.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/reset_vcenter_credentials.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ResetVcenterCredentials_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\PrivateCloud; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ResetVcenterCredentialsRequest; use Google\Rpc\Status; /** @@ -45,10 +46,14 @@ function reset_vcenter_credentials_sample(string $formattedPrivateCloud): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ResetVcenterCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->resetVcenterCredentials($formattedPrivateCloud); + $response = $vmwareEngineClient->resetVcenterCredentials($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/set_iam_policy.php b/VmwareEngine/samples/V1/VmwareEngineClient/set_iam_policy.php index d12caf7bca1e..f5c2b3f2a65b 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/set_iam_policy.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/set_iam_policy.php @@ -25,7 +25,8 @@ // [START vmwareengine_v1_generated_VmwareEngine_SetIamPolicy_sync] use Google\ApiCore\ApiException; use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\Iam\V1\SetIamPolicyRequest; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; /** * Sets the access control policy on the specified resource. Replaces @@ -42,13 +43,16 @@ function set_iam_policy_sample(string $resource): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // 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 = $vmwareEngineClient->setIamPolicy($resource, $policy); + $response = $vmwareEngineClient->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/VmwareEngine/samples/V1/VmwareEngineClient/show_nsx_credentials.php b/VmwareEngine/samples/V1/VmwareEngineClient/show_nsx_credentials.php index 6e37b3281ade..44f91bff98dc 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/show_nsx_credentials.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/show_nsx_credentials.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ShowNsxCredentials_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\Credentials; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ShowNsxCredentialsRequest; /** * Gets details of credentials for NSX appliance. @@ -43,10 +44,14 @@ function show_nsx_credentials_sample(string $formattedPrivateCloud): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ShowNsxCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + // Call the API and handle any network failures. try { /** @var Credentials $response */ - $response = $vmwareEngineClient->showNsxCredentials($formattedPrivateCloud); + $response = $vmwareEngineClient->showNsxCredentials($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/VmwareEngine/samples/V1/VmwareEngineClient/show_vcenter_credentials.php b/VmwareEngine/samples/V1/VmwareEngineClient/show_vcenter_credentials.php index 31808016bb72..e30067c874d4 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/show_vcenter_credentials.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/show_vcenter_credentials.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_ShowVcenterCredentials_sync] use Google\ApiCore\ApiException; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\Credentials; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\ShowVcenterCredentialsRequest; /** * Gets details of credentials for Vcenter appliance. @@ -43,10 +44,14 @@ function show_vcenter_credentials_sample(string $formattedPrivateCloud): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new ShowVcenterCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + // Call the API and handle any network failures. try { /** @var Credentials $response */ - $response = $vmwareEngineClient->showVcenterCredentials($formattedPrivateCloud); + $response = $vmwareEngineClient->showVcenterCredentials($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/VmwareEngine/samples/V1/VmwareEngineClient/test_iam_permissions.php b/VmwareEngine/samples/V1/VmwareEngineClient/test_iam_permissions.php index 342090d9cc37..8c9e382bdb77 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/test_iam_permissions.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/test_iam_permissions.php @@ -24,8 +24,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_TestIamPermissions_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; /** * Returns permissions that a caller has on the specified resource. If the @@ -48,13 +49,16 @@ function test_iam_permissions_sample(string $resource, string $permissionsElemen // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // 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 = $vmwareEngineClient->testIamPermissions($resource, $permissions); + $response = $vmwareEngineClient->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/VmwareEngine/samples/V1/VmwareEngineClient/undelete_private_cloud.php b/VmwareEngine/samples/V1/VmwareEngineClient/undelete_private_cloud.php index 697fabfe1895..62667139cafe 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/undelete_private_cloud.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/undelete_private_cloud.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_UndeletePrivateCloud_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\PrivateCloud; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\UndeletePrivateCloudRequest; use Google\Rpc\Status; /** @@ -47,10 +48,14 @@ function undelete_private_cloud_sample(string $formattedName): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); + // Prepare the request message. + $request = (new UndeletePrivateCloudRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->undeletePrivateCloud($formattedName); + $response = $vmwareEngineClient->undeletePrivateCloud($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/update_cluster.php b/VmwareEngine/samples/V1/VmwareEngineClient/update_cluster.php index e112bfb899ac..aab3a073b7fa 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/update_cluster.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/update_cluster.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_UpdateCluster_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\Cluster; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\UpdateClusterRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -51,16 +52,19 @@ function update_cluster_sample(): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $clusterNodeTypeConfigs = []; $cluster = (new Cluster()) ->setNodeTypeConfigs($clusterNodeTypeConfigs); + $request = (new UpdateClusterRequest()) + ->setUpdateMask($updateMask) + ->setCluster($cluster); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->updateCluster($updateMask, $cluster); + $response = $vmwareEngineClient->updateCluster($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/update_network_policy.php b/VmwareEngine/samples/V1/VmwareEngineClient/update_network_policy.php index d378799fb7a3..8c12ac1f73ec 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/update_network_policy.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/update_network_policy.php @@ -25,8 +25,9 @@ // [START vmwareengine_v1_generated_VmwareEngine_UpdateNetworkPolicy_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\NetworkPolicy; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\UpdateNetworkPolicyRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -54,15 +55,18 @@ function update_network_policy_sample(string $networkPolicyEdgeServicesCidr): vo // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $networkPolicy = (new NetworkPolicy()) ->setEdgeServicesCidr($networkPolicyEdgeServicesCidr); $updateMask = new FieldMask(); + $request = (new UpdateNetworkPolicyRequest()) + ->setNetworkPolicy($networkPolicy) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->updateNetworkPolicy($networkPolicy, $updateMask); + $response = $vmwareEngineClient->updateNetworkPolicy($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/update_private_cloud.php b/VmwareEngine/samples/V1/VmwareEngineClient/update_private_cloud.php index e02d32f25fb2..bcc2465bb84d 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/update_private_cloud.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/update_private_cloud.php @@ -25,10 +25,11 @@ // [START vmwareengine_v1_generated_VmwareEngine_UpdatePrivateCloud_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; use Google\Cloud\VmwareEngine\V1\NetworkConfig; use Google\Cloud\VmwareEngine\V1\PrivateCloud; use Google\Cloud\VmwareEngine\V1\PrivateCloud\ManagementCluster; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\UpdatePrivateCloudRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -60,7 +61,7 @@ function update_private_cloud_sample( // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $privateCloudNetworkConfig = (new NetworkConfig()) ->setManagementCidr($privateCloudNetworkConfigManagementCidr); $privateCloudManagementClusterNodeTypeConfigs = []; @@ -71,11 +72,14 @@ function update_private_cloud_sample( ->setNetworkConfig($privateCloudNetworkConfig) ->setManagementCluster($privateCloudManagementCluster); $updateMask = new FieldMask(); + $request = (new UpdatePrivateCloudRequest()) + ->setPrivateCloud($privateCloud) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->updatePrivateCloud($privateCloud, $updateMask); + $response = $vmwareEngineClient->updatePrivateCloud($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/samples/V1/VmwareEngineClient/update_vmware_engine_network.php b/VmwareEngine/samples/V1/VmwareEngineClient/update_vmware_engine_network.php index ac8a64b7804b..9441a1681b49 100644 --- a/VmwareEngine/samples/V1/VmwareEngineClient/update_vmware_engine_network.php +++ b/VmwareEngine/samples/V1/VmwareEngineClient/update_vmware_engine_network.php @@ -25,7 +25,8 @@ // [START vmwareengine_v1_generated_VmwareEngine_UpdateVmwareEngineNetwork_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\VmwareEngine\V1\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\UpdateVmwareEngineNetworkRequest; use Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork; use Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork\Type; use Google\Protobuf\FieldMask; @@ -43,15 +44,18 @@ function update_vmware_engine_network_sample(int $vmwareEngineNetworkType): void // Create a client. $vmwareEngineClient = new VmwareEngineClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $vmwareEngineNetwork = (new VmwareEngineNetwork()) ->setType($vmwareEngineNetworkType); $updateMask = new FieldMask(); + $request = (new UpdateVmwareEngineNetworkRequest()) + ->setVmwareEngineNetwork($vmwareEngineNetwork) + ->setUpdateMask($updateMask); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $vmwareEngineClient->updateVmwareEngineNetwork($vmwareEngineNetwork, $updateMask); + $response = $vmwareEngineClient->updateVmwareEngineNetwork($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/VmwareEngine/src/V1/Client/BaseClient/VmwareEngineBaseClient.php b/VmwareEngine/src/V1/Client/BaseClient/VmwareEngineBaseClient.php new file mode 100644 index 000000000000..1dd6664b310d --- /dev/null +++ b/VmwareEngine/src/V1/Client/BaseClient/VmwareEngineBaseClient.php @@ -0,0 +1,1408 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/vmware_engine_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/vmware_engine_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/vmware_engine_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/vmware_engine_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 cluster + * resource. + * + * @param string $project + * @param string $location + * @param string $privateCloud + * @param string $cluster + * + * @return string The formatted cluster resource. + */ + public static function clusterName(string $project, string $location, string $privateCloud, string $cluster): string + { + return self::getPathTemplate('cluster')->render([ + 'project' => $project, + 'location' => $location, + 'private_cloud' => $privateCloud, + 'cluster' => $cluster, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * hcx_activation_key resource. + * + * @param string $project + * @param string $location + * @param string $privateCloud + * @param string $hcxActivationKey + * + * @return string The formatted hcx_activation_key resource. + */ + public static function hcxActivationKeyName(string $project, string $location, string $privateCloud, string $hcxActivationKey): string + { + return self::getPathTemplate('hcxActivationKey')->render([ + 'project' => $project, + 'location' => $location, + 'private_cloud' => $privateCloud, + 'hcx_activation_key' => $hcxActivationKey, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a network + * resource. + * + * @param string $project + * @param string $network + * + * @return string The formatted network resource. + */ + public static function networkName(string $project, string $network): string + { + return self::getPathTemplate('network')->render([ + 'project' => $project, + 'network' => $network, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * network_policy resource. + * + * @param string $project + * @param string $location + * @param string $networkPolicy + * + * @return string The formatted network_policy resource. + */ + public static function networkPolicyName(string $project, string $location, string $networkPolicy): string + { + return self::getPathTemplate('networkPolicy')->render([ + 'project' => $project, + 'location' => $location, + 'network_policy' => $networkPolicy, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a node_type + * resource. + * + * @param string $project + * @param string $location + * @param string $nodeType + * + * @return string The formatted node_type resource. + */ + public static function nodeTypeName(string $project, string $location, string $nodeType): string + { + return self::getPathTemplate('nodeType')->render([ + 'project' => $project, + 'location' => $location, + 'node_type' => $nodeType, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * private_cloud resource. + * + * @param string $project + * @param string $location + * @param string $privateCloud + * + * @return string The formatted private_cloud resource. + */ + public static function privateCloudName(string $project, string $location, string $privateCloud): string + { + return self::getPathTemplate('privateCloud')->render([ + 'project' => $project, + 'location' => $location, + 'private_cloud' => $privateCloud, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * vmware_engine_network resource. + * + * @param string $project + * @param string $location + * @param string $vmwareEngineNetwork + * + * @return string The formatted vmware_engine_network resource. + */ + public static function vmwareEngineNetworkName(string $project, string $location, string $vmwareEngineNetwork): string + { + return self::getPathTemplate('vmwareEngineNetwork')->render([ + 'project' => $project, + 'location' => $location, + 'vmware_engine_network' => $vmwareEngineNetwork, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - cluster: projects/{project}/locations/{location}/privateClouds/{private_cloud}/clusters/{cluster} + * - hcxActivationKey: projects/{project}/locations/{location}/privateClouds/{private_cloud}/hcxActivationKeys/{hcx_activation_key} + * - location: projects/{project}/locations/{location} + * - network: projects/{project}/global/networks/{network} + * - networkPolicy: projects/{project}/locations/{location}/networkPolicies/{network_policy} + * - nodeType: projects/{project}/locations/{location}/nodeTypes/{node_type} + * - privateCloud: projects/{project}/locations/{location}/privateClouds/{private_cloud} + * - vmwareEngineNetwork: projects/{project}/locations/{location}/vmwareEngineNetworks/{vmware_engine_network} + * + * 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 'vmwareengine.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 cluster in a given private cloud. + * Creating a new cluster provides additional nodes for + * use in the parent private cloud and requires sufficient [node + * quota](https://cloud.google.com/vmware-engine/quotas). + * + * The async variant is {@see self::createClusterAsync()} . + * + * @param CreateClusterRequest $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 createCluster(CreateClusterRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateCluster', $request, $callOptions)->wait(); + } + + /** + * Creates a new HCX activation key in a given private cloud. + * + * The async variant is {@see self::createHcxActivationKeyAsync()} . + * + * @param CreateHcxActivationKeyRequest $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 createHcxActivationKey(CreateHcxActivationKeyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateHcxActivationKey', $request, $callOptions)->wait(); + } + + /** + * Creates a new network policy in a given VMware Engine network of a + * project and location (region). A new network policy cannot be created if + * another network policy already exists in the same scope. + * + * The async variant is {@see self::createNetworkPolicyAsync()} . + * + * @param CreateNetworkPolicyRequest $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 createNetworkPolicy(CreateNetworkPolicyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateNetworkPolicy', $request, $callOptions)->wait(); + } + + /** + * Creates a new `PrivateCloud` resource in a given project and location. + * Private clouds can only be created in zones, regional private clouds are + * not supported. + * + * Creating a private cloud also creates a [management + * cluster](https://cloud.google.com/vmware-engine/docs/concepts-vmware-components) + * for that private cloud. + * + * The async variant is {@see self::createPrivateCloudAsync()} . + * + * @param CreatePrivateCloudRequest $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 createPrivateCloud(CreatePrivateCloudRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreatePrivateCloud', $request, $callOptions)->wait(); + } + + /** + * Creates a new VMware Engine network that can be used by a private cloud. + * + * The async variant is {@see self::createVmwareEngineNetworkAsync()} . + * + * @param CreateVmwareEngineNetworkRequest $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 createVmwareEngineNetwork(CreateVmwareEngineNetworkRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateVmwareEngineNetwork', $request, $callOptions)->wait(); + } + + /** + * Deletes a `Cluster` resource. To avoid unintended data loss, migrate or + * gracefully shut down any workloads running on the cluster before deletion. + * You cannot delete the management cluster of a private cloud using this + * method. + * + * The async variant is {@see self::deleteClusterAsync()} . + * + * @param DeleteClusterRequest $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 deleteCluster(DeleteClusterRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteCluster', $request, $callOptions)->wait(); + } + + /** + * Deletes a `NetworkPolicy` resource. A network policy cannot be deleted + * when `NetworkService.state` is set to `RECONCILING` for either its external + * IP or internet access service. + * + * The async variant is {@see self::deleteNetworkPolicyAsync()} . + * + * @param DeleteNetworkPolicyRequest $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 deleteNetworkPolicy(DeleteNetworkPolicyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteNetworkPolicy', $request, $callOptions)->wait(); + } + + /** + * Schedules a `PrivateCloud` resource for deletion. + * + * A `PrivateCloud` resource scheduled for deletion has `PrivateCloud.state` + * set to `DELETED` and `expireTime` set to the time when deletion is final + * and can no longer be reversed. The delete operation is marked as done + * as soon as the `PrivateCloud` is successfully scheduled for deletion + * (this also applies when `delayHours` is set to zero), and the operation is + * not kept in pending state until `PrivateCloud` is purged. + * `PrivateCloud` can be restored using `UndeletePrivateCloud` method before + * the `expireTime` elapses. When `expireTime` is reached, deletion is final + * and all private cloud resources are irreversibly removed and billing stops. + * During the final removal process, `PrivateCloud.state` is set to `PURGING`. + * `PrivateCloud` can be polled using standard `GET` method for the whole + * period of deletion and purging. It will not be returned only + * when it is completely purged. + * + * The async variant is {@see self::deletePrivateCloudAsync()} . + * + * @param DeletePrivateCloudRequest $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 deletePrivateCloud(DeletePrivateCloudRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeletePrivateCloud', $request, $callOptions)->wait(); + } + + /** + * Deletes a `VmwareEngineNetwork` resource. You can only delete a VMware + * Engine network after all resources that refer to it are deleted. For + * example, a private cloud, a network peering, and a network policy can all + * refer to the same VMware Engine network. + * + * The async variant is {@see self::deleteVmwareEngineNetworkAsync()} . + * + * @param DeleteVmwareEngineNetworkRequest $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 deleteVmwareEngineNetwork(DeleteVmwareEngineNetworkRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteVmwareEngineNetwork', $request, $callOptions)->wait(); + } + + /** + * Retrieves a `Cluster` resource by its resource name. + * + * The async variant is {@see self::getClusterAsync()} . + * + * @param GetClusterRequest $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 Cluster + * + * @throws ApiException Thrown if the API call fails. + */ + public function getCluster(GetClusterRequest $request, array $callOptions = []): Cluster + { + return $this->startApiCall('GetCluster', $request, $callOptions)->wait(); + } + + /** + * Retrieves a `HcxActivationKey` resource by its resource name. + * + * The async variant is {@see self::getHcxActivationKeyAsync()} . + * + * @param GetHcxActivationKeyRequest $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 HcxActivationKey + * + * @throws ApiException Thrown if the API call fails. + */ + public function getHcxActivationKey(GetHcxActivationKeyRequest $request, array $callOptions = []): HcxActivationKey + { + return $this->startApiCall('GetHcxActivationKey', $request, $callOptions)->wait(); + } + + /** + * Retrieves a `NetworkPolicy` resource by its resource name. + * + * The async variant is {@see self::getNetworkPolicyAsync()} . + * + * @param GetNetworkPolicyRequest $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 NetworkPolicy + * + * @throws ApiException Thrown if the API call fails. + */ + public function getNetworkPolicy(GetNetworkPolicyRequest $request, array $callOptions = []): NetworkPolicy + { + return $this->startApiCall('GetNetworkPolicy', $request, $callOptions)->wait(); + } + + /** + * Gets details of a single `NodeType`. + * + * The async variant is {@see self::getNodeTypeAsync()} . + * + * @param GetNodeTypeRequest $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 NodeType + * + * @throws ApiException Thrown if the API call fails. + */ + public function getNodeType(GetNodeTypeRequest $request, array $callOptions = []): NodeType + { + return $this->startApiCall('GetNodeType', $request, $callOptions)->wait(); + } + + /** + * Retrieves a `PrivateCloud` resource by its resource name. + * + * The async variant is {@see self::getPrivateCloudAsync()} . + * + * @param GetPrivateCloudRequest $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 PrivateCloud + * + * @throws ApiException Thrown if the API call fails. + */ + public function getPrivateCloud(GetPrivateCloudRequest $request, array $callOptions = []): PrivateCloud + { + return $this->startApiCall('GetPrivateCloud', $request, $callOptions)->wait(); + } + + /** + * Retrieves a `VmwareEngineNetwork` resource by its resource name. The + * resource contains details of the VMware Engine network, such as its VMware + * Engine network type, peered networks in a service project, and state + * (for example, `CREATING`, `ACTIVE`, `DELETING`). + * + * The async variant is {@see self::getVmwareEngineNetworkAsync()} . + * + * @param GetVmwareEngineNetworkRequest $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 VmwareEngineNetwork + * + * @throws ApiException Thrown if the API call fails. + */ + public function getVmwareEngineNetwork(GetVmwareEngineNetworkRequest $request, array $callOptions = []): VmwareEngineNetwork + { + return $this->startApiCall('GetVmwareEngineNetwork', $request, $callOptions)->wait(); + } + + /** + * Lists `Cluster` resources in a given private cloud. + * + * The async variant is {@see self::listClustersAsync()} . + * + * @param ListClustersRequest $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 listClusters(ListClustersRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListClusters', $request, $callOptions); + } + + /** + * Lists `HcxActivationKey` resources in a given private cloud. + * + * The async variant is {@see self::listHcxActivationKeysAsync()} . + * + * @param ListHcxActivationKeysRequest $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 listHcxActivationKeys(ListHcxActivationKeysRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListHcxActivationKeys', $request, $callOptions); + } + + /** + * Lists `NetworkPolicy` resources in a specified project and location. + * + * The async variant is {@see self::listNetworkPoliciesAsync()} . + * + * @param ListNetworkPoliciesRequest $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 listNetworkPolicies(ListNetworkPoliciesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListNetworkPolicies', $request, $callOptions); + } + + /** + * Lists node types + * + * The async variant is {@see self::listNodeTypesAsync()} . + * + * @param ListNodeTypesRequest $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 listNodeTypes(ListNodeTypesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListNodeTypes', $request, $callOptions); + } + + /** + * Lists `PrivateCloud` resources in a given project and location. + * + * The async variant is {@see self::listPrivateCloudsAsync()} . + * + * @param ListPrivateCloudsRequest $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 listPrivateClouds(ListPrivateCloudsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListPrivateClouds', $request, $callOptions); + } + + /** + * Lists subnets in a given private cloud. + * + * The async variant is {@see self::listSubnetsAsync()} . + * + * @param ListSubnetsRequest $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 listSubnets(ListSubnetsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListSubnets', $request, $callOptions); + } + + /** + * Lists `VmwareEngineNetwork` resources in a given project and location. + * + * The async variant is {@see self::listVmwareEngineNetworksAsync()} . + * + * @param ListVmwareEngineNetworksRequest $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 listVmwareEngineNetworks(ListVmwareEngineNetworksRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListVmwareEngineNetworks', $request, $callOptions); + } + + /** + * Resets credentials of the NSX appliance. + * + * The async variant is {@see self::resetNsxCredentialsAsync()} . + * + * @param ResetNsxCredentialsRequest $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 resetNsxCredentials(ResetNsxCredentialsRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ResetNsxCredentials', $request, $callOptions)->wait(); + } + + /** + * Resets credentials of the Vcenter appliance. + * + * The async variant is {@see self::resetVcenterCredentialsAsync()} . + * + * @param ResetVcenterCredentialsRequest $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 resetVcenterCredentials(ResetVcenterCredentialsRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ResetVcenterCredentials', $request, $callOptions)->wait(); + } + + /** + * Gets details of credentials for NSX appliance. + * + * The async variant is {@see self::showNsxCredentialsAsync()} . + * + * @param ShowNsxCredentialsRequest $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 Credentials + * + * @throws ApiException Thrown if the API call fails. + */ + public function showNsxCredentials(ShowNsxCredentialsRequest $request, array $callOptions = []): Credentials + { + return $this->startApiCall('ShowNsxCredentials', $request, $callOptions)->wait(); + } + + /** + * Gets details of credentials for Vcenter appliance. + * + * The async variant is {@see self::showVcenterCredentialsAsync()} . + * + * @param ShowVcenterCredentialsRequest $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 Credentials + * + * @throws ApiException Thrown if the API call fails. + */ + public function showVcenterCredentials(ShowVcenterCredentialsRequest $request, array $callOptions = []): Credentials + { + return $this->startApiCall('ShowVcenterCredentials', $request, $callOptions)->wait(); + } + + /** + * Restores a private cloud that was previously scheduled for deletion by + * `DeletePrivateCloud`. A `PrivateCloud` resource scheduled for deletion has + * `PrivateCloud.state` set to `DELETED` and `PrivateCloud.expireTime` set to + * the time when deletion can no longer be reversed. + * + * The async variant is {@see self::undeletePrivateCloudAsync()} . + * + * @param UndeletePrivateCloudRequest $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 undeletePrivateCloud(UndeletePrivateCloudRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UndeletePrivateCloud', $request, $callOptions)->wait(); + } + + /** + * Modifies a `Cluster` resource. Only the following fields can be updated: + * `node_type_configs.*.node_count`. Only fields specified in `updateMask` are + * applied. + * + * During operation processing, the resource is temporarily in the `ACTIVE` + * state before the operation fully completes. For that period of time, you + * can't update the resource. Use the operation status to determine when the + * processing fully completes. + * + * The async variant is {@see self::updateClusterAsync()} . + * + * @param UpdateClusterRequest $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 updateCluster(UpdateClusterRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateCluster', $request, $callOptions)->wait(); + } + + /** + * Modifies a `NetworkPolicy` resource. Only the following fields can be + * updated: `internet_access`, `external_ip`, `edge_services_cidr`. + * Only fields specified in `updateMask` are applied. When updating a network + * policy, the external IP network service can only be disabled if there are + * no external IP addresses present in the scope of the policy. Also, a + * `NetworkService` cannot be updated when `NetworkService.state` is set + * to `RECONCILING`. + * + * During operation processing, the resource is temporarily in the `ACTIVE` + * state before the operation fully completes. For that period of time, you + * can't update the resource. Use the operation status to determine when the + * processing fully completes. + * + * The async variant is {@see self::updateNetworkPolicyAsync()} . + * + * @param UpdateNetworkPolicyRequest $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 updateNetworkPolicy(UpdateNetworkPolicyRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateNetworkPolicy', $request, $callOptions)->wait(); + } + + /** + * Modifies a `PrivateCloud` resource. Only the following fields can be + * updated: `description`. + * Only fields specified in `updateMask` are applied. + * + * During operation processing, the resource is temporarily in the `ACTIVE` + * state before the operation fully completes. For that period of time, you + * can't update the resource. Use the operation status to determine when the + * processing fully completes. + * + * The async variant is {@see self::updatePrivateCloudAsync()} . + * + * @param UpdatePrivateCloudRequest $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 updatePrivateCloud(UpdatePrivateCloudRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdatePrivateCloud', $request, $callOptions)->wait(); + } + + /** + * Modifies a VMware Engine network resource. Only the following fields can be + * updated: `description`. Only fields specified in `updateMask` are + * applied. + * + * The async variant is {@see self::updateVmwareEngineNetworkAsync()} . + * + * @param UpdateVmwareEngineNetworkRequest $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 updateVmwareEngineNetwork(UpdateVmwareEngineNetworkRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('UpdateVmwareEngineNetwork', $request, $callOptions)->wait(); + } + + /** + * Gets information about a location. + * + * The async variant is {@see self::getLocationAsync()} . + * + * @param GetLocationRequest $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 Location + * + * @throws ApiException Thrown if the API call fails. + */ + public function getLocation(GetLocationRequest $request, array $callOptions = []): Location + { + return $this->startApiCall('GetLocation', $request, $callOptions)->wait(); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $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 listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } + + /** + * Gets the access control policy for a resource. Returns an empty policy + if the resource exists and does not have a policy set. + * + * 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(); + } + + /** + * Sets the access control policy on the specified resource. Replaces + any existing policy. + + Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` + errors. + * + * 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 resource. If the + resource does not exist, this will return an empty set of + permissions, not a `NOT_FOUND` error. + + Note: This operation is designed to be used for building + permission-aware UIs and command-line tools, not for authorization + checking. This operation may "fail open" without warning. + * + * 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/VmwareEngine/src/V1/Client/VmwareEngineClient.php b/VmwareEngine/src/V1/Client/VmwareEngineClient.php new file mode 100644 index 000000000000..e10617998cd4 --- /dev/null +++ b/VmwareEngine/src/V1/Client/VmwareEngineClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setCluster($cluster) + ->setClusterId($clusterId); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/CreateHcxActivationKeyRequest.php b/VmwareEngine/src/V1/CreateHcxActivationKeyRequest.php index 08ecfd5791c0..ccbee2d35185 100644 --- a/VmwareEngine/src/V1/CreateHcxActivationKeyRequest.php +++ b/VmwareEngine/src/V1/CreateHcxActivationKeyRequest.php @@ -66,6 +66,39 @@ class CreateHcxActivationKeyRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The resource name of the private cloud to create the key for. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * @param \Google\Cloud\VmwareEngine\V1\HcxActivationKey $hcxActivationKey Required. The initial description of a new HCX activation key. When + * creating a new key, this field must be an empty object. + * @param string $hcxActivationKeyId Required. The user-provided identifier of the `HcxActivationKey` to be + * created. This identifier must be unique among `HcxActivationKey` resources + * within the parent and becomes the final token in the name URI. + * The identifier must meet the following requirements: + * + * * Only contains 1-63 alphanumeric characters and hyphens + * * Begins with an alphabetical character + * * Ends with a non-hyphen character + * * Not formatted as a UUID + * * Complies with [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034) + * (section 3.5) + * + * @return \Google\Cloud\VmwareEngine\V1\CreateHcxActivationKeyRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VmwareEngine\V1\HcxActivationKey $hcxActivationKey, string $hcxActivationKeyId): self + { + return (new self()) + ->setParent($parent) + ->setHcxActivationKey($hcxActivationKey) + ->setHcxActivationKeyId($hcxActivationKeyId); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/CreateNetworkPolicyRequest.php b/VmwareEngine/src/V1/CreateNetworkPolicyRequest.php index 19bf1a1bdbd5..c9aea77523de 100644 --- a/VmwareEngine/src/V1/CreateNetworkPolicyRequest.php +++ b/VmwareEngine/src/V1/CreateNetworkPolicyRequest.php @@ -67,6 +67,40 @@ class CreateNetworkPolicyRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The resource name of the location (region) + * to create the new network policy in. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1` + * Please see {@see VmwareEngineClient::locationName()} for help formatting this field. + * @param \Google\Cloud\VmwareEngine\V1\NetworkPolicy $networkPolicy Required. The network policy configuration to use in the request. + * @param string $networkPolicyId Required. The user-provided identifier of the network policy to be created. + * This identifier must be unique within parent + * `projects/{my-project}/locations/{us-central1}/networkPolicies` and becomes + * the final token in the name URI. + * The identifier must meet the following requirements: + * + * * Only contains 1-63 alphanumeric characters and hyphens + * * Begins with an alphabetical character + * * Ends with a non-hyphen character + * * Not formatted as a UUID + * * Complies with [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034) + * (section 3.5) + * + * @return \Google\Cloud\VmwareEngine\V1\CreateNetworkPolicyRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VmwareEngine\V1\NetworkPolicy $networkPolicy, string $networkPolicyId): self + { + return (new self()) + ->setParent($parent) + ->setNetworkPolicy($networkPolicy) + ->setNetworkPolicyId($networkPolicyId); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/CreatePrivateCloudRequest.php b/VmwareEngine/src/V1/CreatePrivateCloudRequest.php index 1420320fe486..714d0f93ff67 100644 --- a/VmwareEngine/src/V1/CreatePrivateCloudRequest.php +++ b/VmwareEngine/src/V1/CreatePrivateCloudRequest.php @@ -62,6 +62,38 @@ class CreatePrivateCloudRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param string $parent Required. The resource name of the location to create the new + * private cloud in. Resource names are schemeless URIs that follow the + * conventions in https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a` + * Please see {@see VmwareEngineClient::locationName()} for help formatting this field. + * @param \Google\Cloud\VmwareEngine\V1\PrivateCloud $privateCloud Required. The initial description of the new private cloud. + * @param string $privateCloudId Required. The user-provided identifier of the private cloud to be created. + * This identifier must be unique among each `PrivateCloud` within the parent + * and becomes the final token in the name URI. + * The identifier must meet the following requirements: + * + * * Only contains 1-63 alphanumeric characters and hyphens + * * Begins with an alphabetical character + * * Ends with a non-hyphen character + * * Not formatted as a UUID + * * Complies with [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034) + * (section 3.5) + * + * @return \Google\Cloud\VmwareEngine\V1\CreatePrivateCloudRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VmwareEngine\V1\PrivateCloud $privateCloud, string $privateCloudId): self + { + return (new self()) + ->setParent($parent) + ->setPrivateCloud($privateCloud) + ->setPrivateCloudId($privateCloudId); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/CreateVmwareEngineNetworkRequest.php b/VmwareEngine/src/V1/CreateVmwareEngineNetworkRequest.php index 4d61b1c30f20..edc4a5db0cdb 100644 --- a/VmwareEngine/src/V1/CreateVmwareEngineNetworkRequest.php +++ b/VmwareEngine/src/V1/CreateVmwareEngineNetworkRequest.php @@ -70,6 +70,43 @@ class CreateVmwareEngineNetworkRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $parent Required. The resource name of the location to create the new VMware Engine + * network in. A VMware Engine network of type + * `LEGACY` is a regional resource, and a VMware + * Engine network of type `STANDARD` is a global resource. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. For example: + * `projects/my-project/locations/global` + * Please see {@see VmwareEngineClient::locationName()} for help formatting this field. + * @param \Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork $vmwareEngineNetwork Required. The initial description of the new VMware Engine network. + * @param string $vmwareEngineNetworkId Required. The user-provided identifier of the new VMware Engine network. + * This identifier must be unique among VMware Engine network resources + * within the parent and becomes the final token in the name URI. The + * identifier must meet the following requirements: + * + * * For networks of type LEGACY, adheres to the format: + * `{region-id}-default`. Replace `{region-id}` with the region where you want + * to create the VMware Engine network. For example, "us-central1-default". + * * Only contains 1-63 alphanumeric characters and hyphens + * * Begins with an alphabetical character + * * Ends with a non-hyphen character + * * Not formatted as a UUID + * * Complies with [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034) + * (section 3.5) + * + * @return \Google\Cloud\VmwareEngine\V1\CreateVmwareEngineNetworkRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork $vmwareEngineNetwork, string $vmwareEngineNetworkId): self + { + return (new self()) + ->setParent($parent) + ->setVmwareEngineNetwork($vmwareEngineNetwork) + ->setVmwareEngineNetworkId($vmwareEngineNetworkId); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/DeleteClusterRequest.php b/VmwareEngine/src/V1/DeleteClusterRequest.php index 9c7231cf54df..4866a3d67ee3 100644 --- a/VmwareEngine/src/V1/DeleteClusterRequest.php +++ b/VmwareEngine/src/V1/DeleteClusterRequest.php @@ -34,6 +34,24 @@ class DeleteClusterRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The resource name of the cluster to delete. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud/clusters/my-cluster` + * Please see {@see VmwareEngineClient::clusterName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\DeleteClusterRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/DeleteNetworkPolicyRequest.php b/VmwareEngine/src/V1/DeleteNetworkPolicyRequest.php index a90549d8a882..304fa3483143 100644 --- a/VmwareEngine/src/V1/DeleteNetworkPolicyRequest.php +++ b/VmwareEngine/src/V1/DeleteNetworkPolicyRequest.php @@ -44,6 +44,24 @@ class DeleteNetworkPolicyRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The resource name of the network policy to delete. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1/networkPolicies/my-network-policy` + * Please see {@see VmwareEngineClient::networkPolicyName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\DeleteNetworkPolicyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/DeletePrivateCloudRequest.php b/VmwareEngine/src/V1/DeletePrivateCloudRequest.php index 21990dcb72dd..a2ad0ad92ebf 100644 --- a/VmwareEngine/src/V1/DeletePrivateCloudRequest.php +++ b/VmwareEngine/src/V1/DeletePrivateCloudRequest.php @@ -57,6 +57,24 @@ class DeletePrivateCloudRequest extends \Google\Protobuf\Internal\Message */ private $delay_hours = null; + /** + * @param string $name Required. The resource name of the private cloud to delete. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\DeletePrivateCloudRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/DeleteVmwareEngineNetworkRequest.php b/VmwareEngine/src/V1/DeleteVmwareEngineNetworkRequest.php index a4a2a3c6feb5..3b93da5085e3 100644 --- a/VmwareEngine/src/V1/DeleteVmwareEngineNetworkRequest.php +++ b/VmwareEngine/src/V1/DeleteVmwareEngineNetworkRequest.php @@ -53,6 +53,24 @@ class DeleteVmwareEngineNetworkRequest extends \Google\Protobuf\Internal\Message */ private $etag = ''; + /** + * @param string $name Required. The resource name of the VMware Engine network to be deleted. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/global/vmwareEngineNetworks/my-network` + * Please see {@see VmwareEngineClient::vmwareEngineNetworkName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\DeleteVmwareEngineNetworkRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/GetClusterRequest.php b/VmwareEngine/src/V1/GetClusterRequest.php index 0ab2403ae77d..7b4446234e34 100644 --- a/VmwareEngine/src/V1/GetClusterRequest.php +++ b/VmwareEngine/src/V1/GetClusterRequest.php @@ -27,6 +27,24 @@ class GetClusterRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The cluster resource name to retrieve. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud/clusters/my-cluster` + * Please see {@see VmwareEngineClient::clusterName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\GetClusterRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/GetHcxActivationKeyRequest.php b/VmwareEngine/src/V1/GetHcxActivationKeyRequest.php index 92f3262e87a4..5f4aa526cdaf 100644 --- a/VmwareEngine/src/V1/GetHcxActivationKeyRequest.php +++ b/VmwareEngine/src/V1/GetHcxActivationKeyRequest.php @@ -26,6 +26,24 @@ class GetHcxActivationKeyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the HCX activation key to retrieve. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1/privateClouds/my-cloud/hcxActivationKeys/my-key` + * Please see {@see VmwareEngineClient::hcxActivationKeyName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\GetHcxActivationKeyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/GetNetworkPolicyRequest.php b/VmwareEngine/src/V1/GetNetworkPolicyRequest.php index 63ac40e06991..54fcdb48bc63 100644 --- a/VmwareEngine/src/V1/GetNetworkPolicyRequest.php +++ b/VmwareEngine/src/V1/GetNetworkPolicyRequest.php @@ -27,6 +27,24 @@ class GetNetworkPolicyRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the network policy to retrieve. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1/networkPolicies/my-network-policy` + * Please see {@see VmwareEngineClient::networkPolicyName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\GetNetworkPolicyRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/GetNodeTypeRequest.php b/VmwareEngine/src/V1/GetNodeTypeRequest.php index 808c04287f85..097e2209e360 100644 --- a/VmwareEngine/src/V1/GetNodeTypeRequest.php +++ b/VmwareEngine/src/V1/GetNodeTypeRequest.php @@ -27,6 +27,24 @@ class GetNodeTypeRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the node type to retrieve. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-proj/locations/us-central1-a/nodeTypes/standard-72` + * Please see {@see VmwareEngineClient::nodeTypeName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\GetNodeTypeRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/GetPrivateCloudRequest.php b/VmwareEngine/src/V1/GetPrivateCloudRequest.php index 6c62915d0d66..b3cbed260a45 100644 --- a/VmwareEngine/src/V1/GetPrivateCloudRequest.php +++ b/VmwareEngine/src/V1/GetPrivateCloudRequest.php @@ -27,6 +27,24 @@ class GetPrivateCloudRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the private cloud to retrieve. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\GetPrivateCloudRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/GetVmwareEngineNetworkRequest.php b/VmwareEngine/src/V1/GetVmwareEngineNetworkRequest.php index edd190b0dfcd..674de70bb2c5 100644 --- a/VmwareEngine/src/V1/GetVmwareEngineNetworkRequest.php +++ b/VmwareEngine/src/V1/GetVmwareEngineNetworkRequest.php @@ -27,6 +27,24 @@ class GetVmwareEngineNetworkRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the VMware Engine network to retrieve. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/global/vmwareEngineNetworks/my-network` + * Please see {@see VmwareEngineClient::vmwareEngineNetworkName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\GetVmwareEngineNetworkRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ListClustersRequest.php b/VmwareEngine/src/V1/ListClustersRequest.php index c78ae2a0ec3b..41f28f011028 100644 --- a/VmwareEngine/src/V1/ListClustersRequest.php +++ b/VmwareEngine/src/V1/ListClustersRequest.php @@ -72,6 +72,24 @@ class ListClustersRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The resource name of the private cloud to query for clusters. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ListClustersRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ListHcxActivationKeysRequest.php b/VmwareEngine/src/V1/ListHcxActivationKeysRequest.php index fd76bfc53e2a..15a8e5b7d2e8 100644 --- a/VmwareEngine/src/V1/ListHcxActivationKeysRequest.php +++ b/VmwareEngine/src/V1/ListHcxActivationKeysRequest.php @@ -47,6 +47,25 @@ class ListHcxActivationKeysRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The resource name of the private cloud + * to be queried for HCX activation keys. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ListHcxActivationKeysRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ListNetworkPoliciesRequest.php b/VmwareEngine/src/V1/ListNetworkPoliciesRequest.php index 366c9edf64b9..8820062246fc 100644 --- a/VmwareEngine/src/V1/ListNetworkPoliciesRequest.php +++ b/VmwareEngine/src/V1/ListNetworkPoliciesRequest.php @@ -82,6 +82,23 @@ class ListNetworkPoliciesRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The resource name of the location (region) to query for + * network policies. Resource names are schemeless URIs that follow the + * conventions in https://cloud.google.com/apis/design/resource_names. For + * example: `projects/my-project/locations/us-central1` + * Please see {@see VmwareEngineClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ListNetworkPoliciesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ListNodeTypesRequest.php b/VmwareEngine/src/V1/ListNodeTypesRequest.php index b6dab564ed86..b2c76701d3b8 100644 --- a/VmwareEngine/src/V1/ListNodeTypesRequest.php +++ b/VmwareEngine/src/V1/ListNodeTypesRequest.php @@ -72,6 +72,24 @@ class ListNodeTypesRequest extends \Google\Protobuf\Internal\Message */ private $filter = ''; + /** + * @param string $parent Required. The resource name of the location to be queried for node types. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a` + * Please see {@see VmwareEngineClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ListNodeTypesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ListPrivateCloudsRequest.php b/VmwareEngine/src/V1/ListPrivateCloudsRequest.php index 1e688b10d49f..8132ca3b6f41 100644 --- a/VmwareEngine/src/V1/ListPrivateCloudsRequest.php +++ b/VmwareEngine/src/V1/ListPrivateCloudsRequest.php @@ -82,6 +82,24 @@ class ListPrivateCloudsRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The resource name of the private cloud to be queried for + * clusters. Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a` + * Please see {@see VmwareEngineClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ListPrivateCloudsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ListSubnetsRequest.php b/VmwareEngine/src/V1/ListSubnetsRequest.php index 9ff6cb28f9fe..82fa130ece8d 100644 --- a/VmwareEngine/src/V1/ListSubnetsRequest.php +++ b/VmwareEngine/src/V1/ListSubnetsRequest.php @@ -46,6 +46,25 @@ class ListSubnetsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The resource name of the private cloud to be queried for + * subnets. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ListSubnetsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ListVmwareEngineNetworksRequest.php b/VmwareEngine/src/V1/ListVmwareEngineNetworksRequest.php index 956816863781..6d39a393f90b 100644 --- a/VmwareEngine/src/V1/ListVmwareEngineNetworksRequest.php +++ b/VmwareEngine/src/V1/ListVmwareEngineNetworksRequest.php @@ -81,6 +81,23 @@ class ListVmwareEngineNetworksRequest extends \Google\Protobuf\Internal\Message */ private $order_by = ''; + /** + * @param string $parent Required. The resource name of the location to query for + * VMware Engine networks. Resource names are schemeless URIs that follow the + * conventions in https://cloud.google.com/apis/design/resource_names. For + * example: `projects/my-project/locations/global` + * Please see {@see VmwareEngineClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ListVmwareEngineNetworksRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ResetNsxCredentialsRequest.php b/VmwareEngine/src/V1/ResetNsxCredentialsRequest.php index f4a143dbffd8..f628295e204f 100644 --- a/VmwareEngine/src/V1/ResetNsxCredentialsRequest.php +++ b/VmwareEngine/src/V1/ResetNsxCredentialsRequest.php @@ -45,6 +45,25 @@ class ResetNsxCredentialsRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $privateCloud Required. The resource name of the private cloud + * to reset credentials for. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ResetNsxCredentialsRequest + * + * @experimental + */ + public static function build(string $privateCloud): self + { + return (new self()) + ->setPrivateCloud($privateCloud); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ResetVcenterCredentialsRequest.php b/VmwareEngine/src/V1/ResetVcenterCredentialsRequest.php index c81678402d30..b0896e2b1a63 100644 --- a/VmwareEngine/src/V1/ResetVcenterCredentialsRequest.php +++ b/VmwareEngine/src/V1/ResetVcenterCredentialsRequest.php @@ -45,6 +45,25 @@ class ResetVcenterCredentialsRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $privateCloud Required. The resource name of the private cloud + * to reset credentials for. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ResetVcenterCredentialsRequest + * + * @experimental + */ + public static function build(string $privateCloud): self + { + return (new self()) + ->setPrivateCloud($privateCloud); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ShowNsxCredentialsRequest.php b/VmwareEngine/src/V1/ShowNsxCredentialsRequest.php index 7f33050da942..9ec13a7bcc43 100644 --- a/VmwareEngine/src/V1/ShowNsxCredentialsRequest.php +++ b/VmwareEngine/src/V1/ShowNsxCredentialsRequest.php @@ -28,6 +28,25 @@ class ShowNsxCredentialsRequest extends \Google\Protobuf\Internal\Message */ private $private_cloud = ''; + /** + * @param string $privateCloud Required. The resource name of the private cloud + * to be queried for credentials. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ShowNsxCredentialsRequest + * + * @experimental + */ + public static function build(string $privateCloud): self + { + return (new self()) + ->setPrivateCloud($privateCloud); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/ShowVcenterCredentialsRequest.php b/VmwareEngine/src/V1/ShowVcenterCredentialsRequest.php index f73048ac468f..9e7b86f10885 100644 --- a/VmwareEngine/src/V1/ShowVcenterCredentialsRequest.php +++ b/VmwareEngine/src/V1/ShowVcenterCredentialsRequest.php @@ -28,6 +28,25 @@ class ShowVcenterCredentialsRequest extends \Google\Protobuf\Internal\Message */ private $private_cloud = ''; + /** + * @param string $privateCloud Required. The resource name of the private cloud + * to be queried for credentials. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\ShowVcenterCredentialsRequest + * + * @experimental + */ + public static function build(string $privateCloud): self + { + return (new self()) + ->setPrivateCloud($privateCloud); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/UndeletePrivateCloudRequest.php b/VmwareEngine/src/V1/UndeletePrivateCloudRequest.php index 786ac793fe24..fec1fdb9c85c 100644 --- a/VmwareEngine/src/V1/UndeletePrivateCloudRequest.php +++ b/VmwareEngine/src/V1/UndeletePrivateCloudRequest.php @@ -34,6 +34,24 @@ class UndeletePrivateCloudRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param string $name Required. The resource name of the private cloud scheduled for deletion. + * Resource names are schemeless URIs that follow the conventions in + * https://cloud.google.com/apis/design/resource_names. + * For example: + * `projects/my-project/locations/us-central1-a/privateClouds/my-cloud` + * Please see {@see VmwareEngineClient::privateCloudName()} for help formatting this field. + * + * @return \Google\Cloud\VmwareEngine\V1\UndeletePrivateCloudRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/UpdateClusterRequest.php b/VmwareEngine/src/V1/UpdateClusterRequest.php index c48e07196a8b..6301ff2a5604 100644 --- a/VmwareEngine/src/V1/UpdateClusterRequest.php +++ b/VmwareEngine/src/V1/UpdateClusterRequest.php @@ -47,6 +47,25 @@ class UpdateClusterRequest extends \Google\Protobuf\Internal\Message */ private $validate_only = false; + /** + * @param \Google\Cloud\VmwareEngine\V1\Cluster $cluster Required. The description of the cluster. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask is used to specify the fields to be overwritten in the + * `Cluster` resource by the update. The fields specified in the `updateMask` + * are relative to the resource, not the full request. A field will be + * overwritten if it is in the mask. If the user does not provide a mask then + * all fields will be overwritten. + * + * @return \Google\Cloud\VmwareEngine\V1\UpdateClusterRequest + * + * @experimental + */ + public static function build(\Google\Cloud\VmwareEngine\V1\Cluster $cluster, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setCluster($cluster) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/UpdateNetworkPolicyRequest.php b/VmwareEngine/src/V1/UpdateNetworkPolicyRequest.php index 3fa6ee5a2e19..2fd24b76f052 100644 --- a/VmwareEngine/src/V1/UpdateNetworkPolicyRequest.php +++ b/VmwareEngine/src/V1/UpdateNetworkPolicyRequest.php @@ -50,6 +50,25 @@ class UpdateNetworkPolicyRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\VmwareEngine\V1\NetworkPolicy $networkPolicy Required. Network policy description. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask is used to specify the fields to be overwritten in the + * `NetworkPolicy` resource by the update. + * The fields specified in the `update_mask` are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. If the + * user does not provide a mask then all fields will be overwritten. + * + * @return \Google\Cloud\VmwareEngine\V1\UpdateNetworkPolicyRequest + * + * @experimental + */ + public static function build(\Google\Cloud\VmwareEngine\V1\NetworkPolicy $networkPolicy, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setNetworkPolicy($networkPolicy) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/UpdatePrivateCloudRequest.php b/VmwareEngine/src/V1/UpdatePrivateCloudRequest.php index 3802e43892d8..c6a168ad120f 100644 --- a/VmwareEngine/src/V1/UpdatePrivateCloudRequest.php +++ b/VmwareEngine/src/V1/UpdatePrivateCloudRequest.php @@ -40,6 +40,25 @@ class UpdatePrivateCloudRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\VmwareEngine\V1\PrivateCloud $privateCloud Required. Private cloud description. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask is used to specify the fields to be overwritten in the + * `PrivateCloud` resource by the update. The fields specified in `updateMask` + * are relative to the resource, not the full request. A field will be + * overwritten if it is in the mask. If the user does not provide a mask then + * all fields will be overwritten. + * + * @return \Google\Cloud\VmwareEngine\V1\UpdatePrivateCloudRequest + * + * @experimental + */ + public static function build(\Google\Cloud\VmwareEngine\V1\PrivateCloud $privateCloud, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setPrivateCloud($privateCloud) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/UpdateVmwareEngineNetworkRequest.php b/VmwareEngine/src/V1/UpdateVmwareEngineNetworkRequest.php index 665955041095..5cdc0d2ed0ac 100644 --- a/VmwareEngine/src/V1/UpdateVmwareEngineNetworkRequest.php +++ b/VmwareEngine/src/V1/UpdateVmwareEngineNetworkRequest.php @@ -51,6 +51,26 @@ class UpdateVmwareEngineNetworkRequest extends \Google\Protobuf\Internal\Message */ private $request_id = ''; + /** + * @param \Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork $vmwareEngineNetwork Required. VMware Engine network description. + * @param \Google\Protobuf\FieldMask $updateMask Required. Field mask is used to specify the fields to be overwritten in the + * VMware Engine network resource by the update. + * The fields specified in the `update_mask` are relative to the resource, not + * the full request. A field will be overwritten if it is in the mask. If the + * user does not provide a mask then all fields will be overwritten. Only the + * following fields can be updated: `description`. + * + * @return \Google\Cloud\VmwareEngine\V1\UpdateVmwareEngineNetworkRequest + * + * @experimental + */ + public static function build(\Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork $vmwareEngineNetwork, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setVmwareEngineNetwork($vmwareEngineNetwork) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/VmwareEngine/src/V1/resources/vmware_engine_descriptor_config.php b/VmwareEngine/src/V1/resources/vmware_engine_descriptor_config.php index b6b86dab6b3f..af03d9f4cce0 100644 --- a/VmwareEngine/src/V1/resources/vmware_engine_descriptor_config.php +++ b/VmwareEngine/src/V1/resources/vmware_engine_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateHcxActivationKey' => [ 'longRunning' => [ @@ -22,6 +31,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateNetworkPolicy' => [ 'longRunning' => [ @@ -32,6 +50,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreatePrivateCloud' => [ 'longRunning' => [ @@ -42,6 +69,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'CreateVmwareEngineNetwork' => [ 'longRunning' => [ @@ -52,6 +88,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteCluster' => [ 'longRunning' => [ @@ -62,6 +107,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteNetworkPolicy' => [ 'longRunning' => [ @@ -72,6 +126,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeletePrivateCloud' => [ 'longRunning' => [ @@ -82,6 +145,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'DeleteVmwareEngineNetwork' => [ 'longRunning' => [ @@ -92,6 +164,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ResetNsxCredentials' => [ 'longRunning' => [ @@ -102,6 +183,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'private_cloud', + 'fieldAccessors' => [ + 'getPrivateCloud', + ], + ], + ], ], 'ResetVcenterCredentials' => [ 'longRunning' => [ @@ -112,6 +202,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'private_cloud', + 'fieldAccessors' => [ + 'getPrivateCloud', + ], + ], + ], ], 'UndeletePrivateCloud' => [ 'longRunning' => [ @@ -122,6 +221,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'UpdateCluster' => [ 'longRunning' => [ @@ -132,6 +240,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'cluster.name', + 'fieldAccessors' => [ + 'getCluster', + 'getName', + ], + ], + ], ], 'UpdateNetworkPolicy' => [ 'longRunning' => [ @@ -142,6 +260,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'network_policy.name', + 'fieldAccessors' => [ + 'getNetworkPolicy', + 'getName', + ], + ], + ], ], 'UpdatePrivateCloud' => [ 'longRunning' => [ @@ -152,6 +280,16 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'private_cloud.name', + 'fieldAccessors' => [ + 'getPrivateCloud', + 'getName', + ], + ], + ], ], 'UpdateVmwareEngineNetwork' => [ 'longRunning' => [ @@ -162,6 +300,88 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'vmware_engine_network.name', + 'fieldAccessors' => [ + 'getVmwareEngineNetwork', + 'getName', + ], + ], + ], + ], + 'GetCluster' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\Cluster', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetHcxActivationKey' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\HcxActivationKey', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetNetworkPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\NetworkPolicy', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetNodeType' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\NodeType', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetPrivateCloud' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\PrivateCloud', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetVmwareEngineNetwork' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\VmwareEngineNetwork', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListClusters' => [ 'pageStreaming' => [ @@ -172,6 +392,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getClusters', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\ListClustersResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListHcxActivationKeys' => [ 'pageStreaming' => [ @@ -182,6 +412,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getHcxActivationKeys', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\ListHcxActivationKeysResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListNetworkPolicies' => [ 'pageStreaming' => [ @@ -192,6 +432,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getNetworkPolicies', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\ListNetworkPoliciesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListNodeTypes' => [ 'pageStreaming' => [ @@ -202,6 +452,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getNodeTypes', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\ListNodeTypesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListPrivateClouds' => [ 'pageStreaming' => [ @@ -212,6 +472,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getPrivateClouds', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\ListPrivateCloudsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListSubnets' => [ 'pageStreaming' => [ @@ -222,6 +492,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getSubnets', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\ListSubnetsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListVmwareEngineNetworks' => [ 'pageStreaming' => [ @@ -232,8 +512,52 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getVmwareEngineNetworks', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\ListVmwareEngineNetworksResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ShowNsxCredentials' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\Credentials', + 'headerParams' => [ + [ + 'keyName' => 'private_cloud', + 'fieldAccessors' => [ + 'getPrivateCloud', + ], + ], + ], + ], + 'ShowVcenterCredentials' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VmwareEngine\V1\Credentials', + 'headerParams' => [ + [ + 'keyName' => 'private_cloud', + 'fieldAccessors' => [ + 'getPrivateCloud', + ], + ], + ], ], 'GetLocation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Location\Location', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'ListLocations' => [ @@ -245,17 +569,67 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], 'GetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'SetIamPolicy' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\Policy', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'TestIamPermissions' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Iam\V1\TestIamPermissionsResponse', + 'headerParams' => [ + [ + 'keyName' => 'resource', + 'fieldAccessors' => [ + 'getResource', + ], + ], + ], 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], + 'templateMap' => [ + 'cluster' => 'projects/{project}/locations/{location}/privateClouds/{private_cloud}/clusters/{cluster}', + 'hcxActivationKey' => 'projects/{project}/locations/{location}/privateClouds/{private_cloud}/hcxActivationKeys/{hcx_activation_key}', + 'location' => 'projects/{project}/locations/{location}', + 'network' => 'projects/{project}/global/networks/{network}', + 'networkPolicy' => 'projects/{project}/locations/{location}/networkPolicies/{network_policy}', + 'nodeType' => 'projects/{project}/locations/{location}/nodeTypes/{node_type}', + 'privateCloud' => 'projects/{project}/locations/{location}/privateClouds/{private_cloud}', + 'vmwareEngineNetwork' => 'projects/{project}/locations/{location}/vmwareEngineNetworks/{vmware_engine_network}', + ], ], ], ]; diff --git a/VmwareEngine/tests/Unit/V1/Client/VmwareEngineClientTest.php b/VmwareEngine/tests/Unit/V1/Client/VmwareEngineClientTest.php new file mode 100644 index 000000000000..a222ff4fe21b --- /dev/null +++ b/VmwareEngine/tests/Unit/V1/Client/VmwareEngineClientTest.php @@ -0,0 +1,3818 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return VmwareEngineClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new VmwareEngineClient($options); + } + + /** @test */ + public function createClusterTest() + { + $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/createClusterTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $management = false; + $uid = 'uid115792'; + $expectedResponse = new Cluster(); + $expectedResponse->setName($name); + $expectedResponse->setManagement($management); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createClusterTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $clusterId = 'clusterId240280960'; + $cluster = new Cluster(); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $clusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $cluster->setNodeTypeConfigs($clusterNodeTypeConfigs); + $request = (new CreateClusterRequest()) + ->setParent($formattedParent) + ->setClusterId($clusterId) + ->setCluster($cluster); + $response = $gapicClient->createCluster($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.vmwareengine.v1.VmwareEngine/CreateCluster', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getClusterId(); + $this->assertProtobufEquals($clusterId, $actualValue); + $actualValue = $actualApiRequestObject->getCluster(); + $this->assertProtobufEquals($cluster, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClusterTest'); + $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 createClusterExceptionTest() + { + $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/createClusterTest'); + $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->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $clusterId = 'clusterId240280960'; + $cluster = new Cluster(); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $clusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $cluster->setNodeTypeConfigs($clusterNodeTypeConfigs); + $request = (new CreateClusterRequest()) + ->setParent($formattedParent) + ->setClusterId($clusterId) + ->setCluster($cluster); + $response = $gapicClient->createCluster($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClusterTest'); + 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 createHcxActivationKeyTest() + { + $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/createHcxActivationKeyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $activationKey = 'activationKey-1343958090'; + $uid = 'uid115792'; + $expectedResponse = new HcxActivationKey(); + $expectedResponse->setName($name); + $expectedResponse->setActivationKey($activationKey); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createHcxActivationKeyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $hcxActivationKey = new HcxActivationKey(); + $hcxActivationKeyId = 'hcxActivationKeyId26532194'; + $request = (new CreateHcxActivationKeyRequest()) + ->setParent($formattedParent) + ->setHcxActivationKey($hcxActivationKey) + ->setHcxActivationKeyId($hcxActivationKeyId); + $response = $gapicClient->createHcxActivationKey($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.vmwareengine.v1.VmwareEngine/CreateHcxActivationKey', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getHcxActivationKey(); + $this->assertProtobufEquals($hcxActivationKey, $actualValue); + $actualValue = $actualApiRequestObject->getHcxActivationKeyId(); + $this->assertProtobufEquals($hcxActivationKeyId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createHcxActivationKeyTest'); + $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 createHcxActivationKeyExceptionTest() + { + $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/createHcxActivationKeyTest'); + $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->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $hcxActivationKey = new HcxActivationKey(); + $hcxActivationKeyId = 'hcxActivationKeyId26532194'; + $request = (new CreateHcxActivationKeyRequest()) + ->setParent($formattedParent) + ->setHcxActivationKey($hcxActivationKey) + ->setHcxActivationKeyId($hcxActivationKeyId); + $response = $gapicClient->createHcxActivationKey($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createHcxActivationKeyTest'); + 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 createNetworkPolicyTest() + { + $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/createNetworkPolicyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $edgeServicesCidr = 'edgeServicesCidr-792872013'; + $uid = 'uid115792'; + $vmwareEngineNetwork = 'vmwareEngineNetwork-90899684'; + $description = 'description-1724546052'; + $vmwareEngineNetworkCanonical = 'vmwareEngineNetworkCanonical779839377'; + $expectedResponse = new NetworkPolicy(); + $expectedResponse->setName($name); + $expectedResponse->setEdgeServicesCidr($edgeServicesCidr); + $expectedResponse->setUid($uid); + $expectedResponse->setVmwareEngineNetwork($vmwareEngineNetwork); + $expectedResponse->setDescription($description); + $expectedResponse->setVmwareEngineNetworkCanonical($vmwareEngineNetworkCanonical); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createNetworkPolicyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $networkPolicyId = 'networkPolicyId173955703'; + $networkPolicy = new NetworkPolicy(); + $networkPolicyEdgeServicesCidr = 'networkPolicyEdgeServicesCidr-602005393'; + $networkPolicy->setEdgeServicesCidr($networkPolicyEdgeServicesCidr); + $request = (new CreateNetworkPolicyRequest()) + ->setParent($formattedParent) + ->setNetworkPolicyId($networkPolicyId) + ->setNetworkPolicy($networkPolicy); + $response = $gapicClient->createNetworkPolicy($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.vmwareengine.v1.VmwareEngine/CreateNetworkPolicy', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getNetworkPolicyId(); + $this->assertProtobufEquals($networkPolicyId, $actualValue); + $actualValue = $actualApiRequestObject->getNetworkPolicy(); + $this->assertProtobufEquals($networkPolicy, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createNetworkPolicyTest'); + $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 createNetworkPolicyExceptionTest() + { + $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/createNetworkPolicyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $networkPolicyId = 'networkPolicyId173955703'; + $networkPolicy = new NetworkPolicy(); + $networkPolicyEdgeServicesCidr = 'networkPolicyEdgeServicesCidr-602005393'; + $networkPolicy->setEdgeServicesCidr($networkPolicyEdgeServicesCidr); + $request = (new CreateNetworkPolicyRequest()) + ->setParent($formattedParent) + ->setNetworkPolicyId($networkPolicyId) + ->setNetworkPolicy($networkPolicy); + $response = $gapicClient->createNetworkPolicy($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createNetworkPolicyTest'); + 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 createPrivateCloudTest() + { + $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/createPrivateCloudTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $expectedResponse = new PrivateCloud(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createPrivateCloudTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $privateCloudId = 'privateCloudId1366391457'; + $privateCloud = new PrivateCloud(); + $privateCloudNetworkConfig = new NetworkConfig(); + $networkConfigManagementCidr = 'networkConfigManagementCidr2092091783'; + $privateCloudNetworkConfig->setManagementCidr($networkConfigManagementCidr); + $privateCloud->setNetworkConfig($privateCloudNetworkConfig); + $privateCloudManagementCluster = new ManagementCluster(); + $managementClusterClusterId = 'managementClusterClusterId311493182'; + $privateCloudManagementCluster->setClusterId($managementClusterClusterId); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $managementClusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $privateCloudManagementCluster->setNodeTypeConfigs($managementClusterNodeTypeConfigs); + $privateCloud->setManagementCluster($privateCloudManagementCluster); + $request = (new CreatePrivateCloudRequest()) + ->setParent($formattedParent) + ->setPrivateCloudId($privateCloudId) + ->setPrivateCloud($privateCloud); + $response = $gapicClient->createPrivateCloud($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.vmwareengine.v1.VmwareEngine/CreatePrivateCloud', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getPrivateCloudId(); + $this->assertProtobufEquals($privateCloudId, $actualValue); + $actualValue = $actualApiRequestObject->getPrivateCloud(); + $this->assertProtobufEquals($privateCloud, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createPrivateCloudTest'); + $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 createPrivateCloudExceptionTest() + { + $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/createPrivateCloudTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $privateCloudId = 'privateCloudId1366391457'; + $privateCloud = new PrivateCloud(); + $privateCloudNetworkConfig = new NetworkConfig(); + $networkConfigManagementCidr = 'networkConfigManagementCidr2092091783'; + $privateCloudNetworkConfig->setManagementCidr($networkConfigManagementCidr); + $privateCloud->setNetworkConfig($privateCloudNetworkConfig); + $privateCloudManagementCluster = new ManagementCluster(); + $managementClusterClusterId = 'managementClusterClusterId311493182'; + $privateCloudManagementCluster->setClusterId($managementClusterClusterId); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $managementClusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $privateCloudManagementCluster->setNodeTypeConfigs($managementClusterNodeTypeConfigs); + $privateCloud->setManagementCluster($privateCloudManagementCluster); + $request = (new CreatePrivateCloudRequest()) + ->setParent($formattedParent) + ->setPrivateCloudId($privateCloudId) + ->setPrivateCloud($privateCloud); + $response = $gapicClient->createPrivateCloud($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createPrivateCloudTest'); + 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 createVmwareEngineNetworkTest() + { + $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/createVmwareEngineNetworkTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $etag = 'etag3123477'; + $expectedResponse = new VmwareEngineNetwork(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createVmwareEngineNetworkTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $vmwareEngineNetworkId = 'vmwareEngineNetworkId2131972382'; + $vmwareEngineNetwork = new VmwareEngineNetwork(); + $vmwareEngineNetworkType = Type::TYPE_UNSPECIFIED; + $vmwareEngineNetwork->setType($vmwareEngineNetworkType); + $request = (new CreateVmwareEngineNetworkRequest()) + ->setParent($formattedParent) + ->setVmwareEngineNetworkId($vmwareEngineNetworkId) + ->setVmwareEngineNetwork($vmwareEngineNetwork); + $response = $gapicClient->createVmwareEngineNetwork($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.vmwareengine.v1.VmwareEngine/CreateVmwareEngineNetwork', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getVmwareEngineNetworkId(); + $this->assertProtobufEquals($vmwareEngineNetworkId, $actualValue); + $actualValue = $actualApiRequestObject->getVmwareEngineNetwork(); + $this->assertProtobufEquals($vmwareEngineNetwork, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createVmwareEngineNetworkTest'); + $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 createVmwareEngineNetworkExceptionTest() + { + $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/createVmwareEngineNetworkTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $vmwareEngineNetworkId = 'vmwareEngineNetworkId2131972382'; + $vmwareEngineNetwork = new VmwareEngineNetwork(); + $vmwareEngineNetworkType = Type::TYPE_UNSPECIFIED; + $vmwareEngineNetwork->setType($vmwareEngineNetworkType); + $request = (new CreateVmwareEngineNetworkRequest()) + ->setParent($formattedParent) + ->setVmwareEngineNetworkId($vmwareEngineNetworkId) + ->setVmwareEngineNetwork($vmwareEngineNetwork); + $response = $gapicClient->createVmwareEngineNetwork($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createVmwareEngineNetworkTest'); + 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 deleteClusterTest() + { + $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/deleteClusterTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteClusterTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->clusterName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]', '[CLUSTER]'); + $request = (new DeleteClusterRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCluster($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.vmwareengine.v1.VmwareEngine/DeleteCluster', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteClusterTest'); + $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 deleteClusterExceptionTest() + { + $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/deleteClusterTest'); + $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->clusterName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]', '[CLUSTER]'); + $request = (new DeleteClusterRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteCluster($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteClusterTest'); + 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 deleteNetworkPolicyTest() + { + $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/deleteNetworkPolicyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteNetworkPolicyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->networkPolicyName('[PROJECT]', '[LOCATION]', '[NETWORK_POLICY]'); + $request = (new DeleteNetworkPolicyRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteNetworkPolicy($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.vmwareengine.v1.VmwareEngine/DeleteNetworkPolicy', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteNetworkPolicyTest'); + $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 deleteNetworkPolicyExceptionTest() + { + $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/deleteNetworkPolicyTest'); + $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->networkPolicyName('[PROJECT]', '[LOCATION]', '[NETWORK_POLICY]'); + $request = (new DeleteNetworkPolicyRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteNetworkPolicy($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteNetworkPolicyTest'); + 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 deletePrivateCloudTest() + { + $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/deletePrivateCloudTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $expectedResponse = new PrivateCloud(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deletePrivateCloudTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new DeletePrivateCloudRequest()) + ->setName($formattedName); + $response = $gapicClient->deletePrivateCloud($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.vmwareengine.v1.VmwareEngine/DeletePrivateCloud', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deletePrivateCloudTest'); + $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 deletePrivateCloudExceptionTest() + { + $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/deletePrivateCloudTest'); + $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->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new DeletePrivateCloudRequest()) + ->setName($formattedName); + $response = $gapicClient->deletePrivateCloud($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deletePrivateCloudTest'); + 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 deleteVmwareEngineNetworkTest() + { + $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/deleteVmwareEngineNetworkTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteVmwareEngineNetworkTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->vmwareEngineNetworkName('[PROJECT]', '[LOCATION]', '[VMWARE_ENGINE_NETWORK]'); + $request = (new DeleteVmwareEngineNetworkRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteVmwareEngineNetwork($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.vmwareengine.v1.VmwareEngine/DeleteVmwareEngineNetwork', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteVmwareEngineNetworkTest'); + $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 deleteVmwareEngineNetworkExceptionTest() + { + $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/deleteVmwareEngineNetworkTest'); + $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->vmwareEngineNetworkName('[PROJECT]', '[LOCATION]', '[VMWARE_ENGINE_NETWORK]'); + $request = (new DeleteVmwareEngineNetworkRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteVmwareEngineNetwork($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteVmwareEngineNetworkTest'); + 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 getClusterTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $management = false; + $uid = 'uid115792'; + $expectedResponse = new Cluster(); + $expectedResponse->setName($name2); + $expectedResponse->setManagement($management); + $expectedResponse->setUid($uid); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->clusterName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]', '[CLUSTER]'); + $request = (new GetClusterRequest()) + ->setName($formattedName); + $response = $gapicClient->getCluster($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.vmwareengine.v1.VmwareEngine/GetCluster', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getClusterExceptionTest() + { + $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->clusterName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]', '[CLUSTER]'); + $request = (new GetClusterRequest()) + ->setName($formattedName); + try { + $gapicClient->getCluster($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 getHcxActivationKeyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $activationKey = 'activationKey-1343958090'; + $uid = 'uid115792'; + $expectedResponse = new HcxActivationKey(); + $expectedResponse->setName($name2); + $expectedResponse->setActivationKey($activationKey); + $expectedResponse->setUid($uid); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->hcxActivationKeyName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]', '[HCX_ACTIVATION_KEY]'); + $request = (new GetHcxActivationKeyRequest()) + ->setName($formattedName); + $response = $gapicClient->getHcxActivationKey($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.vmwareengine.v1.VmwareEngine/GetHcxActivationKey', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getHcxActivationKeyExceptionTest() + { + $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->hcxActivationKeyName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]', '[HCX_ACTIVATION_KEY]'); + $request = (new GetHcxActivationKeyRequest()) + ->setName($formattedName); + try { + $gapicClient->getHcxActivationKey($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 getNetworkPolicyTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $edgeServicesCidr = 'edgeServicesCidr-792872013'; + $uid = 'uid115792'; + $vmwareEngineNetwork = 'vmwareEngineNetwork-90899684'; + $description = 'description-1724546052'; + $vmwareEngineNetworkCanonical = 'vmwareEngineNetworkCanonical779839377'; + $expectedResponse = new NetworkPolicy(); + $expectedResponse->setName($name2); + $expectedResponse->setEdgeServicesCidr($edgeServicesCidr); + $expectedResponse->setUid($uid); + $expectedResponse->setVmwareEngineNetwork($vmwareEngineNetwork); + $expectedResponse->setDescription($description); + $expectedResponse->setVmwareEngineNetworkCanonical($vmwareEngineNetworkCanonical); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->networkPolicyName('[PROJECT]', '[LOCATION]', '[NETWORK_POLICY]'); + $request = (new GetNetworkPolicyRequest()) + ->setName($formattedName); + $response = $gapicClient->getNetworkPolicy($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.vmwareengine.v1.VmwareEngine/GetNetworkPolicy', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNetworkPolicyExceptionTest() + { + $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->networkPolicyName('[PROJECT]', '[LOCATION]', '[NETWORK_POLICY]'); + $request = (new GetNetworkPolicyRequest()) + ->setName($formattedName); + try { + $gapicClient->getNetworkPolicy($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 getNodeTypeTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $nodeTypeId = 'nodeTypeId585437955'; + $displayName = 'displayName1615086568'; + $virtualCpuCount = 289038212; + $totalCoreCount = 282953654; + $memoryGb = 1726613721; + $diskSizeGb = 757478089; + $expectedResponse = new NodeType(); + $expectedResponse->setName($name2); + $expectedResponse->setNodeTypeId($nodeTypeId); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setVirtualCpuCount($virtualCpuCount); + $expectedResponse->setTotalCoreCount($totalCoreCount); + $expectedResponse->setMemoryGb($memoryGb); + $expectedResponse->setDiskSizeGb($diskSizeGb); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->nodeTypeName('[PROJECT]', '[LOCATION]', '[NODE_TYPE]'); + $request = (new GetNodeTypeRequest()) + ->setName($formattedName); + $response = $gapicClient->getNodeType($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.vmwareengine.v1.VmwareEngine/GetNodeType', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getNodeTypeExceptionTest() + { + $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->nodeTypeName('[PROJECT]', '[LOCATION]', '[NODE_TYPE]'); + $request = (new GetNodeTypeRequest()) + ->setName($formattedName); + try { + $gapicClient->getNodeType($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 getPrivateCloudTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $expectedResponse = new PrivateCloud(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new GetPrivateCloudRequest()) + ->setName($formattedName); + $response = $gapicClient->getPrivateCloud($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.vmwareengine.v1.VmwareEngine/GetPrivateCloud', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getPrivateCloudExceptionTest() + { + $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->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new GetPrivateCloudRequest()) + ->setName($formattedName); + try { + $gapicClient->getPrivateCloud($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 getVmwareEngineNetworkTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $etag = 'etag3123477'; + $expectedResponse = new VmwareEngineNetwork(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->vmwareEngineNetworkName('[PROJECT]', '[LOCATION]', '[VMWARE_ENGINE_NETWORK]'); + $request = (new GetVmwareEngineNetworkRequest()) + ->setName($formattedName); + $response = $gapicClient->getVmwareEngineNetwork($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.vmwareengine.v1.VmwareEngine/GetVmwareEngineNetwork', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getVmwareEngineNetworkExceptionTest() + { + $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->vmwareEngineNetworkName('[PROJECT]', '[LOCATION]', '[VMWARE_ENGINE_NETWORK]'); + $request = (new GetVmwareEngineNetworkRequest()) + ->setName($formattedName); + try { + $gapicClient->getVmwareEngineNetwork($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 listClustersTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $clustersElement = new Cluster(); + $clusters = [ + $clustersElement, + ]; + $expectedResponse = new ListClustersResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setClusters($clusters); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ListClustersRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listClusters($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getClusters()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmwareengine.v1.VmwareEngine/ListClusters', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listClustersExceptionTest() + { + $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->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ListClustersRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listClusters($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 listHcxActivationKeysTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $hcxActivationKeysElement = new HcxActivationKey(); + $hcxActivationKeys = [ + $hcxActivationKeysElement, + ]; + $expectedResponse = new ListHcxActivationKeysResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setHcxActivationKeys($hcxActivationKeys); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ListHcxActivationKeysRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listHcxActivationKeys($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getHcxActivationKeys()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmwareengine.v1.VmwareEngine/ListHcxActivationKeys', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listHcxActivationKeysExceptionTest() + { + $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->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ListHcxActivationKeysRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listHcxActivationKeys($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 listNetworkPoliciesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $networkPoliciesElement = new NetworkPolicy(); + $networkPolicies = [ + $networkPoliciesElement, + ]; + $expectedResponse = new ListNetworkPoliciesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setNetworkPolicies($networkPolicies); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNetworkPoliciesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listNetworkPolicies($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getNetworkPolicies()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmwareengine.v1.VmwareEngine/ListNetworkPolicies', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listNetworkPoliciesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNetworkPoliciesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listNetworkPolicies($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 listNodeTypesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $nodeTypesElement = new NodeType(); + $nodeTypes = [ + $nodeTypesElement, + ]; + $expectedResponse = new ListNodeTypesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setNodeTypes($nodeTypes); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNodeTypesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listNodeTypes($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getNodeTypes()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmwareengine.v1.VmwareEngine/ListNodeTypes', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listNodeTypesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListNodeTypesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listNodeTypes($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 listPrivateCloudsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $privateCloudsElement = new PrivateCloud(); + $privateClouds = [ + $privateCloudsElement, + ]; + $expectedResponse = new ListPrivateCloudsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setPrivateClouds($privateClouds); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListPrivateCloudsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listPrivateClouds($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getPrivateClouds()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmwareengine.v1.VmwareEngine/ListPrivateClouds', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listPrivateCloudsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListPrivateCloudsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listPrivateClouds($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 listSubnetsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $subnetsElement = new Subnet(); + $subnets = [ + $subnetsElement, + ]; + $expectedResponse = new ListSubnetsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setSubnets($subnets); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ListSubnetsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listSubnets($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getSubnets()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmwareengine.v1.VmwareEngine/ListSubnets', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listSubnetsExceptionTest() + { + $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->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ListSubnetsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listSubnets($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 listVmwareEngineNetworksTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $vmwareEngineNetworksElement = new VmwareEngineNetwork(); + $vmwareEngineNetworks = [ + $vmwareEngineNetworksElement, + ]; + $expectedResponse = new ListVmwareEngineNetworksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setVmwareEngineNetworks($vmwareEngineNetworks); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListVmwareEngineNetworksRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listVmwareEngineNetworks($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getVmwareEngineNetworks()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vmwareengine.v1.VmwareEngine/ListVmwareEngineNetworks', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listVmwareEngineNetworksExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListVmwareEngineNetworksRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listVmwareEngineNetworks($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 resetNsxCredentialsTest() + { + $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/resetNsxCredentialsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $expectedResponse = new PrivateCloud(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/resetNsxCredentialsTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedPrivateCloud = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ResetNsxCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + $response = $gapicClient->resetNsxCredentials($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.vmwareengine.v1.VmwareEngine/ResetNsxCredentials', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getPrivateCloud(); + $this->assertProtobufEquals($formattedPrivateCloud, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resetNsxCredentialsTest'); + $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 resetNsxCredentialsExceptionTest() + { + $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/resetNsxCredentialsTest'); + $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 + $formattedPrivateCloud = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ResetNsxCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + $response = $gapicClient->resetNsxCredentials($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resetNsxCredentialsTest'); + 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 resetVcenterCredentialsTest() + { + $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/resetVcenterCredentialsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $expectedResponse = new PrivateCloud(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/resetVcenterCredentialsTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedPrivateCloud = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ResetVcenterCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + $response = $gapicClient->resetVcenterCredentials($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.vmwareengine.v1.VmwareEngine/ResetVcenterCredentials', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getPrivateCloud(); + $this->assertProtobufEquals($formattedPrivateCloud, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resetVcenterCredentialsTest'); + $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 resetVcenterCredentialsExceptionTest() + { + $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/resetVcenterCredentialsTest'); + $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 + $formattedPrivateCloud = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ResetVcenterCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + $response = $gapicClient->resetVcenterCredentials($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/resetVcenterCredentialsTest'); + 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 showNsxCredentialsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $username = 'username-265713450'; + $password = 'password1216985755'; + $expectedResponse = new Credentials(); + $expectedResponse->setUsername($username); + $expectedResponse->setPassword($password); + $transport->addResponse($expectedResponse); + // Mock request + $formattedPrivateCloud = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ShowNsxCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + $response = $gapicClient->showNsxCredentials($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.vmwareengine.v1.VmwareEngine/ShowNsxCredentials', $actualFuncCall); + $actualValue = $actualRequestObject->getPrivateCloud(); + $this->assertProtobufEquals($formattedPrivateCloud, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function showNsxCredentialsExceptionTest() + { + $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 + $formattedPrivateCloud = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ShowNsxCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + try { + $gapicClient->showNsxCredentials($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 showVcenterCredentialsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $username = 'username-265713450'; + $password = 'password1216985755'; + $expectedResponse = new Credentials(); + $expectedResponse->setUsername($username); + $expectedResponse->setPassword($password); + $transport->addResponse($expectedResponse); + // Mock request + $formattedPrivateCloud = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ShowVcenterCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + $response = $gapicClient->showVcenterCredentials($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.vmwareengine.v1.VmwareEngine/ShowVcenterCredentials', $actualFuncCall); + $actualValue = $actualRequestObject->getPrivateCloud(); + $this->assertProtobufEquals($formattedPrivateCloud, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function showVcenterCredentialsExceptionTest() + { + $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 + $formattedPrivateCloud = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new ShowVcenterCredentialsRequest()) + ->setPrivateCloud($formattedPrivateCloud); + try { + $gapicClient->showVcenterCredentials($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 undeletePrivateCloudTest() + { + $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/undeletePrivateCloudTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $expectedResponse = new PrivateCloud(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/undeletePrivateCloudTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new UndeletePrivateCloudRequest()) + ->setName($formattedName); + $response = $gapicClient->undeletePrivateCloud($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.vmwareengine.v1.VmwareEngine/UndeletePrivateCloud', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/undeletePrivateCloudTest'); + $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 undeletePrivateCloudExceptionTest() + { + $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/undeletePrivateCloudTest'); + $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->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $request = (new UndeletePrivateCloudRequest()) + ->setName($formattedName); + $response = $gapicClient->undeletePrivateCloud($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/undeletePrivateCloudTest'); + 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 updateClusterTest() + { + $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/updateClusterTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $management = false; + $uid = 'uid115792'; + $expectedResponse = new Cluster(); + $expectedResponse->setName($name); + $expectedResponse->setManagement($management); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateClusterTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $updateMask = new FieldMask(); + $cluster = new Cluster(); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $clusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $cluster->setNodeTypeConfigs($clusterNodeTypeConfigs); + $request = (new UpdateClusterRequest()) + ->setUpdateMask($updateMask) + ->setCluster($cluster); + $response = $gapicClient->updateCluster($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.vmwareengine.v1.VmwareEngine/UpdateCluster', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $actualValue = $actualApiRequestObject->getCluster(); + $this->assertProtobufEquals($cluster, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateClusterTest'); + $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 updateClusterExceptionTest() + { + $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/updateClusterTest'); + $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 + $updateMask = new FieldMask(); + $cluster = new Cluster(); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $clusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $cluster->setNodeTypeConfigs($clusterNodeTypeConfigs); + $request = (new UpdateClusterRequest()) + ->setUpdateMask($updateMask) + ->setCluster($cluster); + $response = $gapicClient->updateCluster($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateClusterTest'); + 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 updateNetworkPolicyTest() + { + $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/updateNetworkPolicyTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $edgeServicesCidr = 'edgeServicesCidr-792872013'; + $uid = 'uid115792'; + $vmwareEngineNetwork = 'vmwareEngineNetwork-90899684'; + $description = 'description-1724546052'; + $vmwareEngineNetworkCanonical = 'vmwareEngineNetworkCanonical779839377'; + $expectedResponse = new NetworkPolicy(); + $expectedResponse->setName($name); + $expectedResponse->setEdgeServicesCidr($edgeServicesCidr); + $expectedResponse->setUid($uid); + $expectedResponse->setVmwareEngineNetwork($vmwareEngineNetwork); + $expectedResponse->setDescription($description); + $expectedResponse->setVmwareEngineNetworkCanonical($vmwareEngineNetworkCanonical); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateNetworkPolicyTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $networkPolicy = new NetworkPolicy(); + $networkPolicyEdgeServicesCidr = 'networkPolicyEdgeServicesCidr-602005393'; + $networkPolicy->setEdgeServicesCidr($networkPolicyEdgeServicesCidr); + $updateMask = new FieldMask(); + $request = (new UpdateNetworkPolicyRequest()) + ->setNetworkPolicy($networkPolicy) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateNetworkPolicy($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.vmwareengine.v1.VmwareEngine/UpdateNetworkPolicy', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getNetworkPolicy(); + $this->assertProtobufEquals($networkPolicy, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateNetworkPolicyTest'); + $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 updateNetworkPolicyExceptionTest() + { + $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/updateNetworkPolicyTest'); + $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 + $networkPolicy = new NetworkPolicy(); + $networkPolicyEdgeServicesCidr = 'networkPolicyEdgeServicesCidr-602005393'; + $networkPolicy->setEdgeServicesCidr($networkPolicyEdgeServicesCidr); + $updateMask = new FieldMask(); + $request = (new UpdateNetworkPolicyRequest()) + ->setNetworkPolicy($networkPolicy) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateNetworkPolicy($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateNetworkPolicyTest'); + 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 updatePrivateCloudTest() + { + $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/updatePrivateCloudTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $expectedResponse = new PrivateCloud(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updatePrivateCloudTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $privateCloud = new PrivateCloud(); + $privateCloudNetworkConfig = new NetworkConfig(); + $networkConfigManagementCidr = 'networkConfigManagementCidr2092091783'; + $privateCloudNetworkConfig->setManagementCidr($networkConfigManagementCidr); + $privateCloud->setNetworkConfig($privateCloudNetworkConfig); + $privateCloudManagementCluster = new ManagementCluster(); + $managementClusterClusterId = 'managementClusterClusterId311493182'; + $privateCloudManagementCluster->setClusterId($managementClusterClusterId); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $managementClusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $privateCloudManagementCluster->setNodeTypeConfigs($managementClusterNodeTypeConfigs); + $privateCloud->setManagementCluster($privateCloudManagementCluster); + $updateMask = new FieldMask(); + $request = (new UpdatePrivateCloudRequest()) + ->setPrivateCloud($privateCloud) + ->setUpdateMask($updateMask); + $response = $gapicClient->updatePrivateCloud($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.vmwareengine.v1.VmwareEngine/UpdatePrivateCloud', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getPrivateCloud(); + $this->assertProtobufEquals($privateCloud, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updatePrivateCloudTest'); + $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 updatePrivateCloudExceptionTest() + { + $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/updatePrivateCloudTest'); + $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 + $privateCloud = new PrivateCloud(); + $privateCloudNetworkConfig = new NetworkConfig(); + $networkConfigManagementCidr = 'networkConfigManagementCidr2092091783'; + $privateCloudNetworkConfig->setManagementCidr($networkConfigManagementCidr); + $privateCloud->setNetworkConfig($privateCloudNetworkConfig); + $privateCloudManagementCluster = new ManagementCluster(); + $managementClusterClusterId = 'managementClusterClusterId311493182'; + $privateCloudManagementCluster->setClusterId($managementClusterClusterId); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $managementClusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $privateCloudManagementCluster->setNodeTypeConfigs($managementClusterNodeTypeConfigs); + $privateCloud->setManagementCluster($privateCloudManagementCluster); + $updateMask = new FieldMask(); + $request = (new UpdatePrivateCloudRequest()) + ->setPrivateCloud($privateCloud) + ->setUpdateMask($updateMask); + $response = $gapicClient->updatePrivateCloud($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updatePrivateCloudTest'); + 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 updateVmwareEngineNetworkTest() + { + $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/updateVmwareEngineNetworkTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $etag = 'etag3123477'; + $expectedResponse = new VmwareEngineNetwork(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/updateVmwareEngineNetworkTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $vmwareEngineNetwork = new VmwareEngineNetwork(); + $vmwareEngineNetworkType = Type::TYPE_UNSPECIFIED; + $vmwareEngineNetwork->setType($vmwareEngineNetworkType); + $updateMask = new FieldMask(); + $request = (new UpdateVmwareEngineNetworkRequest()) + ->setVmwareEngineNetwork($vmwareEngineNetwork) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateVmwareEngineNetwork($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.vmwareengine.v1.VmwareEngine/UpdateVmwareEngineNetwork', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getVmwareEngineNetwork(); + $this->assertProtobufEquals($vmwareEngineNetwork, $actualValue); + $actualValue = $actualApiRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateVmwareEngineNetworkTest'); + $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 updateVmwareEngineNetworkExceptionTest() + { + $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/updateVmwareEngineNetworkTest'); + $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 + $vmwareEngineNetwork = new VmwareEngineNetwork(); + $vmwareEngineNetworkType = Type::TYPE_UNSPECIFIED; + $vmwareEngineNetwork->setType($vmwareEngineNetworkType); + $updateMask = new FieldMask(); + $request = (new UpdateVmwareEngineNetworkRequest()) + ->setVmwareEngineNetwork($vmwareEngineNetwork) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateVmwareEngineNetwork($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/updateVmwareEngineNetworkTest'); + 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 getLocationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $locationId = 'locationId552319461'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Location(); + $expectedResponse->setName($name2); + $expectedResponse->setLocationId($locationId); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + $request = new GetLocationRequest(); + $response = $gapicClient->getLocation($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.location.Locations/GetLocation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getLocationExceptionTest() + { + $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 GetLocationRequest(); + try { + $gapicClient->getLocation($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 listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $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 ListLocationsRequest(); + try { + $gapicClient->listLocations($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.iam.v1.IAMPolicy/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 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.iam.v1.IAMPolicy/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.iam.v1.IAMPolicy/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 createClusterAsyncTest() + { + $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/createClusterTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $management = false; + $uid = 'uid115792'; + $expectedResponse = new Cluster(); + $expectedResponse->setName($name); + $expectedResponse->setManagement($management); + $expectedResponse->setUid($uid); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createClusterTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->privateCloudName('[PROJECT]', '[LOCATION]', '[PRIVATE_CLOUD]'); + $clusterId = 'clusterId240280960'; + $cluster = new Cluster(); + $nodeTypeConfigsValue = new NodeTypeConfig(); + $valueNodeCount = 1174748740; + $nodeTypeConfigsValue->setNodeCount($valueNodeCount); + $clusterNodeTypeConfigs = [ + 'nodeTypeConfigsKey' => $nodeTypeConfigsValue, + ]; + $cluster->setNodeTypeConfigs($clusterNodeTypeConfigs); + $request = (new CreateClusterRequest()) + ->setParent($formattedParent) + ->setClusterId($clusterId) + ->setCluster($cluster); + $response = $gapicClient->createClusterAsync($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.vmwareengine.v1.VmwareEngine/CreateCluster', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getClusterId(); + $this->assertProtobufEquals($clusterId, $actualValue); + $actualValue = $actualApiRequestObject->getCluster(); + $this->assertProtobufEquals($cluster, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createClusterTest'); + $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()); + } +}