Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 66 additions & 2 deletions src/Transport/GrpcTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class GrpcTransport extends BaseStub implements TransportInterface
use GrpcSupportTrait;
use ServiceAddressTrait;

private BaseStub $stub;

/**
* @param string $hostname
* @param array $opts
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -177,7 +179,6 @@ public function startBidiStreamingCall(Call $call, array $options)
*/
public function startClientStreamingCall(Call $call, array $options)
{

$this->verifyUniverseDomain($options);

return new ClientStream(
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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);
}
}
15 changes: 9 additions & 6 deletions tests/Tests/Unit/Transport/GrpcTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down