1ffe3c632Sopenharmony_ci<?php 2ffe3c632Sopenharmony_ci 3ffe3c632Sopenharmony_cirequire_once('test_base.php'); 4ffe3c632Sopenharmony_cirequire_once('test_util.php'); 5ffe3c632Sopenharmony_ci 6ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\RepeatedField; 7ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\MapField; 8ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\GPBType; 9ffe3c632Sopenharmony_ciuse Foo\Greeter; 10ffe3c632Sopenharmony_ciuse Foo\HelloRequest; 11ffe3c632Sopenharmony_ciuse Foo\HelloReply; 12ffe3c632Sopenharmony_ci 13ffe3c632Sopenharmony_ciclass GeneratedServiceTest extends TestBase 14ffe3c632Sopenharmony_ci{ 15ffe3c632Sopenharmony_ci /** 16ffe3c632Sopenharmony_ci * @var \ReflectionClass 17ffe3c632Sopenharmony_ci */ 18ffe3c632Sopenharmony_ci private $serviceClass; 19ffe3c632Sopenharmony_ci 20ffe3c632Sopenharmony_ci /** 21ffe3c632Sopenharmony_ci * @var \ReflectionClass 22ffe3c632Sopenharmony_ci */ 23ffe3c632Sopenharmony_ci private $namespacedServiceClass; 24ffe3c632Sopenharmony_ci 25ffe3c632Sopenharmony_ci /** 26ffe3c632Sopenharmony_ci * @var array 27ffe3c632Sopenharmony_ci */ 28ffe3c632Sopenharmony_ci private $methodNames = [ 29ffe3c632Sopenharmony_ci 'sayHello', 30ffe3c632Sopenharmony_ci 'sayHelloAgain' 31ffe3c632Sopenharmony_ci ]; 32ffe3c632Sopenharmony_ci 33ffe3c632Sopenharmony_ci public function setUp() 34ffe3c632Sopenharmony_ci { 35ffe3c632Sopenharmony_ci parent::setUp(); 36ffe3c632Sopenharmony_ci 37ffe3c632Sopenharmony_ci $this->serviceClass = new ReflectionClass('Foo\GreeterInterface'); 38ffe3c632Sopenharmony_ci 39ffe3c632Sopenharmony_ci $this->namespacedServiceClass = new ReflectionClass('Bar\OtherGreeterInterface'); 40ffe3c632Sopenharmony_ci } 41ffe3c632Sopenharmony_ci 42ffe3c632Sopenharmony_ci public function testIsInterface() 43ffe3c632Sopenharmony_ci { 44ffe3c632Sopenharmony_ci $this->assertTrue($this->serviceClass->isInterface()); 45ffe3c632Sopenharmony_ci } 46ffe3c632Sopenharmony_ci 47ffe3c632Sopenharmony_ci public function testPhpDocForClass() 48ffe3c632Sopenharmony_ci { 49ffe3c632Sopenharmony_ci $this->assertContains('foo.Greeter', $this->serviceClass->getDocComment()); 50ffe3c632Sopenharmony_ci } 51ffe3c632Sopenharmony_ci 52ffe3c632Sopenharmony_ci public function testPhpDocForNamespacedClass() 53ffe3c632Sopenharmony_ci { 54ffe3c632Sopenharmony_ci $this->assertContains('foo.OtherGreeter', $this->namespacedServiceClass->getDocComment()); 55ffe3c632Sopenharmony_ci } 56ffe3c632Sopenharmony_ci 57ffe3c632Sopenharmony_ci public function testServiceMethodsAreGenerated() 58ffe3c632Sopenharmony_ci { 59ffe3c632Sopenharmony_ci $this->assertCount(count($this->methodNames), $this->serviceClass->getMethods()); 60ffe3c632Sopenharmony_ci foreach ($this->methodNames as $methodName) { 61ffe3c632Sopenharmony_ci $this->assertTrue($this->serviceClass->hasMethod($methodName)); 62ffe3c632Sopenharmony_ci } 63ffe3c632Sopenharmony_ci } 64ffe3c632Sopenharmony_ci 65ffe3c632Sopenharmony_ci public function testPhpDocForServiceMethod() 66ffe3c632Sopenharmony_ci { 67ffe3c632Sopenharmony_ci foreach ($this->methodNames as $methodName) { 68ffe3c632Sopenharmony_ci $docComment = $this->serviceClass->getMethod($methodName)->getDocComment(); 69ffe3c632Sopenharmony_ci $this->assertContains($methodName, $docComment); 70ffe3c632Sopenharmony_ci $this->assertContains('@param \Foo\HelloRequest $request', $docComment); 71ffe3c632Sopenharmony_ci $this->assertContains('@return \Foo\HelloReply', $docComment); 72ffe3c632Sopenharmony_ci } 73ffe3c632Sopenharmony_ci } 74ffe3c632Sopenharmony_ci 75ffe3c632Sopenharmony_ci public function testPhpDocForServiceMethodInNamespacedClass() 76ffe3c632Sopenharmony_ci { 77ffe3c632Sopenharmony_ci foreach ($this->methodNames as $methodName) { 78ffe3c632Sopenharmony_ci $docComment = $this->namespacedServiceClass->getMethod($methodName)->getDocComment(); 79ffe3c632Sopenharmony_ci $this->assertContains($methodName, $docComment); 80ffe3c632Sopenharmony_ci $this->assertContains('@param \Foo\HelloRequest $request', $docComment); 81ffe3c632Sopenharmony_ci $this->assertContains('@return \Foo\HelloReply', $docComment); 82ffe3c632Sopenharmony_ci } 83ffe3c632Sopenharmony_ci } 84ffe3c632Sopenharmony_ci 85ffe3c632Sopenharmony_ci public function testParamForServiceMethod() 86ffe3c632Sopenharmony_ci { 87ffe3c632Sopenharmony_ci foreach ($this->methodNames as $methodName) { 88ffe3c632Sopenharmony_ci $method = $this->serviceClass->getMethod($methodName); 89ffe3c632Sopenharmony_ci $this->assertCount(1, $method->getParameters()); 90ffe3c632Sopenharmony_ci $param = $method->getParameters()[0]; 91ffe3c632Sopenharmony_ci $this->assertFalse($param->isOptional()); 92ffe3c632Sopenharmony_ci $this->assertSame('request', $param->getName()); 93ffe3c632Sopenharmony_ci // ReflectionParameter::getType only exists in PHP 7+, so get the type from __toString 94ffe3c632Sopenharmony_ci $this->assertContains('Foo\HelloRequest $request', (string) $param); 95ffe3c632Sopenharmony_ci } 96ffe3c632Sopenharmony_ci } 97ffe3c632Sopenharmony_ci 98ffe3c632Sopenharmony_ci public function testParamForServiceMethodInNamespacedClass() 99ffe3c632Sopenharmony_ci { 100ffe3c632Sopenharmony_ci foreach ($this->methodNames as $methodName) { 101ffe3c632Sopenharmony_ci $method = $this->serviceClass->getMethod($methodName); 102ffe3c632Sopenharmony_ci $this->assertCount(1, $method->getParameters()); 103ffe3c632Sopenharmony_ci $param = $method->getParameters()[0]; 104ffe3c632Sopenharmony_ci $this->assertFalse($param->isOptional()); 105ffe3c632Sopenharmony_ci $this->assertSame('request', $param->getName()); 106ffe3c632Sopenharmony_ci // ReflectionParameter::getType only exists in PHP 7+, so get the type from __toString 107ffe3c632Sopenharmony_ci $this->assertContains('Foo\HelloRequest $request', (string) $param); 108ffe3c632Sopenharmony_ci } 109ffe3c632Sopenharmony_ci } 110ffe3c632Sopenharmony_ci} 111