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