ClassConstantIteratorTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 96
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 8

6 Methods

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