generated_phpdoc_test.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. require_once('generated/NoNamespaceEnum.php');
  3. require_once('generated/NoNamespaceMessage.php');
  4. require_once('test_base.php');
  5. require_once('test_util.php');
  6. use Foo\TestMessage;
  7. class GeneratedPhpdocTest extends TestBase
  8. {
  9. public function testPhpDocForClass()
  10. {
  11. $class = new ReflectionClass('Foo\TestMessage');
  12. $doc = $class->getDocComment();
  13. $this->assertContains('foo.TestMessage', $doc);
  14. }
  15. public function testPhpDocForConstructor()
  16. {
  17. $class = new ReflectionClass('Foo\TestMessage');
  18. $doc = $class->getMethod('__construct')->getDocComment();
  19. $this->assertContains('@param array $data', $doc);
  20. $this->assertContains('@type int $optional_int32', $doc);
  21. }
  22. /**
  23. * @dataProvider providePhpDocForGettersAndSetters
  24. */
  25. public function testPhpDocForIntGetters($methods, $expectedDoc)
  26. {
  27. $class = new ReflectionClass('Foo\TestMessage');
  28. foreach ($methods as $method) {
  29. $doc = $class->getMethod($method)->getDocComment();
  30. $this->assertContains($expectedDoc, $doc);
  31. }
  32. }
  33. public function providePhpDocForGettersAndSetters()
  34. {
  35. return [
  36. [
  37. [
  38. 'setOptionalInt32',
  39. 'setOptionalUint32',
  40. 'setOptionalSint32',
  41. 'setOptionalFixed32',
  42. 'setOptionalSfixed32',
  43. 'setOneofInt32',
  44. 'setOneofUint32',
  45. 'setOneofSint32',
  46. 'setOneofFixed32',
  47. 'setOneofSfixed32',
  48. 'setOptionalEnum',
  49. 'setOptionalNoNamespaceEnum',
  50. 'setOptionalNestedEnum',
  51. 'setOneofEnum'
  52. ],
  53. '@param int $var'
  54. ],
  55. [
  56. [
  57. 'setOptionalInt64',
  58. 'setOptionalUint64',
  59. 'setOptionalSint64',
  60. 'setOptionalFixed64',
  61. 'setOptionalSfixed64',
  62. 'setOneofInt64',
  63. 'setOneofUint64',
  64. 'setOneofSint64',
  65. 'setOneofFixed64',
  66. 'setOneofSfixed64',
  67. ],
  68. '@param int|string $var'
  69. ],
  70. [
  71. [
  72. 'getOptionalInt32',
  73. 'getOptionalUint32',
  74. 'getOptionalSint32',
  75. 'getOptionalFixed32',
  76. 'getOptionalSfixed32',
  77. 'getOneofInt32',
  78. 'getOneofUint32',
  79. 'getOneofSint32',
  80. 'getOneofFixed32',
  81. 'getOneofSfixed32',
  82. 'getOptionalEnum',
  83. 'getOptionalNoNamespaceEnum',
  84. 'getOptionalNestedEnum',
  85. 'getOneofEnum',
  86. ],
  87. '@return int'
  88. ],
  89. [
  90. [
  91. 'setOptionalInt64',
  92. 'setOptionalUint64',
  93. 'setOptionalSint64',
  94. 'setOptionalFixed64',
  95. 'setOptionalSfixed64',
  96. 'setOneofInt64',
  97. 'setOneofUint64',
  98. 'setOneofSint64',
  99. 'setOneofFixed64',
  100. 'setOneofSfixed64',
  101. ],
  102. '@param int|string $var'
  103. ],
  104. [
  105. [
  106. 'getRepeatedInt32',
  107. 'getRepeatedInt64',
  108. 'getRepeatedUint32',
  109. 'getRepeatedUint64',
  110. 'getRepeatedSint32',
  111. 'getRepeatedSint64',
  112. 'getRepeatedFixed32',
  113. 'getRepeatedFixed64',
  114. 'getRepeatedSfixed32',
  115. 'getRepeatedSfixed64',
  116. 'getRepeatedFloat',
  117. 'getRepeatedDouble',
  118. 'getRepeatedBool',
  119. 'getRepeatedString',
  120. 'getRepeatedBytes',
  121. 'getRepeatedEnum',
  122. 'getRepeatedMessage',
  123. 'getRepeatedRecursive',
  124. 'getRepeatedNoNamespaceMessage',
  125. 'getRepeatedNoNamespaceEnum',
  126. ],
  127. '@return \Google\Protobuf\Internal\RepeatedField'
  128. ],
  129. [
  130. [
  131. 'getMapInt32Int32',
  132. 'getMapInt64Int64',
  133. 'getMapUint32Uint32',
  134. 'getMapUint64Uint64',
  135. 'getMapSint32Sint32',
  136. 'getMapSint64Sint64',
  137. 'getMapFixed32Fixed32',
  138. 'getMapFixed64Fixed64',
  139. 'getMapSfixed32Sfixed32',
  140. 'getMapSfixed64Sfixed64',
  141. 'getMapInt32Float',
  142. 'getMapInt32Double',
  143. 'getMapBoolBool',
  144. 'getMapStringString',
  145. 'getMapInt32Bytes',
  146. 'getMapInt32Enum',
  147. 'getMapInt32Message',
  148. 'getMapRecursive',
  149. ],
  150. '@return \Google\Protobuf\Internal\MapField'
  151. ],
  152. [
  153. [
  154. 'setRepeatedInt32',
  155. 'setRepeatedUint32',
  156. 'setRepeatedSint32',
  157. 'setRepeatedFixed32',
  158. 'setRepeatedSfixed32',
  159. 'setRepeatedEnum',
  160. 'setRepeatedNoNamespaceEnum',
  161. ],
  162. '@param int[]|\Google\Protobuf\Internal\RepeatedField $var'
  163. ],
  164. [
  165. [
  166. 'setRepeatedInt64',
  167. 'setRepeatedUint64',
  168. 'setRepeatedSint64',
  169. 'setRepeatedFixed64',
  170. 'setRepeatedSfixed64',
  171. ],
  172. '@param int[]|string[]|\Google\Protobuf\Internal\RepeatedField $var'
  173. ],
  174. [
  175. [
  176. 'setRepeatedFloat',
  177. 'setRepeatedDouble',
  178. ],
  179. '@param float[]|\Google\Protobuf\Internal\RepeatedField $var'
  180. ],
  181. [
  182. [
  183. 'setRepeatedBool',
  184. ],
  185. '@param bool[]|\Google\Protobuf\Internal\RepeatedField $var'
  186. ],
  187. [
  188. [
  189. 'setRepeatedString',
  190. 'setRepeatedBytes',
  191. ],
  192. '@param string[]|\Google\Protobuf\Internal\RepeatedField $var'
  193. ],
  194. [
  195. [
  196. 'setRepeatedMessage',
  197. ],
  198. '@param \Foo\TestMessage\Sub[]|\Google\Protobuf\Internal\RepeatedField $var'
  199. ],
  200. [
  201. [
  202. 'setRepeatedRecursive',
  203. ],
  204. '@param \Foo\TestMessage[]|\Google\Protobuf\Internal\RepeatedField $var'
  205. ],
  206. [
  207. [
  208. 'setRepeatedNoNamespaceMessage',
  209. ],
  210. '@param \NoNamespaceMessage[]|\Google\Protobuf\Internal\RepeatedField $var'
  211. ],
  212. [
  213. [
  214. 'setMapInt32Int32',
  215. 'setMapInt64Int64',
  216. 'setMapUint32Uint32',
  217. 'setMapUint64Uint64',
  218. 'setMapSint32Sint32',
  219. 'setMapSint64Sint64',
  220. 'setMapFixed32Fixed32',
  221. 'setMapFixed64Fixed64',
  222. 'setMapSfixed32Sfixed32',
  223. 'setMapSfixed64Sfixed64',
  224. 'setMapInt32Float',
  225. 'setMapInt32Double',
  226. 'setMapBoolBool',
  227. 'setMapStringString',
  228. 'setMapInt32Bytes',
  229. 'setMapInt32Enum',
  230. 'setMapInt32Message',
  231. 'setMapRecursive',
  232. ],
  233. '@param array|\Google\Protobuf\Internal\MapField $var'
  234. ],
  235. [
  236. [
  237. 'getOptionalFloat',
  238. 'getOptionalDouble',
  239. 'getOneofDouble',
  240. 'getOneofFloat',
  241. ],
  242. '@return float'
  243. ],
  244. [
  245. [
  246. 'setOptionalFloat',
  247. 'setOptionalDouble',
  248. 'setOneofDouble',
  249. 'setOneofFloat',
  250. ],
  251. '@param float $var'
  252. ],
  253. [
  254. [
  255. 'getOptionalBool',
  256. 'getOneofBool',
  257. ],
  258. '@return bool'],
  259. [
  260. [
  261. 'setOptionalBool',
  262. 'setOneofBool',
  263. ],
  264. '@param bool $var'
  265. ],
  266. [
  267. [
  268. 'getOptionalString',
  269. 'getOptionalBytes',
  270. 'getOneofString',
  271. 'getOneofBytes',
  272. 'getMyOneof',
  273. ],
  274. '@return string'
  275. ],
  276. [
  277. [
  278. 'setOptionalString',
  279. 'setOptionalBytes',
  280. 'setOneofString',
  281. 'setOneofBytes',
  282. ],
  283. '@param string $var'
  284. ],
  285. [
  286. [
  287. 'getOptionalMessage',
  288. 'getOneofMessage'
  289. ],
  290. '@return \Foo\TestMessage\Sub'
  291. ],
  292. [
  293. [
  294. 'setOptionalMessage',
  295. 'setOneofMessage'
  296. ],
  297. '@param \Foo\TestMessage\Sub $var'
  298. ],
  299. [
  300. [
  301. 'getOptionalIncludedMessage'
  302. ],
  303. '@return \Bar\TestInclude'
  304. ],
  305. [
  306. [
  307. 'setOptionalIncludedMessage'
  308. ],
  309. '@param \Bar\TestInclude $var'
  310. ],
  311. [
  312. [
  313. 'getRecursive'
  314. ],
  315. '@return \Foo\TestMessage'
  316. ],
  317. [
  318. [
  319. 'setRecursive'
  320. ],
  321. '@param \Foo\TestMessage $var'
  322. ],
  323. [
  324. [
  325. 'getOptionalNoNamespaceMessage'
  326. ],
  327. '@return \NoNamespaceMessage'
  328. ],
  329. [
  330. [
  331. 'setOptionalNoNamespaceMessage'
  332. ],
  333. '@param \NoNamespaceMessage $var'
  334. ],
  335. ];
  336. }
  337. }