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());
 }
示例#2
0
 /**
  * @param string $name
  * @param array  $values
  *
  * @return \google\protobuf\ServiceDescriptorProto
  */
 protected function createServiceDescriptorProto($name, array $values = [])
 {
     $descriptor = new ServiceDescriptorProto();
     $descriptor->setName($name);
     return $descriptor;
 }