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\Php\Factory; |
15
|
|
|
|
16
|
|
|
use Mockery as m; |
17
|
|
|
use phpDocumentor\Reflection\Fqsen; |
18
|
|
|
use PhpParser\Node\Const_; |
19
|
|
|
use PhpParser\Node\Expr\Variable; |
20
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
21
|
|
|
use PhpParser\Node\Stmt\Property as PropertyNode; |
22
|
|
|
use PhpParser\Node\Stmt\PropertyProperty; |
23
|
|
|
use PHPUnit\Framework\TestCase; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class PropertyIteratorTest |
27
|
|
|
* @coversDefaultClass \phpDocumentor\Reflection\Php\Factory\ClassConstantIterator |
28
|
|
|
*/ |
29
|
|
|
class ClassConstantIteratorTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
protected function tearDown() |
32
|
|
|
{ |
33
|
|
|
m::close(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @covers ::current() |
38
|
|
|
* @covers ::next() |
39
|
|
|
* @covers ::valid() |
40
|
|
|
* @covers ::rewind() |
41
|
|
|
* @covers ::getName() |
42
|
|
|
* @covers ::getFqsen() |
43
|
|
|
*/ |
44
|
|
|
public function testIterateProps() |
45
|
|
|
{ |
46
|
|
|
$const1 = new Const_('\Space\MyClass::MY_CONST1', new Variable('a')); |
47
|
|
|
$const1->fqsen = new Fqsen($const1->name); |
48
|
|
|
$const2 = new Const_('\Space\MyClass::MY_CONST2', new Variable('b')); |
49
|
|
|
$const2->fqsen = new Fqsen($const2->name); |
50
|
|
|
|
51
|
|
|
$classConstantNode = new ClassConst([$const1, $const2]); |
52
|
|
|
|
53
|
|
|
$i = 1; |
54
|
|
|
foreach (new ClassConstantIterator($classConstantNode) as $constant) { |
55
|
|
|
$this->assertEquals('\Space\MyClass::MY_CONST' . $i, $constant->getName()); |
56
|
|
|
$this->assertEquals('\Space\MyClass::MY_CONST' . $i, (string)$constant->getFqsen()); |
57
|
|
|
|
58
|
|
|
$i++; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers ::key() |
64
|
|
|
* @covers ::next() |
65
|
|
|
*/ |
66
|
|
|
public function testKey() |
67
|
|
|
{ |
68
|
|
|
$propertyMock = m::mock(ClassConst::class); |
69
|
|
|
|
70
|
|
|
$fixture = new ClassConstantIterator($propertyMock); |
71
|
|
|
|
72
|
|
|
$this->assertEquals(0, $fixture->key()); |
73
|
|
|
$fixture->next(); |
74
|
|
|
$this->assertEquals(1, $fixture->key()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @covers ::__construct |
79
|
|
|
* @covers ::getLine |
80
|
|
|
*/ |
81
|
|
|
public function testProxyMethods() |
82
|
|
|
{ |
83
|
|
|
$propertyMock = m::mock(ClassConst::class); |
84
|
|
|
$propertyMock->shouldReceive('getLine')->once()->andReturn(10); |
85
|
|
|
|
86
|
|
|
$fixture = new ClassConstantIterator($propertyMock); |
87
|
|
|
|
88
|
|
|
$this->assertEquals(10, $fixture->getLine()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @covers ::getDocComment |
93
|
|
|
*/ |
94
|
|
|
public function testGetDocCommentPropFirst() |
95
|
|
|
{ |
96
|
|
|
$const = m::mock(Const_::class); |
97
|
|
|
$classConstants = m::mock(ClassConst::class); |
98
|
|
|
$classConstants->consts = [$const]; |
99
|
|
|
|
100
|
|
|
$const->shouldReceive('getDocComment')->once()->andReturn('test'); |
101
|
|
|
$classConstants->shouldReceive('getDocComment')->never(); |
102
|
|
|
|
103
|
|
|
$fixture = new ClassConstantIterator($classConstants); |
104
|
|
|
|
105
|
|
|
$this->assertEquals('test', $fixture->getDocComment()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @covers ::getDocComment |
110
|
|
|
*/ |
111
|
|
|
public function testGetDocComment() |
112
|
|
|
{ |
113
|
|
|
$const = m::mock(Const_::class); |
114
|
|
|
$classConstants = m::mock(ClassConst::class); |
115
|
|
|
$classConstants->consts = [$const]; |
116
|
|
|
|
117
|
|
|
$const->shouldReceive('getDocComment')->once()->andReturnNull(); |
118
|
|
|
$classConstants->shouldReceive('getDocComment')->once()->andReturn('test'); |
119
|
|
|
|
120
|
|
|
$fixture = new ClassConstantIterator($classConstants); |
121
|
|
|
|
122
|
|
|
$this->assertEquals('test', $fixture->getDocComment()); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|