|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Parser\Tests\Elements; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Parser\Elements\ElementStorageInterface; |
|
6
|
|
|
use ApiGen\Contracts\Parser\ParserStorageInterface; |
|
7
|
|
|
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface; |
|
8
|
|
|
use ApiGen\Contracts\Parser\Reflection\ConstantReflectionInterface; |
|
9
|
|
|
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface; |
|
10
|
|
|
use ApiGen\Parser\Reflection\ReflectionClass; |
|
11
|
|
|
use ApiGen\Tests\AbstractContainerAwareTestCase; |
|
12
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
|
13
|
|
|
|
|
14
|
|
|
final class ElementStorageTest extends AbstractContainerAwareTestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var ElementStorageInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $elementStorage; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp(): void |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var ParserStorageInterface $parserStorage */ |
|
24
|
|
|
$parserStorage = $this->container->getByType(ParserStorageInterface::class); |
|
25
|
|
|
$parserStorage->setClasses($this->getReflectionClassMocks()); |
|
26
|
|
|
$parserStorage->setFunctions([$this->getFunctionReflectionMock()]); |
|
|
|
|
|
|
27
|
|
|
$parserStorage->setConstants([$this->getConstantReflectionMock()]); |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
$this->elementStorage = $this->container->getByType(ElementStorageInterface::class); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testEnsureCategorization(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertCount(1, $this->elementStorage->getClasses()); |
|
35
|
|
|
$this->assertCount(1, $this->elementStorage->getTraits()); |
|
36
|
|
|
$this->assertCount(1, $this->elementStorage->getInterfaces()); |
|
37
|
|
|
$this->assertCount(1, $this->elementStorage->getExceptions()); |
|
38
|
|
|
$this->assertCount(4, $this->elementStorage->getClassElements()); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertCount(1, $this->elementStorage->getFunctions()); |
|
41
|
|
|
$this->assertCount(1, $this->elementStorage->getConstants()); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertCount(1, $this->elementStorage->getNamespaces()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return ReflectionClass[] |
|
48
|
|
|
*/ |
|
49
|
|
|
private function getReflectionClassMocks(): array |
|
50
|
|
|
{ |
|
51
|
|
|
$classes = []; |
|
52
|
|
|
$reflectionClassMock = $this->getReflectionClassMock(); |
|
53
|
|
|
$reflectionClassMock->method('isDocumented') |
|
54
|
|
|
->willReturn(true); |
|
55
|
|
|
$reflectionClassMock->method('isInterface') |
|
56
|
|
|
->willReturn(false); |
|
57
|
|
|
$reflectionClassMock->method('isTrait') |
|
58
|
|
|
->willReturn(false); |
|
59
|
|
|
$reflectionClassMock->method('isException') |
|
60
|
|
|
->willReturn(false); |
|
61
|
|
|
$classes[] = $reflectionClassMock; |
|
62
|
|
|
|
|
63
|
|
|
$reflectionClassMock2 = $this->getReflectionClassMock(); |
|
64
|
|
|
$reflectionClassMock2->method('isDocumented') |
|
65
|
|
|
->willReturn(false); |
|
66
|
|
|
$classes[] = $reflectionClassMock2; |
|
67
|
|
|
|
|
68
|
|
|
$reflectionClassMock3 = $this->getReflectionClassMock(); |
|
69
|
|
|
$reflectionClassMock3->method('isDocumented') |
|
70
|
|
|
->willReturn(true); |
|
71
|
|
|
$reflectionClassMock3->method('isInterface') |
|
72
|
|
|
->willReturn(true); |
|
73
|
|
|
$reflectionClassMock3->method('isTrait') |
|
74
|
|
|
->willReturn(false); |
|
75
|
|
|
$reflectionClassMock3->method('isException') |
|
76
|
|
|
->willReturn(false); |
|
77
|
|
|
$classes[] = $reflectionClassMock3; |
|
78
|
|
|
|
|
79
|
|
|
$reflectionClassMock4 = $this->getReflectionClassMock(); |
|
80
|
|
|
$reflectionClassMock4->method('isDocumented') |
|
81
|
|
|
->willReturn(true); |
|
82
|
|
|
$reflectionClassMock4->method('isInterface') |
|
83
|
|
|
->willReturn(false); |
|
84
|
|
|
$reflectionClassMock4->method('isTrait') |
|
85
|
|
|
->willReturn(true); |
|
86
|
|
|
$reflectionClassMock4->method('isException') |
|
87
|
|
|
->willReturn(false); |
|
88
|
|
|
$classes[] = $reflectionClassMock4; |
|
89
|
|
|
|
|
90
|
|
|
$reflectionClassMock5 = $this->getReflectionClassMock(); |
|
91
|
|
|
$reflectionClassMock5->method('isDocumented') |
|
92
|
|
|
->willReturn(true); |
|
93
|
|
|
$reflectionClassMock5->method('isInterface') |
|
94
|
|
|
->willReturn(false); |
|
95
|
|
|
$reflectionClassMock5->method('isTrait') |
|
96
|
|
|
->willReturn(false); |
|
97
|
|
|
$reflectionClassMock5->method('isException') |
|
98
|
|
|
->willReturn(true); |
|
99
|
|
|
$classes[] = $reflectionClassMock5; |
|
100
|
|
|
return $classes; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return ClassReflectionInterface|PHPUnit_Framework_MockObject_MockObject |
|
105
|
|
|
|
|
106
|
|
|
*/ |
|
107
|
|
|
private function getReflectionClassMock() |
|
108
|
|
|
{ |
|
109
|
|
|
$reflectionClassMock = $this->createMock(ClassReflectionInterface::class); |
|
110
|
|
|
$reflectionClassMock->method('getPseudoNamespaceName') |
|
111
|
|
|
->willReturn('SomeNamespace'); |
|
112
|
|
|
$reflectionClassMock->method('getShortName') |
|
113
|
|
|
->willReturn('SomeShortClass'); |
|
114
|
|
|
$reflectionClassMock->method('getOwnMethods') |
|
115
|
|
|
->willReturn([]); |
|
116
|
|
|
$reflectionClassMock->method('getOwnConstants') |
|
117
|
|
|
->willReturn([]); |
|
118
|
|
|
$reflectionClassMock->method('getOwnProperties') |
|
119
|
|
|
->willReturn([]); |
|
120
|
|
|
|
|
121
|
|
|
return $reflectionClassMock; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return FunctionReflectionInterface|PHPUnit_Framework_MockObject_MockObject |
|
126
|
|
|
*/ |
|
127
|
|
View Code Duplication |
private function getFunctionReflectionMock() |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
$reflectionFunctionMock = $this->createMock(FunctionReflectionInterface::class); |
|
130
|
|
|
$reflectionFunctionMock->method('isDocumented') |
|
131
|
|
|
->willReturn(true); |
|
132
|
|
|
$reflectionFunctionMock->method('getPseudoNamespaceName') |
|
133
|
|
|
->willReturn('SomeNamespace'); |
|
134
|
|
|
$reflectionFunctionMock->method('getShortName') |
|
135
|
|
|
->willReturn('SomeShortClass'); |
|
136
|
|
|
|
|
137
|
|
|
return $reflectionFunctionMock; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return ConstantReflectionInterface|PHPUnit_Framework_MockObject_MockObject |
|
142
|
|
|
*/ |
|
143
|
|
View Code Duplication |
private function getConstantReflectionMock() |
|
|
|
|
|
|
144
|
|
|
{ |
|
145
|
|
|
$constantReflectionMock = $this->createMock(ConstantReflectionInterface::class); |
|
146
|
|
|
$constantReflectionMock->method('isDocumented') |
|
147
|
|
|
->willReturn(true); |
|
148
|
|
|
$constantReflectionMock->method('getPseudoNamespaceName') |
|
149
|
|
|
->willReturn('SomeNamespace'); |
|
150
|
|
|
$constantReflectionMock->method('getShortName') |
|
151
|
|
|
->willReturn('SomeShortClass'); |
|
152
|
|
|
|
|
153
|
|
|
return $constantReflectionMock; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: