diff --git a/composer.json b/composer.json index 810351fed..9eb581475 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "guzzlehttp/promises": "^2.0", "guzzlehttp/psr7": "^2.0", "google/common-protos": "^4.4", - "google/longrunning": "~0.4", + "google/longrunning": "~0.4||^1.0", "ramsey/uuid": "^4.0" }, "require-dev": { diff --git a/dev/src/Docs/doctum-protobuf-config.php b/dev/src/Docs/doctum-protobuf-config.php index e0efa81bd..6b98b37c9 100644 --- a/dev/src/Docs/doctum-protobuf-config.php +++ b/dev/src/Docs/doctum-protobuf-config.php @@ -1,4 +1,6 @@ credentialsFetcher->getLastReceivedToken(); - if (self::isExpired($token)) { - $this->checkUniverseDomain(); - - $token = $this->credentialsFetcher->fetchAuthToken($this->authHttpHandler); - if (!self::isValid($token)) { - return ''; - } - } - return empty($token['access_token']) ? '' : 'Bearer ' . $token['access_token']; - } - /** * @param string $audience optional audience for self-signed JWTs. * @return callable Callable function that returns an authorization header. diff --git a/src/FixedSizeCollection.php b/src/FixedSizeCollection.php index 03ec835c1..13d4f3219 100644 --- a/src/FixedSizeCollection.php +++ b/src/FixedSizeCollection.php @@ -1,4 +1,6 @@ \Google\Rpc\RetryInfo::class, 'google.rpc.debuginfo-bin' => \Google\Rpc\DebugInfo::class, diff --git a/src/Middleware/CredentialsWrapperMiddleware.php b/src/Middleware/CredentialsWrapperMiddleware.php index 086df0ef0..e406e7766 100644 --- a/src/Middleware/CredentialsWrapperMiddleware.php +++ b/src/Middleware/CredentialsWrapperMiddleware.php @@ -1,4 +1,6 @@ setTransportOptions($transportSpecificOptions); - - return $this; - } - /** * @param RetrySettings|array|null $retrySettings * diff --git a/src/Options/ClientOptions.php b/src/Options/ClientOptions.php index b9677fe20..994bbc81b 100644 --- a/src/Options/ClientOptions.php +++ b/src/Options/ClientOptions.php @@ -1,4 +1,6 @@ getCurrentTimeMillis() > $endTime) { return false; } - $this->sleepMillis($currentPollDelayMillis); + $this->sleepMillis((int) $currentPollDelayMillis); if ($pollCallable()) { return true; } diff --git a/src/RequestBuilder.php b/src/RequestBuilder.php index b0d589dc4..246991c1f 100644 --- a/src/RequestBuilder.php +++ b/src/RequestBuilder.php @@ -1,4 +1,6 @@ renderingException($bindings, "missing required binding '$key' for segment '$segment'"); } $value = $bindings[$key]; - if (!is_null($value) && $segment->matches($value)) { + if (!is_null($value) && $segment->matches((string) $value)) { $literalSegments[] = new Segment( Segment::LITERAL_SEGMENT, - $value, + (string) $value, $segment->getValue(), $segment->getTemplate(), $segment->getSeparator() diff --git a/src/ResourceTemplate/ResourceTemplateInterface.php b/src/ResourceTemplate/ResourceTemplateInterface.php index ffa3c8138..d5cb1357f 100644 --- a/src/ResourceTemplate/ResourceTemplateInterface.php +++ b/src/ResourceTemplate/ResourceTemplateInterface.php @@ -1,4 +1,6 @@ $values) { foreach ($values as $value) { $decodedValue = ['@type' => $key]; - if (self::hasBinaryHeaderSuffix($key)) { + if (is_string($key) && self::hasBinaryHeaderSuffix($key)) { if (isset(KnownTypes::BIN_TYPES[$key])) { $class = KnownTypes::BIN_TYPES[$key]; /** @var Message $message */ diff --git a/src/ServerStream.php b/src/ServerStream.php index 3257e6550..c659041c5 100644 --- a/src/ServerStream.php +++ b/src/ServerStream.php @@ -1,4 +1,6 @@ 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']) { diff --git a/src/Transport/GrpcTransport.php b/src/Transport/GrpcTransport.php index 5fd03a6fe..188133546 100644 --- a/src/Transport/GrpcTransport.php +++ b/src/Transport/GrpcTransport.php @@ -1,4 +1,6 @@ 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/src/Transport/HttpUnaryTransportTrait.php b/src/Transport/HttpUnaryTransportTrait.php index 38c4ca1f5..8a9b3bea1 100644 --- a/src/Transport/HttpUnaryTransportTrait.php +++ b/src/Transport/HttpUnaryTransportTrait.php @@ -1,4 +1,6 @@ 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); diff --git a/src/Transport/TransportInterface.php b/src/Transport/TransportInterface.php index 682a43019..8ae6d918c 100644 --- a/src/Transport/TransportInterface.php +++ b/src/Transport/TransportInterface.php @@ -1,4 +1,6 @@ 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/tests/Unit/CredentialsWrapperTest.php b/tests/Unit/CredentialsWrapperTest.php index ca58ceadf..3b6b28b40 100644 --- a/tests/Unit/CredentialsWrapperTest.php +++ b/tests/Unit/CredentialsWrapperTest.php @@ -218,39 +218,6 @@ public function testCheckUniverseDomainFails(?string $universeDomain, ?string $c $credentialsWrapper->getAuthorizationHeaderCallback()(); } - /** - * Same test as above, but calls the deprecated CredentialsWrapper::getBearerString method - * instead of CredentialsWrapper::getAuthorizationHeaderCallback - * @dataProvider provideCheckUniverseDomainFails - */ - public function testCheckUniverseDomainOnGetBearerStringFails( - ?string $universeDomain, - ?string $credentialsUniverse, - ?string $message = null - ) { - $this->expectException(ValidationException::class); - $this->expectExceptionMessage($message ?: sprintf( - 'The configured universe domain (%s) does not match the credential universe domain (%s)', - is_null($universeDomain) ? GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN : $universeDomain, - is_null($credentialsUniverse) ? GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN : $credentialsUniverse, - )); - $fetcher = $this->prophesize(FetchAuthTokenInterface::class); - // When the $credentialsUniverse is null, the fetcher doesn't implement GetUniverseDomainInterface - if (!is_null($credentialsUniverse)) { - $fetcher->willImplement(GetUniverseDomainInterface::class); - $fetcher->getUniverseDomain()->willReturn($credentialsUniverse); - } - $fetcher->getLastReceivedToken()->willReturn(null); - // When $universeDomain is null, it means no $universeDomain argument was provided - if (is_null($universeDomain)) { - $credentialsWrapper = new CredentialsWrapper($fetcher->reveal()); - } else { - $credentialsWrapper = new CredentialsWrapper($fetcher->reveal(), null, $universeDomain); - } - // Check getBearerString (deprecated) - $credentialsWrapper->getBearerString(); - } - public function provideCheckUniverseDomainFails() { return [ @@ -286,11 +253,6 @@ public function testCheckUniverseDomainPasses(?string $universeDomain, ?string $ ['authorization' => ['Bearer abc']], $credentialsWrapper->getAuthorizationHeaderCallback()() ); - // Check getBearerString (deprecated) - $this->assertEquals( - 'Bearer abc', - $credentialsWrapper->getBearerString() - ); } public function provideCheckUniverseDomainPasses() @@ -316,67 +278,6 @@ public function testCheckUniverseDomainOnGceCredentialsDoesNotCheck() $credentialsWrapper->checkUniverseDomain(); } - /** - * @dataProvider getBearerStringData - */ - public function testGetBearerString($fetcher, $expectedBearerString) - { - $credentialsWrapper = new CredentialsWrapper($fetcher); - $bearerString = $credentialsWrapper->getBearerString(); - $this->assertSame($expectedBearerString, $bearerString); - } - - public function getBearerStringData() - { - $expiredFetcher = $this->prophesize(FetchAuthTokenInterface::class); - $expiredFetcher->getLastReceivedToken() - ->willReturn([ - 'access_token' => 123, - 'expires_at' => time() - 1 - ]); - $expiredFetcher->fetchAuthToken(Argument::any()) - ->willReturn([ - 'access_token' => 456, - 'expires_at' => time() + 1000 - ]); - $eagerExpiredFetcher = $this->prophesize(FetchAuthTokenInterface::class); - $eagerExpiredFetcher->getLastReceivedToken() - ->willReturn([ - 'access_token' => 123, - 'expires_at' => time() + 1 - ]); - $eagerExpiredFetcher->fetchAuthToken(Argument::any()) - ->willReturn([ - 'access_token' => 456, - 'expires_at' => time() + 10 // within 10 second eager threshold - ]); - $unexpiredFetcher = $this->prophesize(FetchAuthTokenInterface::class); - $unexpiredFetcher->getLastReceivedToken() - ->willReturn([ - 'access_token' => 123, - 'expires_at' => time() + 100, - ]); - $insecureFetcher = $this->prophesize(FetchAuthTokenInterface::class); - $insecureFetcher->getLastReceivedToken()->willReturn(null); - $insecureFetcher->fetchAuthToken(Argument::any()) - ->willReturn([ - 'access_token' => '', - ]); - $nullFetcher = $this->prophesize(FetchAuthTokenInterface::class); - $nullFetcher->getLastReceivedToken()->willReturn(null); - $nullFetcher->fetchAuthToken(Argument::any()) - ->willReturn([ - 'access_token' => null, - ]); - return [ - [$expiredFetcher->reveal(), 'Bearer 456'], - [$eagerExpiredFetcher->reveal(), 'Bearer 456'], - [$unexpiredFetcher->reveal(), 'Bearer 123'], - [$insecureFetcher->reveal(), ''], - [$nullFetcher->reveal(), ''] - ]; - } - /** * @dataProvider getAuthorizationHeaderCallbackData */ diff --git a/tests/Unit/Middleware/OperationsMiddlewareTest.php b/tests/Unit/Middleware/OperationsMiddlewareTest.php index 7d7dac941..1c264ae76 100644 --- a/tests/Unit/Middleware/OperationsMiddlewareTest.php +++ b/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/tests/Unit/testdata/src/GapicClientStub.php b/tests/Unit/testdata/src/GapicClientStub.php index ce1eff153..d045f427d 100644 --- a/tests/Unit/testdata/src/GapicClientStub.php +++ b/tests/Unit/testdata/src/GapicClientStub.php @@ -1,4 +1,6 @@