Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Sep 18, 2024
1 parent d5e5245 commit a53fc3d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
66 changes: 62 additions & 4 deletions src/Transport/GrpcTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function startBidiStreamingCall(Call $call, array $options)
$this->verifyUniverseDomain($options);

return new BidiStream(
$this->client->bidiRequest(
$this->_bidiRequest(
'/' . $call->getMethod(),
[$call->getDecodeType(), 'decode'],
isset($options['headers']) ? $options['headers'] : [],
Expand All @@ -176,7 +176,7 @@ public function startClientStreamingCall(Call $call, array $options)
$this->verifyUniverseDomain($options);

return new ClientStream(
$this->client->clientStreamRequest(
$this->_clientStreamRequest(
'/' . $call->getMethod(),
[$call->getDecodeType(), 'decode'],
isset($options['headers']) ? $options['headers'] : [],
Expand All @@ -200,7 +200,7 @@ public function startServerStreamingCall(Call $call, array $options)
}

// This simultaenously creates and starts a \Grpc\ServerStreamingCall.
$stream = $this->client->serverStreamRequest(
$stream = $this->_serverStreamRequest(
'/' . $call->getMethod(),
$message,
[$call->getDecodeType(), 'decode'],
Expand All @@ -220,7 +220,7 @@ public function startUnaryCall(Call $call, array $options)
{
$this->verifyUniverseDomain($options);

$unaryCall = $this->client->simpleRequest(
$unaryCall = $this->_simpleRequest(
'/' . $call->getMethod(),
$call->getMessage(),
[$call->getDecodeType(), 'decode'],
Expand Down Expand Up @@ -283,4 +283,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->client->simpleRequest($method, $arguments, $deserialize, $metadata, $options);
}

/**
* @param string $method
* @param callable $deserialize
*/
protected function _clientStreamRequest(
$method,
$deserialize,
array $metadata = [],
array $options = []
) {
return $this->client->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->client->serverStreamRequest($method, $arguments, $deserialize, $metadata, $options);
}

/**
* @param string $method
* @param callable $deserialize
*/
protected function _bidiRequest(
$method,
$deserialize,
array $metadata = [],
array $options = []
) {
return $this->client->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, 'client');
$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

0 comments on commit a53fc3d

Please sign in to comment.