示例#1
0
 public function testRequest()
 {
     $id = 909;
     $method = 'service.help';
     $params = ['a', 'b', 'c'];
     $request = new Request($id, $method, $params);
     $this->assertEquals($id, $request->getId());
     $this->assertEquals($method, $request->getMethod());
     $this->assertEquals($params, $request->getParams());
     $written = json_encode(["json-rpc" => "2.0", "id" => $id, "method" => $method, "params" => $params]) . "\n";
     $this->assertEquals($written, $request->write());
 }
示例#2
0
 public function testRequest()
 {
     $expected = new Request(null, 'test.method', [123]);
     $serialized = new Deferred();
     $serialized->promise()->then(function (Request $request) use($expected) {
         $this->assertEquals($expected->getMethod(), $request->getMethod());
         $this->assertEquals($expected->getParams(), $request->getParams());
         $this->assertEquals($expected->write(), func_get_args()[0]);
     }, function ($e) {
         $this->fail($e);
     });
     $stream = $this->getMockStream();
     $stream->expects($this->once())->method('write')->willReturnCallback(function () use(&$serialized) {
         $args = func_get_args();
         if (isset($args[0])) {
             $serialized->resolve($args[0]);
         } else {
             $serialized->reject();
         }
     });
     $factory = new RequestFactory();
     $connection = new Connection($stream, $factory);
     $connection->request('test.method', [123]);
 }