1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Common\Reflection; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Reflection\StaticReflectionClass; |
6
|
|
|
use Doctrine\Common\Reflection\StaticReflectionParser; |
7
|
|
|
use Doctrine\Common\Reflection\StaticReflectionProperty; |
8
|
|
|
use PHPStan\Testing\TestCase; |
9
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
10
|
|
|
use ReflectionException; |
11
|
|
|
|
12
|
|
|
class StaticReflectionPropertyTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** @var StaticReflectionParser|MockObject */ |
15
|
|
|
private $staticReflectionParser; |
16
|
|
|
|
17
|
|
|
/** @var string */ |
18
|
|
|
private $propertyName; |
19
|
|
|
|
20
|
|
|
/** @var StaticReflectionProperty */ |
21
|
|
|
private $staticReflectionProperty; |
22
|
|
|
|
23
|
|
|
public function testGetName() : void |
24
|
|
|
{ |
25
|
|
|
self::assertEquals($this->propertyName, $this->staticReflectionProperty->getName()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testGetDeclaringClass() : void |
29
|
|
|
{ |
30
|
|
|
$staticReflectionClass = $this->createMock(StaticReflectionClass::class); |
31
|
|
|
|
32
|
|
|
$this->staticReflectionParser->expects($this->once()) |
33
|
|
|
->method('getReflectionClass') |
34
|
|
|
->willReturn($staticReflectionClass); |
35
|
|
|
|
36
|
|
|
self::assertSame($staticReflectionClass, $this->staticReflectionProperty->getDeclaringClass()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetDocComment() : void |
40
|
|
|
{ |
41
|
|
|
$staticReflectionClass = $this->createMock(StaticReflectionClass::class); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$this->staticReflectionParser->expects($this->once()) |
44
|
|
|
->method('getDocComment') |
45
|
|
|
->with('property', $this->propertyName) |
46
|
|
|
->willReturn('test doc comment'); |
47
|
|
|
|
48
|
|
|
self::assertSame('test doc comment', $this->staticReflectionProperty->getDocComment()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetUseStatements() : void |
52
|
|
|
{ |
53
|
|
|
$staticReflectionClass = $this->createMock(StaticReflectionClass::class); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$this->staticReflectionParser->expects($this->once()) |
56
|
|
|
->method('getUseStatements') |
57
|
|
|
->willReturn(['Test']); |
58
|
|
|
|
59
|
|
|
self::assertSame(['Test'], $this->staticReflectionProperty->getUseStatements()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @dataProvider getNotImplementedMethods |
64
|
|
|
* |
65
|
|
|
* @param mixed[] $args |
66
|
|
|
*/ |
67
|
|
|
public function testNotImplemented(string $method, array $args) : void |
68
|
|
|
{ |
69
|
|
|
$this->expectException(ReflectionException::class); |
70
|
|
|
$this->expectExceptionMessage('Method not implemented'); |
71
|
|
|
|
72
|
|
|
$this->staticReflectionProperty->$method(...$args); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return mixed[] |
77
|
|
|
*/ |
78
|
|
|
public function getNotImplementedMethods() : array |
79
|
|
|
{ |
80
|
|
|
return [ |
81
|
|
|
['export', ['Test', 'Test', true]], |
82
|
|
|
['getModifiers', []], |
83
|
|
|
['getValue', []], |
84
|
|
|
['isDefault', []], |
85
|
|
|
['isPrivate', []], |
86
|
|
|
['isProtected', []], |
87
|
|
|
['isPublic', []], |
88
|
|
|
['isStatic', []], |
89
|
|
|
['setAccessible', [true]], |
90
|
|
|
['setValue', [$this, true]], |
91
|
|
|
['__toString', []], |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function setUp() : void |
96
|
|
|
{ |
97
|
|
|
$this->staticReflectionParser = $this->createMock(StaticReflectionParser::class); |
98
|
|
|
$this->propertyName = 'propertyName'; |
99
|
|
|
|
100
|
|
|
$this->staticReflectionParser->expects($this->any()) |
101
|
|
|
->method('getStaticReflectionParserForDeclaringClass') |
102
|
|
|
->with('property', $this->propertyName) |
103
|
|
|
->willReturn($this->staticReflectionParser); |
104
|
|
|
|
105
|
|
|
$this->staticReflectionProperty = new StaticReflectionProperty( |
106
|
|
|
$this->staticReflectionParser, |
107
|
|
|
$this->propertyName |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|