PropertyIteratorTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A testIterateProps() 0 13 2
A testKey() 0 10 1
A testProxyMethods() 0 17 1
A testGetDefault() 0 10 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 PhpParser\Comment\Doc;
17
use PhpParser\Node\Stmt\Property as PropertyNode;
18
use PhpParser\Node\Stmt\PropertyProperty;
19
use PHPUnit\Framework\TestCase;
20
21
/**
22
 * Class PropertyIteratorTest
23
 * @coversDefaultClass \phpDocumentor\Reflection\Php\Factory\PropertyIterator
24
 */
25
class PropertyIteratorTest extends TestCase
26
{
27
    protected function tearDown()
28
    {
29
        m::close();
30
    }
31
32
    /**
33
     * @covers ::current()
34
     * @covers ::next()
35
     * @covers ::valid()
36
     * @covers ::rewind()
37
     * @covers ::getName()
38
     */
39
    public function testIterateProps()
40
    {
41
        $prop1 = new PropertyProperty('prop1');
42
        $prop2 = new PropertyProperty('prop2');
43
44
        $propertyNode = new PropertyNode(1, [$prop1, $prop2]);
45
46
        $i = 1;
47
        foreach (new PropertyIterator($propertyNode) as $property) {
48
            $this->assertEquals('prop' . $i, $property->getName());
49
            ++$i;
50
        }
51
    }
52
53
    /**
54
     * @covers ::key()
55
     * @covers ::next()
56
     */
57
    public function testKey()
58
    {
59
        $propertyMock = m::mock(PropertyNode::class);
60
61
        $fixture = new PropertyIterator($propertyMock);
62
63
        $this->assertEquals(0, $fixture->key());
64
        $fixture->next();
65
        $this->assertEquals(1, $fixture->key());
66
    }
67
68
    /**
69
     * @covers ::__construct
70
     * @covers ::isPublic
71
     * @covers ::isProtected
72
     * @covers ::isPrivate
73
     * @covers ::isStatic
74
     * @covers ::getLine
75
     */
76
    public function testProxyMethods()
77
    {
78
        $propertyMock = m::mock(PropertyNode::class);
79
        $propertyMock->shouldReceive('isPublic')->once()->andReturn(true);
80
        $propertyMock->shouldReceive('isProtected')->once()->andReturn(true);
81
        $propertyMock->shouldReceive('isPrivate')->once()->andReturn(true);
82
        $propertyMock->shouldReceive('isStatic')->once()->andReturn(true);
83
        $propertyMock->shouldReceive('getLine')->once()->andReturn(10);
84
85
        $fixture = new PropertyIterator($propertyMock);
86
87
        $this->assertTrue($fixture->isStatic());
88
        $this->assertTrue($fixture->isPrivate());
89
        $this->assertTrue($fixture->isProtected());
90
        $this->assertTrue($fixture->isPublic());
91
        $this->assertEquals(10, $fixture->getLine());
92
    }
93
94
    /**
95
     * @covers ::__construct
96
     * @covers ::getDefault
97
     */
98
    public function testGetDefault()
99
    {
100
        $prop = m::mock(PropertyProperty::class);
101
        $prop->default = 'myDefault';
102
        $property = new PropertyNode(1, [$prop]);
103
104
        $fixture = new PropertyIterator($property);
105
106
        $this->assertEquals('myDefault', $fixture->getDefault());
107
    }
108
109
    /**
110
     * @covers ::getDocComment
111
     */
112
    public function testGetDocCommentPropFirst()
113
    {
114
        $prop = m::mock(PropertyProperty::class);
115
        $propertyNode = m::mock(PropertyNode::class);
116
        $propertyNode->props = [$prop];
117
118
        $prop->shouldReceive('getDocComment')->once()->andReturn(new Doc('test'));
119
        $propertyNode->shouldReceive('getDocComment')->never();
120
121
        $fixture = new PropertyIterator($propertyNode);
122
123
        $this->assertEquals('test', $fixture->getDocComment()->getText());
124
    }
125
126
    /**
127
     * @covers ::getDocComment
128
     */
129
    public function testGetDocComment()
130
    {
131
        $prop = m::mock(PropertyProperty::class);
132
        $propertyNode = m::mock(PropertyNode::class);
133
        $propertyNode->props = [$prop];
134
135
        $prop->shouldReceive('getDocComment')->once()->andReturnNull();
136
        $propertyNode->shouldReceive('getDocComment')->once()->andReturn(new Doc('test'));
137
138
        $fixture = new PropertyIterator($propertyNode);
139
140
        $this->assertEquals('test', $fixture->getDocComment()->getText());
141
    }
142
}
143