Add callable test case

This commit is contained in:
huangzhhui 2020-04-08 19:21:18 +08:00
parent c5bb2c7145
commit 6918e1e44c
3 changed files with 30 additions and 0 deletions

View File

@ -142,6 +142,29 @@ class RpcServiceClientTest extends TestCase
$this->assertEquals($uniqid, $ret);
}
public function testProxyCallableParameterAndReturnArray()
{
$container = $this->createContainer();
/** @var MockInterface $transporter */
$transporter = $container->get(JsonRpcTransporter::class);
$transporter->shouldReceive('setLoadBalancer')
->andReturnSelf();
$transporter->shouldReceive('send')
->andReturnUsing(function ($data) {
$data = json_decode($data, true);
return json_encode([
'id' => $data['id'],
'result' => $data['params'],
]);
});
$factory = new ProxyFactory();
$proxyClass = $factory->createProxy(CalculatorServiceInterface::class);
/** @var CalculatorServiceInterface $service */
$service = new $proxyClass($container, CalculatorServiceInterface::class, 'jsonrpc');
$ret = $service->callable(function () {}, null);
$this->assertEquals([[], null], $ret);
}
public function testProxyFactoryWithErrorId()
{
$container = $this->createContainer();

View File

@ -45,4 +45,9 @@ class CalculatorProxyServiceClient extends AbstractProxyService implements Calcu
{
return $this->client->__call(__FUNCTION__, func_get_args());
}
public function callable(callable $a, ?callable $b): array
{
return $this->client->__call(__FUNCTION__, func_get_args());
}
}

View File

@ -25,4 +25,6 @@ interface CalculatorServiceInterface
public function error();
public function getString(): ?string;
public function callable(callable $a, ?callable $b): array ;
}