Completed
Push — master ( c89193...79c6c8 )
by Kyle
11:15 queued 10s
created

getFirstParentReferenceInClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of PDepend.
4
 *
5
 * PHP Version 5
6
 *
7
 * Copyright (c) 2008-2017 Manuel Pichler <[email protected]>.
8
 * All rights reserved.
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions
12
 * are met:
13
 *
14
 *   * Redistributions of source code must retain the above copyright
15
 *     notice, this list of conditions and the following disclaimer.
16
 *
17
 *   * Redistributions in binary form must reproduce the above copyright
18
 *     notice, this list of conditions and the following disclaimer in
19
 *     the documentation and/or other materials provided with the
20
 *     distribution.
21
 *
22
 *   * Neither the name of Manuel Pichler nor the names of his
23
 *     contributors may be used to endorse or promote products derived
24
 *     from this software without specific prior written permission.
25
 *
26
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
 * POSSIBILITY OF SUCH DAMAGE.
38
 *
39
 * @copyright 2008-2017 Manuel Pichler. All rights reserved.
40
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41
 */
42
43
namespace PDepend\Source\AST;
44
45
/**
46
 * Test case for the {@link \PDepend\Source\AST\ASTParentReference} class.
47
 *
48
 * @copyright 2008-2017 Manuel Pichler. All rights reserved.
49
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
50
 *
51
 * @covers \PDepend\Source\Language\PHP\AbstractPHPParser
52
 * @covers \PDepend\Source\AST\ASTParentReference
53
 * @group unittest
54
 */
55
class ASTParentReferenceTest extends ASTNodeTest
56
{
57
    /**
58
     * The mocked reference instance.
59
     *
60
     * @var \PDepend\Source\AST\ASTClassOrInterfaceReference
61
     */
62
    protected $referenceMock = null;
63
64
    /**
65
     * testGetTypeDelegatesCallToInjectedReferenceObject
66
     *
67
     * @return void
68
     */
69
    public function testGetTypeDelegatesCallToInjectedReferenceObject()
70
    {
71
        $reference = $this->createNodeInstance();
72
        $this->referenceMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PDepend\Source\AS...ssOrInterfaceReference>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
            ->method('getType');
74
75
76
        $reference->getType();
77
    }
78
79
    /**
80
     * testMagicSleepReturnsExpectedSetOfPropertyNames
81
     *
82
     * @return void
83
     */
84 View Code Duplication
    public function testMagicSleepReturnsExpectedSetOfPropertyNames()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        $reference = $this->createNodeInstance();
87
        $this->assertEquals(
88
            array(
89
                'reference',
90
                'context',
91
                'comment',
92
                'metadata',
93
                'nodes'
94
            ),
95
            $reference->__sleep()
96
        );
97
    }
98
99
    /**
100
     * testParentReferenceAllocationOutsideOfClassScopeThrowsExpectedException
101
     *
102
     * @return void
103
     * @expectedException \PDepend\Source\Parser\InvalidStateException
104
     */
105
    public function testParentReferenceAllocationOutsideOfClassScopeThrowsExpectedException()
106
    {
107
        $this->parseCodeResourceForTest();
108
    }
109
110
    /**
111
     * testParentReferenceInClassWithoutParentThrowsException
112
     *
113
     * @return void
114
     * @expectedException \PDepend\Source\Parser\InvalidStateException
115
     */
116
    public function testParentReferenceInClassWithoutParentThrowsException()
117
    {
118
        $this->parseCodeResourceForTest();
119
    }
120
121
    /**
122
     * testParentReferenceMemberPrimaryPrefixOutsideOfClassScopeThrowsExpectedException
123
     *
124
     * @return void
125
     * @expectedException \PDepend\Source\Parser\InvalidStateException
126
     */
127
    public function testParentReferenceMemberPrimaryPrefixOutsideOfClassScopeThrowsExpectedException()
128
    {
129
        $this->parseCodeResourceForTest();
130
    }
131
132
    /**
133
     * testGetImageReturnsExpectedValue
134
     *
135
     * @return void
136
     * @since 1.0.0
137
     */
138
    public function testGetImageReturnsExpectedValue()
139
    {
140
        $reference = $this->createNodeInstance();
141
        $this->assertEquals('parent', $reference->getImage());
142
    }
143
144
    /**
145
     * testParentReferenceHasExpectedStartLine
146
     *
147
     * @return void
148
     */
149
    public function testParentReferenceHasExpectedStartLine()
150
    {
151
        $reference = $this->getFirstParentReferenceInClass(__METHOD__);
152
        $this->assertEquals(5, $reference->getStartLine());
153
    }
154
155
    /**
156
     * testParentReferenceHasExpectedStartColumn
157
     *
158
     * @return void
159
     */
160
    public function testParentReferenceHasExpectedStartColumn()
161
    {
162
        $reference = $this->getFirstParentReferenceInClass(__METHOD__);
163
        $this->assertEquals(20, $reference->getStartColumn());
164
    }
165
166
    /**
167
     * testParentReferenceHasExpectedEndLine
168
     *
169
     * @return void
170
     */
171
    public function testParentReferenceHasExpectedEndLine()
172
    {
173
        $reference = $this->getFirstParentReferenceInClass(__METHOD__);
174
        $this->assertEquals(5, $reference->getEndLine());
175
    }
176
177
    /**
178
     * testParentReferenceHasExpectedEndColumn
179
     *
180
     * @return void
181
     */
182
    public function testParentReferenceHasExpectedEndColumn()
183
    {
184
        $reference = $this->getFirstParentReferenceInClass(__METHOD__);
185
        $this->assertEquals(25, $reference->getEndColumn());
186
    }
187
188
    /**
189
     * Creates a concrete node implementation.
190
     *
191
     * @return \PDepend\Source\AST\ASTParentReference
192
     */
193
    protected function createNodeInstance()
194
    {
195
        $this->referenceMock = $this->getMockBuilder('\PDepend\Source\AST\ASTClassOrInterfaceReference')
196
            ->disableOriginalConstructor()
197
            ->getMock();
198
199
        return new \PDepend\Source\AST\ASTParentReference($this->referenceMock);
200
    }
201
202
    /**
203
     * Returns a node instance for the currently executed test case.
204
     *
205
     * @param string $testCase Name of the calling test case.
206
     *
207
     * @return \PDepend\Source\AST\ASTParentReference
208
     */
209
    private function getFirstParentReferenceInClass($testCase)
210
    {
211
        return $this->getFirstNodeOfTypeInClass(
212
            $testCase,
213
            'PDepend\\Source\\AST\\ASTParentReference'
214
        );
215
    }
216
}
217