From 6918e1e44cd4e2b80032fa8b39c372fb8a0e90b0 Mon Sep 17 00:00:00 2001 From: huangzhhui Date: Wed, 8 Apr 2020 19:21:18 +0800 Subject: [PATCH] Add callable test case --- src/json-rpc/tests/RpcServiceClientTest.php | 23 +++++++++++++++++++ .../Stub/CalculatorProxyServiceClient.php | 5 ++++ .../tests/Stub/CalculatorServiceInterface.php | 2 ++ 3 files changed, 30 insertions(+) diff --git a/src/json-rpc/tests/RpcServiceClientTest.php b/src/json-rpc/tests/RpcServiceClientTest.php index 437c1c00a..4874fc6e1 100644 --- a/src/json-rpc/tests/RpcServiceClientTest.php +++ b/src/json-rpc/tests/RpcServiceClientTest.php @@ -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(); diff --git a/src/json-rpc/tests/Stub/CalculatorProxyServiceClient.php b/src/json-rpc/tests/Stub/CalculatorProxyServiceClient.php index d69de9a8f..72d6f0ce6 100644 --- a/src/json-rpc/tests/Stub/CalculatorProxyServiceClient.php +++ b/src/json-rpc/tests/Stub/CalculatorProxyServiceClient.php @@ -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()); + } } diff --git a/src/json-rpc/tests/Stub/CalculatorServiceInterface.php b/src/json-rpc/tests/Stub/CalculatorServiceInterface.php index 4cd7f9dc4..d22bc4fc1 100644 --- a/src/json-rpc/tests/Stub/CalculatorServiceInterface.php +++ b/src/json-rpc/tests/Stub/CalculatorServiceInterface.php @@ -25,4 +25,6 @@ interface CalculatorServiceInterface public function error(); public function getString(): ?string; + + public function callable(callable $a, ?callable $b): array ; }