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; |
14
|
|
|
|
15
|
|
|
use Mockery as m; |
16
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Param; |
17
|
|
|
use phpDocumentor\Reflection\File\LocalFile; |
18
|
|
|
use phpDocumentor\Reflection\Php\Interface_; |
19
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactory; |
20
|
|
|
use phpDocumentor\Reflection\Types\Object_; |
21
|
|
|
use phpDocumentor\Reflection\Types\String_; |
22
|
|
|
use PHPUnit\Framework\TestCase; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Intergration tests to check the correct working of processing a file into a project. |
26
|
|
|
* |
27
|
|
|
* @coversNothing |
28
|
|
|
*/ |
29
|
|
|
class ProjectCreationTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var ProjectFactory |
33
|
|
|
*/ |
34
|
|
|
private $fixture; |
35
|
|
|
|
36
|
|
|
protected function setUp() |
37
|
|
|
{ |
38
|
|
|
$this->fixture = ProjectFactory::createInstance(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function tearDown() |
42
|
|
|
{ |
43
|
|
|
m::close(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testCreateProjectWithFunctions() |
47
|
|
|
{ |
48
|
|
|
$fileName = __DIR__ . '/project/simpleFunction.php'; |
49
|
|
|
|
50
|
|
|
$project = $this->fixture->create('MyProject', [ |
51
|
|
|
new LocalFile($fileName) |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
$this->assertArrayHasKey($fileName, $project->getFiles()); |
55
|
|
|
$this->assertArrayHasKey('\simpleFunction()', $project->getFiles()[$fileName]->getFunctions()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testCreateProjectWithClass() |
59
|
|
|
{ |
60
|
|
|
$fileName = __DIR__ . '/project/Pizza.php'; |
61
|
|
|
$project = $this->fixture->create('MyProject', [ |
62
|
|
|
new LocalFile($fileName) |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
$this->assertArrayHasKey($fileName, $project->getFiles()); |
66
|
|
|
$this->assertArrayHasKey('\\Pizza', $project->getFiles()[$fileName]->getClasses()); |
67
|
|
|
$this->assertArrayHasKey( |
68
|
|
|
'\\Pizza::PACKAGING', |
69
|
|
|
$project->getFiles()[$fileName]->getClasses()['\\Pizza']->getConstants() |
70
|
|
|
); |
71
|
|
|
$constant = $project->getFiles()[$fileName]->getClasses()['\\Pizza']->getConstants()['\\Pizza::PACKAGING']; |
72
|
|
|
|
73
|
|
|
$this->assertEquals('box', $constant->getValue()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testFileWithDocBlock() |
77
|
|
|
{ |
78
|
|
|
$fileName = __DIR__ . '/project/Pizza.php'; |
79
|
|
|
$project = $this->fixture->create('MyProject', [ |
80
|
|
|
new LocalFile($fileName) |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
$this->assertArrayHasKey($fileName, $project->getFiles()); |
84
|
|
|
$this->assertInstanceOf(Docblock::class, $project->getFiles()[$fileName]->getDocBlock()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testWithNamespacedClass() |
88
|
|
|
{ |
89
|
|
|
$fileName = __DIR__ . '/project/Luigi/Pizza.php'; |
90
|
|
|
$project = $this->fixture->create('MyProject', [ |
91
|
|
|
new LocalFile($fileName) |
92
|
|
|
]); |
93
|
|
|
|
94
|
|
|
$this->assertArrayHasKey($fileName, $project->getFiles()); |
95
|
|
|
$this->assertArrayHasKey('\\Luigi\\Pizza', $project->getFiles()[$fileName]->getClasses()); |
96
|
|
|
$this->assertEquals('\Pizza', $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getParent()); |
97
|
|
|
$this->assertArrayHasKey( |
98
|
|
|
'\\Luigi\\Pizza::$instance', |
99
|
|
|
$project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getProperties() |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$methods = $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getMethods(); |
103
|
|
|
$this->assertArrayHasKey( |
104
|
|
|
'\\Luigi\\Pizza::__construct()', |
105
|
|
|
$methods |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$this->assertEquals('style', $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getName()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testDocblockOfMethodIsProcessed() |
112
|
|
|
{ |
113
|
|
|
$fileName = __DIR__ . '/project/Luigi/Pizza.php'; |
114
|
|
|
$project = $this->fixture->create('MyProject', [ |
115
|
|
|
new LocalFile($fileName) |
116
|
|
|
]); |
117
|
|
|
|
118
|
|
|
$this->assertArrayHasKey($fileName, $project->getFiles()); |
119
|
|
|
|
120
|
|
|
$methods = $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getMethods(); |
121
|
|
|
|
122
|
|
|
$createInstanceMethod = $methods['\\Luigi\\Pizza::createInstance()']; |
123
|
|
|
|
124
|
|
|
$this->assertInstanceOf(DocBlock::class, $createInstanceMethod->getDocBlock()); |
125
|
|
|
|
126
|
|
|
$docblock = $createInstanceMethod->getDocBlock(); |
127
|
|
|
/** @var Param[] $params */ |
128
|
|
|
$params = $docblock->getTagsByName('param'); |
129
|
|
|
|
130
|
|
|
/** @var Object_ $objectType */ |
131
|
|
|
$objectType = $params[0]->getType(); |
132
|
|
|
|
133
|
|
|
$this->assertEquals(new Fqsen('\Luigi\Pizza\Style'), $objectType->getFqsen()); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function testWithUsedParent() |
137
|
|
|
{ |
138
|
|
|
$fileName = __DIR__ . '/project/Luigi/StyleFactory.php'; |
139
|
|
|
$project = $this->fixture->create('MyProject', [ |
140
|
|
|
new LocalFile($fileName) |
141
|
|
|
]); |
142
|
|
|
|
143
|
|
|
$this->assertArrayHasKey($fileName, $project->getFiles()); |
144
|
|
|
$this->assertArrayHasKey('\\Luigi\\StyleFactory', $project->getFiles()[$fileName]->getClasses()); |
145
|
|
|
$this->assertEquals( |
146
|
|
|
'\\Luigi\\Pizza\\PizzaComponentFactory', |
147
|
|
|
$project->getFiles()[$fileName]->getClasses()['\\Luigi\\StyleFactory']->getParent() |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function testWithInterface() |
152
|
|
|
{ |
153
|
|
|
$fileName = __DIR__ . '/project/Luigi/Valued.php'; |
154
|
|
|
$project = $this->fixture->create('MyProject', [ |
155
|
|
|
new LocalFile($fileName) |
156
|
|
|
]); |
157
|
|
|
|
158
|
|
|
$this->assertArrayHasKey('\\Luigi\\Valued', $project->getFiles()[$fileName]->getInterfaces()); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function testWithTrait() |
162
|
|
|
{ |
163
|
|
|
$fileName = __DIR__ . '/project/Luigi/ExampleNestedTrait.php'; |
164
|
|
|
$project = $this->fixture->create('MyProject', [ |
165
|
|
|
new LocalFile($fileName) |
166
|
|
|
]); |
167
|
|
|
|
168
|
|
|
$this->assertArrayHasKey('\\Luigi\\ExampleNestedTrait', $project->getFiles()[$fileName]->getTraits()); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testInterfaceExtends() |
172
|
|
|
{ |
173
|
|
|
$fileName = __DIR__ . '/project/Luigi/Packing.php'; |
174
|
|
|
$project = $this->fixture->create('MyProject', [ |
175
|
|
|
new LocalFile($fileName) |
176
|
|
|
]); |
177
|
|
|
|
178
|
|
|
$this->assertArrayHasKey('\\Luigi\\Packing', $project->getFiles()[$fileName]->getInterfaces()); |
179
|
|
|
$interface = current($project->getFiles()[$fileName]->getInterfaces()); |
180
|
|
|
|
181
|
|
|
$this->assertEquals(['\\Packing' => new Fqsen('\\Packing')], $interface->getParents()); |
182
|
|
|
|
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testMethodReturnType() |
186
|
|
|
{ |
187
|
|
|
$fileName = __DIR__ . '/project/Packing.php'; |
188
|
|
|
$project = $this->fixture->create('MyProject', [ |
189
|
|
|
new LocalFile($fileName) |
190
|
|
|
]); |
191
|
|
|
|
192
|
|
|
$this->assertArrayHasKey('\\Packing', $project->getFiles()[$fileName]->getInterfaces()); |
193
|
|
|
$interface = current($project->getFiles()[$fileName]->getInterfaces()); |
194
|
|
|
|
195
|
|
|
$this->assertEquals(new String_(), $interface->getMethods()['\Packing::getName()']->getReturnType()); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|