diff --git a/src/Transport/GrpcTransport.php b/src/Transport/GrpcTransport.php index 9d1e9af0e..1d8869aab 100644 --- a/src/Transport/GrpcTransport.php +++ b/src/Transport/GrpcTransport.php @@ -60,6 +60,8 @@ class GrpcTransport extends BaseStub implements TransportInterface use GrpcSupportTrait; use ServiceAddressTrait; + private BaseStub $stub; + /** * @param string $hostname * @param array $opts @@ -86,7 +88,7 @@ public function __construct(string $hostname, array $opts, Channel $channel = nu ); } - parent::__construct($hostname, $opts, $channel); + $this->stub = new BaseStub($hostname, $opts, $channel); } /** @@ -177,7 +179,6 @@ public function startBidiStreamingCall(Call $call, array $options) */ public function startClientStreamingCall(Call $call, array $options) { - $this->verifyUniverseDomain($options); return new ClientStream( @@ -254,6 +255,11 @@ function () use ($unaryCall, $options, &$promise) { return $promise; } + public function close() + { + $this->stub->close(); + } + private function verifyUniverseDomain(array $options) { if (isset($options['credentialsWrapper'])) { @@ -283,4 +289,62 @@ private static function loadClientCertSource(callable $clientCertSource) { return call_user_func($clientCertSource); } + + /** FOR TESTING */ + + /** + * @param string $method + * @param array $arguments + * @param callable $deserialize + */ + protected function _simpleRequest( + $method, + $arguments, + $deserialize, + array $metadata = [], + array $options = [] + ) { + return $this->stub->_simpleRequest($method, $arguments, $deserialize, $metadata, $options); + } + + /** + * @param string $method + * @param callable $deserialize + */ + protected function _clientStreamRequest( + $method, + $deserialize, + array $metadata = [], + array $options = [] + ) { + return $this->stub->_clientStreamRequest($method, $deserialize, $metadata, $options); + } + + /** + * @param string $method + * @param array $arguments + * @param callable $deserialize + */ + protected function _serverStreamRequest( + $method, + $arguments, + $deserialize, + array $metadata = [], + array $options = [] + ) { + return $this->stub->_serverStreamRequest($method, $arguments, $deserialize, $metadata, $options); + } + + /** + * @param string $method + * @param callable $deserialize + */ + protected function _bidiRequest( + $method, + $deserialize, + array $metadata = [], + array $options = [] + ) { + return $this->stub->_bidiRequest($method, $deserialize, $metadata, $options); + } } diff --git a/tests/Tests/Unit/Transport/GrpcTransportTest.php b/tests/Tests/Unit/Transport/GrpcTransportTest.php index 9d8e37d70..6ab705746 100644 --- a/tests/Tests/Unit/Transport/GrpcTransportTest.php +++ b/tests/Tests/Unit/Transport/GrpcTransportTest.php @@ -505,21 +505,24 @@ public function buildInvalidData() */ public function testExperimentalInterceptors($callType, $interceptor) { + $mockCallInvoker = new MockCallInvoker($this->buildMockCallForInterceptor($callType)); + $transport = new GrpcTransport( 'example.com', [ - 'credentials' => ChannelCredentials::createInsecure() + 'credentials' => ChannelCredentials::createInsecure(), ], null, [$interceptor] ); - $mockCallInvoker = new MockCallInvoker($this->buildMockCallForInterceptor($callType)); + $r1 = new \ReflectionProperty(GrpcTransport::class, 'stub'); + $r1->setAccessible(true); - $r = new \ReflectionProperty(BaseStub::class, 'call_invoker'); - $r->setAccessible(true); - $r->setValue( - $transport, + $r2 = new \ReflectionProperty(BaseStub::class, 'call_invoker'); + $r2->setAccessible(true); + $r2->setValue( + $r1->getValue($transport), $mockCallInvoker );