public function testService() { $serviceDesc = new ServiceDescriptorProto(); $methodDesc = new MethodDescriptorProto(); // rpc search (SearchRequest) returns (SearchResponse); $methodDesc->setName('search'); $methodDesc->setInputType('.ProtobufCompilerTest.Protos.Service.SearchRequest'); $methodDesc->setOutputType('.ProtobufCompilerTest.Protos.Service.SearchResponse'); $serviceDesc->setName('SearchService'); $serviceDesc->addMethod($methodDesc); $context = $this->createContext([['name' => 'service.proto', 'package' => 'ProtobufCompilerTest.Protos.Service', 'values' => ['services' => [$serviceDesc], 'messages' => [['name' => 'SearchRequest', 'fields' => []], ['name' => 'SearchResponse', 'fields' => []]]]]]); $expected = $this->getFixtureFileContent('Service/SearchService.tpl'); $className = 'ProtobufCompilerTest.Protos.Service.SearchService'; $entity = $context->getEntity($className); $generator = new Generator($context); $generator->visit($entity); // file_put_contents(__DIR__ . '/Fixtures/Service/SearchService.tpl', $entity->getContent()); $this->assertEquals($expected, $entity->getContent()); }
/** * @param \google\protobuf\MethodDescriptorProto $method * * @return string */ protected function getMethodOutputDocblock(MethodDescriptorProto $method) { $refType = $method->getOutputType(); $refEntity = $this->getEntity($refType); $refClass = $this->getMethodOutputTypeHint($method); if ($method->getServerStreaming()) { return sprintf('\\Iterator<%s>', $refEntity->getNamespacedName()); } return $refClass; }