Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
71f53fc
feat(Gax)!: refactor OperationResponse with OperationsClientInterface…
bshaffer Sep 30, 2026
938d16c
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Oct 1, 2026
604f5ae
fix(Gax,Spanner): fix php-cs-fixer imports, DocFX @see FQCNs, and Spa…
bshaffer Oct 1, 2026
fd2dfb9
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Oct 1, 2026
953f704
test(Gax): add unit tests for OperationsClientInterface and CustomOpe…
bshaffer Oct 1, 2026
eb46522
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Oct 1, 2026
6581d26
test(Spanner): stub OperationResponse::getLastProtoResponse in snippe…
bshaffer Oct 1, 2026
6794439
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Oct 5, 2026
c2db3e5
chore(Gax): add TODO for removing OperationsClient check
bshaffer Nov 6, 2026
387853c
fix(Gax): preserve custom operation message in getLastProtoResponse
bshaffer Nov 6, 2026
57286ba
refactor(Gax): simplify lastProtoResponse in CustomOperationsClient
bshaffer Nov 6, 2026
7c6551e
revert: remove CustomOperationsClient to preserve GAPIC LRO BC
bshaffer Nov 6, 2026
3ca49f4
feat(Gax): add OperationsClientWrapperInterface and restore CustomOpe…
bshaffer Nov 6, 2026
94be853
refactor(Gax): simplify OperationsClientWrapperInterface to getOperat…
bshaffer Nov 6, 2026
ccb8e66
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Nov 12, 2026
53ded20
test(Gax): return Operation from getOperation mock in testAdditionalA…
bshaffer Nov 12, 2026
b2be3c5
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Nov 13, 2026
1e99d6b
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Nov 13, 2026
3d207f6
chore(Gax): typehint getLastProtoResponse(): ?Message and getOperatio…
bshaffer Nov 13, 2026
43921f6
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Nov 16, 2026
ae122b2
Merge branch 'gax-v2-client-options' into gax-v2-operation-response
bshaffer Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 64 additions & 86 deletions Core/tests/Unit/LongRunning/OperationResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
namespace Google\Cloud\Core\Tests\Unit\LongRunning;

use Google\ApiCore\OperationResponse;
use Google\ApiCore\OperationsClientInterface;
use Google\ApiCore\Serializer;
use Google\Cloud\Core\LongRunning\OperationResponseTrait;
use Google\Cloud\Core\LongRunning\LongRunningOperation;
use Google\Cloud\Core\LongRunning\LongRunningConnectionInterface;
use Google\LongRunning\Operation;
use Google\Protobuf\Any;
use Google\Rpc\Status;
use Prophecy\Argument;
use Google\Cloud\Audit\RequestMetadata;
use Google\Cloud\Audit\AuthorizationInfo;
Expand All @@ -43,6 +47,7 @@ class OperationResponseTraitTest extends TestCase
const OPERATION_NAME = 'test-operation';

private $serializer;
private $operationsClient;
private $lroResponseMappers = [
[
'typeUrl' => self::METADATA_TYPE,
Expand All @@ -57,10 +62,31 @@ public function setUp(): void
{
$serializer = $this->prophesize(Serializer::class);
$serializer->encodeMessage(Argument::any())->will(function ($arg) {
if ($arg[0] instanceof Operation) {
$result = [
'done' => $arg[0]->getDone(),
'metadata' => [
'typeUrl' => $arg[0]->getMetadata()->getTypeUrl(),
'value' => $arg[0]->getMetadata()->getValue(),
],
];
if ($arg[0]->hasResponse()) {
$result['response'] = [
'typeUrl' => $arg[0]->getResponse()->getTypeUrl(),
'value' => $arg[0]->getResponse()->getValue(),
];
}
if ($arg[0]->hasError()) {
$result['error'] = $arg[0]->getError();
}

return $result;
}
$json = $arg[0]->serializeToJsonString();
return json_decode($json, true);
});
$this->serializer = $serializer->reveal();
$this->operationsClient = $this->prophesize(OperationsClientInterface::class)->reveal();
}

public function testOperationWithResponse()
Expand All @@ -73,8 +99,12 @@ public function testOperationWithResponse()
$meta = new RequestMetadata([
'caller_ip' => '127.8.9.10', // Sic(!)
]);
$response = new Response(self::METADATA_TYPE, $meta, self::RESULT_TYPE, $result);
$operation = new OperationResponse(self::OPERATION_NAME, null, ['lastProtoResponse' => $response]);
$response = $this->createOperation(self::METADATA_TYPE, $meta, self::RESULT_TYPE, $result);
$operation = new OperationResponse(
self::OPERATION_NAME,
$this->operationsClient,
['lastProtoResponse' => $response]
);
$got = $this->operationToArray($operation, $this->serializer, $this->lroResponseMappers);

$expected = [
Expand All @@ -95,17 +125,20 @@ public function testOperationWithResponse()

public function testOperationWithError()
{
$error = new AuthorizationInfo([
'resource' => 'any',
'permission' => 'all',
'granted' => true,
$error = new Status([
'code' => 1,
'message' => 'error',
]);
$meta = new RequestMetadata([
'caller_ip' => '127.8.9.10', // Sic(!)
]);
$response = new Response(self::METADATA_TYPE, $meta);
$response->error = $error;
$operation = new OperationResponse(self::OPERATION_NAME, null, ['lastProtoResponse' => $response]);
$response = $this->createOperation(self::METADATA_TYPE, $meta);
$response->setError($error);
$operation = new OperationResponse(
self::OPERATION_NAME,
$this->operationsClient,
['lastProtoResponse' => $response]
);
$got = $this->operationToArray($operation, $this->serializer, $this->lroResponseMappers);

$expected = [
Expand All @@ -115,9 +148,8 @@ public function testOperationWithError()
'typeUrl' => self::METADATA_TYPE,
],
'error' => [
'resource' => 'any',
'permission' => 'all',
'granted' => true,
'code' => 1,
'message' => 'error',
],
'response' => null,
];
Expand All @@ -126,7 +158,7 @@ public function testOperationWithError()

public function testNullProtoResponse()
{
$operation = new OperationResponse(self::OPERATION_NAME, null);
$operation = new OperationResponse(self::OPERATION_NAME, $this->operationsClient);
$got = $this->operationToArray($operation, $this->serializer, $this->lroResponseMappers);
$this->assertNull($got);
}
Expand All @@ -141,8 +173,12 @@ public function testLroCallable()
$meta = new RequestMetadata([
'caller_ip' => '127.8.9.10',
]);
$response = new Response(self::METADATA_TYPE, $meta, self::RESULT_TYPE, $result);
$operation = new OperationResponse(self::OPERATION_NAME, null, ['lastProtoResponse' => $response]);
$response = $this->createOperation(self::METADATA_TYPE, $meta, self::RESULT_TYPE, $result);
$operation = new OperationResponse(
self::OPERATION_NAME,
$this->operationsClient,
['lastProtoResponse' => $response]
);

$connection = $this->prophesize(LongRunningConnectionInterface::class);
$t = $this;
Expand All @@ -162,81 +198,23 @@ public function testLroCallable()
$expected = 'any|all|1';
$this->assertEquals($expected, $got);
}
}

//@codingStandardsIgnoreStart

class Value
{
public $value;

public function __construct($value = null)
{
$this->value = $value;
}

public function getValue()
private function createOperation($metaType, $metadata, $respType = null, $response = null): Operation
{
return $this->value;
}
}

class Response extends \Google\Protobuf\Internal\Message
{
public $metadataType;
public $metadata;
public $responseType;
public $response = null;
public $error = null;

public function __construct($metaType, $metadata, $respType = null, $response = null)
{
$this->metadataType = $metaType;
$this->metadata = $metadata->serializeToString();
$this->responseType = $respType;
if (isset($response)) {
$this->response = $response->serializeToString();
}
}

public function getResponse()
{
return new Value($this->response);
}

public function getMetadata()
{
return new Value($this->metadata);
}

public function getDone()
{
return (isset($this->response) or isset($this->error));
}

public function getError()
{
return $this->error;
}

public function serializeToJsonString($options = 0)
{
$result = [
$operation = new Operation([
'done' => true,
'metadata' => [
'typeUrl' => $this->metadataType,
'value' => $this->metadata,
],
];
if (isset($this->response)) {
$result['response'] = [
'typeUrl' => $this->responseType,
'value' => $this->response,
];
'metadata' => new Any([
'type_url' => $metaType,
'value' => $metadata->serializeToString(),
]),
]);
if (isset($response)) {
$operation->setResponse(new Any([
'type_url' => $respType,
'value' => $response->serializeToString(),
]));
}

return json_encode($result);
return $operation;
}
}

//@codingStandardsIgnoreEnd
8 changes: 8 additions & 0 deletions Gax/MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ Update your `google/gax` dependency to `^2.0`:
- Added `declare(strict_types=1)` across all `Google\ApiCore` files.
- Added native parameter, property, and return type declarations across all `Google\ApiCore` classes, interfaces (`TransportInterface`, `MiddlewareInterface`, `ResourceTemplateInterface`, `ServerStreamingCallInterface`, `ResumableUploadTransportInterface`, `HeaderCredentialsInterface`), and traits.
- **`PathTemplate::__construct(string $path)`** now requires a non-null `string`.
- **`OperationResponse`**:
- `__construct(string $operationName, object $operationsClient, array $options = [])` now requires non-null `$operationName` (`string`) and `$operationsClient` (`object`).
- `getName()` now returns non-nullable `string`.
- `getError()` now returns `?Google\Rpc\Status`.
- `getLastProtoResponse()` now returns `?Google\Protobuf\Internal\Message` (annotated as `Operation|Message|null`), preserving the raw custom operation message (e.g. `Google\Cloud\Compute\V1\Operation`) for custom operation services such as Compute.
- `getOperationsClient()` now returns non-nullable `object` (annotated as `OperationsClient|OperationsClientInterface|object`), unwrapping `OperationsClientWrapperInterface` adapters so custom operation services still receive their underlying operations client.
- Custom operations clients (e.g., Compute's `ZoneOperationsClient`) and custom operation RPC options are now encapsulated in `Google\ApiCore\CustomOperationsClient` (implementing `Google\ApiCore\OperationsClientWrapperInterface`).

Loading
Loading