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-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection\NodeVisitor; |
15
|
|
|
|
16
|
|
|
use PhpParser\Node\Const_; |
17
|
|
|
use PhpParser\Node\Expr\New_; |
18
|
|
|
use PhpParser\Node\Name; |
19
|
|
|
use PhpParser\Node\Scalar\String_; |
20
|
|
|
use PhpParser\Node\Stmt\Class_; |
21
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
22
|
|
|
use PhpParser\Node\Stmt\Function_; |
23
|
|
|
use PhpParser\Node\Stmt\Namespace_; |
24
|
|
|
use PhpParser\NodeTraverser; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Testcase for FqsenResolver |
28
|
|
|
* @coversDefaultClass phpDocumentor\Reflection\NodeVisitor\ElementNameResolver |
29
|
|
|
* @covers ::<private> |
30
|
|
|
*/ |
31
|
|
|
class ElementNameResolverTest extends \PHPUnit_Framework_TestCase |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var ElementNameResolver |
35
|
|
|
*/ |
36
|
|
|
private $fixture; |
37
|
|
|
|
38
|
|
|
protected function setUp() |
39
|
|
|
{ |
40
|
|
|
$this->fixture = new ElementNameResolver(); |
41
|
|
|
$this->fixture->beforeTraverse([]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @covers ::enterNode |
46
|
|
|
*/ |
47
|
|
|
public function testFunctionWithoutNamespace() |
48
|
|
|
{ |
49
|
|
|
$function = new Function_('myFunction'); |
50
|
|
|
$this->fixture->enterNode($function); |
51
|
|
|
|
52
|
|
|
$this->assertEquals('\myFunction()', (string)$function->fqsen); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @covers ::enterNode |
57
|
|
|
*/ |
58
|
|
|
public function testWithClass() |
59
|
|
|
{ |
60
|
|
|
$class = new Class_('myClass'); |
61
|
|
|
$this->fixture->enterNode($class); |
62
|
|
|
|
63
|
|
|
$this->assertEquals('\myClass', (string)$class->fqsen); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* If anonymous classes were processed, we would obtain a |
68
|
|
|
* InvalidArgumentException for an invalid Fqsen. |
69
|
|
|
* |
70
|
|
|
* @covers ::enterNode |
71
|
|
|
*/ |
72
|
|
|
public function testDoesNotEnterAnonymousClass() |
73
|
|
|
{ |
74
|
|
|
$class = new Class_(null); |
75
|
|
|
$this->assertEquals( |
76
|
|
|
NodeTraverser::DONT_TRAVERSE_CHILDREN, |
77
|
|
|
$this->fixture->enterNode($class) |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @link https://github.com/phpDocumentor/Reflection/issues/103 |
83
|
|
|
* @covers ::enterNode |
84
|
|
|
* @covers ::leaveNode |
85
|
|
|
*/ |
86
|
|
|
public function testAnonymousClassDoesNotPopParts() |
87
|
|
|
{ |
88
|
|
|
$anonymousClass = new Class_(null); |
89
|
|
|
|
90
|
|
|
$new = new New_($anonymousClass); |
91
|
|
|
|
92
|
|
|
$namespace = new Namespace_(new Name('ANamespace'), $new); |
93
|
|
|
|
94
|
|
|
$this->fixture->enterNode($namespace); |
95
|
|
|
$this->fixture->enterNode($new); |
96
|
|
|
$this->fixture->enterNode($anonymousClass); |
97
|
|
|
$this->fixture->leaveNode($anonymousClass); |
98
|
|
|
$this->fixture->leaveNode($new); |
99
|
|
|
$this->fixture->leaveNode($namespace); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @covers ::enterNode |
104
|
|
|
*/ |
105
|
|
|
public function testClassConstant() |
106
|
|
|
{ |
107
|
|
|
$const = new Const_('MY_CLASS', new String_('value')); |
108
|
|
|
$classConst = new ClassConst([$const]); |
109
|
|
|
$class = new Class_('myClass'); |
110
|
|
|
|
111
|
|
|
$this->fixture->enterNode($class); |
112
|
|
|
$this->fixture->enterNode($classConst); |
113
|
|
|
$this->fixture->enterNode($const); |
114
|
|
|
|
115
|
|
|
$this->assertEquals('\\myClass::MY_CLASS', (string)$const->fqsen); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @covers ::enterNode |
120
|
|
|
*/ |
121
|
|
|
public function testNamespacedConstant() |
122
|
|
|
{ |
123
|
|
|
$const = new Const_('MY_CLASS', new String_('value')); |
124
|
|
|
$namespace = new Namespace_(new Name('name')); |
125
|
|
|
|
126
|
|
|
$this->fixture->enterNode($namespace); |
127
|
|
|
$this->fixture->enterNode($const); |
128
|
|
|
|
129
|
|
|
$this->assertEquals('\\name\\MY_CLASS', (string)$const->fqsen); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|