Completed
Push — develop ( 5c2bf4...eb0c60 )
by Mike
03:22
created

ProjectCreationTest   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 189
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 7

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A testCreateProjectWithFunctions() 0 11 1
A testCreateProjectWithClass() 0 17 1
A testFileWithDocBlock() 0 10 1
A testWithNamespacedClass() 0 24 1
A testDocblockOfMethodIsProcessed() 0 24 1
A testWithUsedParent() 0 14 1
A testWithInterface() 0 9 1
A testWithTrait() 0 9 1
A testWithGlobalConstants() 0 9 1
A testInterfaceExtends() 0 12 1
A testMethodReturnType() 0 12 1
A testFileDocblock() 0 9 1
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-2018 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\ProjectFactory;
19
use phpDocumentor\Reflection\Types\Object_;
20
use phpDocumentor\Reflection\Types\String_;
21
use PHPUnit\Framework\TestCase;
22
23
/**
24
 * Intergration tests to check the correct working of processing a file into a project.
25
 *
26
 * @coversNothing
27
 */
28
class ProjectCreationTest extends TestCase
29
{
30
    /**
31
     * @var ProjectFactory
32
     */
33
    private $fixture;
34
35
    protected function setUp()
36
    {
37
        $this->fixture = ProjectFactory::createInstance();
38
    }
39
40
    protected function tearDown()
41
    {
42
        m::close();
43
    }
44
45
    public function testCreateProjectWithFunctions()
46
    {
47
        $fileName = __DIR__ . '/project/simpleFunction.php';
48
49
        $project = $this->fixture->create('MyProject', [
50
            new LocalFile($fileName),
51
        ]);
52
53
        $this->assertArrayHasKey($fileName, $project->getFiles());
54
        $this->assertArrayHasKey('\simpleFunction()', $project->getFiles()[$fileName]->getFunctions());
55
    }
56
57
    public function testCreateProjectWithClass()
58
    {
59
        $fileName = __DIR__ . '/project/Pizza.php';
60
        $project = $this->fixture->create('MyProject', [
61
            new LocalFile($fileName),
62
        ]);
63
64
        $this->assertArrayHasKey($fileName, $project->getFiles());
65
        $this->assertArrayHasKey('\\Pizza', $project->getFiles()[$fileName]->getClasses());
66
        $this->assertArrayHasKey(
67
            '\\Pizza::PACKAGING',
68
            $project->getFiles()[$fileName]->getClasses()['\\Pizza']->getConstants()
69
        );
70
        $constant = $project->getFiles()[$fileName]->getClasses()['\\Pizza']->getConstants()['\\Pizza::PACKAGING'];
71
72
        $this->assertEquals('box', $constant->getValue());
73
    }
74
75
    public function testFileWithDocBlock()
76
    {
77
        $fileName = __DIR__ . '/project/Pizza.php';
78
        $project = $this->fixture->create('MyProject', [
79
            new LocalFile($fileName),
80
        ]);
81
82
        $this->assertArrayHasKey($fileName, $project->getFiles());
83
        $this->assertInstanceOf(Docblock::class, $project->getFiles()[$fileName]->getDocBlock());
84
    }
85
86
    public function testWithNamespacedClass()
87
    {
88
        $fileName = __DIR__ . '/project/Luigi/Pizza.php';
89
        $project = $this->fixture->create('MyProject', [
90
            new LocalFile($fileName),
91
        ]);
92
93
        $this->assertArrayHasKey($fileName, $project->getFiles());
94
        $this->assertArrayHasKey('\\Luigi\\Pizza', $project->getFiles()[$fileName]->getClasses());
95
        $this->assertEquals('\Pizza', $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getParent());
96
        $this->assertArrayHasKey(
97
            '\\Luigi\\Pizza::$instance',
98
            $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getProperties()
99
        );
100
101
        $methods = $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getMethods();
102
        $this->assertArrayHasKey(
103
            '\\Luigi\\Pizza::__construct()',
104
            $methods
105
        );
106
107
        $this->assertEquals('style', $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getName());
108
        $this->assertEquals(new Object_(new Fqsen('\\Luigi\\Pizza\Style')), $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getType());
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 testWithGlobalConstants()
172
    {
173
        $fileName = __DIR__ . '/project/Luigi/constants.php';
174
        $project = $this->fixture->create('MyProject', [
175
            new LocalFile($fileName),
176
        ]);
177
178
        $this->assertArrayHasKey('\\Luigi\\OVEN_TEMPERATURE', $project->getFiles()[$fileName]->getConstants());
179
    }
180
181
    public function testInterfaceExtends()
182
    {
183
        $fileName = __DIR__ . '/project/Luigi/Packing.php';
184
        $project = $this->fixture->create('MyProject', [
185
            new LocalFile($fileName),
186
        ]);
187
188
        $this->assertArrayHasKey('\\Luigi\\Packing', $project->getFiles()[$fileName]->getInterfaces());
189
        $interface = current($project->getFiles()[$fileName]->getInterfaces());
190
191
        $this->assertEquals(['\\Packing' => new Fqsen('\\Packing')], $interface->getParents());
192
    }
193
194
    public function testMethodReturnType()
195
    {
196
        $fileName = __DIR__ . '/project/Packing.php';
197
        $project = $this->fixture->create('MyProject', [
198
            new LocalFile($fileName),
199
        ]);
200
201
        $this->assertArrayHasKey('\\Packing', $project->getFiles()[$fileName]->getInterfaces());
202
        $interface = current($project->getFiles()[$fileName]->getInterfaces());
203
204
        $this->assertEquals(new String_(), $interface->getMethods()['\Packing::getName()']->getReturnType());
205
    }
206
207
    public function testFileDocblock()
208
    {
209
        $fileName = __DIR__ . '/project/empty.php';
210
        $project = $this->fixture->create('MyProject', [
211
            new LocalFile($fileName),
212
        ]);
213
214
        $this->assertEquals('This file is part of phpDocumentor.', $project->getFiles()[$fileName]->getDocBlock()->getSummary());
215
    }
216
}
217