mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 11:48:08 +08:00
Add callable test case
This commit is contained in:
parent
c5bb2c7145
commit
6918e1e44c
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -25,4 +25,6 @@ interface CalculatorServiceInterface
|
||||
public function error();
|
||||
|
||||
public function getString(): ?string;
|
||||
|
||||
public function callable(callable $a, ?callable $b): array ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user