Skip to content

Commit fca9ce5

Browse files
committed
Start with restructuring integration tests and splitting them up per
element type
1 parent 93e5914 commit fca9ce5

15 files changed

+177
-23
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"autoload-dev": {
1313
"psr-4": {
1414
"phpDocumentor\\": [
15-
"tests/component/",
15+
"tests/integration/",
1616
"tests/unit/phpDocumentor",
1717
"tests/bench/"
1818
]

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<testsuite name="unit">
1717
<directory>./tests/unit/</directory>
1818
</testsuite>
19-
<testsuite name="component">
20-
<directory>./tests/component/</directory>
19+
<testsuite name="integration">
20+
<directory>./tests/integration/</directory>
2121
</testsuite>
2222
</testsuites>
2323
<filter>

tests/integration/ClassesTest.php

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection;
15+
16+
use Mockery\Adapter\Phpunit\MockeryTestCase;
17+
use phpDocumentor\Reflection\File\LocalFile;
18+
use phpDocumentor\Reflection\Php\Class_;
19+
use phpDocumentor\Reflection\Php\Constant;
20+
use phpDocumentor\Reflection\Php\File as PhpFile;
21+
use phpDocumentor\Reflection\Php\ProjectFactory;
22+
use phpDocumentor\Reflection\Types\Integer;
23+
use phpDocumentor\Reflection\Types\Object_;
24+
25+
/**
26+
* @coversNothing
27+
*/
28+
final class ClassesTest extends MockeryTestCase
29+
{
30+
const FILE_PIZZA = __DIR__ . '/data/Pizza.php';
31+
const FILE_LUIGI_PIZZA = __DIR__ . '/data/Luigi/Pizza.php';
32+
/** @var ProjectFactory */
33+
private $fixture;
34+
35+
/** @var Project */
36+
private $project;
37+
38+
protected function setUp() : void
39+
{
40+
$this->fixture = ProjectFactory::createInstance();
41+
$this->project = $this->fixture->create(
42+
'MyProject',
43+
[
44+
new LocalFile(self::FILE_PIZZA),
45+
new LocalFile(self::FILE_LUIGI_PIZZA),
46+
]
47+
);
48+
}
49+
50+
public function testItHasAllConstants() : void
51+
{
52+
$file = $this->project->getFiles()[self::FILE_PIZZA];
53+
54+
$className = '\\Pizza';
55+
$constantName = '\\Pizza::PACKAGING';
56+
57+
$class = $this->fetchClassFromFile($className, $file);
58+
59+
$this->assertArrayHasKey($constantName, $class->getConstants());
60+
$constant = $class->getConstants()[$constantName];
61+
62+
$this->assertInstanceOf(Constant::class, $constant);
63+
}
64+
65+
public function testTypedPropertiesReturnTheirType() : void
66+
{
67+
$fileName = self::FILE_LUIGI_PIZZA;
68+
$project = $this->fixture->create(
69+
'MyProject',
70+
[new LocalFile($fileName)]
71+
);
72+
73+
/** @var Class_ $pizzaClass */
74+
$pizzaClass = $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza'];
75+
$this->assertArrayHasKey('\\Luigi\\Pizza::$size', $pizzaClass->getProperties());
76+
$this->assertEquals(new Integer(), $pizzaClass->getProperties()['\\Luigi\\Pizza::$size']->getType());
77+
}
78+
79+
public function testWithNamespacedClass() : void
80+
{
81+
$fileName = self::FILE_LUIGI_PIZZA;
82+
$project = $this->fixture->create(
83+
'MyProject',
84+
[new LocalFile($fileName)]
85+
);
86+
87+
$this->assertArrayHasKey($fileName, $project->getFiles());
88+
$this->assertArrayHasKey('\\Luigi\\Pizza', $project->getFiles()[$fileName]->getClasses());
89+
$this->assertEquals('\Pizza', $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getParent());
90+
$this->assertArrayHasKey(
91+
'\\Luigi\\Pizza::$instance',
92+
$project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getProperties()
93+
);
94+
95+
$methods = $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getMethods();
96+
$this->assertArrayHasKey(
97+
'\\Luigi\\Pizza::__construct()',
98+
$methods
99+
);
100+
101+
$this->assertEquals('style', $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getName());
102+
$this->assertEquals(
103+
new Object_(new Fqsen('\\Luigi\\Pizza\Style')),
104+
$methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getType()
105+
);
106+
}
107+
108+
public function testWithUsedParent() : void
109+
{
110+
$fileName = __DIR__ . '/data/Luigi/StyleFactory.php';
111+
$project = $this->fixture->create(
112+
'MyProject',
113+
[new LocalFile($fileName)]
114+
);
115+
116+
$this->assertArrayHasKey($fileName, $project->getFiles());
117+
$this->assertArrayHasKey('\\Luigi\\StyleFactory', $project->getFiles()[$fileName]->getClasses());
118+
$this->assertEquals(
119+
'\\Luigi\\Pizza\\PizzaComponentFactory',
120+
$project->getFiles()[$fileName]->getClasses()['\\Luigi\\StyleFactory']->getParent()
121+
);
122+
}
123+
124+
public function testWithInterface() : void
125+
{
126+
$fileName = __DIR__ . '/data/Luigi/Valued.php';
127+
$project = $this->fixture->create(
128+
'MyProject',
129+
[new LocalFile($fileName)]
130+
);
131+
132+
$this->assertArrayHasKey('\\Luigi\\Valued', $project->getFiles()[$fileName]->getInterfaces());
133+
}
134+
135+
public function testWithTrait() : void
136+
{
137+
$fileName = __DIR__ . '/data/Luigi/ExampleNestedTrait.php';
138+
$project = $this->fixture->create(
139+
'MyProject',
140+
[new LocalFile($fileName)]
141+
);
142+
143+
$this->assertArrayHasKey('\\Luigi\\ExampleNestedTrait', $project->getFiles()[$fileName]->getTraits());
144+
}
145+
146+
private function fetchClassFromFile(string $className, PhpFile $file)
147+
{
148+
$this->assertArrayHasKey($className, $file->getClasses());
149+
150+
return $file->getClasses()[$className];
151+
}
152+
}

tests/component/ProjectCreationTest.php renamed to tests/integration/ProjectCreationTest.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* This file is part of phpDocumentor.
47
*
58
* For the full copyright and license information, please view the LICENSE
69
* file that was distributed with this source code.
710
*
8-
* @copyright 2010-2018 Mike van Riel<[email protected]>
9-
* @license http://www.opensource.org/licenses/mit-license.php MIT
10-
* @link http://phpdoc.org
11+
* @link http://phpdoc.org
1112
*/
1213

1314
namespace phpDocumentor\Reflection;
@@ -39,7 +40,7 @@ protected function setUp() : void
3940

4041
public function testCreateProjectWithFunctions() : void
4142
{
42-
$fileName = __DIR__ . '/project/simpleFunction.php';
43+
$fileName = __DIR__ . '/data/simpleFunction.php';
4344

4445
$project = $this->fixture->create(
4546
'MyProject',
@@ -58,7 +59,7 @@ public function testCreateProjectWithFunctions() : void
5859

5960
public function testCreateProjectWithClass() : void
6061
{
61-
$fileName = __DIR__ . '/project/Pizza.php';
62+
$fileName = __DIR__ . '/data/Pizza.php';
6263
$project = $this->fixture->create(
6364
'MyProject',
6465
[new LocalFile($fileName)]
@@ -77,7 +78,7 @@ public function testCreateProjectWithClass() : void
7778

7879
public function testTypedPropertiesReturnTheirType() : void
7980
{
80-
$fileName = __DIR__ . '/project/Luigi/Pizza.php';
81+
$fileName = __DIR__ . '/data/Luigi/Pizza.php';
8182
$project = $this->fixture->create(
8283
'MyProject',
8384
[new LocalFile($fileName)]
@@ -91,7 +92,7 @@ public function testTypedPropertiesReturnTheirType() : void
9192

9293
public function testFileWithDocBlock() : void
9394
{
94-
$fileName = __DIR__ . '/project/Pizza.php';
95+
$fileName = __DIR__ . '/data/Pizza.php';
9596
$project = $this->fixture->create(
9697
'MyProject',
9798
[new LocalFile($fileName)]
@@ -103,7 +104,7 @@ public function testFileWithDocBlock() : void
103104

104105
public function testWithNamespacedClass() : void
105106
{
106-
$fileName = __DIR__ . '/project/Luigi/Pizza.php';
107+
$fileName = __DIR__ . '/data/Luigi/Pizza.php';
107108
$project = $this->fixture->create(
108109
'MyProject',
109110
[new LocalFile($fileName)]
@@ -132,7 +133,7 @@ public function testWithNamespacedClass() : void
132133

133134
public function testDocblockOfMethodIsProcessed() : void
134135
{
135-
$fileName = __DIR__ . '/project/Luigi/Pizza.php';
136+
$fileName = __DIR__ . '/data/Luigi/Pizza.php';
136137
$project = $this->fixture->create(
137138
'MyProject',
138139
[new LocalFile($fileName)]
@@ -158,7 +159,7 @@ public function testDocblockOfMethodIsProcessed() : void
158159

159160
public function testWithUsedParent() : void
160161
{
161-
$fileName = __DIR__ . '/project/Luigi/StyleFactory.php';
162+
$fileName = __DIR__ . '/data/Luigi/StyleFactory.php';
162163
$project = $this->fixture->create(
163164
'MyProject',
164165
[new LocalFile($fileName)]
@@ -174,7 +175,7 @@ public function testWithUsedParent() : void
174175

175176
public function testWithInterface() : void
176177
{
177-
$fileName = __DIR__ . '/project/Luigi/Valued.php';
178+
$fileName = __DIR__ . '/data/Luigi/Valued.php';
178179
$project = $this->fixture->create(
179180
'MyProject',
180181
[new LocalFile($fileName)]
@@ -185,7 +186,7 @@ public function testWithInterface() : void
185186

186187
public function testWithTrait() : void
187188
{
188-
$fileName = __DIR__ . '/project/Luigi/ExampleNestedTrait.php';
189+
$fileName = __DIR__ . '/data/Luigi/ExampleNestedTrait.php';
189190
$project = $this->fixture->create(
190191
'MyProject',
191192
[new LocalFile($fileName)]
@@ -196,7 +197,7 @@ public function testWithTrait() : void
196197

197198
public function testWithGlobalConstants() : void
198199
{
199-
$fileName = __DIR__ . '/project/Luigi/constants.php';
200+
$fileName = __DIR__ . '/data/Luigi/constants.php';
200201
$project = $this->fixture->create(
201202
'MyProject',
202203
[new LocalFile($fileName)]
@@ -208,7 +209,7 @@ public function testWithGlobalConstants() : void
208209

209210
public function testInterfaceExtends() : void
210211
{
211-
$fileName = __DIR__ . '/project/Luigi/Packing.php';
212+
$fileName = __DIR__ . '/data/Luigi/Packing.php';
212213
$project = $this->fixture->create(
213214
'MyProject',
214215
[new LocalFile($fileName)]
@@ -222,7 +223,7 @@ public function testInterfaceExtends() : void
222223

223224
public function testMethodReturnType() : void
224225
{
225-
$fileName = __DIR__ . '/project/Packing.php';
226+
$fileName = __DIR__ . '/data/Packing.php';
226227
$project = $this->fixture->create(
227228
'MyProject',
228229
[new LocalFile($fileName)]
@@ -236,7 +237,7 @@ public function testMethodReturnType() : void
236237

237238
public function testFileDocblock() : void
238239
{
239-
$fileName = __DIR__ . '/project/empty.php';
240+
$fileName = __DIR__ . '/data/empty.php';
240241
$project = $this->fixture->create(
241242
'MyProject',
242243
[new LocalFile($fileName)]

tests/component/ProjectNamespaceTest.php renamed to tests/integration/ProjectNamespaceTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* This file is part of phpDocumentor.
47
*
58
* For the full copyright and license information, please view the LICENSE
69
* file that was distributed with this source code.
710
*
8-
* @copyright 2010-2018 Mike van Riel<[email protected]>
9-
* @license http://www.opensource.org/licenses/mit-license.php MIT
10-
* @link http://phpdoc.org
11+
* @link http://phpdoc.org
1112
*/
1213

1314
namespace phpDocumentor\Reflection;
@@ -35,7 +36,7 @@ protected function setUp() : void
3536

3637
public function testWithNamespacedClass() : void
3738
{
38-
$fileName = __DIR__ . '/project/Luigi/Pizza.php';
39+
$fileName = __DIR__ . '/data/Luigi/Pizza.php';
3940
$project = $this->fixture->create(
4041
'My Project',
4142
[ new LocalFile($fileName) ]

0 commit comments

Comments
 (0)