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