1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Reflection\Php; |
14
|
|
|
|
15
|
|
|
use \Mockery as m; |
16
|
|
|
use phpDocumentor\Reflection\DocBlock; |
17
|
|
|
use phpDocumentor\Reflection\Fqsen; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Tests the functionality for the File class. |
22
|
|
|
* |
23
|
|
|
* @coversDefaultClass phpDocumentor\Reflection\Php\File |
24
|
|
|
*/ |
25
|
|
|
class FileTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
const EXAMPLE_HASH = 'a-hash-string'; |
28
|
|
|
const EXAMPLE_PATH = 'a-path-string'; |
29
|
|
|
const EXAMPLE_SOURCE = 'a-source-string'; |
30
|
|
|
|
31
|
|
|
/** @var File $fixture */ |
32
|
|
|
protected $fixture; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var DocBlock |
36
|
|
|
*/ |
37
|
|
|
private $docBlock; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Creates a new (emoty) fixture object. |
41
|
|
|
*/ |
42
|
|
|
protected function setUp() |
43
|
|
|
{ |
44
|
|
|
$this->docBlock = new DocBlock(''); |
45
|
|
|
|
46
|
|
|
$this->fixture = new File(static::EXAMPLE_HASH, static::EXAMPLE_PATH, static::EXAMPLE_SOURCE, $this->docBlock); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function tearDown() |
50
|
|
|
{ |
51
|
|
|
m::close(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @covers ::__construct |
56
|
|
|
* @covers ::getClasses |
57
|
|
|
* @covers ::AddClass |
58
|
|
|
*/ |
59
|
|
|
public function testAddAndGetClasses() |
60
|
|
|
{ |
61
|
|
|
$this->assertEmpty($this->fixture->getClasses()); |
62
|
|
|
|
63
|
|
|
$class = new Class_(new Fqsen('\MySpace\MyClass')); |
64
|
|
|
$this->fixture->addClass($class); |
65
|
|
|
|
66
|
|
|
$this->assertEquals(array('\MySpace\MyClass' => $class), $this->fixture->getClasses()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @covers ::__construct |
71
|
|
|
* @covers ::getConstants |
72
|
|
|
* @covers ::addConstant |
73
|
|
|
*/ |
74
|
|
|
public function testAddAndGetConstants() |
75
|
|
|
{ |
76
|
|
|
$this->assertEmpty($this->fixture->getConstants()); |
77
|
|
|
|
78
|
|
|
$constant = new Constant(new Fqsen('\MySpace::MY_CONSTANT')); |
79
|
|
|
$this->fixture->addConstant($constant); |
80
|
|
|
|
81
|
|
|
$this->assertEquals(array('\MySpace::MY_CONSTANT' => $constant), $this->fixture->getConstants()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @covers ::__construct |
86
|
|
|
* @covers ::getFunctions |
87
|
|
|
* @covers ::addFunction |
88
|
|
|
*/ |
89
|
|
|
public function testAddAndGetFunctions() |
90
|
|
|
{ |
91
|
|
|
$this->assertEmpty($this->fixture->getFunctions()); |
92
|
|
|
|
93
|
|
|
$function = new Function_(new Fqsen('\MySpace::MyFunction()')); |
94
|
|
|
$this->fixture->addFunction($function); |
95
|
|
|
|
96
|
|
|
$this->assertEquals(array('\MySpace::MyFunction()' => $function), $this->fixture->getFunctions()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @covers ::__construct |
101
|
|
|
* @covers ::getInterfaces |
102
|
|
|
* @covers ::addInterface |
103
|
|
|
*/ |
104
|
|
|
public function testAddAndGetInterfaces() |
105
|
|
|
{ |
106
|
|
|
$this->assertEmpty($this->fixture->getInterfaces()); |
107
|
|
|
|
108
|
|
|
$interface = new Interface_(new Fqsen('\MySpace\MyInterface'), array()); |
109
|
|
|
$this->fixture->addInterface($interface); |
110
|
|
|
|
111
|
|
|
$this->assertEquals(array('\MySpace\MyInterface' => $interface), $this->fixture->getInterfaces()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @covers ::__construct |
116
|
|
|
* @covers ::getTraits |
117
|
|
|
* @covers ::addTrait |
118
|
|
|
*/ |
119
|
|
|
public function testAddAndGetTraits() |
120
|
|
|
{ |
121
|
|
|
$this->assertEmpty($this->fixture->getTraits()); |
122
|
|
|
|
123
|
|
|
$trait = new Trait_(new Fqsen('\MySpace\MyTrait')); |
124
|
|
|
$this->fixture->addTrait($trait); |
125
|
|
|
|
126
|
|
|
$this->assertEquals(array('\MySpace\MyTrait' => $trait), $this->fixture->getTraits()); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @covers ::__construct |
131
|
|
|
* @covers ::getDocBlock |
132
|
|
|
*/ |
133
|
|
|
public function testGetDocBlock() |
134
|
|
|
{ |
135
|
|
|
$this->assertSame($this->docBlock, $this->fixture->getDocBlock()); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @covers ::__construct |
140
|
|
|
* @covers ::getHash |
141
|
|
|
*/ |
142
|
|
|
public function testGetHash() |
143
|
|
|
{ |
144
|
|
|
$this->assertSame(self::EXAMPLE_HASH, $this->fixture->getHash()); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @covers ::getPath |
149
|
|
|
*/ |
150
|
|
|
public function testSetAndGetPath() |
151
|
|
|
{ |
152
|
|
|
$this->assertSame(self::EXAMPLE_PATH, $this->fixture->getPath()); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @covers ::getSource |
157
|
|
|
*/ |
158
|
|
|
public function testSetAndGetSource() |
159
|
|
|
{ |
160
|
|
|
$this->assertSame(self::EXAMPLE_SOURCE, $this->fixture->getSource()); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @covers ::addNamespace |
165
|
|
|
* @covers ::getNamespaces |
166
|
|
|
*/ |
167
|
|
|
public function testSetAndGetNamespaceAliases() |
168
|
|
|
{ |
169
|
|
|
$this->assertEmpty($this->fixture->getNamespaces()); |
170
|
|
|
|
171
|
|
|
$this->fixture->addNamespace(new Fqsen('\MyNamepace\Foo')); |
172
|
|
|
|
173
|
|
|
$this->assertEquals(array('\MyNamepace\Foo' => new Fqsen('\MyNamepace\Foo')), $this->fixture->getNamespaces()); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @covers ::getIncludes |
178
|
|
|
* @covers ::addInclude |
179
|
|
|
*/ |
180
|
|
|
public function testAddAndGetIncludes() |
181
|
|
|
{ |
182
|
|
|
$this->assertEmpty($this->fixture->getIncludes()); |
183
|
|
|
|
184
|
|
|
$include = static::EXAMPLE_PATH; |
185
|
|
|
$this->fixture->addInclude($include); |
186
|
|
|
|
187
|
|
|
$this->assertSame(array(static::EXAMPLE_PATH => static::EXAMPLE_PATH), $this->fixture->getIncludes()); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|