From 6baf62df5f16fb9dcbf5f69c17ccb3068fe9729f Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 10 Apr 2024 23:13:17 +0000 Subject: [PATCH 1/2] feat(longrunning): enable PHP GAPIC v2 surface generation PiperOrigin-RevId: 621298668 Source-Link: https://github.com/googleapis/googleapis/commit/1406704ced81daab07a859aa8a870ff39432d370 Source-Link: https://github.com/googleapis/googleapis-gen/commit/faf9f396092c902a9c898c8ce2ef356522852bc5 Copy-Tag: eyJwIjoiTG9uZ1J1bm5pbmcvLk93bEJvdC55YW1sIiwiaCI6ImZhZjlmMzk2MDkyYzkwMmE5Yzg5OGM4Y2UyZWYzNTY1MjI4NTJiYzUifQ== --- .../Google/Longrunning/Operations.php | Bin 0 -> 2587 bytes .../LongRunning/CancelOperationRequest.php | 80 ++++ .../LongRunning/DeleteOperationRequest.php | 80 ++++ .../LongRunning/GetOperationRequest.php | 80 ++++ .../LongRunning/ListOperationsRequest.php | 184 ++++++++ .../LongRunning/ListOperationsResponse.php | 101 ++++ .../src/Google/LongRunning/Operation.php | 270 +++++++++++ .../src/Google/LongRunning/OperationInfo.php | 145 ++++++ .../LongRunning/WaitOperationRequest.php | 119 +++++ .../LongRunning/Client/OperationsClient.php | 335 ++++++++++++++ .../Gapic/OperationsGapicClient.php | 436 ++++++++++++++++++ .../src/LongRunning/OperationsClient.php | 34 ++ .../src/LongRunning/gapic_metadata.json | 43 ++ .../resources/operations_client_config.json | 59 +++ .../operations_descriptor_config.php | 68 +++ .../operations_rest_client_config.php | 56 +++ .../Unit/Client/OperationsClientTest.php | 417 +++++++++++++++++ .../tests/Unit/OperationsClientTest.php | 366 +++++++++++++++ 18 files changed, 2873 insertions(+) create mode 100644 owl-bot-staging/LongRunning/proto/src/GPBMetadata/Google/Longrunning/Operations.php create mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/CancelOperationRequest.php create mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/DeleteOperationRequest.php create mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/GetOperationRequest.php create mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsRequest.php create mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsResponse.php create mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/Operation.php create mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/OperationInfo.php create mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/WaitOperationRequest.php create mode 100644 owl-bot-staging/LongRunning/src/LongRunning/Client/OperationsClient.php create mode 100644 owl-bot-staging/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php create mode 100644 owl-bot-staging/LongRunning/src/LongRunning/OperationsClient.php create mode 100644 owl-bot-staging/LongRunning/src/LongRunning/gapic_metadata.json create mode 100644 owl-bot-staging/LongRunning/src/LongRunning/resources/operations_client_config.json create mode 100644 owl-bot-staging/LongRunning/src/LongRunning/resources/operations_descriptor_config.php create mode 100644 owl-bot-staging/LongRunning/src/LongRunning/resources/operations_rest_client_config.php create mode 100644 owl-bot-staging/LongRunning/tests/Unit/Client/OperationsClientTest.php create mode 100644 owl-bot-staging/LongRunning/tests/Unit/OperationsClientTest.php diff --git a/owl-bot-staging/LongRunning/proto/src/GPBMetadata/Google/Longrunning/Operations.php b/owl-bot-staging/LongRunning/proto/src/GPBMetadata/Google/Longrunning/Operations.php new file mode 100644 index 0000000000000000000000000000000000000000..2ed35d91878de9e1a9f899893fad9fbb1a18793b GIT binary patch literal 2587 zcmbVO&u<$=6wani8oxG;Iy8xER2ZD7aZJ0bl$(P=PF&nbfmopuQngaFUXR@s>zVED zY}HU1Bu?Dn${qE>|IsVAp7|pWi(J_v3rt``-9{{$=nifGyl1l!Oi^ zecU_8{29SP$T)MEk9+Z8Ktk-YQQ-L`G%;?U;BQWz;79GFC!Yw{h{d5x8hFUq&?lD9 z=rD{a_2|%Ifeh*~8ks5{0Ch$r3LKZEt|UMdZy!-kLhAT-n?!Et1)POlVcKX63D0PgC$-%)tqkW4a4o^uXuJcmiFp{4 ze0GdO!sC$cE8H@`IQwPKpsE#kc8gLbSrGI#8k3qPA?7(A`W~VD@;(_AEqeYQUhOy$ z!F#xh${&pa{y(yw2Cn_BU?rZziE8tMFTAv=t$si2;a5W6wTyMygB|#D6}B!RY=jac zGpGK_X6on!p5-dalPRd&NiWn)2#Hw^Jx{MbDqi(d^3wYci}ys*lV0kCVc=R)dvQ8; z6+N3-!hR;@#I^c|0i|rz&<(gM2eoWqqgF!qU}cm}YI#wdTz`1mOkgC=q5@MWLwfZY zCFLu^W(94*5(z^Vmai%oq+J9!GilJ{1yqBTP`n31!KA!2KlI~;gB4g7ma)&PTkt`L z@C@uJc^;F9Ph+myHmo0e(Znn&+DTX?bQ6{bo-YPGt@Rd^0%u6hBJrB2VwVsCP)D47 zPpB%cRPDn?F?v!3+5?!pdLrl*LDyYfdrlo@Rsh5Y1bw`;p76lF5Ldk5l^3fQfEd(b-2d85n(Y;yM0H)*YYv-L|2=znngRJ1BTXN zRX6mEp9fk(;#f;4IaUQee7yva`A6tC18z>!igtDGJayAHX%&_FWlWPURX=^(x-J!d zKWYBYfBpUI;wDC`=(XNM@gPJ@qkCBSbz?GH(*12&&YSMHqmic zZVp}J>7nbhxUY?cpEYDt>yZ<4HY7BE7WDRW`Gej+hVgn4b<}=j9*h0xG+C|Q=tEm= hP3dWGSvB~xo$O!iezIxg7L&P4iLy+VhcS!+{sk<}UMBzm literal 0 HcmV?d00001 diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/CancelOperationRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/CancelOperationRequest.php new file mode 100644 index 000000000000..48df7dfedbb4 --- /dev/null +++ b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/CancelOperationRequest.php @@ -0,0 +1,80 @@ +google.longrunning.CancelOperationRequest + */ +class CancelOperationRequest extends \Google\Protobuf\Internal\Message +{ + /** + * The name of the operation resource to be cancelled. + * + * Generated from protobuf field string name = 1; + */ + protected $name = ''; + + /** + * @param string $name The name of the operation resource to be cancelled. + * + * @return \Google\LongRunning\CancelOperationRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The name of the operation resource to be cancelled. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Longrunning\Operations::initOnce(); + parent::__construct($data); + } + + /** + * The name of the operation resource to be cancelled. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The name of the operation resource to be cancelled. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/DeleteOperationRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/DeleteOperationRequest.php new file mode 100644 index 000000000000..7a5dcb344568 --- /dev/null +++ b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/DeleteOperationRequest.php @@ -0,0 +1,80 @@ +google.longrunning.DeleteOperationRequest + */ +class DeleteOperationRequest extends \Google\Protobuf\Internal\Message +{ + /** + * The name of the operation resource to be deleted. + * + * Generated from protobuf field string name = 1; + */ + protected $name = ''; + + /** + * @param string $name The name of the operation resource to be deleted. + * + * @return \Google\LongRunning\DeleteOperationRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The name of the operation resource to be deleted. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Longrunning\Operations::initOnce(); + parent::__construct($data); + } + + /** + * The name of the operation resource to be deleted. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The name of the operation resource to be deleted. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/GetOperationRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/GetOperationRequest.php new file mode 100644 index 000000000000..48e46b0c7f1b --- /dev/null +++ b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/GetOperationRequest.php @@ -0,0 +1,80 @@ +google.longrunning.GetOperationRequest + */ +class GetOperationRequest extends \Google\Protobuf\Internal\Message +{ + /** + * The name of the operation resource. + * + * Generated from protobuf field string name = 1; + */ + protected $name = ''; + + /** + * @param string $name The name of the operation resource. + * + * @return \Google\LongRunning\GetOperationRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The name of the operation resource. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Longrunning\Operations::initOnce(); + parent::__construct($data); + } + + /** + * The name of the operation resource. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The name of the operation resource. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsRequest.php new file mode 100644 index 000000000000..2306f381e884 --- /dev/null +++ b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsRequest.php @@ -0,0 +1,184 @@ +google.longrunning.ListOperationsRequest + */ +class ListOperationsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * The name of the operation's parent resource. + * + * Generated from protobuf field string name = 4; + */ + protected $name = ''; + /** + * The standard list filter. + * + * Generated from protobuf field string filter = 1; + */ + protected $filter = ''; + /** + * The standard list page size. + * + * Generated from protobuf field int32 page_size = 2; + */ + protected $page_size = 0; + /** + * The standard list page token. + * + * Generated from protobuf field string page_token = 3; + */ + protected $page_token = ''; + + /** + * @param string $name The name of the operation's parent resource. + * @param string $filter The standard list filter. + * + * @return \Google\LongRunning\ListOperationsRequest + * + * @experimental + */ + public static function build(string $name, string $filter): self + { + return (new self()) + ->setName($name) + ->setFilter($filter); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The name of the operation's parent resource. + * @type string $filter + * The standard list filter. + * @type int $page_size + * The standard list page size. + * @type string $page_token + * The standard list page token. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Longrunning\Operations::initOnce(); + parent::__construct($data); + } + + /** + * The name of the operation's parent resource. + * + * Generated from protobuf field string name = 4; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The name of the operation's parent resource. + * + * Generated from protobuf field string name = 4; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The standard list filter. + * + * Generated from protobuf field string filter = 1; + * @return string + */ + public function getFilter() + { + return $this->filter; + } + + /** + * The standard list filter. + * + * Generated from protobuf field string filter = 1; + * @param string $var + * @return $this + */ + public function setFilter($var) + { + GPBUtil::checkString($var, True); + $this->filter = $var; + + return $this; + } + + /** + * The standard list page size. + * + * Generated from protobuf field int32 page_size = 2; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * The standard list page size. + * + * Generated from protobuf field int32 page_size = 2; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + + /** + * The standard list page token. + * + * Generated from protobuf field string page_token = 3; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * The standard list page token. + * + * Generated from protobuf field string page_token = 3; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + +} + diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsResponse.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsResponse.php new file mode 100644 index 000000000000..9477276c23a6 --- /dev/null +++ b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsResponse.php @@ -0,0 +1,101 @@ +google.longrunning.ListOperationsResponse + */ +class ListOperationsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * A list of operations that matches the specified filter in the request. + * + * Generated from protobuf field repeated .google.longrunning.Operation operations = 1; + */ + private $operations; + /** + * The standard List next-page token. + * + * Generated from protobuf field string next_page_token = 2; + */ + protected $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\LongRunning\Operation>|\Google\Protobuf\Internal\RepeatedField $operations + * A list of operations that matches the specified filter in the request. + * @type string $next_page_token + * The standard List next-page token. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Longrunning\Operations::initOnce(); + parent::__construct($data); + } + + /** + * A list of operations that matches the specified filter in the request. + * + * Generated from protobuf field repeated .google.longrunning.Operation operations = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOperations() + { + return $this->operations; + } + + /** + * A list of operations that matches the specified filter in the request. + * + * Generated from protobuf field repeated .google.longrunning.Operation operations = 1; + * @param array<\Google\LongRunning\Operation>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOperations($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\LongRunning\Operation::class); + $this->operations = $arr; + + return $this; + } + + /** + * The standard List next-page token. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * The standard List next-page token. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/Operation.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/Operation.php new file mode 100644 index 000000000000..e2116cdba575 --- /dev/null +++ b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/Operation.php @@ -0,0 +1,270 @@ +google.longrunning.Operation + */ +class Operation extends \Google\Protobuf\Internal\Message +{ + /** + * The server-assigned name, which is only unique within the same service that + * originally returns it. If you use the default HTTP mapping, the + * `name` should be a resource name ending with `operations/{unique_id}`. + * + * Generated from protobuf field string name = 1; + */ + protected $name = ''; + /** + * Service-specific metadata associated with the operation. It typically + * contains progress information and common metadata such as create time. + * Some services might not provide such metadata. Any method that returns a + * long-running operation should document the metadata type, if any. + * + * Generated from protobuf field .google.protobuf.Any metadata = 2; + */ + protected $metadata = null; + /** + * If the value is `false`, it means the operation is still in progress. + * If `true`, the operation is completed, and either `error` or `response` is + * available. + * + * Generated from protobuf field bool done = 3; + */ + protected $done = false; + protected $result; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The server-assigned name, which is only unique within the same service that + * originally returns it. If you use the default HTTP mapping, the + * `name` should be a resource name ending with `operations/{unique_id}`. + * @type \Google\Protobuf\Any $metadata + * Service-specific metadata associated with the operation. It typically + * contains progress information and common metadata such as create time. + * Some services might not provide such metadata. Any method that returns a + * long-running operation should document the metadata type, if any. + * @type bool $done + * If the value is `false`, it means the operation is still in progress. + * If `true`, the operation is completed, and either `error` or `response` is + * available. + * @type \Google\Rpc\Status $error + * The error result of the operation in case of failure or cancellation. + * @type \Google\Protobuf\Any $response + * The normal response of the operation in case of success. If the original + * method returns no data on success, such as `Delete`, the response is + * `google.protobuf.Empty`. If the original method is standard + * `Get`/`Create`/`Update`, the response should be the resource. For other + * methods, the response should have the type `XxxResponse`, where `Xxx` + * is the original method name. For example, if the original method name + * is `TakeSnapshot()`, the inferred response type is + * `TakeSnapshotResponse`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Longrunning\Operations::initOnce(); + parent::__construct($data); + } + + /** + * The server-assigned name, which is only unique within the same service that + * originally returns it. If you use the default HTTP mapping, the + * `name` should be a resource name ending with `operations/{unique_id}`. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The server-assigned name, which is only unique within the same service that + * originally returns it. If you use the default HTTP mapping, the + * `name` should be a resource name ending with `operations/{unique_id}`. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Service-specific metadata associated with the operation. It typically + * contains progress information and common metadata such as create time. + * Some services might not provide such metadata. Any method that returns a + * long-running operation should document the metadata type, if any. + * + * Generated from protobuf field .google.protobuf.Any metadata = 2; + * @return \Google\Protobuf\Any|null + */ + public function getMetadata() + { + return $this->metadata; + } + + public function hasMetadata() + { + return isset($this->metadata); + } + + public function clearMetadata() + { + unset($this->metadata); + } + + /** + * Service-specific metadata associated with the operation. It typically + * contains progress information and common metadata such as create time. + * Some services might not provide such metadata. Any method that returns a + * long-running operation should document the metadata type, if any. + * + * Generated from protobuf field .google.protobuf.Any metadata = 2; + * @param \Google\Protobuf\Any $var + * @return $this + */ + public function setMetadata($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Any::class); + $this->metadata = $var; + + return $this; + } + + /** + * If the value is `false`, it means the operation is still in progress. + * If `true`, the operation is completed, and either `error` or `response` is + * available. + * + * Generated from protobuf field bool done = 3; + * @return bool + */ + public function getDone() + { + return $this->done; + } + + /** + * If the value is `false`, it means the operation is still in progress. + * If `true`, the operation is completed, and either `error` or `response` is + * available. + * + * Generated from protobuf field bool done = 3; + * @param bool $var + * @return $this + */ + public function setDone($var) + { + GPBUtil::checkBool($var); + $this->done = $var; + + return $this; + } + + /** + * The error result of the operation in case of failure or cancellation. + * + * Generated from protobuf field .google.rpc.Status error = 4; + * @return \Google\Rpc\Status|null + */ + public function getError() + { + return $this->readOneof(4); + } + + public function hasError() + { + return $this->hasOneof(4); + } + + /** + * The error result of the operation in case of failure or cancellation. + * + * Generated from protobuf field .google.rpc.Status error = 4; + * @param \Google\Rpc\Status $var + * @return $this + */ + public function setError($var) + { + GPBUtil::checkMessage($var, \Google\Rpc\Status::class); + $this->writeOneof(4, $var); + + return $this; + } + + /** + * The normal response of the operation in case of success. If the original + * method returns no data on success, such as `Delete`, the response is + * `google.protobuf.Empty`. If the original method is standard + * `Get`/`Create`/`Update`, the response should be the resource. For other + * methods, the response should have the type `XxxResponse`, where `Xxx` + * is the original method name. For example, if the original method name + * is `TakeSnapshot()`, the inferred response type is + * `TakeSnapshotResponse`. + * + * Generated from protobuf field .google.protobuf.Any response = 5; + * @return \Google\Protobuf\Any|null + */ + public function getResponse() + { + return $this->readOneof(5); + } + + public function hasResponse() + { + return $this->hasOneof(5); + } + + /** + * The normal response of the operation in case of success. If the original + * method returns no data on success, such as `Delete`, the response is + * `google.protobuf.Empty`. If the original method is standard + * `Get`/`Create`/`Update`, the response should be the resource. For other + * methods, the response should have the type `XxxResponse`, where `Xxx` + * is the original method name. For example, if the original method name + * is `TakeSnapshot()`, the inferred response type is + * `TakeSnapshotResponse`. + * + * Generated from protobuf field .google.protobuf.Any response = 5; + * @param \Google\Protobuf\Any $var + * @return $this + */ + public function setResponse($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Any::class); + $this->writeOneof(5, $var); + + return $this; + } + + /** + * @return string + */ + public function getResult() + { + return $this->whichOneof("result"); + } + +} + diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/OperationInfo.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/OperationInfo.php new file mode 100644 index 000000000000..dc3459b60e8a --- /dev/null +++ b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/OperationInfo.php @@ -0,0 +1,145 @@ +google.longrunning.OperationInfo + */ +class OperationInfo extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The message name of the primary return type for this + * long-running operation. + * This type will be used to deserialize the LRO's response. + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * Note: Altering this value constitutes a breaking change. + * + * Generated from protobuf field string response_type = 1; + */ + protected $response_type = ''; + /** + * Required. The message name of the metadata type for this long-running + * operation. + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * Note: Altering this value constitutes a breaking change. + * + * Generated from protobuf field string metadata_type = 2; + */ + protected $metadata_type = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $response_type + * Required. The message name of the primary return type for this + * long-running operation. + * This type will be used to deserialize the LRO's response. + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * Note: Altering this value constitutes a breaking change. + * @type string $metadata_type + * Required. The message name of the metadata type for this long-running + * operation. + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * Note: Altering this value constitutes a breaking change. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Longrunning\Operations::initOnce(); + parent::__construct($data); + } + + /** + * Required. The message name of the primary return type for this + * long-running operation. + * This type will be used to deserialize the LRO's response. + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * Note: Altering this value constitutes a breaking change. + * + * Generated from protobuf field string response_type = 1; + * @return string + */ + public function getResponseType() + { + return $this->response_type; + } + + /** + * Required. The message name of the primary return type for this + * long-running operation. + * This type will be used to deserialize the LRO's response. + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * Note: Altering this value constitutes a breaking change. + * + * Generated from protobuf field string response_type = 1; + * @param string $var + * @return $this + */ + public function setResponseType($var) + { + GPBUtil::checkString($var, True); + $this->response_type = $var; + + return $this; + } + + /** + * Required. The message name of the metadata type for this long-running + * operation. + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * Note: Altering this value constitutes a breaking change. + * + * Generated from protobuf field string metadata_type = 2; + * @return string + */ + public function getMetadataType() + { + return $this->metadata_type; + } + + /** + * Required. The message name of the metadata type for this long-running + * operation. + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * Note: Altering this value constitutes a breaking change. + * + * Generated from protobuf field string metadata_type = 2; + * @param string $var + * @return $this + */ + public function setMetadataType($var) + { + GPBUtil::checkString($var, True); + $this->metadata_type = $var; + + return $this; + } + +} + diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/WaitOperationRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/WaitOperationRequest.php new file mode 100644 index 000000000000..6c6e08fd9349 --- /dev/null +++ b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/WaitOperationRequest.php @@ -0,0 +1,119 @@ +google.longrunning.WaitOperationRequest + */ +class WaitOperationRequest extends \Google\Protobuf\Internal\Message +{ + /** + * The name of the operation resource to wait on. + * + * Generated from protobuf field string name = 1; + */ + protected $name = ''; + /** + * The maximum duration to wait before timing out. If left blank, the wait + * will be at most the time permitted by the underlying HTTP/RPC protocol. + * If RPC context deadline is also specified, the shorter one will be used. + * + * Generated from protobuf field .google.protobuf.Duration timeout = 2; + */ + protected $timeout = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The name of the operation resource to wait on. + * @type \Google\Protobuf\Duration $timeout + * The maximum duration to wait before timing out. If left blank, the wait + * will be at most the time permitted by the underlying HTTP/RPC protocol. + * If RPC context deadline is also specified, the shorter one will be used. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Longrunning\Operations::initOnce(); + parent::__construct($data); + } + + /** + * The name of the operation resource to wait on. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The name of the operation resource to wait on. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The maximum duration to wait before timing out. If left blank, the wait + * will be at most the time permitted by the underlying HTTP/RPC protocol. + * If RPC context deadline is also specified, the shorter one will be used. + * + * Generated from protobuf field .google.protobuf.Duration timeout = 2; + * @return \Google\Protobuf\Duration|null + */ + public function getTimeout() + { + return $this->timeout; + } + + public function hasTimeout() + { + return isset($this->timeout); + } + + public function clearTimeout() + { + unset($this->timeout); + } + + /** + * The maximum duration to wait before timing out. If left blank, the wait + * will be at most the time permitted by the underlying HTTP/RPC protocol. + * If RPC context deadline is also specified, the shorter one will be used. + * + * Generated from protobuf field .google.protobuf.Duration timeout = 2; + * @param \Google\Protobuf\Duration $var + * @return $this + */ + public function setTimeout($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Duration::class); + $this->timeout = $var; + + return $this; + } + +} + diff --git a/owl-bot-staging/LongRunning/src/LongRunning/Client/OperationsClient.php b/owl-bot-staging/LongRunning/src/LongRunning/Client/OperationsClient.php new file mode 100644 index 000000000000..b44b560ec4df --- /dev/null +++ b/owl-bot-staging/LongRunning/src/LongRunning/Client/OperationsClient.php @@ -0,0 +1,335 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../resources/operations_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../resources/operations_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/operations_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../resources/operations_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 'longrunning.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); + } + + /** + * Starts asynchronous cancellation on a long-running operation. The server + * makes a best effort to cancel the operation, but success is not + * guaranteed. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. Clients can use + * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or + * other methods to check whether the cancellation succeeded or whether the + * operation completed despite cancellation. On successful cancellation, + * the operation is not deleted; instead, it becomes an operation with + * an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, + * corresponding to `Code.CANCELLED`. + * + * The async variant is {@see OperationsClient::cancelOperationAsync()} . + * + * @example samples/OperationsClient/cancel_operation.php + * + * @param CancelOperationRequest $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 cancelOperation(CancelOperationRequest $request, array $callOptions = []): void + { + $this->startApiCall('CancelOperation', $request, $callOptions)->wait(); + } + + /** + * Deletes a long-running operation. This method indicates that the client is + * no longer interested in the operation result. It does not cancel the + * operation. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * + * The async variant is {@see OperationsClient::deleteOperationAsync()} . + * + * @example samples/OperationsClient/delete_operation.php + * + * @param DeleteOperationRequest $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 deleteOperation(DeleteOperationRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteOperation', $request, $callOptions)->wait(); + } + + /** + * Gets the latest state of a long-running operation. Clients can use this + * method to poll the operation result at intervals as recommended by the API + * service. + * + * The async variant is {@see OperationsClient::getOperationAsync()} . + * + * @example samples/OperationsClient/get_operation.php + * + * @param GetOperationRequest $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 Operation + * + * @throws ApiException Thrown if the API call fails. + */ + public function getOperation(GetOperationRequest $request, array $callOptions = []): Operation + { + return $this->startApiCall('GetOperation', $request, $callOptions)->wait(); + } + + /** + * Lists operations that match the specified filter in the request. If the + * server doesn't support this method, it returns `UNIMPLEMENTED`. + * + * NOTE: the `name` binding allows API services to override the binding + * to use different resource name schemes, such as `users/*/operations`. To + * override the binding, API services can add a binding such as + * `"/v1/{name=users/*}/operations"` to their service configuration. + * For backwards compatibility, the default name includes the operations + * collection id, however overriding users must ensure the name binding + * is the parent resource, without the operations collection id. + * + * The async variant is {@see OperationsClient::listOperationsAsync()} . + * + * @example samples/OperationsClient/list_operations.php + * + * @param ListOperationsRequest $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 listOperations(ListOperationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListOperations', $request, $callOptions); + } + + /** + * Waits until the specified long-running operation is done or reaches at most + * a specified timeout, returning the latest state. If the operation is + * already done, the latest state is immediately returned. If the timeout + * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + * timeout is used. If the server does not support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * Note that this method is on a best-effort basis. It may return the latest + * state before the specified timeout (including immediately), meaning even an + * immediate response is no guarantee that the operation is done. + * + * The async variant is {@see OperationsClient::waitOperationAsync()} . + * + * @example samples/OperationsClient/wait_operation.php + * + * @param WaitOperationRequest $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 Operation + * + * @throws ApiException Thrown if the API call fails. + */ + public function waitOperation(WaitOperationRequest $request, array $callOptions = []): Operation + { + return $this->startApiCall('WaitOperation', $request, $callOptions)->wait(); + } +} diff --git a/owl-bot-staging/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php b/owl-bot-staging/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php new file mode 100644 index 000000000000..ca0abb04d722 --- /dev/null +++ b/owl-bot-staging/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php @@ -0,0 +1,436 @@ +cancelOperation($name); + * } finally { + * $operationsClient->close(); + * } + * ``` + * + * @deprecated Please use the new service client {@see \Google\LongRunning\Client\OperationsClient}. + */ +class OperationsGapicClient +{ + use GapicClientTrait; + + /** The name of the service. */ + const SERVICE_NAME = 'google.longrunning.Operations'; + + /** + * The default address of the service. + * + * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. + */ + const SERVICE_ADDRESS = 'longrunning.googleapis.com'; + + /** The address template of the service. */ + private const SERVICE_ADDRESS_TEMPLATE = 'longrunning.UNIVERSE_DOMAIN'; + + /** The default port of the service. */ + const DEFAULT_SERVICE_PORT = 443; + + /** The name of the code generator, to be included in the agent header. */ + const CODEGEN_NAME = 'gapic'; + + /** The default scopes required by the service. */ + public static $serviceScopes = []; + + private static function getClientDefaults() + { + return [ + 'serviceName' => self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../resources/operations_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../resources/operations_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/operations_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../resources/operations_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 'longrunning.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); + } + + /** + * Starts asynchronous cancellation on a long-running operation. The server + * makes a best effort to cancel the operation, but success is not + * guaranteed. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. Clients can use + * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or + * other methods to check whether the cancellation succeeded or whether the + * operation completed despite cancellation. On successful cancellation, + * the operation is not deleted; instead, it becomes an operation with + * an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, + * corresponding to `Code.CANCELLED`. + * + * Sample code: + * ``` + * $operationsClient = new OperationsClient(); + * try { + * $name = 'name'; + * $operationsClient->cancelOperation($name); + * } finally { + * $operationsClient->close(); + * } + * ``` + * + * @param string $name The name of the operation resource to be cancelled. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException if the remote call fails + */ + public function cancelOperation($name, array $optionalArgs = []) + { + $request = new CancelOperationRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('CancelOperation', GPBEmpty::class, $optionalArgs, $request)->wait(); + } + + /** + * Deletes a long-running operation. This method indicates that the client is + * no longer interested in the operation result. It does not cancel the + * operation. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * + * Sample code: + * ``` + * $operationsClient = new OperationsClient(); + * try { + * $name = 'name'; + * $operationsClient->deleteOperation($name); + * } finally { + * $operationsClient->close(); + * } + * ``` + * + * @param string $name The name of the operation resource to be deleted. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException if the remote call fails + */ + public function deleteOperation($name, array $optionalArgs = []) + { + $request = new DeleteOperationRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('DeleteOperation', GPBEmpty::class, $optionalArgs, $request)->wait(); + } + + /** + * Gets the latest state of a long-running operation. Clients can use this + * method to poll the operation result at intervals as recommended by the API + * service. + * + * Sample code: + * ``` + * $operationsClient = new OperationsClient(); + * try { + * $name = 'name'; + * $response = $operationsClient->getOperation($name); + * } finally { + * $operationsClient->close(); + * } + * ``` + * + * @param string $name The name of the operation resource. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\LongRunning\Operation + * + * @throws ApiException if the remote call fails + */ + public function getOperation($name, array $optionalArgs = []) + { + $request = new GetOperationRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('GetOperation', Operation::class, $optionalArgs, $request)->wait(); + } + + /** + * Lists operations that match the specified filter in the request. If the + * server doesn't support this method, it returns `UNIMPLEMENTED`. + * + * NOTE: the `name` binding allows API services to override the binding + * to use different resource name schemes, such as `users/*/operations`. To + * override the binding, API services can add a binding such as + * `"/v1/{name=users/*}/operations"` to their service configuration. + * For backwards compatibility, the default name includes the operations + * collection id, however overriding users must ensure the name binding + * is the parent resource, without the operations collection id. + * + * Sample code: + * ``` + * $operationsClient = new OperationsClient(); + * try { + * $name = 'name'; + * $filter = 'filter'; + * // Iterate over pages of elements + * $pagedResponse = $operationsClient->listOperations($name, $filter); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * // Alternatively: + * // Iterate through all elements + * $pagedResponse = $operationsClient->listOperations($name, $filter); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $operationsClient->close(); + * } + * ``` + * + * @param string $name The name of the operation's parent resource. + * @param string $filter The standard list filter. + * @param array $optionalArgs { + * Optional. + * + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\ApiCore\PagedListResponse + * + * @throws ApiException if the remote call fails + */ + public function listOperations($name, $filter, array $optionalArgs = []) + { + $request = new ListOperationsRequest(); + $requestParamHeaders = []; + $request->setName($name); + $request->setFilter($filter); + $requestParamHeaders['name'] = $name; + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListOperations', $optionalArgs, ListOperationsResponse::class, $request); + } + + /** + * Waits until the specified long-running operation is done or reaches at most + * a specified timeout, returning the latest state. If the operation is + * already done, the latest state is immediately returned. If the timeout + * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + * timeout is used. If the server does not support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * Note that this method is on a best-effort basis. It may return the latest + * state before the specified timeout (including immediately), meaning even an + * immediate response is no guarantee that the operation is done. + * + * Sample code: + * ``` + * $operationsClient = new OperationsClient(); + * try { + * $response = $operationsClient->waitOperation(); + * } finally { + * $operationsClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * + * @type string $name + * The name of the operation resource to wait on. + * @type Duration $timeout + * The maximum duration to wait before timing out. If left blank, the wait + * will be at most the time permitted by the underlying HTTP/RPC protocol. + * If RPC context deadline is also specified, the shorter one will be used. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\LongRunning\Operation + * + * @throws ApiException if the remote call fails + */ + public function waitOperation(array $optionalArgs = []) + { + $request = new WaitOperationRequest(); + if (isset($optionalArgs['name'])) { + $request->setName($optionalArgs['name']); + } + + if (isset($optionalArgs['timeout'])) { + $request->setTimeout($optionalArgs['timeout']); + } + + return $this->startCall('WaitOperation', Operation::class, $optionalArgs, $request)->wait(); + } +} diff --git a/owl-bot-staging/LongRunning/src/LongRunning/OperationsClient.php b/owl-bot-staging/LongRunning/src/LongRunning/OperationsClient.php new file mode 100644 index 000000000000..c67e0a4721ef --- /dev/null +++ b/owl-bot-staging/LongRunning/src/LongRunning/OperationsClient.php @@ -0,0 +1,34 @@ + [ + 'google.longrunning.Operations' => [ + 'CancelOperation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteOperation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetOperation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\LongRunning\Operation', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'ListOperations' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getOperations', + ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\LongRunning\ListOperationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'WaitOperation' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\LongRunning\Operation', + ], + ], + ], +]; diff --git a/owl-bot-staging/LongRunning/src/LongRunning/resources/operations_rest_client_config.php b/owl-bot-staging/LongRunning/src/LongRunning/resources/operations_rest_client_config.php new file mode 100644 index 000000000000..fe4811c4f752 --- /dev/null +++ b/owl-bot-staging/LongRunning/src/LongRunning/resources/operations_rest_client_config.php @@ -0,0 +1,56 @@ + [ + 'google.longrunning.Operations' => [ + 'CancelOperation' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{name=operations/**}:cancel', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'DeleteOperation' => [ + 'method' => 'delete', + 'uriTemplate' => '/v1/{name=operations/**}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'GetOperation' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=operations/**}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'ListOperations' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=operations}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + 'queryParams' => [ + 'filter', + ], + ], + ], + ], +]; diff --git a/owl-bot-staging/LongRunning/tests/Unit/Client/OperationsClientTest.php b/owl-bot-staging/LongRunning/tests/Unit/Client/OperationsClientTest.php new file mode 100644 index 000000000000..9bfb9671abca --- /dev/null +++ b/owl-bot-staging/LongRunning/tests/Unit/Client/OperationsClientTest.php @@ -0,0 +1,417 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return \Google\LongRunning\Client\OperationsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new \Google\LongRunning\Client\OperationsClient($options); + } + + /** @test */ + public function cancelOperationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $request = (new CancelOperationRequest()) + ->setName($name); + $gapicClient->cancelOperation($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/CancelOperation', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function cancelOperationExceptionTest() + { + $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 + $name = 'name3373707'; + $request = (new CancelOperationRequest()) + ->setName($name); + try { + $gapicClient->cancelOperation($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 deleteOperationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $request = (new DeleteOperationRequest()) + ->setName($name); + $gapicClient->deleteOperation($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/DeleteOperation', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteOperationExceptionTest() + { + $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 + $name = 'name3373707'; + $request = (new DeleteOperationRequest()) + ->setName($name); + try { + $gapicClient->deleteOperation($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 getOperationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $done = true; + $expectedResponse = new Operation(); + $expectedResponse->setName($name2); + $expectedResponse->setDone($done); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $request = (new GetOperationRequest()) + ->setName($name); + $response = $gapicClient->getOperation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getOperationExceptionTest() + { + $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 + $name = 'name3373707'; + $request = (new GetOperationRequest()) + ->setName($name); + try { + $gapicClient->getOperation($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 listOperationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $operationsElement = new Operation(); + $operations = [ + $operationsElement, + ]; + $expectedResponse = new ListOperationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setOperations($operations); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $filter = 'filter-1274492040'; + $request = (new ListOperationsRequest()) + ->setName($name) + ->setFilter($filter); + $response = $gapicClient->listOperations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getOperations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/ListOperations', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $actualValue = $actualRequestObject->getFilter(); + $this->assertProtobufEquals($filter, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listOperationsExceptionTest() + { + $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 + $name = 'name3373707'; + $filter = 'filter-1274492040'; + $request = (new ListOperationsRequest()) + ->setName($name) + ->setFilter($filter); + try { + $gapicClient->listOperations($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 waitOperationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $done = true; + $expectedResponse = new Operation(); + $expectedResponse->setName($name2); + $expectedResponse->setDone($done); + $transport->addResponse($expectedResponse); + $request = new WaitOperationRequest(); + $response = $gapicClient->waitOperation($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/WaitOperation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function waitOperationExceptionTest() + { + $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 WaitOperationRequest(); + try { + $gapicClient->waitOperation($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 cancelOperationAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $request = (new CancelOperationRequest()) + ->setName($name); + $gapicClient->cancelOperationAsync($request)->wait(); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/CancelOperation', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/owl-bot-staging/LongRunning/tests/Unit/OperationsClientTest.php b/owl-bot-staging/LongRunning/tests/Unit/OperationsClientTest.php new file mode 100644 index 000000000000..03a917c357e7 --- /dev/null +++ b/owl-bot-staging/LongRunning/tests/Unit/OperationsClientTest.php @@ -0,0 +1,366 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return \Google\LongRunning\OperationsClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new \Google\LongRunning\OperationsClient($options); + } + + /** @test */ + public function cancelOperationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $gapicClient->cancelOperation($name); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/CancelOperation', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function cancelOperationExceptionTest() + { + $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 + $name = 'name3373707'; + try { + $gapicClient->cancelOperation($name); + // 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 deleteOperationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $gapicClient->deleteOperation($name); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/DeleteOperation', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteOperationExceptionTest() + { + $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 + $name = 'name3373707'; + try { + $gapicClient->deleteOperation($name); + // 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 getOperationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $done = true; + $expectedResponse = new Operation(); + $expectedResponse->setName($name2); + $expectedResponse->setDone($done); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $response = $gapicClient->getOperation($name); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getOperationExceptionTest() + { + $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 + $name = 'name3373707'; + try { + $gapicClient->getOperation($name); + // 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 listOperationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $operationsElement = new Operation(); + $operations = [ + $operationsElement, + ]; + $expectedResponse = new ListOperationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setOperations($operations); + $transport->addResponse($expectedResponse); + // Mock request + $name = 'name3373707'; + $filter = 'filter-1274492040'; + $response = $gapicClient->listOperations($name, $filter); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getOperations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/ListOperations', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($name, $actualValue); + $actualValue = $actualRequestObject->getFilter(); + $this->assertProtobufEquals($filter, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listOperationsExceptionTest() + { + $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 + $name = 'name3373707'; + $filter = 'filter-1274492040'; + try { + $gapicClient->listOperations($name, $filter); + // 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 waitOperationTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $done = true; + $expectedResponse = new Operation(); + $expectedResponse->setName($name2); + $expectedResponse->setDone($done); + $transport->addResponse($expectedResponse); + $response = $gapicClient->waitOperation(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/WaitOperation', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function waitOperationExceptionTest() + { + $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); + try { + $gapicClient->waitOperation(); + // 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()); + } +} From 990fc42cc73c618248c9609bd4c9061a2a69d5a4 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 10 Apr 2024 23:16:38 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../Google/Longrunning/Operations.php | Bin 2587 -> 0 bytes .../LongRunning/CancelOperationRequest.php | 80 ---- .../LongRunning/DeleteOperationRequest.php | 80 ---- .../LongRunning/GetOperationRequest.php | 80 ---- .../LongRunning/ListOperationsRequest.php | 184 -------- .../LongRunning/ListOperationsResponse.php | 101 ---- .../src/Google/LongRunning/Operation.php | 270 ----------- .../src/Google/LongRunning/OperationInfo.php | 145 ------ .../LongRunning/WaitOperationRequest.php | 119 ----- .../LongRunning/Client/OperationsClient.php | 335 -------------- .../Gapic/OperationsGapicClient.php | 436 ------------------ .../src/LongRunning/OperationsClient.php | 34 -- .../src/LongRunning/gapic_metadata.json | 43 -- .../resources/operations_client_config.json | 59 --- .../operations_descriptor_config.php | 68 --- .../operations_rest_client_config.php | 56 --- .../Unit/Client/OperationsClientTest.php | 417 ----------------- .../tests/Unit/OperationsClientTest.php | 366 --------------- 18 files changed, 2873 deletions(-) delete mode 100644 owl-bot-staging/LongRunning/proto/src/GPBMetadata/Google/Longrunning/Operations.php delete mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/CancelOperationRequest.php delete mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/DeleteOperationRequest.php delete mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/GetOperationRequest.php delete mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsRequest.php delete mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsResponse.php delete mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/Operation.php delete mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/OperationInfo.php delete mode 100644 owl-bot-staging/LongRunning/proto/src/Google/LongRunning/WaitOperationRequest.php delete mode 100644 owl-bot-staging/LongRunning/src/LongRunning/Client/OperationsClient.php delete mode 100644 owl-bot-staging/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php delete mode 100644 owl-bot-staging/LongRunning/src/LongRunning/OperationsClient.php delete mode 100644 owl-bot-staging/LongRunning/src/LongRunning/gapic_metadata.json delete mode 100644 owl-bot-staging/LongRunning/src/LongRunning/resources/operations_client_config.json delete mode 100644 owl-bot-staging/LongRunning/src/LongRunning/resources/operations_descriptor_config.php delete mode 100644 owl-bot-staging/LongRunning/src/LongRunning/resources/operations_rest_client_config.php delete mode 100644 owl-bot-staging/LongRunning/tests/Unit/Client/OperationsClientTest.php delete mode 100644 owl-bot-staging/LongRunning/tests/Unit/OperationsClientTest.php diff --git a/owl-bot-staging/LongRunning/proto/src/GPBMetadata/Google/Longrunning/Operations.php b/owl-bot-staging/LongRunning/proto/src/GPBMetadata/Google/Longrunning/Operations.php deleted file mode 100644 index 2ed35d91878de9e1a9f899893fad9fbb1a18793b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2587 zcmbVO&u<$=6wani8oxG;Iy8xER2ZD7aZJ0bl$(P=PF&nbfmopuQngaFUXR@s>zVED zY}HU1Bu?Dn${qE>|IsVAp7|pWi(J_v3rt``-9{{$=nifGyl1l!Oi^ zecU_8{29SP$T)MEk9+Z8Ktk-YQQ-L`G%;?U;BQWz;79GFC!Yw{h{d5x8hFUq&?lD9 z=rD{a_2|%Ifeh*~8ks5{0Ch$r3LKZEt|UMdZy!-kLhAT-n?!Et1)POlVcKX63D0PgC$-%)tqkW4a4o^uXuJcmiFp{4 ze0GdO!sC$cE8H@`IQwPKpsE#kc8gLbSrGI#8k3qPA?7(A`W~VD@;(_AEqeYQUhOy$ z!F#xh${&pa{y(yw2Cn_BU?rZziE8tMFTAv=t$si2;a5W6wTyMygB|#D6}B!RY=jac zGpGK_X6on!p5-dalPRd&NiWn)2#Hw^Jx{MbDqi(d^3wYci}ys*lV0kCVc=R)dvQ8; z6+N3-!hR;@#I^c|0i|rz&<(gM2eoWqqgF!qU}cm}YI#wdTz`1mOkgC=q5@MWLwfZY zCFLu^W(94*5(z^Vmai%oq+J9!GilJ{1yqBTP`n31!KA!2KlI~;gB4g7ma)&PTkt`L z@C@uJc^;F9Ph+myHmo0e(Znn&+DTX?bQ6{bo-YPGt@Rd^0%u6hBJrB2VwVsCP)D47 zPpB%cRPDn?F?v!3+5?!pdLrl*LDyYfdrlo@Rsh5Y1bw`;p76lF5Ldk5l^3fQfEd(b-2d85n(Y;yM0H)*YYv-L|2=znngRJ1BTXN zRX6mEp9fk(;#f;4IaUQee7yva`A6tC18z>!igtDGJayAHX%&_FWlWPURX=^(x-J!d zKWYBYfBpUI;wDC`=(XNM@gPJ@qkCBSbz?GH(*12&&YSMHqmic zZVp}J>7nbhxUY?cpEYDt>yZ<4HY7BE7WDRW`Gej+hVgn4b<}=j9*h0xG+C|Q=tEm= hP3dWGSvB~xo$O!iezIxg7L&P4iLy+VhcS!+{sk<}UMBzm diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/CancelOperationRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/CancelOperationRequest.php deleted file mode 100644 index 48df7dfedbb4..000000000000 --- a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/CancelOperationRequest.php +++ /dev/null @@ -1,80 +0,0 @@ -google.longrunning.CancelOperationRequest - */ -class CancelOperationRequest extends \Google\Protobuf\Internal\Message -{ - /** - * The name of the operation resource to be cancelled. - * - * Generated from protobuf field string name = 1; - */ - protected $name = ''; - - /** - * @param string $name The name of the operation resource to be cancelled. - * - * @return \Google\LongRunning\CancelOperationRequest - * - * @experimental - */ - public static function build(string $name): self - { - return (new self()) - ->setName($name); - } - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $name - * The name of the operation resource to be cancelled. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Longrunning\Operations::initOnce(); - parent::__construct($data); - } - - /** - * The name of the operation resource to be cancelled. - * - * Generated from protobuf field string name = 1; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * The name of the operation resource to be cancelled. - * - * Generated from protobuf field string name = 1; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - -} - diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/DeleteOperationRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/DeleteOperationRequest.php deleted file mode 100644 index 7a5dcb344568..000000000000 --- a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/DeleteOperationRequest.php +++ /dev/null @@ -1,80 +0,0 @@ -google.longrunning.DeleteOperationRequest - */ -class DeleteOperationRequest extends \Google\Protobuf\Internal\Message -{ - /** - * The name of the operation resource to be deleted. - * - * Generated from protobuf field string name = 1; - */ - protected $name = ''; - - /** - * @param string $name The name of the operation resource to be deleted. - * - * @return \Google\LongRunning\DeleteOperationRequest - * - * @experimental - */ - public static function build(string $name): self - { - return (new self()) - ->setName($name); - } - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $name - * The name of the operation resource to be deleted. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Longrunning\Operations::initOnce(); - parent::__construct($data); - } - - /** - * The name of the operation resource to be deleted. - * - * Generated from protobuf field string name = 1; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * The name of the operation resource to be deleted. - * - * Generated from protobuf field string name = 1; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - -} - diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/GetOperationRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/GetOperationRequest.php deleted file mode 100644 index 48e46b0c7f1b..000000000000 --- a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/GetOperationRequest.php +++ /dev/null @@ -1,80 +0,0 @@ -google.longrunning.GetOperationRequest - */ -class GetOperationRequest extends \Google\Protobuf\Internal\Message -{ - /** - * The name of the operation resource. - * - * Generated from protobuf field string name = 1; - */ - protected $name = ''; - - /** - * @param string $name The name of the operation resource. - * - * @return \Google\LongRunning\GetOperationRequest - * - * @experimental - */ - public static function build(string $name): self - { - return (new self()) - ->setName($name); - } - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $name - * The name of the operation resource. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Longrunning\Operations::initOnce(); - parent::__construct($data); - } - - /** - * The name of the operation resource. - * - * Generated from protobuf field string name = 1; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * The name of the operation resource. - * - * Generated from protobuf field string name = 1; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - -} - diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsRequest.php deleted file mode 100644 index 2306f381e884..000000000000 --- a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsRequest.php +++ /dev/null @@ -1,184 +0,0 @@ -google.longrunning.ListOperationsRequest - */ -class ListOperationsRequest extends \Google\Protobuf\Internal\Message -{ - /** - * The name of the operation's parent resource. - * - * Generated from protobuf field string name = 4; - */ - protected $name = ''; - /** - * The standard list filter. - * - * Generated from protobuf field string filter = 1; - */ - protected $filter = ''; - /** - * The standard list page size. - * - * Generated from protobuf field int32 page_size = 2; - */ - protected $page_size = 0; - /** - * The standard list page token. - * - * Generated from protobuf field string page_token = 3; - */ - protected $page_token = ''; - - /** - * @param string $name The name of the operation's parent resource. - * @param string $filter The standard list filter. - * - * @return \Google\LongRunning\ListOperationsRequest - * - * @experimental - */ - public static function build(string $name, string $filter): self - { - return (new self()) - ->setName($name) - ->setFilter($filter); - } - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $name - * The name of the operation's parent resource. - * @type string $filter - * The standard list filter. - * @type int $page_size - * The standard list page size. - * @type string $page_token - * The standard list page token. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Longrunning\Operations::initOnce(); - parent::__construct($data); - } - - /** - * The name of the operation's parent resource. - * - * Generated from protobuf field string name = 4; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * The name of the operation's parent resource. - * - * Generated from protobuf field string name = 4; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - - /** - * The standard list filter. - * - * Generated from protobuf field string filter = 1; - * @return string - */ - public function getFilter() - { - return $this->filter; - } - - /** - * The standard list filter. - * - * Generated from protobuf field string filter = 1; - * @param string $var - * @return $this - */ - public function setFilter($var) - { - GPBUtil::checkString($var, True); - $this->filter = $var; - - return $this; - } - - /** - * The standard list page size. - * - * Generated from protobuf field int32 page_size = 2; - * @return int - */ - public function getPageSize() - { - return $this->page_size; - } - - /** - * The standard list page size. - * - * Generated from protobuf field int32 page_size = 2; - * @param int $var - * @return $this - */ - public function setPageSize($var) - { - GPBUtil::checkInt32($var); - $this->page_size = $var; - - return $this; - } - - /** - * The standard list page token. - * - * Generated from protobuf field string page_token = 3; - * @return string - */ - public function getPageToken() - { - return $this->page_token; - } - - /** - * The standard list page token. - * - * Generated from protobuf field string page_token = 3; - * @param string $var - * @return $this - */ - public function setPageToken($var) - { - GPBUtil::checkString($var, True); - $this->page_token = $var; - - return $this; - } - -} - diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsResponse.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsResponse.php deleted file mode 100644 index 9477276c23a6..000000000000 --- a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/ListOperationsResponse.php +++ /dev/null @@ -1,101 +0,0 @@ -google.longrunning.ListOperationsResponse - */ -class ListOperationsResponse extends \Google\Protobuf\Internal\Message -{ - /** - * A list of operations that matches the specified filter in the request. - * - * Generated from protobuf field repeated .google.longrunning.Operation operations = 1; - */ - private $operations; - /** - * The standard List next-page token. - * - * Generated from protobuf field string next_page_token = 2; - */ - protected $next_page_token = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type array<\Google\LongRunning\Operation>|\Google\Protobuf\Internal\RepeatedField $operations - * A list of operations that matches the specified filter in the request. - * @type string $next_page_token - * The standard List next-page token. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Longrunning\Operations::initOnce(); - parent::__construct($data); - } - - /** - * A list of operations that matches the specified filter in the request. - * - * Generated from protobuf field repeated .google.longrunning.Operation operations = 1; - * @return \Google\Protobuf\Internal\RepeatedField - */ - public function getOperations() - { - return $this->operations; - } - - /** - * A list of operations that matches the specified filter in the request. - * - * Generated from protobuf field repeated .google.longrunning.Operation operations = 1; - * @param array<\Google\LongRunning\Operation>|\Google\Protobuf\Internal\RepeatedField $var - * @return $this - */ - public function setOperations($var) - { - $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\LongRunning\Operation::class); - $this->operations = $arr; - - return $this; - } - - /** - * The standard List next-page token. - * - * Generated from protobuf field string next_page_token = 2; - * @return string - */ - public function getNextPageToken() - { - return $this->next_page_token; - } - - /** - * The standard List next-page token. - * - * Generated from protobuf field string next_page_token = 2; - * @param string $var - * @return $this - */ - public function setNextPageToken($var) - { - GPBUtil::checkString($var, True); - $this->next_page_token = $var; - - return $this; - } - -} - diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/Operation.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/Operation.php deleted file mode 100644 index e2116cdba575..000000000000 --- a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/Operation.php +++ /dev/null @@ -1,270 +0,0 @@ -google.longrunning.Operation - */ -class Operation extends \Google\Protobuf\Internal\Message -{ - /** - * The server-assigned name, which is only unique within the same service that - * originally returns it. If you use the default HTTP mapping, the - * `name` should be a resource name ending with `operations/{unique_id}`. - * - * Generated from protobuf field string name = 1; - */ - protected $name = ''; - /** - * Service-specific metadata associated with the operation. It typically - * contains progress information and common metadata such as create time. - * Some services might not provide such metadata. Any method that returns a - * long-running operation should document the metadata type, if any. - * - * Generated from protobuf field .google.protobuf.Any metadata = 2; - */ - protected $metadata = null; - /** - * If the value is `false`, it means the operation is still in progress. - * If `true`, the operation is completed, and either `error` or `response` is - * available. - * - * Generated from protobuf field bool done = 3; - */ - protected $done = false; - protected $result; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $name - * The server-assigned name, which is only unique within the same service that - * originally returns it. If you use the default HTTP mapping, the - * `name` should be a resource name ending with `operations/{unique_id}`. - * @type \Google\Protobuf\Any $metadata - * Service-specific metadata associated with the operation. It typically - * contains progress information and common metadata such as create time. - * Some services might not provide such metadata. Any method that returns a - * long-running operation should document the metadata type, if any. - * @type bool $done - * If the value is `false`, it means the operation is still in progress. - * If `true`, the operation is completed, and either `error` or `response` is - * available. - * @type \Google\Rpc\Status $error - * The error result of the operation in case of failure or cancellation. - * @type \Google\Protobuf\Any $response - * The normal response of the operation in case of success. If the original - * method returns no data on success, such as `Delete`, the response is - * `google.protobuf.Empty`. If the original method is standard - * `Get`/`Create`/`Update`, the response should be the resource. For other - * methods, the response should have the type `XxxResponse`, where `Xxx` - * is the original method name. For example, if the original method name - * is `TakeSnapshot()`, the inferred response type is - * `TakeSnapshotResponse`. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Longrunning\Operations::initOnce(); - parent::__construct($data); - } - - /** - * The server-assigned name, which is only unique within the same service that - * originally returns it. If you use the default HTTP mapping, the - * `name` should be a resource name ending with `operations/{unique_id}`. - * - * Generated from protobuf field string name = 1; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * The server-assigned name, which is only unique within the same service that - * originally returns it. If you use the default HTTP mapping, the - * `name` should be a resource name ending with `operations/{unique_id}`. - * - * Generated from protobuf field string name = 1; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - - /** - * Service-specific metadata associated with the operation. It typically - * contains progress information and common metadata such as create time. - * Some services might not provide such metadata. Any method that returns a - * long-running operation should document the metadata type, if any. - * - * Generated from protobuf field .google.protobuf.Any metadata = 2; - * @return \Google\Protobuf\Any|null - */ - public function getMetadata() - { - return $this->metadata; - } - - public function hasMetadata() - { - return isset($this->metadata); - } - - public function clearMetadata() - { - unset($this->metadata); - } - - /** - * Service-specific metadata associated with the operation. It typically - * contains progress information and common metadata such as create time. - * Some services might not provide such metadata. Any method that returns a - * long-running operation should document the metadata type, if any. - * - * Generated from protobuf field .google.protobuf.Any metadata = 2; - * @param \Google\Protobuf\Any $var - * @return $this - */ - public function setMetadata($var) - { - GPBUtil::checkMessage($var, \Google\Protobuf\Any::class); - $this->metadata = $var; - - return $this; - } - - /** - * If the value is `false`, it means the operation is still in progress. - * If `true`, the operation is completed, and either `error` or `response` is - * available. - * - * Generated from protobuf field bool done = 3; - * @return bool - */ - public function getDone() - { - return $this->done; - } - - /** - * If the value is `false`, it means the operation is still in progress. - * If `true`, the operation is completed, and either `error` or `response` is - * available. - * - * Generated from protobuf field bool done = 3; - * @param bool $var - * @return $this - */ - public function setDone($var) - { - GPBUtil::checkBool($var); - $this->done = $var; - - return $this; - } - - /** - * The error result of the operation in case of failure or cancellation. - * - * Generated from protobuf field .google.rpc.Status error = 4; - * @return \Google\Rpc\Status|null - */ - public function getError() - { - return $this->readOneof(4); - } - - public function hasError() - { - return $this->hasOneof(4); - } - - /** - * The error result of the operation in case of failure or cancellation. - * - * Generated from protobuf field .google.rpc.Status error = 4; - * @param \Google\Rpc\Status $var - * @return $this - */ - public function setError($var) - { - GPBUtil::checkMessage($var, \Google\Rpc\Status::class); - $this->writeOneof(4, $var); - - return $this; - } - - /** - * The normal response of the operation in case of success. If the original - * method returns no data on success, such as `Delete`, the response is - * `google.protobuf.Empty`. If the original method is standard - * `Get`/`Create`/`Update`, the response should be the resource. For other - * methods, the response should have the type `XxxResponse`, where `Xxx` - * is the original method name. For example, if the original method name - * is `TakeSnapshot()`, the inferred response type is - * `TakeSnapshotResponse`. - * - * Generated from protobuf field .google.protobuf.Any response = 5; - * @return \Google\Protobuf\Any|null - */ - public function getResponse() - { - return $this->readOneof(5); - } - - public function hasResponse() - { - return $this->hasOneof(5); - } - - /** - * The normal response of the operation in case of success. If the original - * method returns no data on success, such as `Delete`, the response is - * `google.protobuf.Empty`. If the original method is standard - * `Get`/`Create`/`Update`, the response should be the resource. For other - * methods, the response should have the type `XxxResponse`, where `Xxx` - * is the original method name. For example, if the original method name - * is `TakeSnapshot()`, the inferred response type is - * `TakeSnapshotResponse`. - * - * Generated from protobuf field .google.protobuf.Any response = 5; - * @param \Google\Protobuf\Any $var - * @return $this - */ - public function setResponse($var) - { - GPBUtil::checkMessage($var, \Google\Protobuf\Any::class); - $this->writeOneof(5, $var); - - return $this; - } - - /** - * @return string - */ - public function getResult() - { - return $this->whichOneof("result"); - } - -} - diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/OperationInfo.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/OperationInfo.php deleted file mode 100644 index dc3459b60e8a..000000000000 --- a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/OperationInfo.php +++ /dev/null @@ -1,145 +0,0 @@ -google.longrunning.OperationInfo - */ -class OperationInfo extends \Google\Protobuf\Internal\Message -{ - /** - * Required. The message name of the primary return type for this - * long-running operation. - * This type will be used to deserialize the LRO's response. - * If the response is in a different package from the rpc, a fully-qualified - * message name must be used (e.g. `google.protobuf.Struct`). - * Note: Altering this value constitutes a breaking change. - * - * Generated from protobuf field string response_type = 1; - */ - protected $response_type = ''; - /** - * Required. The message name of the metadata type for this long-running - * operation. - * If the response is in a different package from the rpc, a fully-qualified - * message name must be used (e.g. `google.protobuf.Struct`). - * Note: Altering this value constitutes a breaking change. - * - * Generated from protobuf field string metadata_type = 2; - */ - protected $metadata_type = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $response_type - * Required. The message name of the primary return type for this - * long-running operation. - * This type will be used to deserialize the LRO's response. - * If the response is in a different package from the rpc, a fully-qualified - * message name must be used (e.g. `google.protobuf.Struct`). - * Note: Altering this value constitutes a breaking change. - * @type string $metadata_type - * Required. The message name of the metadata type for this long-running - * operation. - * If the response is in a different package from the rpc, a fully-qualified - * message name must be used (e.g. `google.protobuf.Struct`). - * Note: Altering this value constitutes a breaking change. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Longrunning\Operations::initOnce(); - parent::__construct($data); - } - - /** - * Required. The message name of the primary return type for this - * long-running operation. - * This type will be used to deserialize the LRO's response. - * If the response is in a different package from the rpc, a fully-qualified - * message name must be used (e.g. `google.protobuf.Struct`). - * Note: Altering this value constitutes a breaking change. - * - * Generated from protobuf field string response_type = 1; - * @return string - */ - public function getResponseType() - { - return $this->response_type; - } - - /** - * Required. The message name of the primary return type for this - * long-running operation. - * This type will be used to deserialize the LRO's response. - * If the response is in a different package from the rpc, a fully-qualified - * message name must be used (e.g. `google.protobuf.Struct`). - * Note: Altering this value constitutes a breaking change. - * - * Generated from protobuf field string response_type = 1; - * @param string $var - * @return $this - */ - public function setResponseType($var) - { - GPBUtil::checkString($var, True); - $this->response_type = $var; - - return $this; - } - - /** - * Required. The message name of the metadata type for this long-running - * operation. - * If the response is in a different package from the rpc, a fully-qualified - * message name must be used (e.g. `google.protobuf.Struct`). - * Note: Altering this value constitutes a breaking change. - * - * Generated from protobuf field string metadata_type = 2; - * @return string - */ - public function getMetadataType() - { - return $this->metadata_type; - } - - /** - * Required. The message name of the metadata type for this long-running - * operation. - * If the response is in a different package from the rpc, a fully-qualified - * message name must be used (e.g. `google.protobuf.Struct`). - * Note: Altering this value constitutes a breaking change. - * - * Generated from protobuf field string metadata_type = 2; - * @param string $var - * @return $this - */ - public function setMetadataType($var) - { - GPBUtil::checkString($var, True); - $this->metadata_type = $var; - - return $this; - } - -} - diff --git a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/WaitOperationRequest.php b/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/WaitOperationRequest.php deleted file mode 100644 index 6c6e08fd9349..000000000000 --- a/owl-bot-staging/LongRunning/proto/src/Google/LongRunning/WaitOperationRequest.php +++ /dev/null @@ -1,119 +0,0 @@ -google.longrunning.WaitOperationRequest - */ -class WaitOperationRequest extends \Google\Protobuf\Internal\Message -{ - /** - * The name of the operation resource to wait on. - * - * Generated from protobuf field string name = 1; - */ - protected $name = ''; - /** - * The maximum duration to wait before timing out. If left blank, the wait - * will be at most the time permitted by the underlying HTTP/RPC protocol. - * If RPC context deadline is also specified, the shorter one will be used. - * - * Generated from protobuf field .google.protobuf.Duration timeout = 2; - */ - protected $timeout = null; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $name - * The name of the operation resource to wait on. - * @type \Google\Protobuf\Duration $timeout - * The maximum duration to wait before timing out. If left blank, the wait - * will be at most the time permitted by the underlying HTTP/RPC protocol. - * If RPC context deadline is also specified, the shorter one will be used. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Google\Longrunning\Operations::initOnce(); - parent::__construct($data); - } - - /** - * The name of the operation resource to wait on. - * - * Generated from protobuf field string name = 1; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * The name of the operation resource to wait on. - * - * Generated from protobuf field string name = 1; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - - /** - * The maximum duration to wait before timing out. If left blank, the wait - * will be at most the time permitted by the underlying HTTP/RPC protocol. - * If RPC context deadline is also specified, the shorter one will be used. - * - * Generated from protobuf field .google.protobuf.Duration timeout = 2; - * @return \Google\Protobuf\Duration|null - */ - public function getTimeout() - { - return $this->timeout; - } - - public function hasTimeout() - { - return isset($this->timeout); - } - - public function clearTimeout() - { - unset($this->timeout); - } - - /** - * The maximum duration to wait before timing out. If left blank, the wait - * will be at most the time permitted by the underlying HTTP/RPC protocol. - * If RPC context deadline is also specified, the shorter one will be used. - * - * Generated from protobuf field .google.protobuf.Duration timeout = 2; - * @param \Google\Protobuf\Duration $var - * @return $this - */ - public function setTimeout($var) - { - GPBUtil::checkMessage($var, \Google\Protobuf\Duration::class); - $this->timeout = $var; - - return $this; - } - -} - diff --git a/owl-bot-staging/LongRunning/src/LongRunning/Client/OperationsClient.php b/owl-bot-staging/LongRunning/src/LongRunning/Client/OperationsClient.php deleted file mode 100644 index b44b560ec4df..000000000000 --- a/owl-bot-staging/LongRunning/src/LongRunning/Client/OperationsClient.php +++ /dev/null @@ -1,335 +0,0 @@ - self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__ . '/../resources/operations_client_config.json', - 'descriptorsConfigPath' => __DIR__ . '/../resources/operations_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__ . '/../resources/operations_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => __DIR__ . '/../resources/operations_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 'longrunning.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); - } - - /** - * Starts asynchronous cancellation on a long-running operation. The server - * makes a best effort to cancel the operation, but success is not - * guaranteed. If the server doesn't support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. Clients can use - * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or - * other methods to check whether the cancellation succeeded or whether the - * operation completed despite cancellation. On successful cancellation, - * the operation is not deleted; instead, it becomes an operation with - * an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, - * corresponding to `Code.CANCELLED`. - * - * The async variant is {@see OperationsClient::cancelOperationAsync()} . - * - * @example samples/OperationsClient/cancel_operation.php - * - * @param CancelOperationRequest $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 cancelOperation(CancelOperationRequest $request, array $callOptions = []): void - { - $this->startApiCall('CancelOperation', $request, $callOptions)->wait(); - } - - /** - * Deletes a long-running operation. This method indicates that the client is - * no longer interested in the operation result. It does not cancel the - * operation. If the server doesn't support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. - * - * The async variant is {@see OperationsClient::deleteOperationAsync()} . - * - * @example samples/OperationsClient/delete_operation.php - * - * @param DeleteOperationRequest $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 deleteOperation(DeleteOperationRequest $request, array $callOptions = []): void - { - $this->startApiCall('DeleteOperation', $request, $callOptions)->wait(); - } - - /** - * Gets the latest state of a long-running operation. Clients can use this - * method to poll the operation result at intervals as recommended by the API - * service. - * - * The async variant is {@see OperationsClient::getOperationAsync()} . - * - * @example samples/OperationsClient/get_operation.php - * - * @param GetOperationRequest $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 Operation - * - * @throws ApiException Thrown if the API call fails. - */ - public function getOperation(GetOperationRequest $request, array $callOptions = []): Operation - { - return $this->startApiCall('GetOperation', $request, $callOptions)->wait(); - } - - /** - * Lists operations that match the specified filter in the request. If the - * server doesn't support this method, it returns `UNIMPLEMENTED`. - * - * NOTE: the `name` binding allows API services to override the binding - * to use different resource name schemes, such as `users/*/operations`. To - * override the binding, API services can add a binding such as - * `"/v1/{name=users/*}/operations"` to their service configuration. - * For backwards compatibility, the default name includes the operations - * collection id, however overriding users must ensure the name binding - * is the parent resource, without the operations collection id. - * - * The async variant is {@see OperationsClient::listOperationsAsync()} . - * - * @example samples/OperationsClient/list_operations.php - * - * @param ListOperationsRequest $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 listOperations(ListOperationsRequest $request, array $callOptions = []): PagedListResponse - { - return $this->startApiCall('ListOperations', $request, $callOptions); - } - - /** - * Waits until the specified long-running operation is done or reaches at most - * a specified timeout, returning the latest state. If the operation is - * already done, the latest state is immediately returned. If the timeout - * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC - * timeout is used. If the server does not support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. - * Note that this method is on a best-effort basis. It may return the latest - * state before the specified timeout (including immediately), meaning even an - * immediate response is no guarantee that the operation is done. - * - * The async variant is {@see OperationsClient::waitOperationAsync()} . - * - * @example samples/OperationsClient/wait_operation.php - * - * @param WaitOperationRequest $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 Operation - * - * @throws ApiException Thrown if the API call fails. - */ - public function waitOperation(WaitOperationRequest $request, array $callOptions = []): Operation - { - return $this->startApiCall('WaitOperation', $request, $callOptions)->wait(); - } -} diff --git a/owl-bot-staging/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php b/owl-bot-staging/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php deleted file mode 100644 index ca0abb04d722..000000000000 --- a/owl-bot-staging/LongRunning/src/LongRunning/Gapic/OperationsGapicClient.php +++ /dev/null @@ -1,436 +0,0 @@ -cancelOperation($name); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @deprecated Please use the new service client {@see \Google\LongRunning\Client\OperationsClient}. - */ -class OperationsGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.longrunning.Operations'; - - /** - * The default address of the service. - * - * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. - */ - const SERVICE_ADDRESS = 'longrunning.googleapis.com'; - - /** The address template of the service. */ - private const SERVICE_ADDRESS_TEMPLATE = 'longrunning.UNIVERSE_DOMAIN'; - - /** The default port of the service. */ - const DEFAULT_SERVICE_PORT = 443; - - /** The name of the code generator, to be included in the agent header. */ - const CODEGEN_NAME = 'gapic'; - - /** The default scopes required by the service. */ - public static $serviceScopes = []; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__ . '/../resources/operations_client_config.json', - 'descriptorsConfigPath' => __DIR__ . '/../resources/operations_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__ . '/../resources/operations_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => __DIR__ . '/../resources/operations_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 'longrunning.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); - } - - /** - * Starts asynchronous cancellation on a long-running operation. The server - * makes a best effort to cancel the operation, but success is not - * guaranteed. If the server doesn't support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. Clients can use - * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or - * other methods to check whether the cancellation succeeded or whether the - * operation completed despite cancellation. On successful cancellation, - * the operation is not deleted; instead, it becomes an operation with - * an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, - * corresponding to `Code.CANCELLED`. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $name = 'name'; - * $operationsClient->cancelOperation($name); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param string $name The name of the operation resource to be cancelled. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - */ - public function cancelOperation($name, array $optionalArgs = []) - { - $request = new CancelOperationRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('CancelOperation', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Deletes a long-running operation. This method indicates that the client is - * no longer interested in the operation result. It does not cancel the - * operation. If the server doesn't support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $name = 'name'; - * $operationsClient->deleteOperation($name); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param string $name The name of the operation resource to be deleted. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - */ - public function deleteOperation($name, array $optionalArgs = []) - { - $request = new DeleteOperationRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('DeleteOperation', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets the latest state of a long-running operation. Clients can use this - * method to poll the operation result at intervals as recommended by the API - * service. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $name = 'name'; - * $response = $operationsClient->getOperation($name); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param string $name The name of the operation resource. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\LongRunning\Operation - * - * @throws ApiException if the remote call fails - */ - public function getOperation($name, array $optionalArgs = []) - { - $request = new GetOperationRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetOperation', Operation::class, $optionalArgs, $request)->wait(); - } - - /** - * Lists operations that match the specified filter in the request. If the - * server doesn't support this method, it returns `UNIMPLEMENTED`. - * - * NOTE: the `name` binding allows API services to override the binding - * to use different resource name schemes, such as `users/*/operations`. To - * override the binding, API services can add a binding such as - * `"/v1/{name=users/*}/operations"` to their service configuration. - * For backwards compatibility, the default name includes the operations - * collection id, however overriding users must ensure the name binding - * is the parent resource, without the operations collection id. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $name = 'name'; - * $filter = 'filter'; - * // Iterate over pages of elements - * $pagedResponse = $operationsClient->listOperations($name, $filter); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $operationsClient->listOperations($name, $filter); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param string $name The name of the operation's parent resource. - * @param string $filter The standard list filter. - * @param array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listOperations($name, $filter, array $optionalArgs = []) - { - $request = new ListOperationsRequest(); - $requestParamHeaders = []; - $request->setName($name); - $request->setFilter($filter); - $requestParamHeaders['name'] = $name; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListOperations', $optionalArgs, ListOperationsResponse::class, $request); - } - - /** - * Waits until the specified long-running operation is done or reaches at most - * a specified timeout, returning the latest state. If the operation is - * already done, the latest state is immediately returned. If the timeout - * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC - * timeout is used. If the server does not support this method, it returns - * `google.rpc.Code.UNIMPLEMENTED`. - * Note that this method is on a best-effort basis. It may return the latest - * state before the specified timeout (including immediately), meaning even an - * immediate response is no guarantee that the operation is done. - * - * Sample code: - * ``` - * $operationsClient = new OperationsClient(); - * try { - * $response = $operationsClient->waitOperation(); - * } finally { - * $operationsClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * - * @type string $name - * The name of the operation resource to wait on. - * @type Duration $timeout - * The maximum duration to wait before timing out. If left blank, the wait - * will be at most the time permitted by the underlying HTTP/RPC protocol. - * If RPC context deadline is also specified, the shorter one will be used. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\LongRunning\Operation - * - * @throws ApiException if the remote call fails - */ - public function waitOperation(array $optionalArgs = []) - { - $request = new WaitOperationRequest(); - if (isset($optionalArgs['name'])) { - $request->setName($optionalArgs['name']); - } - - if (isset($optionalArgs['timeout'])) { - $request->setTimeout($optionalArgs['timeout']); - } - - return $this->startCall('WaitOperation', Operation::class, $optionalArgs, $request)->wait(); - } -} diff --git a/owl-bot-staging/LongRunning/src/LongRunning/OperationsClient.php b/owl-bot-staging/LongRunning/src/LongRunning/OperationsClient.php deleted file mode 100644 index c67e0a4721ef..000000000000 --- a/owl-bot-staging/LongRunning/src/LongRunning/OperationsClient.php +++ /dev/null @@ -1,34 +0,0 @@ - [ - 'google.longrunning.Operations' => [ - 'CancelOperation' => [ - 'callType' => \Google\ApiCore\Call::UNARY_CALL, - 'responseType' => 'Google\Protobuf\GPBEmpty', - 'headerParams' => [ - [ - 'keyName' => 'name', - 'fieldAccessors' => [ - 'getName', - ], - ], - ], - ], - 'DeleteOperation' => [ - 'callType' => \Google\ApiCore\Call::UNARY_CALL, - 'responseType' => 'Google\Protobuf\GPBEmpty', - 'headerParams' => [ - [ - 'keyName' => 'name', - 'fieldAccessors' => [ - 'getName', - ], - ], - ], - ], - 'GetOperation' => [ - 'callType' => \Google\ApiCore\Call::UNARY_CALL, - 'responseType' => 'Google\LongRunning\Operation', - 'headerParams' => [ - [ - 'keyName' => 'name', - 'fieldAccessors' => [ - 'getName', - ], - ], - ], - ], - 'ListOperations' => [ - 'pageStreaming' => [ - 'requestPageTokenGetMethod' => 'getPageToken', - 'requestPageTokenSetMethod' => 'setPageToken', - 'requestPageSizeGetMethod' => 'getPageSize', - 'requestPageSizeSetMethod' => 'setPageSize', - 'responsePageTokenGetMethod' => 'getNextPageToken', - 'resourcesGetMethod' => 'getOperations', - ], - 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, - 'responseType' => 'Google\LongRunning\ListOperationsResponse', - 'headerParams' => [ - [ - 'keyName' => 'name', - 'fieldAccessors' => [ - 'getName', - ], - ], - ], - ], - 'WaitOperation' => [ - 'callType' => \Google\ApiCore\Call::UNARY_CALL, - 'responseType' => 'Google\LongRunning\Operation', - ], - ], - ], -]; diff --git a/owl-bot-staging/LongRunning/src/LongRunning/resources/operations_rest_client_config.php b/owl-bot-staging/LongRunning/src/LongRunning/resources/operations_rest_client_config.php deleted file mode 100644 index fe4811c4f752..000000000000 --- a/owl-bot-staging/LongRunning/src/LongRunning/resources/operations_rest_client_config.php +++ /dev/null @@ -1,56 +0,0 @@ - [ - 'google.longrunning.Operations' => [ - 'CancelOperation' => [ - 'method' => 'post', - 'uriTemplate' => '/v1/{name=operations/**}:cancel', - 'body' => '*', - 'placeholders' => [ - 'name' => [ - 'getters' => [ - 'getName', - ], - ], - ], - ], - 'DeleteOperation' => [ - 'method' => 'delete', - 'uriTemplate' => '/v1/{name=operations/**}', - 'placeholders' => [ - 'name' => [ - 'getters' => [ - 'getName', - ], - ], - ], - ], - 'GetOperation' => [ - 'method' => 'get', - 'uriTemplate' => '/v1/{name=operations/**}', - 'placeholders' => [ - 'name' => [ - 'getters' => [ - 'getName', - ], - ], - ], - ], - 'ListOperations' => [ - 'method' => 'get', - 'uriTemplate' => '/v1/{name=operations}', - 'placeholders' => [ - 'name' => [ - 'getters' => [ - 'getName', - ], - ], - ], - 'queryParams' => [ - 'filter', - ], - ], - ], - ], -]; diff --git a/owl-bot-staging/LongRunning/tests/Unit/Client/OperationsClientTest.php b/owl-bot-staging/LongRunning/tests/Unit/Client/OperationsClientTest.php deleted file mode 100644 index 9bfb9671abca..000000000000 --- a/owl-bot-staging/LongRunning/tests/Unit/Client/OperationsClientTest.php +++ /dev/null @@ -1,417 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return \Google\LongRunning\Client\OperationsClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new \Google\LongRunning\Client\OperationsClient($options); - } - - /** @test */ - public function cancelOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $request = (new CancelOperationRequest()) - ->setName($name); - $gapicClient->cancelOperation($request); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/CancelOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function cancelOperationExceptionTest() - { - $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 - $name = 'name3373707'; - $request = (new CancelOperationRequest()) - ->setName($name); - try { - $gapicClient->cancelOperation($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 deleteOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $request = (new DeleteOperationRequest()) - ->setName($name); - $gapicClient->deleteOperation($request); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/DeleteOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteOperationExceptionTest() - { - $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 - $name = 'name3373707'; - $request = (new DeleteOperationRequest()) - ->setName($name); - try { - $gapicClient->deleteOperation($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 getOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $done = true; - $expectedResponse = new Operation(); - $expectedResponse->setName($name2); - $expectedResponse->setDone($done); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $request = (new GetOperationRequest()) - ->setName($name); - $response = $gapicClient->getOperation($request); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getOperationExceptionTest() - { - $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 - $name = 'name3373707'; - $request = (new GetOperationRequest()) - ->setName($name); - try { - $gapicClient->getOperation($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 listOperationsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $operationsElement = new Operation(); - $operations = [ - $operationsElement, - ]; - $expectedResponse = new ListOperationsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setOperations($operations); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $filter = 'filter-1274492040'; - $request = (new ListOperationsRequest()) - ->setName($name) - ->setFilter($filter); - $response = $gapicClient->listOperations($request); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getOperations()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/ListOperations', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $actualValue = $actualRequestObject->getFilter(); - $this->assertProtobufEquals($filter, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listOperationsExceptionTest() - { - $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 - $name = 'name3373707'; - $filter = 'filter-1274492040'; - $request = (new ListOperationsRequest()) - ->setName($name) - ->setFilter($filter); - try { - $gapicClient->listOperations($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 waitOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $done = true; - $expectedResponse = new Operation(); - $expectedResponse->setName($name2); - $expectedResponse->setDone($done); - $transport->addResponse($expectedResponse); - $request = new WaitOperationRequest(); - $response = $gapicClient->waitOperation($request); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/WaitOperation', $actualFuncCall); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function waitOperationExceptionTest() - { - $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 WaitOperationRequest(); - try { - $gapicClient->waitOperation($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 cancelOperationAsyncTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $request = (new CancelOperationRequest()) - ->setName($name); - $gapicClient->cancelOperationAsync($request)->wait(); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/CancelOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } -} diff --git a/owl-bot-staging/LongRunning/tests/Unit/OperationsClientTest.php b/owl-bot-staging/LongRunning/tests/Unit/OperationsClientTest.php deleted file mode 100644 index 03a917c357e7..000000000000 --- a/owl-bot-staging/LongRunning/tests/Unit/OperationsClientTest.php +++ /dev/null @@ -1,366 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return \Google\LongRunning\OperationsClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new \Google\LongRunning\OperationsClient($options); - } - - /** @test */ - public function cancelOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $gapicClient->cancelOperation($name); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/CancelOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function cancelOperationExceptionTest() - { - $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 - $name = 'name3373707'; - try { - $gapicClient->cancelOperation($name); - // 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 deleteOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $gapicClient->deleteOperation($name); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/DeleteOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteOperationExceptionTest() - { - $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 - $name = 'name3373707'; - try { - $gapicClient->deleteOperation($name); - // 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 getOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $done = true; - $expectedResponse = new Operation(); - $expectedResponse->setName($name2); - $expectedResponse->setDone($done); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $response = $gapicClient->getOperation($name); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getOperationExceptionTest() - { - $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 - $name = 'name3373707'; - try { - $gapicClient->getOperation($name); - // 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 listOperationsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $operationsElement = new Operation(); - $operations = [ - $operationsElement, - ]; - $expectedResponse = new ListOperationsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setOperations($operations); - $transport->addResponse($expectedResponse); - // Mock request - $name = 'name3373707'; - $filter = 'filter-1274492040'; - $response = $gapicClient->listOperations($name, $filter); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getOperations()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/ListOperations', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $actualValue = $actualRequestObject->getFilter(); - $this->assertProtobufEquals($filter, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listOperationsExceptionTest() - { - $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 - $name = 'name3373707'; - $filter = 'filter-1274492040'; - try { - $gapicClient->listOperations($name, $filter); - // 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 waitOperationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $done = true; - $expectedResponse = new Operation(); - $expectedResponse->setName($name2); - $expectedResponse->setDone($done); - $transport->addResponse($expectedResponse); - $response = $gapicClient->waitOperation(); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/WaitOperation', $actualFuncCall); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function waitOperationExceptionTest() - { - $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); - try { - $gapicClient->waitOperation(); - // 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()); - } -}