@@ -3,42 +3,42 @@ discard block |
||
3 | 3 | class PreprocessorTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 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 |
|
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 | 42 | /** |
43 | 43 | * @rest\ifdef test |
44 | 44 | * @rest\whatever |
@@ -46,25 +46,25 @@ discard block |
||
46 | 46 | */ |
47 | 47 | '); |
48 | 48 | |
49 | - $this->assertEquals('<?php |
|
49 | + $this->assertEquals('<?php |
|
50 | 50 | /** |
51 | 51 | * @!rest\ifdef test |
52 | 52 | * @!rest\whatever |
53 | 53 | * @!rest\endif |
54 | 54 | */ |
55 | 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 |
|
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 | 68 | /** |
69 | 69 | * @rest\ifdef test |
70 | 70 | * @rest\whatever |
@@ -72,23 +72,23 @@ discard block |
||
72 | 72 | */ |
73 | 73 | '); |
74 | 74 | |
75 | - $this->assertEquals('<?php |
|
75 | + $this->assertEquals('<?php |
|
76 | 76 | /** |
77 | 77 | * @!rest\ifdef test |
78 | 78 | * @rest\whatever |
79 | 79 | * @!rest\endif |
80 | 80 | */ |
81 | 81 | ', $out); |
82 | - } |
|
82 | + } |
|
83 | 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 |
|
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 | 92 | /** |
93 | 93 | * @rest\ifndef test |
94 | 94 | * @rest\whatever |
@@ -96,25 +96,25 @@ discard block |
||
96 | 96 | */ |
97 | 97 | '); |
98 | 98 | |
99 | - $this->assertEquals('<?php |
|
99 | + $this->assertEquals('<?php |
|
100 | 100 | /** |
101 | 101 | * @!rest\ifndef test |
102 | 102 | * @rest\whatever |
103 | 103 | * @!rest\endif |
104 | 104 | */ |
105 | 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 |
|
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 | 118 | /** |
119 | 119 | * @rest\ifndef test |
120 | 120 | * @rest\whatever |
@@ -122,23 +122,23 @@ discard block |
||
122 | 122 | */ |
123 | 123 | '); |
124 | 124 | |
125 | - $this->assertEquals('<?php |
|
125 | + $this->assertEquals('<?php |
|
126 | 126 | /** |
127 | 127 | * @!rest\ifndef test |
128 | 128 | * @!rest\whatever |
129 | 129 | * @!rest\endif |
130 | 130 | */ |
131 | 131 | ', $out); |
132 | - } |
|
132 | + } |
|
133 | 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 |
|
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 | 142 | /** |
143 | 143 | * @rest\define test |
144 | 144 | * @rest\ifndef test |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | '); |
149 | 149 | |
150 | - $this->assertEquals('<?php |
|
150 | + $this->assertEquals('<?php |
|
151 | 151 | /** |
152 | 152 | * @!rest\define test |
153 | 153 | * @!rest\ifndef test |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | * @!rest\endif |
156 | 156 | */ |
157 | 157 | ', $out); |
158 | - } |
|
158 | + } |
|
159 | 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 |
|
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 | 168 | /** |
169 | 169 | * @rest\define test |
170 | 170 | * @rest\undef test |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | '); |
176 | 176 | |
177 | - $this->assertEquals('<?php |
|
177 | + $this->assertEquals('<?php |
|
178 | 178 | /** |
179 | 179 | * @!rest\define test |
180 | 180 | * @!rest\undef test |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | * @!rest\endif |
184 | 184 | */ |
185 | 185 | ', $out); |
186 | - } |
|
186 | + } |
|
187 | 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 |
|
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 | 196 | /** |
197 | 197 | * @rest\if test red |
198 | 198 | * @rest\whatever |
@@ -200,25 +200,25 @@ discard block |
||
200 | 200 | */ |
201 | 201 | '); |
202 | 202 | |
203 | - $this->assertEquals('<?php |
|
203 | + $this->assertEquals('<?php |
|
204 | 204 | /** |
205 | 205 | * @!rest\if test red |
206 | 206 | * @!rest\whatever |
207 | 207 | * @!rest\endif |
208 | 208 | */ |
209 | 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 |
|
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 | 222 | /** |
223 | 223 | * @rest\if test |
224 | 224 | * @rest\whatever |
@@ -226,25 +226,25 @@ discard block |
||
226 | 226 | */ |
227 | 227 | '); |
228 | 228 | |
229 | - $this->assertEquals('<?php |
|
229 | + $this->assertEquals('<?php |
|
230 | 230 | /** |
231 | 231 | * @!rest\if test |
232 | 232 | * @rest\whatever |
233 | 233 | * @!rest\endif |
234 | 234 | */ |
235 | 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 |
|
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 | 248 | /** |
249 | 249 | * @rest\if test red |
250 | 250 | * @rest\whatever |
@@ -252,25 +252,25 @@ discard block |
||
252 | 252 | */ |
253 | 253 | '); |
254 | 254 | |
255 | - $this->assertEquals('<?php |
|
255 | + $this->assertEquals('<?php |
|
256 | 256 | /** |
257 | 257 | * @!rest\if test red |
258 | 258 | * @!rest\whatever |
259 | 259 | * @!rest\endif |
260 | 260 | */ |
261 | 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 |
|
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 | 274 | /** |
275 | 275 | * @rest\if test red |
276 | 276 | * @rest\whatever |
@@ -278,25 +278,25 @@ discard block |
||
278 | 278 | */ |
279 | 279 | '); |
280 | 280 | |
281 | - $this->assertEquals('<?php |
|
281 | + $this->assertEquals('<?php |
|
282 | 282 | /** |
283 | 283 | * @!rest\if test red |
284 | 284 | * @!rest\whatever |
285 | 285 | * @!rest\endif |
286 | 286 | */ |
287 | 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 |
|
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 | 300 | /** |
301 | 301 | * @rest\if test red |
302 | 302 | * @rest\whatever |
@@ -304,25 +304,25 @@ discard block |
||
304 | 304 | */ |
305 | 305 | '); |
306 | 306 | |
307 | - $this->assertEquals('<?php |
|
307 | + $this->assertEquals('<?php |
|
308 | 308 | /** |
309 | 309 | * @!rest\if test red |
310 | 310 | * @rest\whatever |
311 | 311 | * @!rest\endif |
312 | 312 | */ |
313 | 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 |
|
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 | 326 | /** |
327 | 327 | * @rest\if test red |
328 | 328 | * @rest\whatever |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | */ |
333 | 333 | '); |
334 | 334 | |
335 | - $this->assertEquals('<?php |
|
335 | + $this->assertEquals('<?php |
|
336 | 336 | /** |
337 | 337 | * @!rest\if test red |
338 | 338 | * @!rest\whatever |
@@ -341,18 +341,18 @@ discard block |
||
341 | 341 | * @!rest\endif |
342 | 342 | */ |
343 | 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 |
|
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 | 356 | /** |
357 | 357 | * @rest\if test red |
358 | 358 | * @rest\whatever |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | */ |
365 | 365 | '); |
366 | 366 | |
367 | - $this->assertEquals('<?php |
|
367 | + $this->assertEquals('<?php |
|
368 | 368 | /** |
369 | 369 | * @!rest\if test red |
370 | 370 | * @!rest\whatever |
@@ -375,18 +375,18 @@ discard block |
||
375 | 375 | * @!rest\endif |
376 | 376 | */ |
377 | 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 |
|
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 | 390 | /** |
391 | 391 | * @rest\if test red |
392 | 392 | * @rest\whatever |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | */ |
399 | 399 | '); |
400 | 400 | |
401 | - $this->assertEquals('<?php |
|
401 | + $this->assertEquals('<?php |
|
402 | 402 | /** |
403 | 403 | * @!rest\if test red |
404 | 404 | * @!rest\whatever |
@@ -409,16 +409,16 @@ discard block |
||
409 | 409 | * @!rest\endif |
410 | 410 | */ |
411 | 411 | ', $out); |
412 | - } |
|
412 | + } |
|
413 | 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 |
|
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 | 422 | /** |
423 | 423 | * @rest\ifdef test |
424 | 424 | * @rest\whatever |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | */ |
430 | 430 | '); |
431 | 431 | |
432 | - $this->assertEquals('<?php |
|
432 | + $this->assertEquals('<?php |
|
433 | 433 | /** |
434 | 434 | * @!rest\ifdef test |
435 | 435 | * @!rest\whatever |
@@ -439,20 +439,20 @@ discard block |
||
439 | 439 | * @!rest\endif |
440 | 440 | */ |
441 | 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 |
|
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 | 456 | /** |
457 | 457 | * @rest\ifdef test |
458 | 458 | * @rest\whatever |
@@ -460,27 +460,27 @@ discard block |
||
460 | 460 | */ |
461 | 461 | '); |
462 | 462 | |
463 | - $this->assertEquals('<?php |
|
463 | + $this->assertEquals('<?php |
|
464 | 464 | /** |
465 | 465 | * @!rest\ifdef test |
466 | 466 | * @!rest\whatever |
467 | 467 | * @!rest\endif |
468 | 468 | */ |
469 | 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 |
|
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 | 484 | /** |
485 | 485 | * @rest\ifdef test |
486 | 486 | * @rest\whatever |
@@ -488,25 +488,25 @@ discard block |
||
488 | 488 | */ |
489 | 489 | '); |
490 | 490 | |
491 | - $this->assertEquals('<?php |
|
491 | + $this->assertEquals('<?php |
|
492 | 492 | /** |
493 | 493 | * @!rest\ifdef test |
494 | 494 | * @!rest\whatever |
495 | 495 | * @!rest\endif |
496 | 496 | */ |
497 | 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 |
|
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 | 510 | /** |
511 | 511 | * @rest\ifdef test |
512 | 512 | * @rest\whatever |
@@ -514,23 +514,23 @@ discard block |
||
514 | 514 | */ |
515 | 515 | '); |
516 | 516 | |
517 | - $this->assertEquals('<?php |
|
517 | + $this->assertEquals('<?php |
|
518 | 518 | /** |
519 | 519 | * @!rest\ifdef test |
520 | 520 | * @rest\whatever |
521 | 521 | * @!rest\endif |
522 | 522 | */ |
523 | 523 | ', $out); |
524 | - } |
|
524 | + } |
|
525 | 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 |
|
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 | 534 | /** |
535 | 535 | * @foo\ifdef test |
536 | 536 | * @foo\whatever |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | '); |
541 | 541 | |
542 | - $this->assertEquals('<?php |
|
542 | + $this->assertEquals('<?php |
|
543 | 543 | /** |
544 | 544 | * @!foo\ifdef test |
545 | 545 | * @!foo\whatever |
@@ -547,31 +547,31 @@ discard block |
||
547 | 547 | * @!foo\endif |
548 | 548 | */ |
549 | 549 | ', $out); |
550 | - } |
|
550 | + } |
|
551 | 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'); |
|
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 | 561 | |
562 | - $out = $object->preprocessFile(__DIR__ . '/PreprocessorTest/testPreprocessFile.php'); |
|
562 | + $out = $object->preprocessFile(__DIR__ . '/PreprocessorTest/testPreprocessFile.php'); |
|
563 | 563 | |
564 | - $this->assertEquals('<?php |
|
564 | + $this->assertEquals('<?php |
|
565 | 565 | |
566 | 566 | /** |
567 | 567 | * @!rest\ifdef test |
568 | 568 | * @rest\whatever |
569 | 569 | * @!rest\endif |
570 | 570 | */', $out); |
571 | - } |
|
571 | + } |
|
572 | 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 |
|
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 | 577 | } |
@@ -5,191 +5,191 @@ |
||
5 | 5 | class ParserTest extends \SwaggerGen_TestCase |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @covers \SwaggerGen\Parser\Text\Parser::__construct |
|
10 | - */ |
|
11 | - public function testConstructor_Empty() |
|
12 | - { |
|
13 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
14 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
15 | - } |
|
16 | - |
|
17 | - /** |
|
18 | - * @covers \SwaggerGen\Parser\Text\Parser::__construct |
|
19 | - */ |
|
20 | - public function testConstructor_Dirs() |
|
21 | - { |
|
22 | - $this->markTestIncomplete('Not yet implemented.'); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @covers \SwaggerGen\Parser\Text\Parser::addDirs |
|
27 | - */ |
|
28 | - public function testAddDirs() |
|
29 | - { |
|
30 | - $this->markTestIncomplete('Not yet implemented.'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
35 | - */ |
|
36 | - public function testParseText() |
|
37 | - { |
|
38 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
39 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
40 | - |
|
41 | - $statements = $object->parseText('title Some words'); |
|
42 | - |
|
43 | - $this->assertCount(1, $statements); |
|
44 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
45 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
46 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
51 | - */ |
|
52 | - public function testParseText_Whitespace() |
|
53 | - { |
|
54 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
55 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
56 | - |
|
57 | - $statements = $object->parseText(" \t title \t\t Some words \t "); |
|
58 | - |
|
59 | - $this->assertCount(1, $statements); |
|
60 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
61 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
62 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
67 | - */ |
|
68 | - public function testParseText_Multiple_LF() |
|
69 | - { |
|
70 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
71 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
72 | - |
|
73 | - $statements = $object->parseText("title Some words\nSome Random words"); |
|
74 | - |
|
75 | - $this->assertCount(2, $statements); |
|
76 | - |
|
77 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
78 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
79 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
80 | - |
|
81 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
82 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
83 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
88 | - */ |
|
89 | - public function testParseText_Multiple_CR() |
|
90 | - { |
|
91 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
92 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
93 | - |
|
94 | - $statements = $object->parseText("title Some words\rSome Random words"); |
|
95 | - |
|
96 | - $this->assertCount(2, $statements); |
|
97 | - |
|
98 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
99 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
100 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
101 | - |
|
102 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
103 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
104 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
109 | - */ |
|
110 | - public function testParseText_Multiple_CRLF() |
|
111 | - { |
|
112 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
113 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
114 | - |
|
115 | - $statements = $object->parseText("title Some words\r\nSome Random words"); |
|
116 | - |
|
117 | - $this->assertCount(2, $statements); |
|
118 | - |
|
119 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
120 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
121 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
122 | - |
|
123 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
124 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
125 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
130 | - */ |
|
131 | - public function testParseText_Multiple_BlankLines() |
|
132 | - { |
|
133 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
134 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
135 | - |
|
136 | - $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words"); |
|
137 | - |
|
138 | - $this->assertCount(2, $statements); |
|
139 | - |
|
140 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
141 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
142 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
143 | - |
|
144 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
145 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
146 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
151 | - */ |
|
152 | - public function testParseText_Dirs() |
|
153 | - { |
|
154 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
155 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
156 | - |
|
157 | - $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words", array( |
|
158 | - __DIR__ . '/ParserTest/not used by text parser', |
|
159 | - )); |
|
160 | - |
|
161 | - $this->assertCount(2, $statements); |
|
162 | - |
|
163 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
164 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
165 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
166 | - |
|
167 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
168 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
169 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @covers \SwaggerGen\Parser\Text\Parser::parse |
|
174 | - */ |
|
175 | - public function testParse() |
|
176 | - { |
|
177 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
178 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
179 | - |
|
180 | - $statements = $object->parse(__DIR__ . '/ParserTest/testParse.txt', array( |
|
181 | - __DIR__ . '/ParserTest/not used by text parser', |
|
182 | - )); |
|
183 | - |
|
184 | - $this->assertCount(2, $statements); |
|
185 | - |
|
186 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
187 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
188 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
189 | - |
|
190 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
191 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
192 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
193 | - } |
|
8 | + /** |
|
9 | + * @covers \SwaggerGen\Parser\Text\Parser::__construct |
|
10 | + */ |
|
11 | + public function testConstructor_Empty() |
|
12 | + { |
|
13 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
14 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
15 | + } |
|
16 | + |
|
17 | + /** |
|
18 | + * @covers \SwaggerGen\Parser\Text\Parser::__construct |
|
19 | + */ |
|
20 | + public function testConstructor_Dirs() |
|
21 | + { |
|
22 | + $this->markTestIncomplete('Not yet implemented.'); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @covers \SwaggerGen\Parser\Text\Parser::addDirs |
|
27 | + */ |
|
28 | + public function testAddDirs() |
|
29 | + { |
|
30 | + $this->markTestIncomplete('Not yet implemented.'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
35 | + */ |
|
36 | + public function testParseText() |
|
37 | + { |
|
38 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
39 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
40 | + |
|
41 | + $statements = $object->parseText('title Some words'); |
|
42 | + |
|
43 | + $this->assertCount(1, $statements); |
|
44 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
45 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
46 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
51 | + */ |
|
52 | + public function testParseText_Whitespace() |
|
53 | + { |
|
54 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
55 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
56 | + |
|
57 | + $statements = $object->parseText(" \t title \t\t Some words \t "); |
|
58 | + |
|
59 | + $this->assertCount(1, $statements); |
|
60 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
61 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
62 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
67 | + */ |
|
68 | + public function testParseText_Multiple_LF() |
|
69 | + { |
|
70 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
71 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
72 | + |
|
73 | + $statements = $object->parseText("title Some words\nSome Random words"); |
|
74 | + |
|
75 | + $this->assertCount(2, $statements); |
|
76 | + |
|
77 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
78 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
79 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
80 | + |
|
81 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
82 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
83 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
88 | + */ |
|
89 | + public function testParseText_Multiple_CR() |
|
90 | + { |
|
91 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
92 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
93 | + |
|
94 | + $statements = $object->parseText("title Some words\rSome Random words"); |
|
95 | + |
|
96 | + $this->assertCount(2, $statements); |
|
97 | + |
|
98 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
99 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
100 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
101 | + |
|
102 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
103 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
104 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
109 | + */ |
|
110 | + public function testParseText_Multiple_CRLF() |
|
111 | + { |
|
112 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
113 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
114 | + |
|
115 | + $statements = $object->parseText("title Some words\r\nSome Random words"); |
|
116 | + |
|
117 | + $this->assertCount(2, $statements); |
|
118 | + |
|
119 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
120 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
121 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
122 | + |
|
123 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
124 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
125 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
130 | + */ |
|
131 | + public function testParseText_Multiple_BlankLines() |
|
132 | + { |
|
133 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
134 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
135 | + |
|
136 | + $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words"); |
|
137 | + |
|
138 | + $this->assertCount(2, $statements); |
|
139 | + |
|
140 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
141 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
142 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
143 | + |
|
144 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
145 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
146 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
151 | + */ |
|
152 | + public function testParseText_Dirs() |
|
153 | + { |
|
154 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
155 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
156 | + |
|
157 | + $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words", array( |
|
158 | + __DIR__ . '/ParserTest/not used by text parser', |
|
159 | + )); |
|
160 | + |
|
161 | + $this->assertCount(2, $statements); |
|
162 | + |
|
163 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
164 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
165 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
166 | + |
|
167 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
168 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
169 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @covers \SwaggerGen\Parser\Text\Parser::parse |
|
174 | + */ |
|
175 | + public function testParse() |
|
176 | + { |
|
177 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
178 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
179 | + |
|
180 | + $statements = $object->parse(__DIR__ . '/ParserTest/testParse.txt', array( |
|
181 | + __DIR__ . '/ParserTest/not used by text parser', |
|
182 | + )); |
|
183 | + |
|
184 | + $this->assertCount(2, $statements); |
|
185 | + |
|
186 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
187 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
188 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
189 | + |
|
190 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
191 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
192 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
193 | + } |
|
194 | 194 | |
195 | 195 | } |
@@ -3,34 +3,34 @@ |
||
3 | 3 | class ExceptionTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @covers \SwaggerGen\Exception::__construct |
|
8 | - */ |
|
9 | - public function testConstructor0() |
|
10 | - { |
|
11 | - $this->expectException('\SwaggerGen\Exception'); |
|
12 | - |
|
13 | - throw new \SwaggerGen\Exception('', 0); |
|
14 | - } |
|
15 | - |
|
16 | - /** |
|
17 | - * @covers \SwaggerGen\Exception::__construct |
|
18 | - */ |
|
19 | - public function testConstructor1() |
|
20 | - { |
|
21 | - $this->expectException('\SwaggerGen\Exception', 'This is a message'); |
|
22 | - |
|
23 | - throw new \SwaggerGen\Exception('This is a message', 0); |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * @covers \SwaggerGen\Exception::__construct |
|
28 | - */ |
|
29 | - public function testConstructor2() |
|
30 | - { |
|
31 | - $this->expectException('\SwaggerGen\Exception', 'This is a message', 1234); |
|
32 | - |
|
33 | - throw new \SwaggerGen\Exception('This is a message', 1234); |
|
34 | - } |
|
6 | + /** |
|
7 | + * @covers \SwaggerGen\Exception::__construct |
|
8 | + */ |
|
9 | + public function testConstructor0() |
|
10 | + { |
|
11 | + $this->expectException('\SwaggerGen\Exception'); |
|
12 | + |
|
13 | + throw new \SwaggerGen\Exception('', 0); |
|
14 | + } |
|
15 | + |
|
16 | + /** |
|
17 | + * @covers \SwaggerGen\Exception::__construct |
|
18 | + */ |
|
19 | + public function testConstructor1() |
|
20 | + { |
|
21 | + $this->expectException('\SwaggerGen\Exception', 'This is a message'); |
|
22 | + |
|
23 | + throw new \SwaggerGen\Exception('This is a message', 0); |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * @covers \SwaggerGen\Exception::__construct |
|
28 | + */ |
|
29 | + public function testConstructor2() |
|
30 | + { |
|
31 | + $this->expectException('\SwaggerGen\Exception', 'This is a message', 1234); |
|
32 | + |
|
33 | + throw new \SwaggerGen\Exception('This is a message', 1234); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -11,15 +11,15 @@ |
||
11 | 11 | class Example |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @rest\endpoint /endpoint/{listid} |
|
16 | - * @rest\method GET Something |
|
17 | - * @rest\param listid |
|
18 | - * @rest\response 200 |
|
19 | - */ |
|
20 | - public function Dummy() |
|
21 | - { |
|
14 | + /** |
|
15 | + * @rest\endpoint /endpoint/{listid} |
|
16 | + * @rest\method GET Something |
|
17 | + * @rest\param listid |
|
18 | + * @rest\response 200 |
|
19 | + */ |
|
20 | + public function Dummy() |
|
21 | + { |
|
22 | 22 | |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | 25 | } |
@@ -14,44 +14,44 @@ |
||
14 | 14 | class ExternalDocumentation extends AbstractObject |
15 | 15 | { |
16 | 16 | |
17 | - private $url; |
|
18 | - private $description; |
|
19 | - |
|
20 | - public function __construct(AbstractObject $parent, $url, $description = null) |
|
21 | - { |
|
22 | - parent::__construct($parent); |
|
23 | - $this->url = $url; |
|
24 | - $this->description = $description; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * @param string $command |
|
29 | - * @param string $data |
|
30 | - * @return AbstractObject|boolean |
|
31 | - */ |
|
32 | - public function handleCommand($command, $data = null) |
|
33 | - { |
|
34 | - switch (strtolower($command)) { |
|
35 | - case 'url': |
|
36 | - case 'description': |
|
37 | - $this->$command = $data; |
|
38 | - return $this; |
|
39 | - } |
|
40 | - |
|
41 | - return parent::handleCommand($command, $data); |
|
42 | - } |
|
43 | - |
|
44 | - public function toArray(): array |
|
45 | - { |
|
46 | - return self::arrayFilterNull(array_merge(array( |
|
47 | - 'url' => $this->url, |
|
48 | - 'description' => empty($this->description) ? null : $this->description, |
|
49 | - ), parent::toArray())); |
|
50 | - } |
|
51 | - |
|
52 | - public function __toString() |
|
53 | - { |
|
54 | - return __CLASS__ . ' ' . $this->url; |
|
55 | - } |
|
17 | + private $url; |
|
18 | + private $description; |
|
19 | + |
|
20 | + public function __construct(AbstractObject $parent, $url, $description = null) |
|
21 | + { |
|
22 | + parent::__construct($parent); |
|
23 | + $this->url = $url; |
|
24 | + $this->description = $description; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * @param string $command |
|
29 | + * @param string $data |
|
30 | + * @return AbstractObject|boolean |
|
31 | + */ |
|
32 | + public function handleCommand($command, $data = null) |
|
33 | + { |
|
34 | + switch (strtolower($command)) { |
|
35 | + case 'url': |
|
36 | + case 'description': |
|
37 | + $this->$command = $data; |
|
38 | + return $this; |
|
39 | + } |
|
40 | + |
|
41 | + return parent::handleCommand($command, $data); |
|
42 | + } |
|
43 | + |
|
44 | + public function toArray(): array |
|
45 | + { |
|
46 | + return self::arrayFilterNull(array_merge(array( |
|
47 | + 'url' => $this->url, |
|
48 | + 'description' => empty($this->description) ? null : $this->description, |
|
49 | + ), parent::toArray())); |
|
50 | + } |
|
51 | + |
|
52 | + public function __toString() |
|
53 | + { |
|
54 | + return __CLASS__ . ' ' . $this->url; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
@@ -15,166 +15,166 @@ |
||
15 | 15 | class IntegerType extends AbstractType |
16 | 16 | { |
17 | 17 | |
18 | - /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
19 | - const REGEX_RANGE = '(?:([[<])(-?\d*)?,(-?\d*)?([\\]>]))?'; |
|
20 | - /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
21 | - const REGEX_DEFAULT = '(?:=(-?\d+))?'; |
|
22 | - |
|
23 | - private static $formats = array( |
|
24 | - 'int32' => 'int32', |
|
25 | - 'integer' => 'int32', |
|
26 | - 'int' => 'int32', |
|
27 | - 'int64' => 'int64', |
|
28 | - 'long' => 'int64', |
|
29 | - ); |
|
30 | - private $format; |
|
31 | - private $default = null; |
|
32 | - private $maximum = null; |
|
33 | - private $exclusiveMaximum = null; |
|
34 | - private $minimum = null; |
|
35 | - private $exclusiveMinimum = null; |
|
36 | - private $enum = array(); |
|
37 | - private $multipleOf = null; |
|
38 | - |
|
39 | - /** |
|
40 | - * @throws Exception |
|
41 | - */ |
|
42 | - protected function parseDefinition($definition) |
|
43 | - { |
|
44 | - $definition = self::trim($definition); |
|
45 | - |
|
46 | - $match = array(); |
|
47 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
48 | - throw new Exception("Unparseable integer definition: '{$definition}'"); |
|
49 | - } |
|
50 | - |
|
51 | - $this->parseFormat($definition, $match); |
|
52 | - $this->parseRange($definition, $match); |
|
53 | - $this->parseDefault($definition, $match); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $definition |
|
58 | - * @param string[] $match |
|
59 | - * @throws Exception |
|
60 | - */ |
|
61 | - private function parseFormat($definition, $match) |
|
62 | - { |
|
63 | - $type = strtolower($match[1]); |
|
64 | - if (!isset(self::$formats[$type])) { |
|
65 | - throw new Exception("Not an integer: '{$definition}'"); |
|
66 | - } |
|
67 | - $this->format = self::$formats[$type]; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param string $definition |
|
72 | - * @param string[] $match |
|
73 | - * @throws Exception |
|
74 | - */ |
|
75 | - private function parseRange($definition, $match) |
|
76 | - { |
|
77 | - if (!empty($match[2])) { |
|
78 | - if ($match[3] === '' && $match[4] === '') { |
|
79 | - throw new Exception("Empty integer range: '{$definition}'"); |
|
80 | - } |
|
81 | - |
|
82 | - $this->exclusiveMinimum = $match[2] == '<'; |
|
83 | - $this->minimum = $match[3] === '' ? null : (int)$match[3]; |
|
84 | - $this->maximum = $match[4] === '' ? null : (int)$match[4]; |
|
85 | - $this->exclusiveMaximum = isset($match[5]) ? ($match[5] == '>') : null; |
|
86 | - if ($this->minimum && $this->maximum && $this->minimum > $this->maximum) { |
|
87 | - self::swap($this->minimum, $this->maximum); |
|
88 | - self::swap($this->exclusiveMinimum, $this->exclusiveMaximum); |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $definition |
|
95 | - * @param string[] $match |
|
96 | - * @throws Exception |
|
97 | - */ |
|
98 | - private function parseDefault($definition, $match) |
|
99 | - { |
|
100 | - $this->default = isset($match[6]) && $match[6] !== '' ? $this->validateDefault($match[6]) : null; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $command The comment command |
|
105 | - * @param string $data Any data added after the command |
|
106 | - * @return AbstractType|boolean |
|
107 | - * @throws Exception |
|
108 | - * @throws Exception |
|
109 | - * @throws Exception |
|
110 | - */ |
|
111 | - public function handleCommand($command, $data = null) |
|
112 | - { |
|
113 | - switch (strtolower($command)) { |
|
114 | - case 'default': |
|
115 | - $this->default = $this->validateDefault($data); |
|
116 | - return $this; |
|
117 | - |
|
118 | - case 'enum': |
|
119 | - $words = self::wordSplit($data); |
|
120 | - foreach ($words as &$word) { |
|
121 | - $word = $this->validateDefault($word); |
|
122 | - } |
|
123 | - unset($word); |
|
124 | - $this->enum = array_merge($this->enum, $words); |
|
125 | - return $this; |
|
126 | - |
|
127 | - case 'step': |
|
128 | - if (($step = (int)$data) > 0) { |
|
129 | - $this->multipleOf = $step; |
|
130 | - } |
|
131 | - return $this; |
|
132 | - } |
|
133 | - |
|
134 | - return parent::handleCommand($command, $data); |
|
135 | - } |
|
136 | - |
|
137 | - public function toArray(): array |
|
138 | - { |
|
139 | - return self::arrayFilterNull(array_merge(array( |
|
140 | - 'type' => 'integer', |
|
141 | - 'format' => $this->format, |
|
142 | - 'default' => $this->default, |
|
143 | - 'minimum' => $this->minimum, |
|
144 | - 'exclusiveMinimum' => ($this->exclusiveMinimum && !is_null($this->minimum)) ? true : null, |
|
145 | - 'maximum' => $this->maximum, |
|
146 | - 'exclusiveMaximum' => ($this->exclusiveMaximum && !is_null($this->maximum)) ? true : null, |
|
147 | - 'enum' => $this->enum, |
|
148 | - 'multipleOf' => $this->multipleOf, |
|
149 | - ), parent::toArray())); |
|
150 | - } |
|
151 | - |
|
152 | - public function __toString() |
|
153 | - { |
|
154 | - return __CLASS__; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @throws Exception |
|
159 | - */ |
|
160 | - private function validateDefault($value) |
|
161 | - { |
|
162 | - if (preg_match('~^-?\d+$~', $value) !== 1) { |
|
163 | - throw new Exception("Invalid integer default: '{$value}'"); |
|
164 | - } |
|
165 | - |
|
166 | - if ($this->maximum) { |
|
167 | - if (($value > $this->maximum) || ($this->exclusiveMaximum && $value == $this->maximum)) { |
|
168 | - throw new Exception("Default integer beyond maximum: '{$value}'"); |
|
169 | - } |
|
170 | - } |
|
171 | - if ($this->minimum) { |
|
172 | - if (($value < $this->minimum) || ($this->exclusiveMinimum && $value == $this->minimum)) { |
|
173 | - throw new Exception("Default integer beyond minimum: '{$value}'"); |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - return (int)$value; |
|
178 | - } |
|
18 | + /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
19 | + const REGEX_RANGE = '(?:([[<])(-?\d*)?,(-?\d*)?([\\]>]))?'; |
|
20 | + /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
21 | + const REGEX_DEFAULT = '(?:=(-?\d+))?'; |
|
22 | + |
|
23 | + private static $formats = array( |
|
24 | + 'int32' => 'int32', |
|
25 | + 'integer' => 'int32', |
|
26 | + 'int' => 'int32', |
|
27 | + 'int64' => 'int64', |
|
28 | + 'long' => 'int64', |
|
29 | + ); |
|
30 | + private $format; |
|
31 | + private $default = null; |
|
32 | + private $maximum = null; |
|
33 | + private $exclusiveMaximum = null; |
|
34 | + private $minimum = null; |
|
35 | + private $exclusiveMinimum = null; |
|
36 | + private $enum = array(); |
|
37 | + private $multipleOf = null; |
|
38 | + |
|
39 | + /** |
|
40 | + * @throws Exception |
|
41 | + */ |
|
42 | + protected function parseDefinition($definition) |
|
43 | + { |
|
44 | + $definition = self::trim($definition); |
|
45 | + |
|
46 | + $match = array(); |
|
47 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
48 | + throw new Exception("Unparseable integer definition: '{$definition}'"); |
|
49 | + } |
|
50 | + |
|
51 | + $this->parseFormat($definition, $match); |
|
52 | + $this->parseRange($definition, $match); |
|
53 | + $this->parseDefault($definition, $match); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $definition |
|
58 | + * @param string[] $match |
|
59 | + * @throws Exception |
|
60 | + */ |
|
61 | + private function parseFormat($definition, $match) |
|
62 | + { |
|
63 | + $type = strtolower($match[1]); |
|
64 | + if (!isset(self::$formats[$type])) { |
|
65 | + throw new Exception("Not an integer: '{$definition}'"); |
|
66 | + } |
|
67 | + $this->format = self::$formats[$type]; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param string $definition |
|
72 | + * @param string[] $match |
|
73 | + * @throws Exception |
|
74 | + */ |
|
75 | + private function parseRange($definition, $match) |
|
76 | + { |
|
77 | + if (!empty($match[2])) { |
|
78 | + if ($match[3] === '' && $match[4] === '') { |
|
79 | + throw new Exception("Empty integer range: '{$definition}'"); |
|
80 | + } |
|
81 | + |
|
82 | + $this->exclusiveMinimum = $match[2] == '<'; |
|
83 | + $this->minimum = $match[3] === '' ? null : (int)$match[3]; |
|
84 | + $this->maximum = $match[4] === '' ? null : (int)$match[4]; |
|
85 | + $this->exclusiveMaximum = isset($match[5]) ? ($match[5] == '>') : null; |
|
86 | + if ($this->minimum && $this->maximum && $this->minimum > $this->maximum) { |
|
87 | + self::swap($this->minimum, $this->maximum); |
|
88 | + self::swap($this->exclusiveMinimum, $this->exclusiveMaximum); |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $definition |
|
95 | + * @param string[] $match |
|
96 | + * @throws Exception |
|
97 | + */ |
|
98 | + private function parseDefault($definition, $match) |
|
99 | + { |
|
100 | + $this->default = isset($match[6]) && $match[6] !== '' ? $this->validateDefault($match[6]) : null; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $command The comment command |
|
105 | + * @param string $data Any data added after the command |
|
106 | + * @return AbstractType|boolean |
|
107 | + * @throws Exception |
|
108 | + * @throws Exception |
|
109 | + * @throws Exception |
|
110 | + */ |
|
111 | + public function handleCommand($command, $data = null) |
|
112 | + { |
|
113 | + switch (strtolower($command)) { |
|
114 | + case 'default': |
|
115 | + $this->default = $this->validateDefault($data); |
|
116 | + return $this; |
|
117 | + |
|
118 | + case 'enum': |
|
119 | + $words = self::wordSplit($data); |
|
120 | + foreach ($words as &$word) { |
|
121 | + $word = $this->validateDefault($word); |
|
122 | + } |
|
123 | + unset($word); |
|
124 | + $this->enum = array_merge($this->enum, $words); |
|
125 | + return $this; |
|
126 | + |
|
127 | + case 'step': |
|
128 | + if (($step = (int)$data) > 0) { |
|
129 | + $this->multipleOf = $step; |
|
130 | + } |
|
131 | + return $this; |
|
132 | + } |
|
133 | + |
|
134 | + return parent::handleCommand($command, $data); |
|
135 | + } |
|
136 | + |
|
137 | + public function toArray(): array |
|
138 | + { |
|
139 | + return self::arrayFilterNull(array_merge(array( |
|
140 | + 'type' => 'integer', |
|
141 | + 'format' => $this->format, |
|
142 | + 'default' => $this->default, |
|
143 | + 'minimum' => $this->minimum, |
|
144 | + 'exclusiveMinimum' => ($this->exclusiveMinimum && !is_null($this->minimum)) ? true : null, |
|
145 | + 'maximum' => $this->maximum, |
|
146 | + 'exclusiveMaximum' => ($this->exclusiveMaximum && !is_null($this->maximum)) ? true : null, |
|
147 | + 'enum' => $this->enum, |
|
148 | + 'multipleOf' => $this->multipleOf, |
|
149 | + ), parent::toArray())); |
|
150 | + } |
|
151 | + |
|
152 | + public function __toString() |
|
153 | + { |
|
154 | + return __CLASS__; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @throws Exception |
|
159 | + */ |
|
160 | + private function validateDefault($value) |
|
161 | + { |
|
162 | + if (preg_match('~^-?\d+$~', $value) !== 1) { |
|
163 | + throw new Exception("Invalid integer default: '{$value}'"); |
|
164 | + } |
|
165 | + |
|
166 | + if ($this->maximum) { |
|
167 | + if (($value > $this->maximum) || ($this->exclusiveMaximum && $value == $this->maximum)) { |
|
168 | + throw new Exception("Default integer beyond maximum: '{$value}'"); |
|
169 | + } |
|
170 | + } |
|
171 | + if ($this->minimum) { |
|
172 | + if (($value < $this->minimum) || ($this->exclusiveMinimum && $value == $this->minimum)) { |
|
173 | + throw new Exception("Default integer beyond minimum: '{$value}'"); |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + return (int)$value; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | $this->exclusiveMinimum = $match[2] == '<'; |
83 | - $this->minimum = $match[3] === '' ? null : (int)$match[3]; |
|
84 | - $this->maximum = $match[4] === '' ? null : (int)$match[4]; |
|
83 | + $this->minimum = $match[3] === '' ? null : (int) $match[3]; |
|
84 | + $this->maximum = $match[4] === '' ? null : (int) $match[4]; |
|
85 | 85 | $this->exclusiveMaximum = isset($match[5]) ? ($match[5] == '>') : null; |
86 | 86 | if ($this->minimum && $this->maximum && $this->minimum > $this->maximum) { |
87 | 87 | self::swap($this->minimum, $this->maximum); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | return $this; |
126 | 126 | |
127 | 127 | case 'step': |
128 | - if (($step = (int)$data) > 0) { |
|
128 | + if (($step = (int) $data) > 0) { |
|
129 | 129 | $this->multipleOf = $step; |
130 | 130 | } |
131 | 131 | return $this; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
177 | - return (int)$value; |
|
177 | + return (int) $value; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | } |
@@ -14,52 +14,52 @@ |
||
14 | 14 | */ |
15 | 15 | class AllOfType extends AbstractType |
16 | 16 | { |
17 | - private $allOfItems = array(); |
|
18 | - private $mostRecentItem; |
|
17 | + private $allOfItems = array(); |
|
18 | + private $mostRecentItem; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @throws Exception |
|
22 | - */ |
|
23 | - protected function parseDefinition($definition) |
|
24 | - { |
|
25 | - $pattern = self::REGEX_START . 'allof' . self::REGEX_CONTENT . self::REGEX_END; |
|
26 | - $inlineDef = ''; |
|
27 | - if (preg_match($pattern, $definition, $matches) |
|
28 | - && isset($matches[1])) { |
|
29 | - $inlineDef = $matches[1]; |
|
30 | - } |
|
31 | - if ($inlineDef) { |
|
32 | - foreach (self::parseList($inlineDef) as $item) { |
|
33 | - $this->handleCommand('item', $item); |
|
34 | - } |
|
35 | - } |
|
36 | - } |
|
20 | + /** |
|
21 | + * @throws Exception |
|
22 | + */ |
|
23 | + protected function parseDefinition($definition) |
|
24 | + { |
|
25 | + $pattern = self::REGEX_START . 'allof' . self::REGEX_CONTENT . self::REGEX_END; |
|
26 | + $inlineDef = ''; |
|
27 | + if (preg_match($pattern, $definition, $matches) |
|
28 | + && isset($matches[1])) { |
|
29 | + $inlineDef = $matches[1]; |
|
30 | + } |
|
31 | + if ($inlineDef) { |
|
32 | + foreach (self::parseList($inlineDef) as $item) { |
|
33 | + $this->handleCommand('item', $item); |
|
34 | + } |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @throws Exception |
|
40 | - */ |
|
41 | - public function handleCommand($command, $data = null) |
|
42 | - { |
|
43 | - if (strtolower($command) === 'item') { |
|
44 | - $this->mostRecentItem = self::typeFactory($this, $data); |
|
45 | - $this->allOfItems[] = $this->mostRecentItem; |
|
46 | - return $this; |
|
47 | - } |
|
48 | - if (isset($this->mostRecentItem) |
|
49 | - && $this->mostRecentItem->handleCommand($command, $data)) { |
|
50 | - return $this; |
|
51 | - } |
|
52 | - return parent::handleCommand($command, $data); |
|
53 | - } |
|
38 | + /** |
|
39 | + * @throws Exception |
|
40 | + */ |
|
41 | + public function handleCommand($command, $data = null) |
|
42 | + { |
|
43 | + if (strtolower($command) === 'item') { |
|
44 | + $this->mostRecentItem = self::typeFactory($this, $data); |
|
45 | + $this->allOfItems[] = $this->mostRecentItem; |
|
46 | + return $this; |
|
47 | + } |
|
48 | + if (isset($this->mostRecentItem) |
|
49 | + && $this->mostRecentItem->handleCommand($command, $data)) { |
|
50 | + return $this; |
|
51 | + } |
|
52 | + return parent::handleCommand($command, $data); |
|
53 | + } |
|
54 | 54 | |
55 | - public function toArray(): array |
|
56 | - { |
|
57 | - $allOf = array(); |
|
58 | - foreach ($this->allOfItems as $item) { |
|
59 | - $allOf[] = $item->toArray(); |
|
60 | - } |
|
61 | - return self::arrayFilterNull(array_merge(array( |
|
62 | - 'allOf' => $allOf, |
|
63 | - ), parent::toArray())); |
|
64 | - } |
|
55 | + public function toArray(): array |
|
56 | + { |
|
57 | + $allOf = array(); |
|
58 | + foreach ($this->allOfItems as $item) { |
|
59 | + $allOf[] = $item->toArray(); |
|
60 | + } |
|
61 | + return self::arrayFilterNull(array_merge(array( |
|
62 | + 'allOf' => $allOf, |
|
63 | + ), parent::toArray())); |
|
64 | + } |
|
65 | 65 | } |
@@ -16,61 +16,61 @@ |
||
16 | 16 | class AbstractRegexType extends StringType |
17 | 17 | { |
18 | 18 | |
19 | - public const REGEX_DEFAULT_START = '(?:=('; |
|
20 | - public const REGEX_DEFAULT_END = '))?'; |
|
19 | + public const REGEX_DEFAULT_START = '(?:=('; |
|
20 | + public const REGEX_DEFAULT_END = '))?'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * The raw regular expression to use. |
|
24 | - * Exclude start (`^`) and end (`$`) anchors. |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - private $regex; |
|
22 | + /** |
|
23 | + * The raw regular expression to use. |
|
24 | + * Exclude start (`^`) and end (`$`) anchors. |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + private $regex; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Construct and set up the regular expression for this type |
|
31 | - * |
|
32 | - * @param AbstractObject $parent |
|
33 | - * @param string $definition |
|
34 | - * @param string $format Name of the string format |
|
35 | - * @param string $regex Regular expression to use as the format and for default validation |
|
36 | - */ |
|
37 | - public function __construct(AbstractObject $parent, $definition, $format, $regex) |
|
38 | - { |
|
39 | - $this->format = $format; |
|
40 | - $this->regex = $regex; |
|
29 | + /** |
|
30 | + * Construct and set up the regular expression for this type |
|
31 | + * |
|
32 | + * @param AbstractObject $parent |
|
33 | + * @param string $definition |
|
34 | + * @param string $format Name of the string format |
|
35 | + * @param string $regex Regular expression to use as the format and for default validation |
|
36 | + */ |
|
37 | + public function __construct(AbstractObject $parent, $definition, $format, $regex) |
|
38 | + { |
|
39 | + $this->format = $format; |
|
40 | + $this->regex = $regex; |
|
41 | 41 | |
42 | - parent::__construct($parent, $definition); |
|
43 | - } |
|
42 | + parent::__construct($parent, $definition); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @throws Exception |
|
47 | - */ |
|
48 | - protected function parseDefinition($definition) |
|
49 | - { |
|
50 | - $definition = self::trim($definition); |
|
45 | + /** |
|
46 | + * @throws Exception |
|
47 | + */ |
|
48 | + protected function parseDefinition($definition) |
|
49 | + { |
|
50 | + $definition = self::trim($definition); |
|
51 | 51 | |
52 | - $match = array(); |
|
53 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT_START . $this->regex . self::REGEX_DEFAULT_END . self::REGEX_END, $definition, $match) !== 1) { |
|
54 | - throw new Exception('Unparseable ' . $this->format . ' definition: \'' . $definition . '\''); |
|
55 | - } |
|
52 | + $match = array(); |
|
53 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT_START . $this->regex . self::REGEX_DEFAULT_END . self::REGEX_END, $definition, $match) !== 1) { |
|
54 | + throw new Exception('Unparseable ' . $this->format . ' definition: \'' . $definition . '\''); |
|
55 | + } |
|
56 | 56 | |
57 | - if (strtolower($match[1]) !== $this->format) { |
|
58 | - throw new Exception('Not a ' . $this->format . ': \'' . $definition . '\''); |
|
59 | - } |
|
57 | + if (strtolower($match[1]) !== $this->format) { |
|
58 | + throw new Exception('Not a ' . $this->format . ': \'' . $definition . '\''); |
|
59 | + } |
|
60 | 60 | |
61 | - $this->pattern = '^' . $this->regex . '$'; |
|
62 | - $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
63 | - } |
|
61 | + $this->pattern = '^' . $this->regex . '$'; |
|
62 | + $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
63 | + } |
|
64 | 64 | |
65 | - protected function validateDefault($value) |
|
66 | - { |
|
67 | - $value = parent::validateDefault($value); |
|
65 | + protected function validateDefault($value) |
|
66 | + { |
|
67 | + $value = parent::validateDefault($value); |
|
68 | 68 | |
69 | - if (preg_match('/' . $this->pattern . '/', $value) !== 1) { |
|
70 | - throw new Exception('Invalid ' . $this->format . ' default value'); |
|
71 | - } |
|
69 | + if (preg_match('/' . $this->pattern . '/', $value) !== 1) { |
|
70 | + throw new Exception('Invalid ' . $this->format . ' default value'); |
|
71 | + } |
|
72 | 72 | |
73 | - return $value; |
|
74 | - } |
|
73 | + return $value; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -17,98 +17,98 @@ |
||
17 | 17 | class DateType extends AbstractType |
18 | 18 | { |
19 | 19 | |
20 | - /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
21 | - const REGEX_DEFAULT = '(?:=(\S+))?'; |
|
22 | - |
|
23 | - /** |
|
24 | - * Map of recognized format names to Swagger formats |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - private static $formats = array( |
|
28 | - 'date' => 'date', |
|
29 | - 'date-time' => 'date-time', |
|
30 | - 'datetime' => 'date-time', |
|
31 | - ); |
|
32 | - private static $datetime_formats = array( |
|
33 | - 'date' => 'Y-m-d', |
|
34 | - 'date-time' => DateTimeInterface::RFC3339, |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * @var String |
|
39 | - */ |
|
40 | - private $format; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var DateTime |
|
44 | - */ |
|
45 | - private $default = null; |
|
46 | - |
|
47 | - /** |
|
48 | - * @throws Exception |
|
49 | - */ |
|
50 | - protected function parseDefinition($definition) |
|
51 | - { |
|
52 | - $match = array(); |
|
53 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
54 | - throw new Exception("Unparseable date definition: '{$definition}'"); |
|
55 | - } |
|
56 | - |
|
57 | - $type = strtolower($match[1]); |
|
58 | - |
|
59 | - if (!isset(self::$formats[$type])) { |
|
60 | - throw new Exception("Not a date: '{$definition}'"); |
|
61 | - } |
|
62 | - $this->format = self::$formats[$type]; |
|
63 | - |
|
64 | - $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @param string $command The comment command |
|
69 | - * @param string $data Any data added after the command |
|
70 | - * @return AbstractType|boolean |
|
71 | - * @throws Exception |
|
72 | - * @throws Exception |
|
73 | - */ |
|
74 | - public function handleCommand($command, $data = null) |
|
75 | - { |
|
76 | - if (strtolower($command) === 'default') { |
|
77 | - $this->default = $this->validateDefault($data); |
|
78 | - return $this; |
|
79 | - } |
|
80 | - |
|
81 | - return parent::handleCommand($command, $data); |
|
82 | - } |
|
83 | - |
|
84 | - public function toArray(): array |
|
85 | - { |
|
86 | - return self::arrayFilterNull(array_merge(array( |
|
87 | - 'type' => 'string', |
|
88 | - 'format' => $this->format, |
|
89 | - 'default' => $this->default ? $this->default->format(self::$datetime_formats[$this->format]) : null, |
|
90 | - ), parent::toArray())); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @throws Exception |
|
95 | - */ |
|
96 | - private function validateDefault($value) |
|
97 | - { |
|
98 | - if (empty($value)) { |
|
99 | - throw new Exception("Empty date default"); |
|
100 | - } |
|
101 | - |
|
102 | - if (($DateTime = date_create($value)) !== false) { |
|
103 | - return $DateTime; |
|
104 | - } |
|
105 | - |
|
106 | - throw new Exception("Invalid '{$this->format}' default: '{$value}'"); |
|
107 | - } |
|
108 | - |
|
109 | - public function __toString() |
|
110 | - { |
|
111 | - return __CLASS__; |
|
112 | - } |
|
20 | + /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
21 | + const REGEX_DEFAULT = '(?:=(\S+))?'; |
|
22 | + |
|
23 | + /** |
|
24 | + * Map of recognized format names to Swagger formats |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + private static $formats = array( |
|
28 | + 'date' => 'date', |
|
29 | + 'date-time' => 'date-time', |
|
30 | + 'datetime' => 'date-time', |
|
31 | + ); |
|
32 | + private static $datetime_formats = array( |
|
33 | + 'date' => 'Y-m-d', |
|
34 | + 'date-time' => DateTimeInterface::RFC3339, |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * @var String |
|
39 | + */ |
|
40 | + private $format; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var DateTime |
|
44 | + */ |
|
45 | + private $default = null; |
|
46 | + |
|
47 | + /** |
|
48 | + * @throws Exception |
|
49 | + */ |
|
50 | + protected function parseDefinition($definition) |
|
51 | + { |
|
52 | + $match = array(); |
|
53 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
54 | + throw new Exception("Unparseable date definition: '{$definition}'"); |
|
55 | + } |
|
56 | + |
|
57 | + $type = strtolower($match[1]); |
|
58 | + |
|
59 | + if (!isset(self::$formats[$type])) { |
|
60 | + throw new Exception("Not a date: '{$definition}'"); |
|
61 | + } |
|
62 | + $this->format = self::$formats[$type]; |
|
63 | + |
|
64 | + $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @param string $command The comment command |
|
69 | + * @param string $data Any data added after the command |
|
70 | + * @return AbstractType|boolean |
|
71 | + * @throws Exception |
|
72 | + * @throws Exception |
|
73 | + */ |
|
74 | + public function handleCommand($command, $data = null) |
|
75 | + { |
|
76 | + if (strtolower($command) === 'default') { |
|
77 | + $this->default = $this->validateDefault($data); |
|
78 | + return $this; |
|
79 | + } |
|
80 | + |
|
81 | + return parent::handleCommand($command, $data); |
|
82 | + } |
|
83 | + |
|
84 | + public function toArray(): array |
|
85 | + { |
|
86 | + return self::arrayFilterNull(array_merge(array( |
|
87 | + 'type' => 'string', |
|
88 | + 'format' => $this->format, |
|
89 | + 'default' => $this->default ? $this->default->format(self::$datetime_formats[$this->format]) : null, |
|
90 | + ), parent::toArray())); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @throws Exception |
|
95 | + */ |
|
96 | + private function validateDefault($value) |
|
97 | + { |
|
98 | + if (empty($value)) { |
|
99 | + throw new Exception("Empty date default"); |
|
100 | + } |
|
101 | + |
|
102 | + if (($DateTime = date_create($value)) !== false) { |
|
103 | + return $DateTime; |
|
104 | + } |
|
105 | + |
|
106 | + throw new Exception("Invalid '{$this->format}' default: '{$value}'"); |
|
107 | + } |
|
108 | + |
|
109 | + public function __toString() |
|
110 | + { |
|
111 | + return __CLASS__; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | } |