generated_phpdoc_test.php 11 KB

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