GeneratedPhpdocTest.php 11 KB

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