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\Php; |
14
|
|
|
|
15
|
|
|
use \Mockery as m; |
16
|
|
|
use phpDocumentor\Reflection\DocBlock; |
17
|
|
|
use phpDocumentor\Reflection\Fqsen; |
18
|
|
|
use phpDocumentor\Reflection\Types\Mixed_; |
19
|
|
|
use phpDocumentor\Reflection\Types\String_; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Tests the functionality for the Method class. |
24
|
|
|
* @coversDefaultClass phpDocumentor\Reflection\Php\Method |
25
|
|
|
*/ |
26
|
|
|
class MethodTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** @var Method $fixture */ |
29
|
|
|
protected $fixture; |
30
|
|
|
|
31
|
|
|
private $fqsen; |
32
|
|
|
|
33
|
|
|
private $visibility; |
34
|
|
|
|
35
|
|
|
private $docblock; |
36
|
|
|
|
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$this->fqsen = new Fqsen('\My\Space::MyMethod()'); |
40
|
|
|
$this->visibility = new Visibility('private'); |
41
|
|
|
$this->docblock = new DocBlock(''); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function tearDown() |
45
|
|
|
{ |
46
|
|
|
m::close(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers ::getFqsen |
51
|
|
|
* @covers ::getName |
52
|
|
|
* @covers ::__construct |
53
|
|
|
*/ |
54
|
|
|
public function testGetFqsenAndGetName() |
55
|
|
|
{ |
56
|
|
|
$method = new Method($this->fqsen); |
57
|
|
|
|
58
|
|
|
$this->assertSame($this->fqsen, $method->getFqsen()); |
59
|
|
|
$this->assertEquals($this->fqsen->getName(), $method->getName()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers ::getDocblock |
64
|
|
|
* @covers ::__construct |
65
|
|
|
*/ |
66
|
|
|
public function testGetDocBlock() |
67
|
|
|
{ |
68
|
|
|
$method = new Method($this->fqsen, $this->visibility, $this->docblock); |
69
|
|
|
|
70
|
|
|
$this->assertSame($this->docblock, $method->getDocBlock()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @covers ::getArguments |
75
|
|
|
* @covers ::addArgument |
76
|
|
|
*/ |
77
|
|
|
public function testAddingAndGettingArguments() |
78
|
|
|
{ |
79
|
|
|
$method = new Method($this->fqsen); |
80
|
|
|
$this->assertEquals([], $method->getArguments()); |
81
|
|
|
|
82
|
|
|
$argument = new Argument('myArgument'); |
83
|
|
|
$method->addArgument($argument); |
84
|
|
|
|
85
|
|
|
$this->assertEquals([$argument], $method->getArguments()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @covers ::isAbstract |
90
|
|
|
* @covers ::__construct |
91
|
|
|
*/ |
92
|
|
|
public function testGettingWhetherMethodIsAbstract() |
93
|
|
|
{ |
94
|
|
|
$method = new Method($this->fqsen, $this->visibility, $this->docblock, false); |
95
|
|
|
$this->assertFalse($method->isAbstract()); |
96
|
|
|
|
97
|
|
|
$method = new Method($this->fqsen, $this->visibility, $this->docblock, true); |
98
|
|
|
$this->assertTrue($method->isAbstract()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @covers ::isFinal |
103
|
|
|
* @covers ::__construct |
104
|
|
|
*/ |
105
|
|
|
public function testGettingWhetherMethodIsFinal() |
106
|
|
|
{ |
107
|
|
|
$method = new Method($this->fqsen, $this->visibility, $this->docblock, false, false, false); |
108
|
|
|
$this->assertFalse($method->isFinal()); |
109
|
|
|
|
110
|
|
|
$method = new Method($this->fqsen, $this->visibility, $this->docblock, false, false, true); |
111
|
|
|
$this->assertTrue($method->isFinal()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @covers ::isStatic |
116
|
|
|
* @covers ::__construct |
117
|
|
|
*/ |
118
|
|
|
public function testGettingWhetherMethodIsStatic() |
119
|
|
|
{ |
120
|
|
|
$method = new Method($this->fqsen, $this->visibility, $this->docblock, false, false, false); |
121
|
|
|
$this->assertFalse($method->isStatic()); |
122
|
|
|
|
123
|
|
|
$method = new Method($this->fqsen, $this->visibility, $this->docblock, false, true, false); |
124
|
|
|
$this->assertTrue($method->isStatic()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @covers ::getVisibility |
129
|
|
|
* @covers ::__construct |
130
|
|
|
*/ |
131
|
|
|
public function testGettingVisibility() |
132
|
|
|
{ |
133
|
|
|
$method = new Method($this->fqsen, $this->visibility, $this->docblock, false, false, false); |
134
|
|
|
$this->assertSame($this->visibility, $method->getVisibility()); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @covers ::getVisibility |
139
|
|
|
* @covers ::__construct |
140
|
|
|
*/ |
141
|
|
|
public function testGetDefaultVisibility() |
142
|
|
|
{ |
143
|
|
|
$method = new Method($this->fqsen); |
144
|
|
|
$this->assertEquals(new Visibility('public'), $method->getVisibility()); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @covers ::getReturnType |
149
|
|
|
* @covers ::__construct |
150
|
|
|
*/ |
151
|
|
|
public function testGetDefaultReturnType() |
152
|
|
|
{ |
153
|
|
|
$method = new Method($this->fqsen); |
154
|
|
|
$this->assertEquals(new Mixed_(), $method->getReturnType()); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @covers ::getReturnType |
159
|
|
|
* @covers ::__construct |
160
|
|
|
*/ |
161
|
|
|
public function testGetReturnTypeFromConstructor() |
162
|
|
|
{ |
163
|
|
|
$returnType = new String_(); |
164
|
|
|
$method = new Method( |
165
|
|
|
$this->fqsen, |
166
|
|
|
new Visibility('public'), |
167
|
|
|
null, |
168
|
|
|
false, |
169
|
|
|
false, |
170
|
|
|
false, |
171
|
|
|
null, |
172
|
|
|
$returnType |
173
|
|
|
); |
174
|
|
|
|
175
|
|
|
$this->assertSame($returnType, $method->getReturnType()); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|