1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Common\Reflection; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Reflection\StaticReflectionClass; |
6
|
|
|
use Doctrine\Common\Reflection\StaticReflectionMethod; |
7
|
|
|
use Doctrine\Common\Reflection\StaticReflectionParser; |
8
|
|
|
use Doctrine\Common\Reflection\StaticReflectionProperty; |
9
|
|
|
use PHPStan\Testing\TestCase; |
10
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
11
|
|
|
use ReflectionException; |
12
|
|
|
|
13
|
|
|
class StaticReflectionClassTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** @var StaticReflectionParser|MockObject */ |
16
|
|
|
private $staticReflectionParser; |
17
|
|
|
|
18
|
|
|
/** @var StaticReflectionClass */ |
19
|
|
|
private $staticReflectionClass; |
20
|
|
|
|
21
|
|
|
public function testGetName() : void |
22
|
|
|
{ |
23
|
|
|
$this->staticReflectionParser->expects($this->once()) |
24
|
|
|
->method('getClassName') |
25
|
|
|
->willReturn('ClassName'); |
26
|
|
|
|
27
|
|
|
self::assertSame('ClassName', $this->staticReflectionClass->getName()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testGetDocComment() : void |
31
|
|
|
{ |
32
|
|
|
$this->staticReflectionParser->expects($this->once()) |
33
|
|
|
->method('getDocComment') |
34
|
|
|
->willReturn('test doc comment'); |
35
|
|
|
|
36
|
|
|
self::assertSame('test doc comment', $this->staticReflectionClass->getDocComment()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetNamespaceName() : void |
40
|
|
|
{ |
41
|
|
|
$this->staticReflectionParser->expects($this->once()) |
42
|
|
|
->method('getNamespaceName') |
43
|
|
|
->willReturn('Namespace'); |
44
|
|
|
|
45
|
|
|
self::assertSame('Namespace', $this->staticReflectionClass->getNamespaceName()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGetUseStatements() : void |
49
|
|
|
{ |
50
|
|
|
$this->staticReflectionParser->expects($this->once()) |
51
|
|
|
->method('getUseStatements') |
52
|
|
|
->willReturn(['ClassName']); |
53
|
|
|
|
54
|
|
|
self::assertSame(['ClassName'], $this->staticReflectionClass->getUseStatements()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testGetMethod() : void |
58
|
|
|
{ |
59
|
|
|
$staticReflectionMethod = $this->createPartialMock(StaticReflectionMethod::class, []); |
60
|
|
|
|
61
|
|
|
$this->staticReflectionParser->expects($this->once()) |
62
|
|
|
->method('getReflectionMethod') |
63
|
|
|
->with('method') |
64
|
|
|
->willReturn($staticReflectionMethod); |
65
|
|
|
|
66
|
|
|
self::assertSame($staticReflectionMethod, $this->staticReflectionClass->getMethod('method')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetProperty() : void |
70
|
|
|
{ |
71
|
|
|
$staticReflectionProperty = $this->createMock(StaticReflectionProperty::class); |
72
|
|
|
|
73
|
|
|
$this->staticReflectionParser->expects($this->once()) |
74
|
|
|
->method('getReflectionProperty') |
75
|
|
|
->with('property') |
76
|
|
|
->willReturn($staticReflectionProperty); |
77
|
|
|
|
78
|
|
|
self::assertSame($staticReflectionProperty, $this->staticReflectionClass->getProperty('property')); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param mixed[] $args |
83
|
|
|
* |
84
|
|
|
* @dataProvider getNotImplementedMethods |
85
|
|
|
*/ |
86
|
|
|
public function testNotImplemented(string $method, array $args) : void |
87
|
|
|
{ |
88
|
|
|
$this->expectException(ReflectionException::class); |
89
|
|
|
$this->expectExceptionMessage('Method not implemented'); |
90
|
|
|
|
91
|
|
|
$this->staticReflectionClass->$method(...$args); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return mixed[] |
96
|
|
|
*/ |
97
|
|
|
public function getNotImplementedMethods() : array |
98
|
|
|
{ |
99
|
|
|
return [ |
100
|
|
|
['export', ['Test', 'Test', true]], |
101
|
|
|
['getConstant', [null]], |
102
|
|
|
['getConstants', []], |
103
|
|
|
['getConstructor', []], |
104
|
|
|
['getDefaultProperties', []], |
105
|
|
|
['getEndLine', []], |
106
|
|
|
['getExtension', []], |
107
|
|
|
['getExtensionName', []], |
108
|
|
|
['getFileName', []], |
109
|
|
|
['getInterfaceNames', []], |
110
|
|
|
['getInterfaces', []], |
111
|
|
|
['getMethods', [null]], |
112
|
|
|
['getModifiers', []], |
113
|
|
|
['getParentClass', []], |
114
|
|
|
['getProperties', [null]], |
115
|
|
|
['getShortName', []], |
116
|
|
|
['getStartLine', []], |
117
|
|
|
['getStaticProperties', []], |
118
|
|
|
['getStaticPropertyValue', ['test', 'test']], |
119
|
|
|
['getTraitAliases', []], |
120
|
|
|
['getTraitNames', []], |
121
|
|
|
['getTraits', []], |
122
|
|
|
['hasConstant', ['test']], |
123
|
|
|
['hasMethod', ['method']], |
124
|
|
|
['hasProperty', ['property']], |
125
|
|
|
['implementsInterface', ['Interface']], |
126
|
|
|
['inNamespace', []], |
127
|
|
|
['isAbstract', []], |
128
|
|
|
['isCloneable', []], |
129
|
|
|
['isFinal', []], |
130
|
|
|
['isInstance', [$this]], |
131
|
|
|
['isInstantiable', []], |
132
|
|
|
['isInterface', []], |
133
|
|
|
['isInternal', []], |
134
|
|
|
['isIterateable', []], |
135
|
|
|
['isSubclassOf', [self::class]], |
136
|
|
|
['isTrait', []], |
137
|
|
|
['isUserDefined', []], |
138
|
|
|
['newInstance', [[]]], |
139
|
|
|
['newInstanceArgs', [[]]], |
140
|
|
|
['newInstanceWithoutConstructor', []], |
141
|
|
|
['setStaticPropertyValue', ['name', 'value']], |
142
|
|
|
['__toString', []], |
143
|
|
|
]; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
protected function setUp() : void |
147
|
|
|
{ |
148
|
|
|
$this->staticReflectionParser = $this->createMock(StaticReflectionParser::class); |
149
|
|
|
|
150
|
|
|
$this->staticReflectionClass = new StaticReflectionClass( |
151
|
|
|
$this->staticReflectionParser |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|