public function testBatchJsonRpcRequest() { $request = BatchJsonRpcRequest::create()->addRequest(new SingleJsonRpcRequest('noParamsMethod', null, 1))->addRequest(new SingleJsonRpcRequest('noParamsMethod', 'ssdf', 2))->addRequest(new SingleJsonRpcRequest('mathMethod', null, 3))->addRequest(new NotificationJsonRpcRequest('mathMethod', array(1, 2)))->addRequest(new SingleJsonRpcRequest('mathMethod', array(10, 5), 4))->addRequest(new NotificationJsonRpcRequest('notExistsMethod', array(1, 2)))->addRequest(new SingleJsonRpcRequest('notExistsMethod', array(1, 4), 'nonexist'))->addRequest(new SingleJsonRpcRequest('errorMethod', null, 'errormethod')); // Test for BatchJsonRequest::getRequestById $req = $request->getRequestById('nonexist'); $this->assertEquals('nonexist', $req->getId()); $this->assertEquals('notExistsMethod', $req->getMethod()); $this->assertEquals(array(1, 4), $req->getParams()); $req = $request->getRequestById('asdf'); $this->assertNull($req); // End }
public function testBatchRequest() { $request = BatchJsonRpcRequest::create()->addRequest(new SingleJsonRpcRequest('noParamsMethod', null, 1))->addRequest(new SingleJsonRpcRequest('noParamsMethod', 'ssdf', 2))->addRequest(new SingleJsonRpcRequest('mathMethod', null, 3))->addRequest(new NotificationJsonRpcRequest('mathMethod', array(1, 2)))->addRequest(new SingleJsonRpcRequest('mathMethod', array(10, 5), 4))->addRequest(new NotificationJsonRpcRequest('notExistsMethod', array(1, 2)))->addRequest(new SingleJsonRpcRequest('notExistsMethod', array(1, 4), 'nonexist'))->addRequest(new SingleJsonRpcRequest('errorMethod', null, 'errormethod')); $response = $this->client->makeBatchRequest($request); $rows = $response->getAllResponses(); $this->assertCount(6, $rows); $errormethod = $response->getResponseById('errormethod'); $this->assertTrue($errormethod->isError()); $this->assertNotFalse($errormethod->getErrorData()); $this->assertEquals(JsonRpcException::ERROR_INTERNAL_ERROR, $errormethod->getErrorCode()); $method = $response->getResponseById('1'); $this->assertTrue($method->isSuccess()); $this->assertEquals('answer', $method->getResult()); $method = $response->getResponseById('4'); $this->assertTrue($method->isSuccess()); $this->assertEquals(10 - 5, $method->getResult()); $method = $response->getResponseById('errormethod'); $this->assertTrue($method->isError()); $this->assertEquals(JsonRpcException::ERROR_INTERNAL_ERROR, $method->getErrorCode()); $this->assertNotEmpty($method->getErrorData()); }