/** * @covers \Aveiv\JsonRpc\FrontController\FrontController::handle * @covers \Aveiv\JsonRpc\FrontController\FrontController::normalizeJson * @covers \Aveiv\JsonRpc\FrontController\FrontController::successResponse */ public function testValidRequest() { $this->methodCaller->expects($this->exactly(3))->method('call')->withConsecutive(['method_name'], ['method_name', ['test_param'], 999], ['method_name'])->willReturn(['key' => 'value']); $resultJson = $this->frontController->handle('{"jsonrpc":"2.0","method":"method_name"}'); $this->assertJsonStringEqualsJsonString($resultJson, '{"jsonrpc":"2.0","result":{"key": "value"},"id":null}'); $resultJson = $this->frontController->handle('{"jsonrpc":"2.0","method":"method_name","params":["test_param"],"id":999}'); $this->assertJsonStringEqualsJsonString($resultJson, '{"jsonrpc":"2.0","result":{"key": "value"},"id":999}'); $serializationContext = $this->getMock(SerializationContext::class); $serializer = $this->getMock(SerializerInterface::class); $serializer->expects($this->once())->method('serialize')->with(['key' => 'value'], 'json', $serializationContext)->willReturn('{"key":"value"}'); /** @noinspection PhpParamsInspection */ $this->frontController->setSerializer($serializer); /** @noinspection PhpParamsInspection */ $this->frontController->setSerializationContext($serializationContext); $resultJson = $this->frontController->handle('{"jsonrpc":"2.0","method":"method_name"}'); $this->assertJsonStringEqualsJsonString($resultJson, '{"jsonrpc":"2.0","result":{"key": "value"},"id":null}'); }