DocblockTest.php
2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* This file is part of Psy Shell.
*
* (c) 2012-2018 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\Util;
use Psy\Util\Docblock;
class DocblockTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider comments
*/
public function testDocblockParsing($comment, $body, $tags)
{
$reflector = $this
->getMockBuilder('ReflectionClass')
->disableOriginalConstructor()
->getMock();
$reflector->expects($this->once())
->method('getDocComment')
->will($this->returnValue($comment));
$docblock = new Docblock($reflector);
$this->assertSame($body, $docblock->desc);
foreach ($tags as $tag => $value) {
$this->assertTrue($docblock->hasTag($tag));
$this->assertEquals($value, $docblock->tag($tag));
}
}
public function comments()
{
if (\defined('HHVM_VERSION')) {
$this->markTestSkipped('We have issues with PHPUnit mocks on HHVM.');
}
return [
['', '', []],
[
'/**
* This is a docblock
*
* @throws \Exception with a description
*/',
'This is a docblock',
[
'throws' => [['type' => '\Exception', 'desc' => 'with a description']],
],
],
[
'/**
* This is a slightly longer docblock
*
* @param int $foo Is a Foo
* @param string $bar With some sort of description
* @param \ClassName $baz is cool too
*
* @return int At least it isn\'t a string
*/',
'This is a slightly longer docblock',
[
'param' => [
['type' => 'int', 'desc' => 'Is a Foo', 'var' => '$foo'],
['type' => 'string', 'desc' => 'With some sort of description', 'var' => '$bar'],
['type' => '\ClassName', 'desc' => 'is cool too', 'var' => '$baz'],
],
'return' => [
['type' => 'int', 'desc' => 'At least it isn\'t a string'],
],
],
],
[
'/**
* This is a docblock!
*
* It spans lines, too!
*
* @tagname plus a description
*
* @return
*/',
"This is a docblock!\n\nIt spans lines, too!",
[
'tagname' => ['plus a description'],
],
],
];
}
}