1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @author Mike van Riel <[email protected]> |
8
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Parser; |
14
|
|
|
|
15
|
|
|
use Mockery as m; |
16
|
|
|
use phpDocumentor\Reflection\ProjectFactory; |
17
|
|
|
use Psr\Log\NullLogger; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test class for \phpDocumentor\Parser\Parser. |
21
|
|
|
* |
22
|
|
|
* @coversDefaultClass \phpDocumentor\Parser\Parser |
23
|
|
|
* @covers ::__construct |
24
|
|
|
* @covers ::<private> |
25
|
|
|
*/ |
26
|
|
|
class ParserTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
27
|
|
|
{ |
28
|
|
|
/** @var Parser */ |
29
|
|
|
protected $fixture = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Instantiates a new parser object as fixture. |
33
|
|
|
*/ |
34
|
|
|
protected function setUp() |
35
|
|
|
{ |
36
|
|
|
ini_set('zend.script_encoding', null); |
37
|
|
|
$this->fixture = new Parser( |
38
|
|
|
m::mock(ProjectFactory::class), |
39
|
|
|
m::mock('Symfony\Component\Stopwatch\Stopwatch'), |
40
|
|
|
new NullLogger() |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @covers ::getIgnoredTags |
46
|
|
|
* @covers ::setIgnoredTags |
47
|
|
|
*/ |
48
|
|
|
public function testSetAndGetIgnoredTags() |
49
|
|
|
{ |
50
|
|
|
$parser = new Parser( |
51
|
|
|
m::mock(ProjectFactory::class), |
52
|
|
|
m::mock('Symfony\Component\Stopwatch\Stopwatch'), |
53
|
|
|
new NullLogger() |
54
|
|
|
); |
55
|
|
|
$this->assertEquals([], $parser->getIgnoredTags()); |
56
|
|
|
|
57
|
|
|
$parser->setIgnoredTags(['param']); |
58
|
|
|
$this->assertEquals(['param'], $parser->getIgnoredTags()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @covers ::setForced |
63
|
|
|
* @covers ::isForced |
64
|
|
|
*/ |
65
|
|
|
public function testSetAndCheckWhetherParsingIsForced() |
66
|
|
|
{ |
67
|
|
|
$this->assertEquals(false, $this->fixture->isForced()); |
68
|
|
|
|
69
|
|
|
$this->fixture->setForced(true); |
70
|
|
|
$this->assertEquals(true, $this->fixture->isForced()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @covers ::setEncoding |
75
|
|
|
* @covers ::getEncoding |
76
|
|
|
*/ |
77
|
|
|
public function testSettingAndRetrievingTheEncodingOfTheProvidedFiles() |
78
|
|
|
{ |
79
|
|
|
$this->assertEquals('utf-8', $this->fixture->getEncoding()); |
80
|
|
|
|
81
|
|
|
$this->fixture->setEncoding('iso-8859-1'); |
82
|
|
|
$this->assertEquals('iso-8859-1', $this->fixture->getEncoding()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @covers ::setPath |
87
|
|
|
* @covers ::getPath |
88
|
|
|
*/ |
89
|
|
|
public function testSettingAndRetrievingTheBasePath() |
90
|
|
|
{ |
91
|
|
|
// Arrange |
92
|
|
|
$this->assertSame('', $this->fixture->getPath()); |
93
|
|
|
|
94
|
|
|
// Act |
95
|
|
|
$this->fixture->setPath(sys_get_temp_dir()); |
96
|
|
|
|
97
|
|
|
// Assert |
98
|
|
|
$this->assertSame(sys_get_temp_dir(), $this->fixture->getPath()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Tests whether the doValidation() and setValidate methods function |
103
|
|
|
* properly. |
104
|
|
|
* |
105
|
|
|
* @covers ::setValidate |
106
|
|
|
* @covers ::doValidation |
107
|
|
|
*/ |
108
|
|
|
public function testValidate() |
109
|
|
|
{ |
110
|
|
|
// defaults to false |
111
|
|
|
$this->assertEquals(false, $this->fixture->doValidation()); |
112
|
|
|
|
113
|
|
|
$this->fixture->setValidate(true); |
114
|
|
|
$this->assertEquals(true, $this->fixture->doValidation()); |
115
|
|
|
|
116
|
|
|
$this->fixture->setValidate(false); |
117
|
|
|
$this->assertEquals(false, $this->fixture->doValidation()); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Tests whether the getMarker() and setMarkers methods function |
122
|
|
|
* properly. |
123
|
|
|
* |
124
|
|
|
* @covers ::setMarkers |
125
|
|
|
* @covers ::getMarkers |
126
|
|
|
*/ |
127
|
|
|
public function testMarkers() |
128
|
|
|
{ |
129
|
|
|
$fixture_data = ['FIXME', 'TODO', 'DOIT']; |
130
|
|
|
|
131
|
|
|
// default is TODO and FIXME |
132
|
|
|
$this->assertEquals(['TODO', 'FIXME'], $this->fixture->getMarkers()); |
133
|
|
|
|
134
|
|
|
$this->fixture->setMarkers($fixture_data); |
135
|
|
|
$this->assertEquals($fixture_data, $this->fixture->getMarkers()); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @covers ::setDefaultPackageName |
140
|
|
|
* @covers ::getDefaultPackageName |
141
|
|
|
*/ |
142
|
|
|
public function testSetAndGetDefaultPackageName() |
143
|
|
|
{ |
144
|
|
|
$parser = new Parser( |
145
|
|
|
m::mock(ProjectFactory::class), |
146
|
|
|
m::mock('Symfony\Component\Stopwatch\Stopwatch'), |
147
|
|
|
new NullLogger() |
148
|
|
|
); |
149
|
|
|
|
150
|
|
|
$this->assertEquals('Default', $parser->getDefaultPackageName()); |
151
|
|
|
|
152
|
|
|
$parser->setDefaultPackageName('test'); |
153
|
|
|
|
154
|
|
|
$this->assertSame('test', $parser->getDefaultPackageName()); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|