Skip to content

Commit

Permalink
fix: correct method for supportedTransports (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Feb 28, 2024
1 parent 5409e38 commit e7e08da
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/Generation/GapicClientGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function generateClass(): PhpClass
->withMember($this->operationsClient())
->withMember($this->getClientDefaults())
->withMember($this->defaultTransport())
->withMember($this->getSupportedTransports())
->withMember($this->supportedTransports())
->withMembers($this->resourceMethods())
->withMembers($this->operationMethods())
->withMember($this->construct())
Expand Down Expand Up @@ -488,13 +488,13 @@ private function defaultTransport()
));
}

private function getSupportedTransports()
private function supportedTransports()
{
if ($this->serviceDetails->transportType !== Transport::REST) {
return null;
}
return AST::method('getSupportedTransports')
->withPhpDocText('Implements GapicClientTrait::getSupportedTransports.')
return AST::method('supportedTransports')
->withPhpDocText('Implements GapicClientTrait::supportedTransports.')
->withAccess(Access::PRIVATE, Access::STATIC)
->withBody(AST::block(
AST::return(AST::array(['rest']))
Expand Down
8 changes: 4 additions & 4 deletions src/Generation/GapicClientV2Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function generateClass(): PhpClass
->withMember($this->operationsClient())
->withMember($this->getClientDefaults())
->withMember($this->defaultTransport())
->withMember($this->getSupportedTransports())
->withMember($this->supportedTransports())
->withMembers($this->operationMethods())
->withMembers($this->resourceMethods())
->withMember($this->construct())
Expand Down Expand Up @@ -476,13 +476,13 @@ private function defaultTransport()
));
}

private function getSupportedTransports()
private function supportedTransports()
{
if ($this->serviceDetails->transportType !== Transport::REST) {
return null;
}
return AST::method('getSupportedTransports')
->withPhpDocText('Implements GapicClientTrait::getSupportedTransports.')
return AST::method('supportedTransports')
->withPhpDocText('Implements GapicClientTrait::supportedTransports.')
->withAccess(Access::PRIVATE, Access::STATIC)
->withBody(AST::block(
AST::return(AST::array(['rest']))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ private static function defaultTransport()
return 'rest';
}

/** Implements GapicClientTrait::getSupportedTransports. */
private static function getSupportedTransports()
/** Implements GapicClientTrait::supportedTransports. */
private static function supportedTransports()
{
return [
'rest',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ private static function defaultTransport()
return 'rest';
}

/** Implements GapicClientTrait::getSupportedTransports. */
private static function getSupportedTransports()
/** Implements GapicClientTrait::supportedTransports. */
private static function supportedTransports()
{
return [
'rest',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ private static function defaultTransport()
return 'rest';
}

/** Implements GapicClientTrait::getSupportedTransports. */
private static function getSupportedTransports()
/** Implements GapicClientTrait::supportedTransports. */
private static function supportedTransports()
{
return [
'rest',
Expand Down
38 changes: 38 additions & 0 deletions tests/Unit/ProtoTests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare(strict_types=1);

namespace Google\Generator\Tests\Unit\ProtoTests;

use PHPUnit\Framework\TestCase;
use Testing\BasicDiregapic\LibraryClient;
use Google\ApiCore\InsecureCredentialsWrapper;
use Google\ApiCore\ValidationException;

final class ClientTest extends TestCase
{
public function testUnsupportedTransportThrowsException()
{
$this->expectException(ValidationException::class);
$this->expectExceptionMessage('Unexpected transport option "grpc". Supported transports: rest');

$client = new LibraryClient([
'transport' => 'grpc',
'credentials' => new InsecureCredentialsWrapper(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ private static function defaultTransport()
return 'rest';
}

/** Implements GapicClientTrait::getSupportedTransports. */
private static function getSupportedTransports()
/** Implements GapicClientTrait::supportedTransports. */
private static function supportedTransports()
{
return [
'rest',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private static function defaultTransport()
return 'rest';
}

/** Implements GapicClientTrait::getSupportedTransports. */
private static function getSupportedTransports()
/** Implements GapicClientTrait::supportedTransports. */
private static function supportedTransports()
{
return [
'rest',
Expand Down

0 comments on commit e7e08da

Please sign in to comment.