Completed
Push — develop ( 28aa0b...3fae3c )
by Jaap
13s
created

PropertyIteratorTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 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
28
    protected function tearDown()
29
    {
30
        m::close();
31
    }
32
33
    /**
34
     * @covers ::current()
35
     * @covers ::next()
36
     * @covers ::valid()
37
     * @covers ::rewind()
38
     * @covers ::getName()
39
     */
40
    public function testIterateProps()
41
    {
42
        $prop1 = new PropertyProperty('prop1');
43
        $prop2 = new PropertyProperty('prop2');
44
45
        $propertyNode = new PropertyNode(1, [$prop1, $prop2]);
46
47
        $i = 1;
48
        foreach (new PropertyIterator($propertyNode) as $property) {
49
            $this->assertEquals('prop' . $i, $property->getName());
50
            $i++;
51
        }
52
    }
53
54
    /**
55
     * @covers ::key()
56
     * @covers ::next()
57
     */
58
    public function testKey()
59
    {
60
        $propertyMock = m::mock(PropertyNode::class);
61
62
        $fixture = new PropertyIterator($propertyMock);
63
64
        $this->assertEquals(0, $fixture->key());
65
        $fixture->next();
66
        $this->assertEquals(1, $fixture->key());
67
    }
68
69
    /**
70
     * @covers ::__construct
71
     * @covers ::isPublic
72
     * @covers ::isProtected
73
     * @covers ::isPrivate
74
     * @covers ::isStatic
75
     * @covers ::getLine
76
     */
77
    public function testProxyMethods()
78
    {
79
        $propertyMock = m::mock(PropertyNode::class);
80
        $propertyMock->shouldReceive('isPublic')->once()->andReturn(true);
81
        $propertyMock->shouldReceive('isProtected')->once()->andReturn(true);
82
        $propertyMock->shouldReceive('isPrivate')->once()->andReturn(true);
83
        $propertyMock->shouldReceive('isStatic')->once()->andReturn(true);
84
        $propertyMock->shouldReceive('getLine')->once()->andReturn(10);
85
86
        $fixture = new PropertyIterator($propertyMock);
87
88
        $this->assertTrue($fixture->isStatic());
89
        $this->assertTrue($fixture->isPrivate());
90
        $this->assertTrue($fixture->isProtected());
91
        $this->assertTrue($fixture->isPublic());
92
        $this->assertEquals(10, $fixture->getLine());
93
    }
94
95
    /**
96
     * @covers ::__construct
97
     * @covers ::getDefault
98
     */
99
    public function testGetDefault()
100
    {
101
        $prop = m::mock(PropertyProperty::class);
102
        $prop->default = 'myDefault';
103
        $property = new PropertyNode(1, [$prop]);
104
105
        $fixture = new PropertyIterator($property);
106
107
        $this->assertEquals('myDefault', $fixture->getDefault());
108
    }
109
110
    /**
111
     * @covers ::getDocComment
112
     */
113
    public function testGetDocCommentPropFirst()
114
    {
115
        $prop = m::mock(PropertyProperty::class);
116
        $propertyNode = m::mock(PropertyNode::class);
117
        $propertyNode->props = [$prop];
118
119
        $prop->shouldReceive('getDocComment')->once()->andReturn('test');
120
        $propertyNode->shouldReceive('getDocComment')->never();
121
122
        $fixture = new PropertyIterator($propertyNode);
123
124
        $this->assertEquals('test', $fixture->getDocComment());
125
    }
126
127
    /**
128
     * @covers ::getDocComment
129
     */
130
    public function testGetDocComment()
131
    {
132
        $prop = m::mock(PropertyProperty::class);
133
        $propertyNode = m::mock(PropertyNode::class);
134
        $propertyNode->props = [$prop];
135
136
        $prop->shouldReceive('getDocComment')->once()->andReturnNull();
137
        $propertyNode->shouldReceive('getDocComment')->once()->andReturn('test');
138
139
        $fixture = new PropertyIterator($propertyNode);
140
141
        $this->assertEquals('test', $fixture->getDocComment());
142
    }
143
}
144