server = new \Grpc\RpcServer(); $this->mockService = $this->getMockBuilder(stdClass::class) ->setMethods(['getMethodDescriptors', 'hello']) ->getMock(); } public function testHandleServices() { $helloMethodDescriptor = new \Grpc\MethodDescriptor( $this->mockService, 'hello', 'String', \Grpc\MethodDescriptor::UNARY_CALL ); $this->mockService->expects($this->once()) ->method('getMethodDescriptors') ->with() ->will($this->returnValue([ '/test/hello' => $helloMethodDescriptor ])); $pathMap = $this->server->handle($this->mockService); $this->assertEquals($pathMap, [ '/test/hello' => $helloMethodDescriptor ]); $mockService2 = $this->getMockBuilder(stdClass::class) ->setMethods(['getMethodDescriptors', 'hello', 'bye']) ->getMock(); $helloMethodDescriptor2 = new \Grpc\MethodDescriptor( $this->mockService, 'hello', 'Number', \Grpc\MethodDescriptor::UNARY_CALL ); $byeMethodDescritor = new \Grpc\MethodDescriptor( $this->mockService, 'bye', 'String', \Grpc\MethodDescriptor::UNARY_CALL ); $mockService2->expects($this->once()) ->method('getMethodDescriptors') ->with() ->will($this->returnValue([ '/test/hello' => $helloMethodDescriptor2, '/test/bye' => $byeMethodDescritor ])); $pathMap = $this->server->handle($mockService2); $this->assertEquals($pathMap, [ '/test/hello' => $helloMethodDescriptor2, '/test/bye' => $byeMethodDescritor ]); } }