1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Parser_Php_PreprocessorTest extends SwaggerGen_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::__construct |
8
|
|
|
*/ |
9
|
|
|
public function testConstructor_Empty() |
10
|
|
|
{ |
11
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
12
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::__construct |
17
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::getPrefix |
18
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::setPrefix |
19
|
|
|
*/ |
20
|
|
|
public function testConstructor_Prefix() |
21
|
|
|
{ |
22
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
23
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
24
|
|
|
$this->assertEquals('rest', $object->getPrefix()); |
25
|
|
|
|
26
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor('foo'); |
27
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
28
|
|
|
$this->assertEquals('foo', $object->getPrefix()); |
29
|
|
|
|
30
|
|
|
$object->setPrefix('bar'); |
31
|
|
|
$this->assertEquals('bar', $object->getPrefix()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
36
|
|
|
*/ |
37
|
|
|
public function testPreprocess_Ifdef_NotDefined() |
38
|
|
|
{ |
39
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
40
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
41
|
|
|
$out = $object->preprocess('<?php |
42
|
|
|
/** |
43
|
|
|
* @rest\ifdef test |
44
|
|
|
* @rest\whatever |
45
|
|
|
* @rest\endif |
46
|
|
|
*/ |
47
|
|
|
'); |
48
|
|
|
|
49
|
|
|
$this->assertEquals('<?php |
50
|
|
|
/** |
51
|
|
|
* @!rest\ifdef test |
52
|
|
|
* @!rest\whatever |
53
|
|
|
* @!rest\endif |
54
|
|
|
*/ |
55
|
|
|
', $out); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
60
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
61
|
|
|
*/ |
62
|
|
|
public function testPreprocess_Ifdef_Defined() |
63
|
|
|
{ |
64
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
65
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
66
|
|
|
$object->define('test'); |
67
|
|
|
$out = $object->preprocess('<?php |
68
|
|
|
/** |
69
|
|
|
* @rest\ifdef test |
70
|
|
|
* @rest\whatever |
71
|
|
|
* @rest\endif |
72
|
|
|
*/ |
73
|
|
|
'); |
74
|
|
|
|
75
|
|
|
$this->assertEquals('<?php |
76
|
|
|
/** |
77
|
|
|
* @!rest\ifdef test |
78
|
|
|
* @rest\whatever |
79
|
|
|
* @!rest\endif |
80
|
|
|
*/ |
81
|
|
|
', $out); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
86
|
|
|
*/ |
87
|
|
|
public function testPreprocess_Ifndef_NotDefined() |
88
|
|
|
{ |
89
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
90
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
91
|
|
|
$out = $object->preprocess('<?php |
92
|
|
|
/** |
93
|
|
|
* @rest\ifndef test |
94
|
|
|
* @rest\whatever |
95
|
|
|
* @rest\endif |
96
|
|
|
*/ |
97
|
|
|
'); |
98
|
|
|
|
99
|
|
|
$this->assertEquals('<?php |
100
|
|
|
/** |
101
|
|
|
* @!rest\ifndef test |
102
|
|
|
* @rest\whatever |
103
|
|
|
* @!rest\endif |
104
|
|
|
*/ |
105
|
|
|
', $out); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
110
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
111
|
|
|
*/ |
112
|
|
|
public function testPreprocess_Ifndef_Defined() |
113
|
|
|
{ |
114
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
115
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
116
|
|
|
$object->define('test'); |
117
|
|
|
$out = $object->preprocess('<?php |
118
|
|
|
/** |
119
|
|
|
* @rest\ifndef test |
120
|
|
|
* @rest\whatever |
121
|
|
|
* @rest\endif |
122
|
|
|
*/ |
123
|
|
|
'); |
124
|
|
|
|
125
|
|
|
$this->assertEquals('<?php |
126
|
|
|
/** |
127
|
|
|
* @!rest\ifndef test |
128
|
|
|
* @!rest\whatever |
129
|
|
|
* @!rest\endif |
130
|
|
|
*/ |
131
|
|
|
', $out); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
136
|
|
|
*/ |
137
|
|
|
public function testPreprocess_Define() |
138
|
|
|
{ |
139
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
140
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
141
|
|
|
$out = $object->preprocess('<?php |
142
|
|
|
/** |
143
|
|
|
* @rest\define test |
144
|
|
|
* @rest\ifndef test |
145
|
|
|
* @rest\whatever |
146
|
|
|
* @rest\endif |
147
|
|
|
*/ |
148
|
|
|
'); |
149
|
|
|
|
150
|
|
|
$this->assertEquals('<?php |
151
|
|
|
/** |
152
|
|
|
* @!rest\define test |
153
|
|
|
* @!rest\ifndef test |
154
|
|
|
* @!rest\whatever |
155
|
|
|
* @!rest\endif |
156
|
|
|
*/ |
157
|
|
|
', $out); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
162
|
|
|
*/ |
163
|
|
|
public function testPreprocess_Undef() |
164
|
|
|
{ |
165
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
166
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
167
|
|
|
$out = $object->preprocess('<?php |
168
|
|
|
/** |
169
|
|
|
* @rest\define test |
170
|
|
|
* @rest\undef test |
171
|
|
|
* @rest\ifdef test |
172
|
|
|
* @rest\whatever |
173
|
|
|
* @rest\endif |
174
|
|
|
*/ |
175
|
|
|
'); |
176
|
|
|
|
177
|
|
|
$this->assertEquals('<?php |
178
|
|
|
/** |
179
|
|
|
* @!rest\define test |
180
|
|
|
* @!rest\undef test |
181
|
|
|
* @!rest\ifdef test |
182
|
|
|
* @!rest\whatever |
183
|
|
|
* @!rest\endif |
184
|
|
|
*/ |
185
|
|
|
', $out); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
190
|
|
|
*/ |
191
|
|
|
public function testPreprocess_If_NotDefined() |
192
|
|
|
{ |
193
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
194
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
195
|
|
|
$out = $object->preprocess('<?php |
196
|
|
|
/** |
197
|
|
|
* @rest\if test red |
198
|
|
|
* @rest\whatever |
199
|
|
|
* @rest\endif |
200
|
|
|
*/ |
201
|
|
|
'); |
202
|
|
|
|
203
|
|
|
$this->assertEquals('<?php |
204
|
|
|
/** |
205
|
|
|
* @!rest\if test red |
206
|
|
|
* @!rest\whatever |
207
|
|
|
* @!rest\endif |
208
|
|
|
*/ |
209
|
|
|
', $out); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
214
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
215
|
|
|
*/ |
216
|
|
|
public function testPreprocess_If_AnyValue() |
217
|
|
|
{ |
218
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
219
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
220
|
|
|
$object->define('test', 'green'); |
221
|
|
|
$out = $object->preprocess('<?php |
222
|
|
|
/** |
223
|
|
|
* @rest\if test |
224
|
|
|
* @rest\whatever |
225
|
|
|
* @rest\endif |
226
|
|
|
*/ |
227
|
|
|
'); |
228
|
|
|
|
229
|
|
|
$this->assertEquals('<?php |
230
|
|
|
/** |
231
|
|
|
* @!rest\if test |
232
|
|
|
* @rest\whatever |
233
|
|
|
* @!rest\endif |
234
|
|
|
*/ |
235
|
|
|
', $out); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
240
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
241
|
|
|
*/ |
242
|
|
|
public function testPreprocess_If_NoValue() |
243
|
|
|
{ |
244
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
245
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
246
|
|
|
$object->define('test'); |
247
|
|
|
$out = $object->preprocess('<?php |
248
|
|
|
/** |
249
|
|
|
* @rest\if test red |
250
|
|
|
* @rest\whatever |
251
|
|
|
* @rest\endif |
252
|
|
|
*/ |
253
|
|
|
'); |
254
|
|
|
|
255
|
|
|
$this->assertEquals('<?php |
256
|
|
|
/** |
257
|
|
|
* @!rest\if test red |
258
|
|
|
* @!rest\whatever |
259
|
|
|
* @!rest\endif |
260
|
|
|
*/ |
261
|
|
|
', $out); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
266
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
267
|
|
|
*/ |
268
|
|
|
public function testPreprocess_If_Mismatch() |
269
|
|
|
{ |
270
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
271
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
272
|
|
|
$object->define('test', 'green'); |
273
|
|
|
$out = $object->preprocess('<?php |
274
|
|
|
/** |
275
|
|
|
* @rest\if test red |
276
|
|
|
* @rest\whatever |
277
|
|
|
* @rest\endif |
278
|
|
|
*/ |
279
|
|
|
'); |
280
|
|
|
|
281
|
|
|
$this->assertEquals('<?php |
282
|
|
|
/** |
283
|
|
|
* @!rest\if test red |
284
|
|
|
* @!rest\whatever |
285
|
|
|
* @!rest\endif |
286
|
|
|
*/ |
287
|
|
|
', $out); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
292
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
293
|
|
|
*/ |
294
|
|
|
public function testPreprocess_If_Match() |
295
|
|
|
{ |
296
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
297
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
298
|
|
|
$object->define('test', 'red'); |
299
|
|
|
$out = $object->preprocess('<?php |
300
|
|
|
/** |
301
|
|
|
* @rest\if test red |
302
|
|
|
* @rest\whatever |
303
|
|
|
* @rest\endif |
304
|
|
|
*/ |
305
|
|
|
'); |
306
|
|
|
|
307
|
|
|
$this->assertEquals('<?php |
308
|
|
|
/** |
309
|
|
|
* @!rest\if test red |
310
|
|
|
* @rest\whatever |
311
|
|
|
* @!rest\endif |
312
|
|
|
*/ |
313
|
|
|
', $out); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
318
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
319
|
|
|
*/ |
320
|
|
|
public function testPreprocess_Else_Match() |
321
|
|
|
{ |
322
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
323
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
324
|
|
|
$object->define('test', 'blue'); |
325
|
|
|
$out = $object->preprocess('<?php |
326
|
|
|
/** |
327
|
|
|
* @rest\if test red |
328
|
|
|
* @rest\whatever |
329
|
|
|
* @rest\else |
330
|
|
|
* @rest\otherwise |
331
|
|
|
* @rest\endif |
332
|
|
|
*/ |
333
|
|
|
'); |
334
|
|
|
|
335
|
|
|
$this->assertEquals('<?php |
336
|
|
|
/** |
337
|
|
|
* @!rest\if test red |
338
|
|
|
* @!rest\whatever |
339
|
|
|
* @!rest\else |
340
|
|
|
* @rest\otherwise |
341
|
|
|
* @!rest\endif |
342
|
|
|
*/ |
343
|
|
|
', $out); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
348
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
349
|
|
|
*/ |
350
|
|
|
public function testPreprocess_Elif_Match() |
351
|
|
|
{ |
352
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
353
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
354
|
|
|
$object->define('test', 'blue'); |
355
|
|
|
$out = $object->preprocess('<?php |
356
|
|
|
/** |
357
|
|
|
* @rest\if test red |
358
|
|
|
* @rest\whatever |
359
|
|
|
* @rest\elif test green |
360
|
|
|
* @rest\second |
361
|
|
|
* @rest\elif test blue |
362
|
|
|
* @rest\otherwise |
363
|
|
|
* @rest\endif |
364
|
|
|
*/ |
365
|
|
|
'); |
366
|
|
|
|
367
|
|
|
$this->assertEquals('<?php |
368
|
|
|
/** |
369
|
|
|
* @!rest\if test red |
370
|
|
|
* @!rest\whatever |
371
|
|
|
* @!rest\elif test green |
372
|
|
|
* @!rest\second |
373
|
|
|
* @!rest\elif test blue |
374
|
|
|
* @rest\otherwise |
375
|
|
|
* @!rest\endif |
376
|
|
|
*/ |
377
|
|
|
', $out); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
382
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
383
|
|
|
*/ |
384
|
|
|
public function testPreprocess_Elif_NoValue() |
385
|
|
|
{ |
386
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
387
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
388
|
|
|
$object->define('test', 'blue'); |
389
|
|
|
$out = $object->preprocess('<?php |
390
|
|
|
/** |
391
|
|
|
* @rest\if test red |
392
|
|
|
* @rest\whatever |
393
|
|
|
* @rest\elif test green |
394
|
|
|
* @rest\second |
395
|
|
|
* @rest\elif test |
396
|
|
|
* @rest\otherwise |
397
|
|
|
* @rest\endif |
398
|
|
|
*/ |
399
|
|
|
'); |
400
|
|
|
|
401
|
|
|
$this->assertEquals('<?php |
402
|
|
|
/** |
403
|
|
|
* @!rest\if test red |
404
|
|
|
* @!rest\whatever |
405
|
|
|
* @!rest\elif test green |
406
|
|
|
* @!rest\second |
407
|
|
|
* @!rest\elif test |
408
|
|
|
* @rest\otherwise |
409
|
|
|
* @!rest\endif |
410
|
|
|
*/ |
411
|
|
|
', $out); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
416
|
|
|
*/ |
417
|
|
|
public function testPreprocess_Ifdef_AffectPrefixedOnly() |
418
|
|
|
{ |
419
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
420
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
421
|
|
|
$out = $object->preprocess('<?php |
422
|
|
|
/** |
423
|
|
|
* @rest\ifdef test |
424
|
|
|
* @rest\whatever |
425
|
|
|
* @other\whatever |
426
|
|
|
* @whatever |
427
|
|
|
* whatever |
428
|
|
|
* @rest\endif |
429
|
|
|
*/ |
430
|
|
|
'); |
431
|
|
|
|
432
|
|
|
$this->assertEquals('<?php |
433
|
|
|
/** |
434
|
|
|
* @!rest\ifdef test |
435
|
|
|
* @!rest\whatever |
436
|
|
|
* @other\whatever |
437
|
|
|
* @whatever |
438
|
|
|
* whatever |
439
|
|
|
* @!rest\endif |
440
|
|
|
*/ |
441
|
|
|
', $out); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
446
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::undefine |
447
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
448
|
|
|
*/ |
449
|
|
|
public function testPreprocess_Undefine() |
450
|
|
|
{ |
451
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
452
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
453
|
|
|
$object->define('test'); |
454
|
|
|
$object->undefine('test'); |
455
|
|
|
$out = $object->preprocess('<?php |
456
|
|
|
/** |
457
|
|
|
* @rest\ifdef test |
458
|
|
|
* @rest\whatever |
459
|
|
|
* @rest\endif |
460
|
|
|
*/ |
461
|
|
|
'); |
462
|
|
|
|
463
|
|
|
$this->assertEquals('<?php |
464
|
|
|
/** |
465
|
|
|
* @!rest\ifdef test |
466
|
|
|
* @!rest\whatever |
467
|
|
|
* @!rest\endif |
468
|
|
|
*/ |
469
|
|
|
', $out); |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
474
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::resetDefines |
475
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
476
|
|
|
*/ |
477
|
|
|
public function testPreprocess_ResetDefines() |
478
|
|
|
{ |
479
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
480
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
481
|
|
|
$object->define('test'); |
482
|
|
|
$object->resetDefines(); |
483
|
|
|
$out = $object->preprocess('<?php |
484
|
|
|
/** |
485
|
|
|
* @rest\ifdef test |
486
|
|
|
* @rest\whatever |
487
|
|
|
* @rest\endif |
488
|
|
|
*/ |
489
|
|
|
'); |
490
|
|
|
|
491
|
|
|
$this->assertEquals('<?php |
492
|
|
|
/** |
493
|
|
|
* @!rest\ifdef test |
494
|
|
|
* @!rest\whatever |
495
|
|
|
* @!rest\endif |
496
|
|
|
*/ |
497
|
|
|
', $out); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::addDefines |
502
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
503
|
|
|
*/ |
504
|
|
|
public function testPreprocess_AddDefines() |
505
|
|
|
{ |
506
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
507
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
508
|
|
|
$object->addDefines(array('test' => true)); |
509
|
|
|
$out = $object->preprocess('<?php |
510
|
|
|
/** |
511
|
|
|
* @rest\ifdef test |
512
|
|
|
* @rest\whatever |
513
|
|
|
* @rest\endif |
514
|
|
|
*/ |
515
|
|
|
'); |
516
|
|
|
|
517
|
|
|
$this->assertEquals('<?php |
518
|
|
|
/** |
519
|
|
|
* @!rest\ifdef test |
520
|
|
|
* @rest\whatever |
521
|
|
|
* @!rest\endif |
522
|
|
|
*/ |
523
|
|
|
', $out); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess |
528
|
|
|
*/ |
529
|
|
|
public function testPreprocess_AlternativePrefix() |
530
|
|
|
{ |
531
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor('foo'); |
532
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
533
|
|
|
$out = $object->preprocess('<?php |
534
|
|
|
/** |
535
|
|
|
* @foo\ifdef test |
536
|
|
|
* @foo\whatever |
537
|
|
|
* @rest\whatever |
538
|
|
|
* @foo\endif |
539
|
|
|
*/ |
540
|
|
|
'); |
541
|
|
|
|
542
|
|
|
$this->assertEquals('<?php |
543
|
|
|
/** |
544
|
|
|
* @!foo\ifdef test |
545
|
|
|
* @!foo\whatever |
546
|
|
|
* @rest\whatever |
547
|
|
|
* @!foo\endif |
548
|
|
|
*/ |
549
|
|
|
', $out); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
/** |
553
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::define |
554
|
|
|
* @covers \SwaggerGen\Parser\Php\Preprocessor::preprocessFile |
555
|
|
|
*/ |
556
|
|
|
public function testPreprocessFile() |
557
|
|
|
{ |
558
|
|
|
$object = new \SwaggerGen\Parser\Php\Preprocessor(); |
559
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object); |
560
|
|
|
$object->define('test'); |
561
|
|
|
|
562
|
|
|
$out = $object->preprocessFile(__DIR__ . '/PreprocessorTest/testPreprocessFile.php'); |
563
|
|
|
|
564
|
|
|
$this->assertEquals('<?php |
565
|
|
|
|
566
|
|
|
/** |
567
|
|
|
* @!rest\ifdef test |
568
|
|
|
* @rest\whatever |
569
|
|
|
* @!rest\endif |
570
|
|
|
*/', $out); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
//@todo preprocess($content) -> mingle with other PHP code |
574
|
|
|
//@todo preprocess($content) -> Condition within comment |
575
|
|
|
//@todo preprocess($content) -> Condition over comments |
576
|
|
|
//@todo preprocess($content) -> Condition over code |
577
|
|
|
} |
578
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.