Completed
Push — master ( 088bf6...a47832 )
by Martijn
02:41
created

Parser_Text_PreprocessorTest   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 407
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 407
rs 10
c 0
b 0
f 0
wmc 18
lcom 0
cbo 2

18 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructor_Empty() 0 5 1
A testPreprocess_Ifdef_NotDefined() 0 16 1
A testPreprocess_Ifdef_Defined() 0 17 1
A testPreprocess_Ifndef_NotDefined() 0 16 1
A testPreprocess_Ifndef_Defined() 0 17 1
A testPreprocess_Define() 0 18 1
A testPreprocess_Undef() 0 20 1
A testPreprocess_If_NotDefined() 0 16 1
A testPreprocess_If_AnyValue() 0 17 1
A testPreprocess_If_NoValue() 0 17 1
A testPreprocess_If_Mismatch() 0 17 1
A testPreprocess_If_Match() 0 17 1
A testPreprocess_Else_Match() 0 21 1
B testPreprocess_Elif_Match() 0 25 1
B testPreprocess_Elif_NoValue() 0 25 1
A testPreprocess_Undefine() 0 18 1
A testPreprocess_ResetDefines() 0 18 1
A testPreprocess_AddDefines() 0 17 1
1
<?php
2
3
class Parser_Text_PreprocessorTest extends SwaggerGen_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
	/**
7
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::__construct
8
	 */
9
	public function testConstructor_Empty()
10
	{
11
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
12
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
13
	}
14
15
	/**
16
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
17
	 */
18
	public function testPreprocess_Ifdef_NotDefined()
19
	{
20
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
21
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
22
		$out = $object->preprocess('
23
			ifdef test
24
			whatever
25
			endif
26
		');
27
28
		$this->assertEquals('
29
30
31
32
		', $out);
33
	}
34
35
	/**
36
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
37
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
38
	 */
39
	public function testPreprocess_Ifdef_Defined()
40
	{
41
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
42
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
43
		$object->define('test');
44
		$out = $object->preprocess('
45
			ifdef test
46
			whatever
47
			endif
48
		');
49
50
		$this->assertEquals('
51
52
			whatever
53
54
		', $out);
55
	}
56
57
	/**
58
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
59
	 */
60
	public function testPreprocess_Ifndef_NotDefined()
61
	{
62
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
63
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
64
		$out = $object->preprocess('
65
			ifndef test
66
			whatever
67
			endif
68
		');
69
70
		$this->assertEquals('
71
72
			whatever
73
74
		', $out);
75
	}
76
77
	/**
78
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
79
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
80
	 */
81
	public function testPreprocess_Ifndef_Defined()
82
	{
83
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
84
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
85
		$object->define('test');
86
		$out = $object->preprocess('
87
			ifndef test
88
			whatever
89
			endif
90
		');
91
92
		$this->assertEquals('
93
94
95
96
		', $out);
97
	}
98
99
	/**
100
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
101
	 */
102
	public function testPreprocess_Define()
103
	{
104
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
105
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
106
		$out = $object->preprocess('
107
			define test
108
			ifndef test
109
			whatever
110
			endif
111
		');
112
113
		$this->assertEquals('
114
115
116
117
118
		', $out);
119
	}
120
121
	/**
122
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
123
	 */
124
	public function testPreprocess_Undef()
125
	{
126
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
127
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
128
		$out = $object->preprocess('
129
			define test
130
			undef test
131
			ifdef test
132
			whatever
133
			endif
134
		');
135
136
		$this->assertEquals('
137
138
139
140
141
142
		', $out);
143
	}
144
145
	/**
146
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
147
	 */
148
	public function testPreprocess_If_NotDefined()
149
	{
150
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
151
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
152
		$out = $object->preprocess('
153
			if test red
154
			whatever
155
			endif
156
		');
157
158
		$this->assertEquals('
159
160
161
162
		', $out);
163
	}
164
165
	/**
166
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
167
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
168
	 */
169
	public function testPreprocess_If_AnyValue()
170
	{
171
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
172
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
173
		$object->define('test', 'green');
174
		$out = $object->preprocess('
175
			if test
176
			whatever
177
			endif
178
		');
179
180
		$this->assertEquals('
181
182
			whatever
183
184
		', $out);
185
	}
186
187
	/**
188
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
189
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
190
	 */
191
	public function testPreprocess_If_NoValue()
192
	{
193
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
194
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
195
		$object->define('test');
196
		$out = $object->preprocess('
197
			if test red
198
			whatever
199
			endif
200
		');
201
202
		$this->assertEquals('
203
204
205
206
		', $out);
207
	}
208
209
	/**
210
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
211
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
212
	 */
213
	public function testPreprocess_If_Mismatch()
214
	{
215
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
216
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
217
		$object->define('test', 'green');
218
		$out = $object->preprocess('
219
			if test red
220
			whatever
221
			endif
222
		');
223
224
		$this->assertEquals('
225
226
227
228
		', $out);
229
	}
230
231
	/**
232
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
233
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
234
	 */
235
	public function testPreprocess_If_Match()
236
	{
237
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
238
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
239
		$object->define('test', 'red');
240
		$out = $object->preprocess('
241
			if test red
242
			whatever
243
			endif
244
		');
245
246
		$this->assertEquals('
247
248
			whatever
249
250
		', $out);
251
	}
252
253
	/**
254
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
255
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
256
	 */
257
	public function testPreprocess_Else_Match()
258
	{
259
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
260
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
261
		$object->define('test', 'blue');
262
		$out = $object->preprocess('
263
			if test red
264
			whatever
265
			else
266
			otherwise
267
			endif
268
		');
269
270
		$this->assertEquals('
271
272
273
274
			otherwise
275
276
		', $out);
277
	}
278
279
	/**
280
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
281
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
282
	 */
283
	public function testPreprocess_Elif_Match()
284
	{
285
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
286
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
287
		$object->define('test', 'blue');
288
		$out = $object->preprocess('
289
			if test red
290
			whatever
291
			elif test green
292
			second
293
			elif test blue
294
			otherwise
295
			endif
296
		');
297
298
		$this->assertEquals('
299
300
301
302
303
304
			otherwise
305
306
		', $out);
307
	}
308
309
	/**
310
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
311
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
312
	 */
313
	public function testPreprocess_Elif_NoValue()
314
	{
315
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
316
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
317
		$object->define('test', 'blue');
318
		$out = $object->preprocess('
319
			if test red
320
			whatever
321
			elif test green
322
			second
323
			elif test
324
			otherwise
325
			endif
326
		');
327
328
		$this->assertEquals('
329
330
331
332
333
334
			otherwise
335
336
		', $out);
337
	}
338
339
	/**
340
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
341
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::undefine
342
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
343
	 */
344
	public function testPreprocess_Undefine()
345
	{
346
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
347
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
348
		$object->define('test');
349
		$object->undefine('test');
350
		$out = $object->preprocess('
351
			ifdef test
352
			whatever
353
			endif
354
		');
355
356
		$this->assertEquals('
357
358
359
360
		', $out);
361
	}
362
363
	/**
364
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
365
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::resetDefines
366
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
367
	 */
368
	public function testPreprocess_ResetDefines()
369
	{
370
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
371
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
372
		$object->define('test');
373
		$object->resetDefines();
374
		$out = $object->preprocess('
375
			ifdef test
376
			whatever
377
			endif
378
		');
379
380
		$this->assertEquals('
381
382
383
384
		', $out);
385
	}
386
387
	/**
388
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::addDefines
389
	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
390
	 */
391
	public function testPreprocess_AddDefines()
392
	{
393
		$object = new \SwaggerGen\Parser\Text\Preprocessor();
394
		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
395
		$object->addDefines(array('test' => true));
396
		$out = $object->preprocess('
397
			ifdef test
398
			whatever
399
			endif
400
		');
401
402
		$this->assertEquals('
403
404
			whatever
405
406
		', $out);
407
	}
408
409
}
410