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