diff --git a/Gax/composer.json b/Gax/composer.json
index 3d9607c015b1..f904c2ffe5a3 100644
--- a/Gax/composer.json
+++ b/Gax/composer.json
@@ -16,7 +16,7 @@
"guzzlehttp/promises": "^2.0.3||^3.0",
"guzzlehttp/psr7": "^2.6.3||^3.0",
"google/common-protos": "^4.9",
- "google/longrunning": "~0.4",
+ "google/longrunning": "~0.4||^1.0",
"ramsey/uuid": "^4.2.3"
},
"require-dev": {
diff --git a/Gax/src/ServiceAddressTrait.php b/Gax/src/ApiEndpointTrait.php
similarity index 89%
rename from Gax/src/ServiceAddressTrait.php
rename to Gax/src/ApiEndpointTrait.php
index 1343a233caed..df74fed5ccba 100644
--- a/Gax/src/ServiceAddressTrait.php
+++ b/Gax/src/ApiEndpointTrait.php
@@ -1,4 +1,6 @@
isBackwardsCompatibilityMode()) {
- $preModifiedOptions = $options;
- $this->modifyClientOptions($options);
- // NOTE: this is required to ensure backwards compatiblity with $options['apiEndpoint']
- if ($options['apiEndpoint'] !== $preModifiedOptions['apiEndpoint']) {
- $apiEndpoint = $options['apiEndpoint'];
- }
-
- // serviceAddress is now deprecated and acts as an alias for apiEndpoint
- if (isset($options['serviceAddress'])) {
- $apiEndpoint = $this->pluck('serviceAddress', $options, false);
- }
- } else {
- // Ads is using this method in their new surface clients, so we need to call it.
- // However, this method is not used anywhere else for the new surface clients
- // @TODO: Remove this in GAX V2
- $this->modifyClientOptions($options);
+ $preModifiedOptions = $options;
+ $this->modifyClientOptions($options);
+ // NOTE: this is required to ensure backwards compatiblity with $options['apiEndpoint']
+ if ($options['apiEndpoint'] !== $preModifiedOptions['apiEndpoint']) {
+ $apiEndpoint = $options['apiEndpoint'];
+ }
+ // serviceAddress is now deprecated and acts as an alias for apiEndpoint
+ if (isset($options['serviceAddress'])) {
+ $apiEndpoint = $this->pluck('serviceAddress', $options, false);
}
// If an API endpoint is different form the default, ensure the "audience" does not conflict
// with the custom endpoint by setting "user defined" scopes.
@@ -366,14 +357,6 @@ protected function modifyClientOptions(array &$options)
// Do nothing - this method exists to allow option modification by partial veneers.
}
- /**
- * @internal
- */
- private function isBackwardsCompatibilityMode(): bool
- {
- return false;
- }
-
/**
* @param null|false|LoggerInterface $logger
* @param string $options
diff --git a/Gax/src/GPBLabel.php b/Gax/src/GPBLabel.php
deleted file mode 100644
index 18208cd64862..000000000000
--- a/Gax/src/GPBLabel.php
+++ /dev/null
@@ -1,43 +0,0 @@
- 'startClientStreamingCall',
Call::SERVER_STREAMING_CALL => 'startServerStreamingCall',
];
- private bool $backwardsCompatibilityMode;
/**
* Add a middleware to the call stack by providing a callable which will be
@@ -295,20 +293,8 @@ private function setClientOptions(array $options)
// Therefore, we need to remove it from the $options array before
// creating the ClientOptions.
$hasEmulator = $this->pluck('hasEmulator', $options, false) ?? false;
- if ($this->isBackwardsCompatibilityMode()) {
- if (is_string($options['clientConfig'])) {
- // perform validation for V1 surfaces which is done in the
- // ClientOptions class for v2 surfaces.
- $options['clientConfig'] = json_decode(
- file_get_contents($options['clientConfig']),
- true
- );
- self::validateFileExists($options['descriptorsConfigPath']);
- }
- } else {
- // cast to ClientOptions for new surfaces only
- $options = new ClientOptions($options);
- }
+ // cast to ClientOptions for new surfaces only
+ $options = new ClientOptions($options);
$this->serviceName = $options['serviceName'];
$this->retrySettings = RetrySettings::load(
$this->serviceName,
@@ -331,14 +317,6 @@ private function setClientOptions(array $options)
}
$this->agentHeader = AgentHeader::buildAgentHeader($headerInfo);
- // Set "client_library_name" depending on client library surface being used
- $userAgentHeader = sprintf(
- 'gcloud-php-%s/%s',
- $this->isBackwardsCompatibilityMode() ? 'legacy' : 'new',
- $options['gapicVersion']
- );
- $this->agentHeader['User-Agent'] = [$userAgentHeader];
-
self::validateFileExists($options['descriptorsConfigPath']);
$descriptors = require($options['descriptorsConfigPath']);
@@ -455,7 +433,7 @@ private function createTransport(
/**
* @param array $options
- * @return DeprecatedOperationsClient|OperationsClient|object
+ * @return OperationsClient|object
*/
private function createOperationsClient(array $options)
{
@@ -471,12 +449,7 @@ private function createOperationsClient(array $options)
}
// operationsClientClass option
- $defaultClass = $this->isBackwardsCompatibilityMode()
- ? DeprecatedOperationsClient::class
- : OperationsClient::class;
- $operationsClientClass = $this->pluck('operationsClientClass', $options, false)
- ?: $defaultClass;
- return new $operationsClientClass($options);
+ return new OperationsClient($options);
}
/**
@@ -796,9 +769,6 @@ private function configureCallConstructionOptions(string $methodName, array $opt
*/
private function configureCallOptions(array $optionalArgs): array
{
- if ($this->isBackwardsCompatibilityMode()) {
- return $optionalArgs;
- }
// cast to CallOptions for new surfaces only
return (new CallOptions($optionalArgs))->toArray();
}
@@ -1075,13 +1045,4 @@ protected function modifyStreamingCallable(callable &$callable)
{
// Do nothing - this method exists to allow callable modification by partial veneers.
}
-
- /**
- * @internal
- */
- private function isBackwardsCompatibilityMode(): bool
- {
- return $this->backwardsCompatibilityMode
- ?? $this->backwardsCompatibilityMode = substr(__CLASS__, -11) === 'GapicClient';
- }
}
diff --git a/Gax/src/OperationResponse.php b/Gax/src/OperationResponse.php
index 9dfeb0a73129..51c39770a6d6 100644
--- a/Gax/src/OperationResponse.php
+++ b/Gax/src/OperationResponse.php
@@ -37,7 +37,6 @@
use Google\LongRunning\DeleteOperationRequest;
use Google\LongRunning\GetOperationRequest;
use Google\LongRunning\Operation;
-use Google\LongRunning\OperationsClient as LegacyOperationsClient;
use Google\Protobuf\Any;
use Google\Protobuf\Internal\Message;
use Google\Rpc\Status;
@@ -67,7 +66,6 @@ class OperationResponse
const DEFAULT_POLLING_MULTIPLIER = 2;
const DEFAULT_MAX_POLLING_INTERVAL = 60000;
const DEFAULT_MAX_POLLING_DURATION = 0;
- private const NEW_CLIENT_NAMESPACE = '\\Client\\';
private string $operationName;
private ?object $operationsClient;
@@ -277,8 +275,7 @@ public function reload()
throw new ValidationException('Cannot call reload() on a deleted operation');
}
- $requestClass = $this->isNewSurfaceOperationsClient() ? $this->getOperationRequest : null;
- $this->lastProtoResponse = $this->operationsCall($this->getOperationMethod, $requestClass);
+ $this->lastProtoResponse = $this->operationsCall($this->getOperationMethod, $this->getOperationRequest);
}
/**
@@ -403,8 +400,7 @@ public function cancel()
throw new LogicException('The cancel operation is not supported by this API');
}
- $requestClass = $this->isNewSurfaceOperationsClient() ? $this->cancelOperationRequest : null;
- $this->operationsCall($this->cancelOperationMethod, $requestClass);
+ $this->operationsCall($this->cancelOperationMethod, $this->cancelOperationRequest);
}
/**
@@ -424,8 +420,7 @@ public function delete()
throw new LogicException('The delete operation is not supported by this API');
}
- $requestClass = $this->isNewSurfaceOperationsClient() ? $this->deleteOperationRequest : null;
- $this->operationsCall($this->deleteOperationMethod, $requestClass);
+ $this->operationsCall($this->deleteOperationMethod, $this->deleteOperationRequest);
$this->deleted = true;
}
@@ -471,22 +466,10 @@ public function getMetadata()
* Call the operations client to perform an operation.
*
* @param string $method The method to call on the operations client.
- * @param string|null $requestClass The request class to use for the call.
- * Will be null for legacy operations clients.
+ * @param string $requestClass The request class to use for the call.
*/
- private function operationsCall(string $method, ?string $requestClass)
+ private function operationsCall(string $method, string $requestClass)
{
- // V1 GAPIC clients have an empty $requestClass
- if (empty($requestClass)) {
- if ($this->additionalArgs) {
- return $this->operationsClient->$method(
- $this->getName(),
- ...array_values($this->additionalArgs)
- );
- }
- return $this->operationsClient->$method($this->getName());
- }
-
if (!method_exists($requestClass, 'build')) {
throw new LogicException('Request class must support the static build method');
}
@@ -530,10 +513,4 @@ private function hasProtoResponse()
{
return !is_null($this->lastProtoResponse);
}
-
- private function isNewSurfaceOperationsClient(): bool
- {
- return !$this->operationsClient instanceof LegacyOperationsClient
- && false !== strpos(get_class($this->operationsClient), self::NEW_CLIENT_NAMESPACE);
- }
}
diff --git a/Gax/src/Options/CallOptions.php b/Gax/src/Options/CallOptions.php
index c58c53ed14f2..20577eadd72d 100644
--- a/Gax/src/Options/CallOptions.php
+++ b/Gax/src/Options/CallOptions.php
@@ -52,6 +52,7 @@ class CallOptions implements ArrayAccess, OptionsInterface
private ?int $timeoutMillis;
private array $transportOptions;
private ?array $middlewareOptions;
+ private ?string $audience;
/** @var callable|null $metadataCallback */
private $metadataCallback;
@@ -94,6 +95,9 @@ private function fromArray(array $arr): void
$this->setRetrySettings($arr['retrySettings'] ?? null);
$this->setMetadataCallback($arr['metadataCallback'] ?? null);
$this->setMiddlewareOptions($arr['middlewareOptions'] ?? null);
+ if (isset($arr['audience'])) {
+ $this->setAudience($arr['audience']);
+ }
}
/**
@@ -142,16 +146,6 @@ public function setTransportOptions(array $transportOptions): self
return $this;
}
- /**
- * @deprecated use CallOptions::setTransportOptions
- */
- public function setTransportSpecificOptions(array $transportSpecificOptions): self
- {
- $this->setTransportOptions($transportSpecificOptions);
-
- return $this;
- }
-
/**
* @param RetrySettings|array|null $retrySettings
*
@@ -182,4 +176,11 @@ public function setMetadataCallback(callable|null $metadataCallback): self
return $this;
}
+
+ public function setAudience(?string $audience): self
+ {
+ $this->audience = $audience;
+
+ return $this;
+ }
}
diff --git a/Gax/src/Options/TransportOptions/GrpcTransportOptions.php b/Gax/src/Options/TransportOptions/GrpcTransportOptions.php
index 051b57bbea04..c1b622d045e1 100644
--- a/Gax/src/Options/TransportOptions/GrpcTransportOptions.php
+++ b/Gax/src/Options/TransportOptions/GrpcTransportOptions.php
@@ -36,7 +36,6 @@
use Closure;
use Google\ApiCore\Options\OptionsInterface;
use Google\ApiCore\Options\OptionsTrait;
-use Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface;
use Grpc\Channel;
use Grpc\Interceptor;
use Psr\Log\LoggerInterface;
@@ -56,7 +55,7 @@ class GrpcTransportOptions implements ArrayAccess, OptionsInterface
private null|false|LoggerInterface $logger;
/**
- * @var Interceptor[]|UnaryInterceptorInterface[]
+ * @var Interceptor[]
*/
private array $interceptors;
@@ -69,14 +68,8 @@ class GrpcTransportOptions implements ArrayAccess, OptionsInterface
* @type array $stubOpts Options used to construct the gRPC stub (see
* {@link https://grpc.github.io/grpc/core/group__grpc__arg__keys.html}).
* @type Channel $channel Grpc channel to be used.
- * @type Interceptor[]|UnaryInterceptorInterface[] $interceptors *EXPERIMENTAL*
+ * @type Interceptor[] $interceptors *EXPERIMENTAL*
* Interceptors used to intercept RPC invocations before a call starts.
- * Please note that implementations of
- * {@see \Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface} are
- * considered deprecated and support will be removed in a future
- * release. To prepare for this, please take the time to convert
- * `UnaryInterceptorInterface` implementations over to a class which
- * extends {@see Grpc\Interceptor}.
* @type callable $clientCertSource A callable which returns the client cert as a string.
* @type null|false|LoggerInterface A PSR-3 Logger Interface.
* }
@@ -125,7 +118,7 @@ public function setChannel(?Channel $channel): self
}
/**
- * @param Interceptor[]|UnaryInterceptorInterface[] $interceptors
+ * @param Interceptor[] $interceptors
*
* @return $this
*/
diff --git a/Gax/src/Serializer.php b/Gax/src/Serializer.php
index 3f50da5fcd13..b65fffdebfaa 100644
--- a/Gax/src/Serializer.php
+++ b/Gax/src/Serializer.php
@@ -36,6 +36,8 @@
use Google\Protobuf\Descriptor;
use Google\Protobuf\DescriptorPool;
use Google\Protobuf\FieldDescriptor;
+use Google\Protobuf\Internal\GPBLabel;
+use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\Message;
use Google\Rpc\BadRequest;
use Google\Rpc\DebugInfo;
diff --git a/Gax/src/Transport/Grpc/UnaryInterceptorInterface.php b/Gax/src/Transport/Grpc/UnaryInterceptorInterface.php
deleted file mode 100644
index fa510ea39a6f..000000000000
--- a/Gax/src/Transport/Grpc/UnaryInterceptorInterface.php
+++ /dev/null
@@ -1,61 +0,0 @@
- null,
'logger' => null,
];
- list($baseUri, $port) = self::normalizeServiceAddress($apiEndpoint);
+ list($baseUri, $port) = self::normalizeApiEndpoint($apiEndpoint);
$httpHandler = $config['httpHandler'] ?: self::buildHttpHandlerAsync(logger: $config['logger']);
$transport = new GrpcFallbackTransport("$baseUri:$port", $httpHandler);
if ($config['clientCertSource']) {
@@ -98,6 +98,16 @@ public static function build(string $apiEndpoint, array $config = [])
return $transport;
}
+ /**
+ * {@inheritdoc}
+ * @return never
+ * @throws \BadMethodCallException
+ */
+ public function startServerStreamingCall(Call $call, array $options)
+ {
+ $this->throwUnsupportedException();
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/Gax/src/Transport/GrpcTransport.php b/Gax/src/Transport/GrpcTransport.php
index 50bdc3d7de1a..cce4b4e7865a 100644
--- a/Gax/src/Transport/GrpcTransport.php
+++ b/Gax/src/Transport/GrpcTransport.php
@@ -33,15 +33,14 @@
namespace Google\ApiCore\Transport;
use Exception;
+use Google\ApiCore\ApiEndpointTrait;
use Google\ApiCore\ApiException;
use Google\ApiCore\BidiStream;
use Google\ApiCore\Call;
use Google\ApiCore\ClientStream;
use Google\ApiCore\GrpcSupportTrait;
use Google\ApiCore\ServerStream;
-use Google\ApiCore\ServiceAddressTrait;
use Google\ApiCore\Transport\Grpc\ServerStreamingCallWrapper;
-use Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface;
use Google\ApiCore\ValidationException;
use Google\ApiCore\ValidationTrait;
use Google\Auth\Logging\LoggingTrait;
@@ -59,9 +58,9 @@
*/
class GrpcTransport extends BaseStub implements TransportInterface
{
+ use ApiEndpointTrait;
use ValidationTrait;
use GrpcSupportTrait;
- use ServiceAddressTrait;
use LoggingTrait;
private null|LoggerInterface $logger;
@@ -73,14 +72,8 @@ class GrpcTransport extends BaseStub implements TransportInterface
* metadata array, and returns an updated metadata array
* - 'grpc.primary_user_agent': (optional) a user-agent string
* @param Channel $channel An already created Channel object (optional)
- * @param Interceptor[]|UnaryInterceptorInterface[] $interceptors *EXPERIMENTAL*
+ * @param Interceptor[] $interceptors *EXPERIMENTAL*
* Interceptors used to intercept RPC invocations before a call starts.
- * Please note that implementations of
- * {@see \Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface} are
- * considered deprecated and support will be removed in a future
- * release. To prepare for this, please take the time to convert
- * `UnaryInterceptorInterface` implementations over to a class which
- * extends {@see Grpc\Interceptor}.
* @param null|false|LoggerInterface $logger A PSR-3 Compliant logger.
* @throws Exception
*/
@@ -114,14 +107,8 @@ public function __construct(
* @type array $stubOpts Options used to construct the gRPC stub (see
* {@link https://grpc.github.io/grpc/core/group__grpc__arg__keys.html}).
* @type Channel $channel Grpc channel to be used.
- * @type Interceptor[]|UnaryInterceptorInterface[] $interceptors *EXPERIMENTAL*
+ * @type Interceptor[] $interceptors *EXPERIMENTAL*
* Interceptors used to intercept RPC invocations before a call starts.
- * Please note that implementations of
- * {@see \Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface} are
- * considered deprecated and support will be removed in a future
- * release. To prepare for this, please take the time to convert
- * `UnaryInterceptorInterface` implementations over to a class which
- * extends {@see Grpc\Interceptor}.
* @type callable $clientCertSource A callable which returns the client cert as a string.
* }
* @return GrpcTransport
@@ -137,7 +124,7 @@ public static function build(string $apiEndpoint, array $config = [])
'clientCertSource' => null,
'logger' => null,
];
- list($addr, $port) = self::normalizeServiceAddress($apiEndpoint);
+ list($addr, $port) = self::normalizeApiEndpoint($apiEndpoint);
$host = "$addr:$port";
$stubOpts = $config['stubOpts'];
// Set the required 'credentials' key in stubOpts if it is not already set. Use
diff --git a/Gax/src/Transport/HttpUnaryTransportTrait.php b/Gax/src/Transport/HttpUnaryTransportTrait.php
index 38c4ca1f5522..5e4bb242d23c 100644
--- a/Gax/src/Transport/HttpUnaryTransportTrait.php
+++ b/Gax/src/Transport/HttpUnaryTransportTrait.php
@@ -59,16 +59,6 @@ public function startClientStreamingCall(Call $call, array $options)
$this->throwUnsupportedException();
}
- /**
- * {@inheritdoc}
- * @return never
- * @throws \BadMethodCallException
- */
- public function startServerStreamingCall(Call $call, array $options)
- {
- $this->throwUnsupportedException();
- }
-
/**
* {@inheritdoc}
* @return never
diff --git a/Gax/src/Transport/RestTransport.php b/Gax/src/Transport/RestTransport.php
index ae0245130dd9..2ab582338320 100644
--- a/Gax/src/Transport/RestTransport.php
+++ b/Gax/src/Transport/RestTransport.php
@@ -31,13 +31,13 @@
*/
namespace Google\ApiCore\Transport;
+use Google\ApiCore\ApiEndpointTrait;
use Google\ApiCore\ApiException;
use Google\ApiCore\Call;
use Google\ApiCore\InsecureRequestBuilder;
use Google\ApiCore\RequestBuilder;
use Google\ApiCore\ResumableUpload\ResumableUploadTransportInterface;
use Google\ApiCore\ServerStream;
-use Google\ApiCore\ServiceAddressTrait;
use Google\ApiCore\Transport\Rest\RestServerStreamingCall;
use Google\ApiCore\ValidationException;
use Google\ApiCore\ValidationTrait;
@@ -51,11 +51,9 @@
*/
class RestTransport implements TransportInterface, ResumableUploadTransportInterface
{
+ use ApiEndpointTrait;
use ValidationTrait;
- use ServiceAddressTrait;
- use HttpUnaryTransportTrait {
- startServerStreamingCall as protected unsupportedServerStreamingCall;
- }
+ use HttpUnaryTransportTrait;
private RequestBuilder $requestBuilder;
@@ -98,7 +96,7 @@ public static function build(string $apiEndpoint, string $restConfigPath, array
'hasEmulator' => false,
'logger' => null,
];
- list($baseUri, $port) = self::normalizeServiceAddress($apiEndpoint);
+ list($baseUri, $port) = self::normalizeApiEndpoint($apiEndpoint);
$requestBuilder = $config['hasEmulator']
? new InsecureRequestBuilder("$baseUri:$port", $restConfigPath)
: new RequestBuilder("$baseUri:$port", $restConfigPath);
@@ -196,7 +194,7 @@ public function startServerStreamingCall(Call $call, array $options)
// Maintain forwards compatibility with older GAPIC clients not configured for REST server streaming
// @see https://github.com/googleapis/gax-php/issues/370
if (!$this->requestBuilder->pathExists($call->getMethod())) {
- $this->unsupportedServerStreamingCall($call, $options);
+ $this->throwUnsupportedException();
}
$headers = self::buildCommonHeaders($options);
diff --git a/Gax/src/Testing/MockGrpcTransport.php b/Gax/tests/Testing/MockGrpcTransport.php
similarity index 95%
rename from Gax/src/Testing/MockGrpcTransport.php
rename to Gax/tests/Testing/MockGrpcTransport.php
index d6af2fe4f4b7..8b1baa203146 100644
--- a/Gax/src/Testing/MockGrpcTransport.php
+++ b/Gax/tests/Testing/MockGrpcTransport.php
@@ -1,4 +1,6 @@
mockCall;
}
+ // phpcs:enable
+
/**
* @param string $method
* @param callable $deserialize
diff --git a/Gax/tests/Unit/ServiceAddressTraitTest.php b/Gax/tests/Unit/ApiEndpointTraitTest.php
similarity index 62%
rename from Gax/tests/Unit/ServiceAddressTraitTest.php
rename to Gax/tests/Unit/ApiEndpointTraitTest.php
index ba5cf81c7a64..807f2beee0d7 100644
--- a/Gax/tests/Unit/ServiceAddressTraitTest.php
+++ b/Gax/tests/Unit/ApiEndpointTraitTest.php
@@ -17,29 +17,25 @@
namespace Google\ApiCore\Tests\Unit;
-use Google\ApiCore\ServiceAddressTrait;
+use Google\ApiCore\ApiEndpointTrait;
use Google\ApiCore\ValidationException;
use PHPUnit\Framework\TestCase;
-/**
- * @todo (dwsupplee) serviceAddress is deprecated now in favor of
- * apiEndpoint. Rename the tests/variables in our next major release.
- */
-class ServiceAddressTraitTest extends TestCase
+class ApiEndpointTraitTest extends TestCase
{
- use ServiceAddressTrait;
+ use ApiEndpointTrait;
/**
- * @dataProvider normalizeServiceAddressData
+ * @dataProvider normalizeApiEndpointData
*/
- public function testNormalizeServiceAddress($serviceAddressString, $expectedAddress, $expectedPort)
+ public function testNormalizeApiEndpoint($apiEndpointString, $expectedAddress, $expectedPort)
{
- list($actualAddress, $actualPort) = self::normalizeServiceAddress($serviceAddressString);
+ list($actualAddress, $actualPort) = self::normalizeApiEndpoint($apiEndpointString);
$this->assertSame($expectedAddress, $actualAddress);
$this->assertSame($expectedPort, $actualPort);
}
- public function normalizeServiceAddressData()
+ public function normalizeApiEndpointData()
{
return [
['simple.com:123', 'simple.com', '123'],
@@ -49,17 +45,17 @@ public function normalizeServiceAddressData()
}
/**
- * @dataProvider normalizeServiceAddressInvalidData
+ * @dataProvider normalizeApiEndpointInvalidData
*/
- public function testNormalizeServiceAddressInvalid($serviceAddressString)
+ public function testNormalizeApiEndpointInvalid($apiEndpointString)
{
$this->expectException(ValidationException::class);
$this->expectExceptionMessage('Invalid apiEndpoint');
- self::normalizeServiceAddress($serviceAddressString);
+ self::normalizeApiEndpoint($apiEndpointString);
}
- public function normalizeServiceAddressInvalidData()
+ public function normalizeApiEndpointInvalidData()
{
return [
['too.many:colons:123'],
diff --git a/Gax/tests/Unit/GapicClientTraitTest.php b/Gax/tests/Unit/GapicClientTraitTest.php
index e1115ad00ae4..556b90745983 100644
--- a/Gax/tests/Unit/GapicClientTraitTest.php
+++ b/Gax/tests/Unit/GapicClientTraitTest.php
@@ -40,7 +40,6 @@
use Google\ApiCore\CredentialsWrapper;
use Google\ApiCore\GapicClientTrait;
use Google\ApiCore\IamProviderInterface;
-use Google\ApiCore\LongRunning\OperationsClient as DeprecatedOperationsClient;
use Google\ApiCore\LongRunningOperationProviderInterface;
use Google\ApiCore\Middleware\MiddlewareInterface;
use Google\ApiCore\OperationResponse;
@@ -78,6 +77,11 @@ class GapicClientTraitTest extends TestCase
use ProphecyTrait;
use TestTrait;
+ public static function setUpBeforeClass(): void
+ {
+ self::autoloadTestdata('mocks', 'Google');
+ }
+
public function setUp(): void
{
$keyFilePath = __DIR__ . '/testdata/creds/json-key-file.json';
@@ -124,14 +128,16 @@ public function testHeadersOverwriteBehavior()
'x-goog-request-params' => ['name=foos%2F123%2Fbars%2F456']
];
$transport = $this->prophesize(TransportInterface::class);
- $credentialsWrapper = CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ]);
+ $credentialsWrapper = CredentialsWrapper::build();
$transport->startUnaryCall(
Argument::type(Call::class),
[
'headers' => $expectedHeaders,
'credentialsWrapper' => $credentialsWrapper,
+ 'timeoutMillis' => 30000,
+ 'transportOptions' => [],
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -140,7 +146,7 @@ public function testHeadersOverwriteBehavior()
$client->set('agentHeader', $header);
$client->set(
'retrySettings',
- ['method' => $this->prophesize(RetrySettings::class)->reveal()]
+ ['method' => RetrySettings::constructDefault()]
);
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
@@ -173,15 +179,13 @@ public function testMiddlewareOptionsIsPreservedByFilterAndVisibleToMiddlewares(
->shouldBeCalledOnce()
->willReturn($this->prophesize(PromiseInterface::class)->reveal());
- $credentialsWrapper = CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ]);
+ $credentialsWrapper = CredentialsWrapper::build();
$client = new StubGapicClient();
$client->set('agentHeader', []);
$client->set(
'retrySettings',
- ['method' => $this->prophesize(RetrySettings::class)->reveal()]
+ ['method' => RetrySettings::constructDefault()]
);
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
@@ -240,20 +244,14 @@ public function testMiddlewareOptionsPreservedByCallOptionsOnNewSurface()
->shouldBeCalledOnce()
->willReturn($this->prophesize(PromiseInterface::class)->reveal());
- $credentialsWrapper = CredentialsWrapper::build([
- "keyFile" => __DIR__ . "/testdata/creds/json-key-file.json"
- ]);
+ $credentialsWrapper = CredentialsWrapper::build();
- $client = new class extends StubGapicClient {
- protected function isNewClientSurface(): bool {
- return true;
- }
- };
+ $client = new StubGapicClient();
$client->set("agentHeader", []);
$client->set(
"retrySettings",
- ["method" => $this->prophesize(RetrySettings::class)->reveal()]
+ ["method" => RetrySettings::constructDefault()]
);
$client->set("transport", $transport->reveal());
$client->set("credentialsWrapper", $credentialsWrapper);
@@ -312,14 +310,16 @@ public function testVersionedHeadersOverwriteBehavior()
'x-goog-request-params' => ['name=foos%2F123%2Fbars%2F456'],
];
$transport = $this->prophesize(TransportInterface::class);
- $credentialsWrapper = CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ]);
+ $credentialsWrapper = CredentialsWrapper::build();
$transport->startUnaryCall(
Argument::type(Call::class),
[
'headers' => $expectedHeaders,
'credentialsWrapper' => $credentialsWrapper,
+ 'timeoutMillis' => 30000,
+ 'transportOptions' => [],
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -328,7 +328,7 @@ public function testVersionedHeadersOverwriteBehavior()
$client->set('agentHeader', $header);
$client->set(
'retrySettings',
- ['method' => $this->prophesize(RetrySettings::class)->reveal()]
+ ['method' => RetrySettings::constructDefault()]
);
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
@@ -386,7 +386,7 @@ public function testConfigureCallConstructionOptionsAcceptsRetryObjectOrArray()
public function testStartOperationsCall()
{
$header = AgentHeader::buildAgentHeader([]);
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$longRunningDescriptors = [
'longRunning' => [
'operationReturnType' => 'operationType',
@@ -407,7 +407,7 @@ public function testStartOperationsCall()
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
$client->set('agentHeader', $header);
- $client->set('retrySettings', ['method' => $retrySettings->reveal()]);
+ $client->set('retrySettings', ['method' => $retrySettings]);
$client->set('descriptors', ['method' => $longRunningDescriptors]);
$message = new MockRequest();
$operationsClient = $this->prophesize(OperationsClient::class);
@@ -431,7 +431,7 @@ public function testStartOperationsCall()
public function testStartApiCallOperation()
{
$header = AgentHeader::buildAgentHeader([]);
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$longRunningDescriptors = [
'callType' => Call::LONGRUNNING_CALL,
@@ -454,7 +454,7 @@ public function testStartApiCallOperation()
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
$client->set('agentHeader', $header);
- $client->set('retrySettings', ['method' => $retrySettings->reveal()]);
+ $client->set('retrySettings', ['method' => $retrySettings]);
$client->set('descriptors', ['method' => $longRunningDescriptors]);
$operationsClient = $this->prophesize(OperationsClient::class);
$client->set('operationsClient', $operationsClient->reveal());
@@ -477,7 +477,7 @@ public function testStartApiCallOperation()
public function testStartApiCallCustomOperation()
{
$header = AgentHeader::buildAgentHeader([]);
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$longRunningDescriptors = [
'callType' => Call::LONGRUNNING_CALL,
@@ -501,7 +501,7 @@ public function testStartApiCallCustomOperation()
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
$client->set('agentHeader', $header);
- $client->set('retrySettings', ['method' => $retrySettings->reveal()]);
+ $client->set('retrySettings', ['method' => $retrySettings]);
$client->set('descriptors', ['method' => $longRunningDescriptors]);
$operationsClient = $this->prophesize(OperationsClient::class)->reveal();
$client->set('operationsClient', $operationsClient);
@@ -583,7 +583,7 @@ public function startApiCallExceptions()
public function testStartApiCallUnary()
{
$header = AgentHeader::buildAgentHeader([]);
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$unaryDescriptors = [
'callType' => Call::UNARY_CALL,
'responseType' => 'Google\Longrunning\Operation',
@@ -604,7 +604,7 @@ public function testStartApiCallUnary()
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
$client->set('agentHeader', $header);
- $client->set('retrySettings', ['method' => $retrySettings->reveal()]);
+ $client->set('retrySettings', ['method' => $retrySettings]);
$client->set('descriptors', ['method' => $unaryDescriptors]);
$request = new MockRequest();
@@ -617,7 +617,7 @@ public function testStartApiCallUnary()
public function testStartApiCallPaged()
{
$header = AgentHeader::buildAgentHeader([]);
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$pagedDescriptors = [
'callType' => Call::PAGINATED_CALL,
'responseType' => 'Google\Longrunning\ListOperationsResponse',
@@ -640,7 +640,7 @@ public function testStartApiCallPaged()
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
$client->set('agentHeader', $header);
- $client->set('retrySettings', ['method' => $retrySettings->reveal()]);
+ $client->set('retrySettings', ['method' => $retrySettings]);
$client->set('descriptors', ['method' => $pagedDescriptors]);
$request = new MockRequest();
@@ -653,7 +653,7 @@ public function testStartApiCallPaged()
public function testStartAsyncCall()
{
$header = AgentHeader::buildAgentHeader([]);
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$unaryDescriptors = [
'callType' => Call::UNARY_CALL,
'responseType' => 'Google\Longrunning\Operation'
@@ -668,7 +668,7 @@ public function testStartAsyncCall()
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
$client->set('agentHeader', $header);
- $client->set('retrySettings', ['Method' => $retrySettings->reveal()]);
+ $client->set('retrySettings', ['Method' => $retrySettings]);
$client->set('descriptors', ['Method' => $unaryDescriptors]);
$request = new MockRequest();
@@ -681,7 +681,7 @@ public function testStartAsyncCall()
public function testStartAsyncCallPaged()
{
$header = AgentHeader::buildAgentHeader([]);
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$pagedDescriptors = [
'callType' => Call::PAGINATED_CALL,
'responseType' => 'Google\Longrunning\ListOperationsResponse',
@@ -710,7 +710,7 @@ public function testStartAsyncCallPaged()
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
$client->set('agentHeader', $header);
- $client->set('retrySettings', ['Method' => $retrySettings->reveal()]);
+ $client->set('retrySettings', ['Method' => $retrySettings]);
$client->set('descriptors', ['Method' => $pagedDescriptors]);
$request = new MockRequest();
@@ -856,34 +856,11 @@ public function createTransportDataInvalid()
],
];
return [
- [$apiEndpoint, null, $transportConfig],
- [$apiEndpoint, ['transport' => 'weirdstring'], $transportConfig],
- [$apiEndpoint, ['transport' => new \stdClass()], $transportConfig],
- [$apiEndpoint, ['transport' => 'rest'], []],
+ [$apiEndpoint, 'weirdstring', $transportConfig],
+ [$apiEndpoint, 'rest', []],
];
}
- public function testServiceAddressAlias()
- {
- $client = new StubGapicClient();
- $apiEndpoint = 'test.address.com:443';
- $updatedOptions = $client->buildClientOptions(
- ['serviceAddress' => $apiEndpoint]
- );
- $client->setClientOptions($updatedOptions);
-
- $this->assertEquals($apiEndpoint, $updatedOptions['apiEndpoint']);
- $this->assertArrayNotHasKey('serviceAddress', $updatedOptions);
- }
-
- public function testOperationClientClassOption()
- {
- $options = ['operationsClientClass' => CustomOperationsClient::class];
- $client = new StubGapicClient();
- $operationsClient = $client->createOperationsClient($options);
- $this->assertInstanceOf(CustomOperationsClient::class, $operationsClient);
- }
-
public function testAdditionalArgumentMethods()
{
$client = new StubGapicClient();
@@ -891,6 +868,7 @@ public function testAdditionalArgumentMethods()
// Set the LRO descriptors we are testing.
$longRunningDescriptors = [
'longRunning' => [
+ 'getOperationRequest' => \Google\CustomOperation\GetOperationRequest::class,
'additionalArgumentMethods' => [
'getPageToken',
'getPageSize',
@@ -910,7 +888,6 @@ public function testAdditionalArgumentMethods()
// Set up things for the mock call to work.
$client->set('credentialsWrapper', CredentialsWrapper::build([]));
$client->set('agentHeader', []);
- $retrySettings = $this->prophesize(RetrySettings::class);
$client->set('retrySettings', [
'method.name' => RetrySettings::constructDefault()
]);
@@ -925,7 +902,9 @@ public function testAdditionalArgumentMethods()
// Create mock operations client to test the additional arguments from
// the request object are used.
$operationsClient = $this->prophesize(CustomOperationsClient::class);
- $operationsClient->getOperation('test-123', 'abc', 100)
+ $operationsClient->getOperation(
+ \Google\CustomOperation\GetOperationRequest::build('abc', 100, 'test-123')
+ )
->shouldBeCalledOnce();
$operationResponse = $client->startOperationsCall(
@@ -969,7 +948,7 @@ public function setClientOptionsData()
}
$expectedProperties = [
'serviceName' => 'test.interface.v1.api',
- 'agentHeader' => AgentHeader::buildAgentHeader([]) + ['User-Agent' => ['gcloud-php-legacy/']],
+ 'agentHeader' => AgentHeader::buildAgentHeader([]),
'retrySettings' => $expectedRetrySettings,
];
return [
@@ -1106,6 +1085,19 @@ public function buildRequestHeaderParams()
];
}
+ public function testServiceAddressOption()
+ {
+ $client = new StubGapicClient();
+ $apiEndpoint = 'test.address.com:443';
+ $updatedOptions = $client->buildClientOptions(
+ ['serviceAddress' => $apiEndpoint]
+ );
+ $client->setClientOptions($updatedOptions);
+
+ $this->assertEquals($apiEndpoint, $updatedOptions['apiEndpoint']);
+ $this->assertArrayNotHasKey('serviceAddress', $updatedOptions);
+ }
+
public function testModifyClientOptions()
{
$options = [];
@@ -1121,7 +1113,7 @@ public function testModifyClientOptions()
private function buildClientToTestModifyCallMethods($clientClass = null)
{
$header = AgentHeader::buildAgentHeader([]);
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$longRunningDescriptors = [
'longRunning' => [
@@ -1140,21 +1132,19 @@ private function buildClientToTestModifyCallMethods($clientClass = null)
],
];
$transport = $this->prophesize(TransportInterface::class);
- $credentialsWrapper = CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ]);
+ $credentialsWrapper = CredentialsWrapper::build();
$clientClass = $clientClass ?: StubGapicClientExtension::class;
$client = new $clientClass();
$client->set('transport', $transport->reveal());
$client->set('credentialsWrapper', $credentialsWrapper);
$client->set('agentHeader', $header);
$client->set('retrySettings', [
- 'simpleMethod' => $retrySettings->reveal(),
- 'longRunningMethod' => $retrySettings->reveal(),
- 'pagedMethod' => $retrySettings->reveal(),
- 'bidiStreamingMethod' => $retrySettings->reveal(),
- 'clientStreamingMethod' => $retrySettings->reveal(),
- 'serverStreamingMethod' => $retrySettings->reveal(),
+ 'simpleMethod' => $retrySettings,
+ 'longRunningMethod' => $retrySettings,
+ 'pagedMethod' => $retrySettings,
+ 'bidiStreamingMethod' => $retrySettings,
+ 'clientStreamingMethod' => $retrySettings,
+ 'serverStreamingMethod' => $retrySettings,
]);
$client->set('descriptors', [
'longRunningMethod' => $longRunningDescriptors,
@@ -1173,9 +1163,10 @@ public function testModifyUnaryCallFromStartCall()
'custom' => ['addModifyUnaryCallableOption' => true]
],
'headers' => AgentHeader::buildAgentHeader([]),
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ])
+ 'credentialsWrapper' => CredentialsWrapper::build(),
+ 'timeoutMillis' => 30000,
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1199,10 +1190,11 @@ public function testModifyUnaryCallFromOperationsCall()
'custom' => ['addModifyUnaryCallableOption' => true]
],
'headers' => AgentHeader::buildAgentHeader([]),
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ]),
- 'metadataReturnType' => 'metadataType'
+ 'credentialsWrapper' => CredentialsWrapper::build(),
+ 'metadataReturnType' => 'metadataType',
+ 'timeoutMillis' => 30000,
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1227,9 +1219,10 @@ public function testModifyUnaryCallFromGetPagedListResponse()
'custom' => ['addModifyUnaryCallableOption' => true]
],
'headers' => AgentHeader::buildAgentHeader([]),
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ])
+ 'credentialsWrapper' => CredentialsWrapper::build(),
+ 'timeoutMillis' => 30000,
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1255,9 +1248,10 @@ public function testModifyStreamingCallFromStartCall($callArgs, $expectedMethod,
'custom' => ['addModifyStreamingCallable' => true]
],
'headers' => AgentHeader::buildAgentHeader([]),
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ])
+ 'credentialsWrapper' => CredentialsWrapper::build(),
+ 'timeoutMillis' => 30000,
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1333,9 +1327,12 @@ public function testUserProjectHeaderIsSetWhenProvidingQuotaProject()
[
'headers' => AgentHeader::buildAgentHeader([]) + [
'X-Goog-User-Project' => [$quotaProject],
- 'User-Agent' => ['gcloud-php-legacy/']
],
- 'credentialsWrapper' => $credentialsWrapper->reveal()
+ 'credentialsWrapper' => $credentialsWrapper->reveal(),
+ 'timeoutMillis' => 30000,
+ 'transportOptions' => [],
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1350,7 +1347,7 @@ public function testUserProjectHeaderIsSetWhenProvidingQuotaProject()
$client->setClientOptions($updatedOptions);
$client->set(
'retrySettings',
- ['method' => $this->prophesize(RetrySettings::class)->reveal()]
+ ['method' => RetrySettings::constructDefault()]
);
$client->startCall(
'method',
@@ -1360,7 +1357,7 @@ public function testUserProjectHeaderIsSetWhenProvidingQuotaProject()
public function testDefaultAudience()
{
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$credentialsWrapper = $this->prophesize(CredentialsWrapper::class)
->reveal();
$transport = $this->prophesize(TransportInterface::class);
@@ -1371,6 +1368,10 @@ public function testDefaultAudience()
'audience' => 'https://service-address/',
'headers' => [],
'credentialsWrapper' => $credentialsWrapper,
+ 'timeoutMillis' => 30000,
+ 'transportOptions' => [],
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1381,7 +1382,7 @@ public function testDefaultAudience()
$client->set('agentHeader', []);
$client->set(
'retrySettings',
- ['method.name' => $retrySettings->reveal()]
+ ['method.name' => $retrySettings]
);
$client->set('transport', $transport->reveal());
$client->startCall('method.name', 'decodeType');
@@ -1393,6 +1394,10 @@ public function testDefaultAudience()
'audience' => 'custom-audience',
'headers' => [],
'credentialsWrapper' => $credentialsWrapper,
+ 'timeoutMillis' => 30000,
+ 'transportOptions' => [],
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1405,7 +1410,7 @@ public function testDefaultAudience()
public function testDefaultAudienceWithOperations()
{
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$credentialsWrapper = $this->prophesize(CredentialsWrapper::class)
->reveal();
$transport = $this->prophesize(TransportInterface::class);
@@ -1416,7 +1421,11 @@ public function testDefaultAudienceWithOperations()
'audience' => 'https://service-address/',
'headers' => [],
'credentialsWrapper' => $credentialsWrapper,
- 'metadataReturnType' => 'metadataType'
+ 'metadataReturnType' => 'metadataType',
+ 'timeoutMillis' => 30000,
+ 'transportOptions' => [],
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1437,7 +1446,7 @@ public function testDefaultAudienceWithOperations()
$client->set('agentHeader', []);
$client->set(
'retrySettings',
- ['method.name' => $retrySettings->reveal()]
+ ['method.name' => $retrySettings]
);
$client->set('transport', $transport->reveal());
$client->set('descriptors', ['method.name' => $longRunningDescriptors]);
@@ -1454,7 +1463,7 @@ public function testDefaultAudienceWithOperations()
public function testDefaultAudienceWithPagedList()
{
- $retrySettings = $this->prophesize(RetrySettings::class);
+ $retrySettings = RetrySettings::constructDefault();
$credentialsWrapper = $this->prophesize(CredentialsWrapper::class)
->reveal();
$transport = $this->prophesize(TransportInterface::class);
@@ -1465,6 +1474,10 @@ public function testDefaultAudienceWithPagedList()
'audience' => 'https://service-address/',
'headers' => [],
'credentialsWrapper' => $credentialsWrapper,
+ 'timeoutMillis' => 30000,
+ 'transportOptions' => [],
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1484,7 +1497,7 @@ public function testDefaultAudienceWithPagedList()
$client->set('agentHeader', []);
$client->set(
'retrySettings',
- ['method.name' => $retrySettings->reveal()]
+ ['method.name' => $retrySettings]
);
$client->set('transport', $transport->reveal());
$client->set('descriptors', [
@@ -1572,9 +1585,10 @@ public function __invoke(Call $call, array $options)
'custom' => ['addModifyUnaryCallableOption' => true]
],
'headers' => AgentHeader::buildAgentHeader([]),
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ])
+ 'credentialsWrapper' => CredentialsWrapper::build(),
+ 'timeoutMillis' => 30000,
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1642,9 +1656,10 @@ public function __invoke(Call $call, array $options)
'custom' => ['addModifyUnaryCallableOption' => true]
],
'headers' => AgentHeader::buildAgentHeader([]),
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ])
+ 'credentialsWrapper' => CredentialsWrapper::build(),
+ 'timeoutMillis' => 30000,
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
->shouldBeCalledOnce()
@@ -1712,13 +1727,14 @@ public function __invoke(Call $call, array $options)
'custom' => ['addModifyUnaryCallableOption' => true]
],
'headers' => AgentHeader::buildAgentHeader([]),
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ])
+ 'credentialsWrapper' => CredentialsWrapper::build(),
+ 'timeoutMillis' => 30000,
+ 'metadataCallback' => null,
+ 'middlewareOptions' => null,
]
)
- ->shouldBeCalledOnce()
- ->willReturn(new FulfilledPromise(new Operation()));
+ ->shouldBeCalledOnce()
+ ->willReturn(new FulfilledPromise(new Operation()));
$client->startCall(
'simpleMethod',
@@ -1730,12 +1746,8 @@ public function __invoke(Call $call, array $options)
$this->assertEquals(['middleware2', 'middleware1'], $callOrder);
}
- public function testInvalidClientOptionsTypeThrowsExceptionForV2SurfaceOnly()
+ public function testInvalidClientOptionsTypeThrowsException()
{
- // v1 client
- new StubGapicClient(['apiEndpoint' => ['foo']]);
- $this->assertTrue(true, 'Test made it to here without throwing an exception');
-
$this->expectException(\TypeError::class);
$this->expectExceptionMessage(
PHP_MAJOR_VERSION < 8
@@ -1745,7 +1757,6 @@ public function testInvalidClientOptionsTypeThrowsExceptionForV2SurfaceOnly()
. '($apiEndpoint) must be of type ?string, array given'
);
- // v2 client
new GapicV2SurfaceClient(['apiEndpoint' => ['foo']]);
}
@@ -1759,10 +1770,8 @@ public function testCallOptionsForV2Surface()
Argument::type(Call::class),
[
'headers' => AgentHeader::buildAgentHeader([]) + ['Foo' => 'Bar'],
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ]),
- 'timeoutMillis' => null, // adds null timeoutMillis,
+ 'credentialsWrapper' => CredentialsWrapper::build(),
+ 'timeoutMillis' => 30000, // adds null timeoutMillis,
'transportOptions' => [],
'metadataCallback' => null,
'middlewareOptions' => null,
@@ -1784,32 +1793,6 @@ public function testCallOptionsForV2Surface()
)->wait();
}
- public function testInvalidCallOptionsTypeForV1SurfaceDoesNotThrowException()
- {
- list($client, $transport) = $this->buildClientToTestModifyCallMethods();
-
- $transport->startUnaryCall(
- Argument::type(Call::class),
- [
- 'transportOptions' => ['custom' => ['addModifyUnaryCallableOption' => true]],
- 'headers' => AgentHeader::buildAgentHeader([]),
- 'credentialsWrapper' => CredentialsWrapper::build([
- 'keyFile' => __DIR__ . '/testdata/creds/json-key-file.json'
- ]),
- 'timeoutMillis' => 'blue', // invalid type, this is ignored
- ]
- )
- ->shouldBeCalledOnce()
- ->willReturn(new FulfilledPromise(new Operation()));
-
- $client->startCall(
- 'simpleMethod',
- 'decodeType',
- ['timeoutMillis' => 'blue'],
- new MockRequest(),
- )->wait();
- }
-
public function testInvalidCallOptionsTypeForV2SurfaceThrowsException()
{
$this->expectException(\TypeError::class);
@@ -1831,25 +1814,6 @@ public function testInvalidCallOptionsTypeForV2SurfaceThrowsException()
)->wait();
}
- public function testSurfaceAgentHeaders()
- {
- // V1 does not contain new headers
- $client = new RestOnlyGapicClient([
- 'gapicVersion' => '0.0.2',
- ]);
- $agentHeader = $client->getAgentHeader();
- $this->assertStringContainsString(' gapic/0.0.2 ', $agentHeader['x-goog-api-client'][0]);
- $this->assertEquals('gcloud-php-legacy/0.0.2', $agentHeader['User-Agent'][0]);
-
- // V2 contains new headers
- $client = new GapicV2SurfaceClient([
- 'gapicVersion' => '0.0.1',
- ]);
- $agentHeader = $client->getAgentHeader();
- $this->assertStringContainsString(' gapic/0.0.1 ', $agentHeader['x-goog-api-client'][0]);
- $this->assertEquals('gcloud-php-new/0.0.1', $agentHeader['User-Agent'][0]);
- }
-
public function testApiKeyOption()
{
$transport = $this->prophesize(TransportInterface::class);
@@ -1981,17 +1945,10 @@ public function testGetServiceScopes()
public function testCreateOperationsClientDefaultClass()
{
- $v1Client = new StubGapicClient();
- $this->assertInstanceOf(
- DeprecatedOperationsClient::class,
- $v1Client->createOperationsClient([])
- );
-
- $v2Client = new GapicV2SurfaceClient();
- $method = new \ReflectionMethod($v2Client, 'createOperationsClient');
+ $client = new StubGapicClient();
$this->assertInstanceOf(
OperationsClient::class,
- $method->invoke($v2Client, [])
+ $client->createOperationsClient([])
);
}
@@ -2270,7 +2227,7 @@ public function getOperationsClient()
class CustomOperationsClient
{
- public function getOperation($name, $arg1, $arg2)
+ public function getOperation($request)
{
}
}
diff --git a/Gax/tests/Unit/Middleware/OperationsMiddlewareTest.php b/Gax/tests/Unit/Middleware/OperationsMiddlewareTest.php
index 7d7dac94189e..1c264ae76ee9 100644
--- a/Gax/tests/Unit/Middleware/OperationsMiddlewareTest.php
+++ b/Gax/tests/Unit/Middleware/OperationsMiddlewareTest.php
@@ -33,9 +33,9 @@
namespace Google\ApiCore\Tests\Unit\Middleware;
use Google\ApiCore\Call;
-use Google\ApiCore\LongRunning\OperationsClient;
+use Google\LongRunning\Client\OperationsClient;
use Google\ApiCore\Middleware\OperationsMiddleware;
-use Google\ApiCore\Testing\MockResponse;
+use Google\ApiCore\Testing\MockRequest;
use GuzzleHttp\Promise\Promise;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
@@ -50,11 +50,11 @@ public function testOperationNameMethodDescriptor()
$operationsClient = $this->prophesize(OperationsClient::class);
$descriptor = [
- 'operationNameMethod' => 'getNumber'
+ 'operationNameMethod' => 'getPageToken'
];
$handler = function (Call $call, $options) use (&$callCount) {
return $promise = new Promise(function () use (&$promise) {
- $response = new MockResponse(['number' => 123]);
+ $response = new MockRequest(['page_token' => 'abc']);
$promise->resolve($response);
});
};
@@ -64,6 +64,6 @@ public function testOperationNameMethodDescriptor()
[]
)->wait();
- $this->assertEquals(123, $response->getName());
+ $this->assertEquals('abc', $response->getName());
}
}
diff --git a/Gax/tests/Unit/OperationResponseTest.php b/Gax/tests/Unit/OperationResponseTest.php
index 0901be1bb5c8..4ef50bb3ac77 100644
--- a/Gax/tests/Unit/OperationResponseTest.php
+++ b/Gax/tests/Unit/OperationResponseTest.php
@@ -38,14 +38,14 @@
use Google\CustomOperation\CustomOperationWithErrorAnnotations;
use Google\CustomOperation\DeleteOperationRequest as CustomDeleteOperationRequest;
use Google\CustomOperation\GetOperationRequest as CustomGetOperationRequest;
-use Google\ApiCore\LongRunning\OperationsClient;
use Google\ApiCore\OperationResponse;
use Google\LongRunning\CancelOperationRequest;
-use Google\LongRunning\Client\OperationsClient as LROOperationsClient;
+use Google\LongRunning\Client\OperationsClient;
use Google\LongRunning\DeleteOperationRequest;
use Google\LongRunning\GetOperationRequest;
use Google\LongRunning\Operation;
use Google\Protobuf\Any;
+use Google\Protobuf\Internal\Message;
use Google\Rpc\Code;
use LogicException;
use PHPUnit\Framework\TestCase;
@@ -78,7 +78,7 @@ public function provideOperationsClients()
{
return [
[$this->createOperationsClient()],
- [$this->prophesize(LROOperationsClient::class)->reveal()],
+ [$this->prophesize(OperationsClient::class)->reveal()],
];
}
@@ -237,13 +237,13 @@ public function testCustomOperation()
->shouldBeCalledOnce()
->willReturn(null);
$operationClient = $this->prophesize(CustomOperationClient::class);
- $operationClient->getMyOperationPlease($operationName, 'arg1', 'arg2')
+ $operationClient->getMyOperationPlease(Argument::type(Message::class))
->shouldBeCalledOnce()
->willReturn($operation->reveal());
- $operationClient->cancelMyOperationPlease($operationName, 'arg1', 'arg2')
+ $operationClient->cancelMyOperationPlease(Argument::type(Message::class))
->shouldBeCalledOnce()
->willReturn(true);
- $operationClient->deleteMyOperationPlease($operationName, 'arg1', 'arg2')
+ $operationClient->deleteMyOperationPlease(Argument::type(Message::class))
->shouldBeCalledOnce()
->willReturn(true);
$options = [
@@ -481,9 +481,9 @@ public function testPollingCastToInt()
$this->assertEquals($op->getSleeps(), [3, 4, 6]);
}
- public function testReloadWithLROOperationsClient()
+ public function testReloadWithOperationsClient()
{
- $operationClient = $this->prophesize(LROOperationsClient::class);
+ $operationClient = $this->prophesize(OperationsClient::class);
$request = new GetOperationRequest(['name' => 'test-123']);
$operationClient->getOperation($request)
->shouldBeCalledOnce()
@@ -493,9 +493,9 @@ public function testReloadWithLROOperationsClient()
$operationResponse->reload();
}
- public function testCancelWithLROOperationsClient()
+ public function testCancelWithOperationsClient()
{
- $operationClient = $this->prophesize(LROOperationsClient::class);
+ $operationClient = $this->prophesize(OperationsClient::class);
$request = new CancelOperationRequest(['name' => 'test-123']);
$operationClient->cancelOperation($request)
->shouldBeCalledOnce();
@@ -504,9 +504,9 @@ public function testCancelWithLROOperationsClient()
$operationResponse->cancel();
}
- public function testDeleteWithLROOperationsClient()
+ public function testDeleteWithOperationsClient()
{
- $operationClient = $this->prophesize(LROOperationsClient::class);
+ $operationClient = $this->prophesize(OperationsClient::class);
$request = new DeleteOperationRequest(['name' => 'test-123']);
$operationClient->deleteOperation($request)
->shouldBeCalledOnce();
@@ -555,7 +555,7 @@ private function createOperationClient($reloadCount)
$opClient = $this->prophesize(OperationsClient::class);
- $opClient->getOperation(Argument::type('string'))
+ $opClient->getOperation(Argument::type('object'))
->shouldBeCalledTimes($reloadCount)
->willReturn(...$consecutiveCalls);
diff --git a/Gax/tests/Unit/Transport/GrpcTransportTest.php b/Gax/tests/Unit/Transport/GrpcTransportTest.php
index f2c69e1f0401..66a0616e1c86 100644
--- a/Gax/tests/Unit/Transport/GrpcTransportTest.php
+++ b/Gax/tests/Unit/Transport/GrpcTransportTest.php
@@ -35,8 +35,8 @@
use Google\ApiCore\ApiException;
use Google\ApiCore\Call;
use Google\ApiCore\CredentialsWrapper;
-use Google\ApiCore\Testing\MockGrpcTransport;
use Google\ApiCore\Testing\MockRequest;
+use Google\ApiCore\Tests\Testing\MockGrpcTransport;
use Google\ApiCore\Tests\Unit\TestTrait;
use Google\ApiCore\Transport\GrpcTransport;
use Google\ApiCore\ValidationException;
@@ -50,7 +50,6 @@
use Grpc\CallInvoker;
use Grpc\ChannelCredentials;
use Grpc\ClientStreamingCall;
-use Grpc\Interceptor;
use Grpc\ServerStreamingCall;
use Grpc\UnaryCall;
use GuzzleHttp\Promise\Promise;
@@ -668,13 +667,8 @@ public function interceptorDataProvider()
{
$this->autoloadTestdata('mocks', __NAMESPACE__);
- $deprecatedInterceptors = (new \ReflectionClass(Interceptor::class))
- ->getMethod('interceptUnaryUnary')
- ->getParameters()[3]
- ->getName() === 'metadata';
-
- $interceptor = $deprecatedInterceptors ? new DeprecatedTestInterceptor(): new TestInterceptor();
- $unaryInterceptor = $deprecatedInterceptors ? new DeprecatedTestUnaryInterceptor(): new TestUnaryInterceptor();
+ $interceptor = new TestInterceptor();
+ $unaryInterceptor = new TestUnaryInterceptor();
return [
[
diff --git a/Gax/tests/Unit/testdata/mocks/CustomOperation/CustomOperationClient.php b/Gax/tests/Unit/testdata/mocks/CustomOperation/CustomOperationClient.php
index f7d992940db5..1b1b5def6ad2 100644
--- a/Gax/tests/Unit/testdata/mocks/CustomOperation/CustomOperationClient.php
+++ b/Gax/tests/Unit/testdata/mocks/CustomOperation/CustomOperationClient.php
@@ -4,7 +4,7 @@
interface CustomOperationClient
{
- public function getMyOperationPlease($name, $requiredArg1, $requiredArg2);
- public function cancelMyOperationPlease($name, $requiredArg1, $requiredArg2);
- public function deleteMyOperationPlease($name, $requiredArg1, $requiredArg2);
+ public function getMyOperationPlease($request);
+ public function cancelMyOperationPlease($request);
+ public function deleteMyOperationPlease($request);
}
diff --git a/Gax/tests/Unit/testdata/mocks/CustomOperation/GetOperationRequest.php b/Gax/tests/Unit/testdata/mocks/CustomOperation/GetOperationRequest.php
index 7e2783ccb015..31af507fad80 100644
--- a/Gax/tests/Unit/testdata/mocks/CustomOperation/GetOperationRequest.php
+++ b/Gax/tests/Unit/testdata/mocks/CustomOperation/GetOperationRequest.php
@@ -6,9 +6,9 @@ class GetOperationRequest
{
public string $name;
public string $arg2;
- public string $arg3;
+ public string|int $arg3;
- public static function build(string $arg2, string $arg3, string $name): static
+ public static function build(string $arg2, string|int $arg3, string $name): static
{
$request = new static();
$request->name = $name;
diff --git a/Gax/tests/Unit/testdata/mocks/DeprecatedTestInterceptor.php b/Gax/tests/Unit/testdata/mocks/DeprecatedTestInterceptor.php
deleted file mode 100644
index cc625ae4477f..000000000000
--- a/Gax/tests/Unit/testdata/mocks/DeprecatedTestInterceptor.php
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- UnaryInterceptorInterface
- \Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface
-
- Temporary class to support an interceptor-like interface until gRPC interceptor support is
-available.
-
-
-
-
-
-
-
- interceptUnaryUnary
- \Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface::interceptUnaryUnary()
-
-
- method
-
- string
-
-
-
- argument
-
- \Google\Protobuf\Internal\Message
-
-
-
- deserialize
-
- callable
-
-
-
- metadata
-
- array
-
-
-
- options
-
- array
-
-
-
- continuation
-
- callable
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-