Completed
Pull Request — master (#45)
by
unknown
02:24
created

testParse_PropertyOptional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
class Parser_Php_ParserTest extends SwaggerGen_TestCase
4
{
5
6
	/**
7
	 * Test if the statement matches the expected values
8
	 * @param \SwaggerGen\Statement $statement
9
	 * @param string $command
10
	 * @param string $data
11
	 */
12
	private function assertStatement($statement, $command, $data = '')
13
	{
14
		$this->assertInstanceOf('\SwaggerGen\Statement', $statement);
15
		$this->assertSame($command, $statement->getCommand());
16
		$this->assertSame($data, $statement->getData());
17
	}
18
19
	/**
20
	 * Test if the statement matches the expected values
21
	 * @param array[] $expected
22
	 * @param SwaggerGen\Parser\Php\Statement[] $statements
23
	 */
24
	private function assertStatements(array $expected, array $statements)
25
	{
26
		$this->assertCount(count($expected), $statements, join("\n", $statements));
27
		foreach ($expected as $index => $command) {
28
			$statement = $statements[$index];
29
			$this->assertInstanceOf('\SwaggerGen\Statement', $statement);
30
			$this->assertSame($command[0], $statement->getCommand());
31
			$this->assertSame($command[1], $statement->getData());
32
		}
33
	}
34
35
	/**
36
	 * @covers \SwaggerGen\Parser\Php\Parser::__construct
37
	 */
38
	public function testConstructor_Empty()
39
	{
40
		$object = new \SwaggerGen\Parser\Php\Parser();
41
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
42
	}
43
44
	/**
45
	 * @covers \SwaggerGen\Parser\Php\Parser::__construct
46
	 */
47
	public function testConstructor_Dirs()
48
	{
49
		$this->markTestIncomplete('Not yet implemented.');
50
	}
51
52
	/**
53
	 * @covers \SwaggerGen\Parser\Php\Parser::addDirs
54
	 */
55
	public function testAddDirs()
56
	{
57
		$this->markTestIncomplete('Not yet implemented.');
58
	}
59
60
	/**
61
	 * Test all open-curlies are (ac-)counted for in functions
62
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
63
	 */
64
	public function testParse_CurlyBraceFunction()
65
	{
66
		$object = new \SwaggerGen\Parser\Php\Parser();
67
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
68
69
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_CurlyBraceFunction.php');
70
		$this->assertCount(6, $statements);
71
		$this->assertStatement($statements[0], 'title', 'CurlyBraceFunction');
72
	}
73
74
	/**
75
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
76
	 */
77
	public function testParse_NoMethods()
78
	{
79
		$object = new \SwaggerGen\Parser\Php\Parser();
80
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
81
82
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_NoMethods.php');
83
84
		$this->assertCount(2, $statements);
85
86
		$this->assertStatement($statements[0], 'title', 'Some words');
87
		$this->assertStatement($statements[1], 'version', '2');
88
	}
89
90
	/**
91
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
92
	 */
93
	public function testParse_WithMethod()
94
	{
95
		$object = new \SwaggerGen\Parser\Php\Parser();
96
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
97
98
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_WithMethod.php');
99
100
		$this->assertCount(4, $statements);
101
102
		$this->assertStatement($statements[0], 'title', 'Some words');
103
		$this->assertStatement($statements[1], 'version', '2');
104
		$this->assertStatement($statements[2], 'description', 'some description');
105
		$this->assertStatement($statements[3], 'method', 'get something');
106
	}
107
108
	/**
109
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
110
	 */
111
	public function testParse_LineContinuation()
112
	{
113
		$object = new \SwaggerGen\Parser\Php\Parser();
114
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
115
116
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_LineContinuation.php');
117
118
		$this->assertCount(2, $statements);
119
120
		$this->assertStatement($statements[0], 'title', 'Some words');
121
		$this->assertStatement($statements[1], 'description', 'About this strange little class');
122
	}
123
124
	/**
125
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
126
	 */
127
	public function testParse_InClass()
128
	{
129
		$object = new \SwaggerGen\Parser\Php\Parser();
130
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
131
132
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_InClass.php');
133
134
		$this->assertCount(3, $statements);
135
136
		$this->assertStatement($statements[0], 'title', 'Some words');
137
		$this->assertStatement($statements[1], 'description', 'Some description');
138
		$this->assertStatement($statements[2], 'license', 'mit');
139
	}
140
141
	/**
142
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
143
	 */
144
	public function testParse_CommentsTypes()
145
	{
146
		$object = new \SwaggerGen\Parser\Php\Parser();
147
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
148
149
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_CommentsTypes.php');
150
151
		$this->assertCount(3, $statements);
152
153
		$this->assertStatement($statements[0], 'title', 'Some words');
154
		$this->assertStatement($statements[1], 'version', '2');
155
		$this->assertStatement($statements[2], 'license', 'mit');
156
	}
157
158
	/**
159
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
160
	 */
161
	public function testParse_MethodNonDoc()
162
	{
163
		$object = new \SwaggerGen\Parser\Php\Parser();
164
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
165
166
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_MethodNonDoc.php');
167
168
		$this->assertCount(3, $statements);
169
170
		$this->assertStatement($statements[0], 'title', 'Some words');
171
		$this->assertStatement($statements[1], 'version', '2');
172
		$this->assertStatement($statements[2], 'method', 'get something');
173
	}
174
175
	/**
176
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
177
	 */
178
	public function testParse_InMethod()
179
	{
180
		$object = new \SwaggerGen\Parser\Php\Parser();
181
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
182
183
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_InMethod.php');
184
185
		$this->assertCount(4, $statements);
186
187
		$this->assertStatement($statements[0], 'title', 'Some words');
188
		$this->assertStatement($statements[1], 'version', '2');
189
		$this->assertStatement($statements[2], 'description', 'some description');
190
		$this->assertStatement($statements[3], 'method', 'get something');
191
	}
192
193
	/**
194
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
195
	 */
196
	public function testParse_AfterClass()
197
	{
198
		$object = new \SwaggerGen\Parser\Php\Parser();
199
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
200
201
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_AfterClass.php');
202
203
		$this->assertCount(2, $statements);
204
205
		$this->assertStatement($statements[0], 'license', 'mit');
206
		$this->assertStatement($statements[1], 'title', 'Some words');
207
	}
208
209
	/**
210
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
211
	 */
212
	public function testParse_Prefix()
213
	{
214
		$object = new \SwaggerGen\Parser\Php\Parser();
215
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
216
217
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_Prefix.php');
218
219
		$this->assertCount(1, $statements);
220
221
		$this->assertStatement($statements[0], 'title', 'Some words');
222
	}
223
224
    /**
225
     * @covers \SwaggerGen\Parser\Php\Parser::parse
226
     */
227
    public function testParse_PropertyReadOnly()
228
    {
229
        $object = new \SwaggerGen\Parser\Php\Parser();
230
        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
231
232
        $statements = $object->parse(__DIR__ . '/ParserTest/testParse_PropertyReadOnly.php');
233
234
        $this->assertCount(4, $statements);
235
236
        $this->assertStatement($statements[0], 'title', 'Some words');
237
        $this->assertStatement($statements[1], 'version', '2');
238
        $this->assertStatement($statements[2], 'definition', 'Foo');
239
        $this->assertStatement($statements[3], 'property!', 'string bar');
240
    }
241
242
    /**
243
     * @covers \SwaggerGen\Parser\Php\Parser::parse
244
     */
245
    public function testParse_PropertyOptional()
246
    {
247
        $object = new \SwaggerGen\Parser\Php\Parser();
248
        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
249
250
        $statements = $object->parse(__DIR__ . '/ParserTest/testParse_PropertyOptional.php');
251
252
        $this->assertCount(4, $statements);
253
254
        $this->assertStatement($statements[0], 'title', 'Some words');
255
        $this->assertStatement($statements[1], 'version', '2');
256
        $this->assertStatement($statements[2], 'definition', 'Foo');
257
        $this->assertStatement($statements[3], 'property?', 'string bar');
258
    }
259
260
	/**
261
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
262
	 */
263
	public function testParse_Minimal()
264
	{
265
		$object = new \SwaggerGen\Parser\Php\Parser();
266
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
267
268
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_Minimal.php');
269
270
		$this->assertCount(4, $statements);
271
272
		$this->assertStatement($statements[0], 'title', 'Minimal');
273
		$this->assertStatement($statements[1], 'api', 'MyApi Example');
274
		$this->assertStatement($statements[2], 'endpoint', '/endpoint');
275
		$this->assertStatement($statements[3], 'method', 'GET Something');
276
	}
277
278
	/**
279
	 * Tests FunctionName
280
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
281
	 */
282
	public function testParse_SeeFunction()
283
	{
284
		$object = new \SwaggerGen\Parser\Php\Parser();
285
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
286
287
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_SeeFunction.php');
288
289
		$this->assertStatements(array(
290
			array('api', 'MyApi Example'),
291
			array('endpoint', '/endpoint'),
292
			array('method', 'GET Something'),
293
			array('error', '400'),
294
				), $statements);
295
	}
296
297
	/**
298
	 * Tests $this->MethodName
299
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
300
	 */
301
	public function testParse_SeeThisMethod()
302
	{
303
		$object = new \SwaggerGen\Parser\Php\Parser();
304
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
305
306
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_SeeThisMethod.php');
307
308
		$this->assertStatements(array(
309
			array('api', 'MyApi Example'),
310
			array('endpoint', '/endpoint'),
311
			array('method', 'GET Something'),
312
			array('error', '400'),
313
				), $statements);
314
	}
315
316
	/**
317
	 * Tests Class->MethodName
318
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
319
	 */
320
	public function testParse_SeeObjectMethod()
321
	{
322
		$object = new \SwaggerGen\Parser\Php\Parser();
323
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
324
325
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_SeeObjectMethod.php');
326
327
		$this->assertStatements(array(
328
			array('api', 'MyApi Example'),
329
			array('endpoint', '/endpoint'),
330
			array('method', 'GET Something'),
331
			array('error', '400'),
332
				), $statements);
333
	}
334
335
	/**
336
	 * Tests self::MethodName
337
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
338
	 */
339
	public function testParse_SeeSelfMethod()
340
	{
341
		$object = new \SwaggerGen\Parser\Php\Parser();
342
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
343
344
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_SeeSelfMethod.php');
345
346
		$this->assertStatements(array(
347
			array('api', 'MyApi Example'),
348
			array('endpoint', '/endpoint'),
349
			array('method', 'GET Something'),
350
			array('error', '400'),
351
				), $statements);
352
	}
353
354
	/**
355
	 * Tests Class::MethodName
356
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
357
	 */
358
	public function testParse_SeeClassMethod()
359
	{
360
		$object = new \SwaggerGen\Parser\Php\Parser();
361
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
362
363
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_SeeClassMethod.php');
364
365
		$this->assertStatements(array(
366
			array('api', 'MyApi Example'),
367
			array('endpoint', '/endpoint'),
368
			array('method', 'GET Something'),
369
			array('error', '400'),
370
				), $statements);
371
	}
372
373
	/**
374
	 * Tests static::MethodName
375
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
376
	 */
377
	public function testParse_StaticMethod()
378
	{
379
		$object = new \SwaggerGen\Parser\Php\Parser();
380
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
381
382
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_StaticMethod.php');
383
384
		$this->assertStatements(array(
385
			array('api', 'MyApi Example'),
386
			array('endpoint', '/endpoint'),
387
			array('method', 'GET Something'),
388
			array('error', '400'),
389
				), $statements);
390
	}
391
392
	/**
393
	 * Tests $this->MethodName with inheritance
394
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
395
	 */
396
	public function testParse_SeeInheritedThisMethod()
397
	{
398
		$object = new \SwaggerGen\Parser\Php\Parser();
399
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
400
401
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_SeeInheritedThisMethod.php');
402
403
		$this->assertStatements(array(
404
			array('api', 'MyApi Example'),
405
			array('endpoint', '/endpoint'),
406
			array('method', 'GET Something'),
407
			array('error', '400'),
408
				), $statements);
409
	}
410
411
	/**
412
	 * Tests Class->MethodName with inheritance
413
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
414
	 */
415
	public function testParse_SeeInheritedObjectMethod()
416
	{
417
		$object = new \SwaggerGen\Parser\Php\Parser();
418
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
419
420
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_SeeInheritedObjectMethod.php');
421
422
		$this->assertStatements(array(
423
			array('api', 'MyApi Example'),
424
			array('endpoint', '/endpoint'),
425
			array('method', 'GET Something'),
426
			array('error', '400'),
427
				), $statements);
428
	}
429
430
	/**
431
	 * Tests Autoloading other class when referenced
432
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
433
	 */
434
	public function testParse_Autoload_Parse()
435
	{
436
		$object = new \SwaggerGen\Parser\Php\Parser();
437
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
438
439
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_Autoload.php', array(
440
			__DIR__ . '/ParserTest',
441
		));
442
443
		$this->assertStatements(array(
444
			array('api', 'MyApi Example'),
445
			array('endpoint', '/endpoint'),
446
			array('method', 'GET Something'),
447
			array('error', '400'),
448
				), $statements);
449
	}
450
451
	/**
452
	 * Tests Autoloading other class when referenced
453
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
454
	 */
455
	public function testParse_Autoload_Construct()
456
	{
457
		$object = new \SwaggerGen\Parser\Php\Parser(array(
458
			__DIR__ . '/ParserTest',
459
		));
460
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
461
462
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_Autoload.php');
463
464
		$this->assertStatements(array(
465
			array('api', 'MyApi Example'),
466
			array('endpoint', '/endpoint'),
467
			array('method', 'GET Something'),
468
			array('error', '400'),
469
				), $statements);
470
	}
471
472
	/**
473
	 * Tests Autoloading other class when referenced
474
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
475
	 */
476
	public function testParse_Autoload_AddDirs()
477
	{
478
		$object = new \SwaggerGen\Parser\Php\Parser();
479
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
480
481
		$object->addDirs(array(
482
			__DIR__ . '/ParserTest',
483
		));
484
485
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_Autoload.php');
486
487
		$this->assertStatements(array(
488
			array('api', 'MyApi Example'),
489
			array('endpoint', '/endpoint'),
490
			array('method', 'GET Something'),
491
			array('error', '400'),
492
				), $statements);
493
	}
494
495
	/**
496
	 * @covers \SwaggerGen\Parser\Php\Parser::parse
497
	 */
498
	public function testParse_XTag()
499
	{
500
		$object = new \SwaggerGen\Parser\Php\Parser();
501
		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
502
503
		$object->addDirs(array(
504
			__DIR__ . '/ParserTest',
505
		));
506
507
		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_XTag.php');
508
509
		$this->assertStatements(array(
510
			array('api', 'MyApi Example'),
511
			array('endpoint', '/endpoint'),
512
			array('x-something', 'else'),
513
			array('method', 'GET Something'),
514
				), $statements);
515
	}
516
517
}
518