|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2009, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category PHP |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Code |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2009 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://www.pdepend.org/ |
|
48 |
+ */ |
|
49 |
+ |
|
50 |
+require_once 'PHP/Depend/Code/ASTNodeTest.php'; |
|
51 |
+ |
|
52 |
+require_once 'PHP/Depend/Code/ASTVariable.php'; |
|
53 |
+ |
|
54 |
+/** |
|
55 |
+ * Test case for the {@link PHP_Depend_Code_ASTVariable} class. |
|
56 |
+ * |
|
57 |
+ * @category PHP |
|
58 |
+ * @package PHP_Depend |
|
59 |
+ * @subpackage Code |
|
60 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
61 |
+ * @copyright 2008-2009 Manuel Pichler. All rights reserved. |
|
62 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
63 |
+ * @version Release: @package_version@ |
|
64 |
+ * @link http://www.pdepend.org/ |
|
65 |
+ */ |
|
66 |
+class PHP_Depend_Code_ASTVariableTest extends PHP_Depend_Code_ASTNodeTest |
|
67 |
+{ |
|
68 |
+ /** |
|
69 |
+ * Tests that the variable has the expected start line value. |
|
70 |
+ * |
|
71 |
+ * @return void |
|
72 |
+ * @group ast |
|
73 |
+ */ |
|
74 |
+ public function testVariableHasExpectedStartLine() |
|
75 |
+ { |
|
76 |
+ $declarator = $this->_getFirstVariableInFunction(__METHOD__); |
|
77 |
+ $this->assertSame(6, $declarator->getStartLine()); |
|
78 |
+ } |
|
79 |
+ |
|
80 |
+ /** |
|
81 |
+ * Tests that the variable has the expected start column value. |
|
82 |
+ * |
|
83 |
+ * @return void |
|
84 |
+ * @group ast |
|
85 |
+ */ |
|
86 |
+ public function testVariableHasExpectedStartColumn() |
|
87 |
+ { |
|
88 |
+ $declarator = $this->_getFirstVariableInFunction(__METHOD__); |
|
89 |
+ $this->assertSame(9, $declarator->getStartColumn()); |
|
90 |
+ } |
|
91 |
+ |
|
92 |
+ /** |
|
93 |
+ * Tests that the variable has the expected end line value. |
|
94 |
+ * |
|
95 |
+ * @return void |
|
96 |
+ * @group ast |
|
97 |
+ */ |
|
98 |
+ public function testVariableHasExpectedEndLine() |
|
99 |
+ { |
|
100 |
+ $declarator = $this->_getFirstVariableInFunction(__METHOD__); |
|
101 |
+ $this->assertSame(6, $declarator->getEndLine()); |
|
102 |
+ } |
|
103 |
+ |
|
104 |
+ /** |
|
105 |
+ * Tests that the variable has the expected end column value. |
|
106 |
+ * |
|
107 |
+ * @return void |
|
108 |
+ * @group ast |
|
109 |
+ */ |
|
110 |
+ public function testVariableHasExpectedEndColumn() |
|
111 |
+ { |
|
112 |
+ $declarator = $this->_getFirstVariableInFunction(__METHOD__); |
|
113 |
+ $this->assertSame(10, $declarator->getEndColumn()); |
|
114 |
+ } |
|
115 |
+ |
|
116 |
+ /** |
|
117 |
+ * Returns a node instance for the currently executed test case. |
|
118 |
+ * |
|
119 |
+ * @param string $testCase Name of the calling test case. |
|
120 |
+ * |
|
121 |
+ * @return PHP_Depend_Code_ASTVariable |
|
122 |
+ */ |
|
123 |
+ private function _getFirstVariableInFunction($testCase) |
|
124 |
+ { |
|
125 |
+ return $this->getFirstNodeOfTypeInFunction( |
|
126 |
+ $testCase, PHP_Depend_Code_ASTVariable::CLAZZ |
|
127 |
+ ); |
|
128 |
+ } |
|
129 |
+} |
| 114 |
114 |
} |
| 115 |
115 |
|
| 116 |
116 |
/** |
|
117 |
+ * testCatchStatementVariableHasExpectedStartLine |
|
118 |
+ * |
|
119 |
+ * @return void |
|
120 |
+ * @group ast |
|
121 |
+ */ |
|
122 |
+ public function testCatchStatementVariableHasExpectedStartLine() |
|
123 |
+ { |
|
124 |
+ $variable = $this->_getFirstCatchStatementInFunction(__METHOD__) |
|
125 |
+ ->getFirstChildOfType(PHP_Depend_Code_ASTVariable::CLAZZ); |
|
126 |
+ $this->assertEquals(8, $variable->getStartLine()); |
|
127 |
+ } |
|
128 |
+ |
|
129 |
+ /** |
|
130 |
+ * testCatchStatementVariableHasExpectedStartColumn |
|
131 |
+ * |
|
132 |
+ * @return void |
|
133 |
+ * @group ast |
|
134 |
+ */ |
|
135 |
+ public function testCatchStatementVariableHasExpectedStartColumn() |
|
136 |
+ { |
|
137 |
+ $variable = $this->_getFirstCatchStatementInFunction(__METHOD__) |
|
138 |
+ ->getFirstChildOfType(PHP_Depend_Code_ASTVariable::CLAZZ); |
|
139 |
+ $this->assertEquals(9, $variable->getStartColumn()); |
|
140 |
+ } |
|
141 |
+ |
|
142 |
+ /** |
|
143 |
+ * testCatchStatementVariableHasExpectedEndLine |
|
144 |
+ * |
|
145 |
+ * @return void |
|
146 |
+ * @group ast |
|
147 |
+ */ |
|
148 |
+ public function testCatchStatementVariableHasExpectedEndLine() |
|
149 |
+ { |
|
150 |
+ $variable = $this->_getFirstCatchStatementInFunction(__METHOD__) |
|
151 |
+ ->getFirstChildOfType(PHP_Depend_Code_ASTVariable::CLAZZ); |
|
152 |
+ $this->assertEquals(8, $variable->getStartLine()); |
|
153 |
+ } |
|
154 |
+ |
|
155 |
+ /** |
|
156 |
+ * testCatchStatementVariableHasExpectedEndColumn |
|
157 |
+ * |
|
158 |
+ * @return void |
|
159 |
+ * @group ast |
|
160 |
+ */ |
|
161 |
+ public function testCatchStatementVariableHasExpectedEndColumn() |
|
162 |
+ { |
|
163 |
+ $variable = $this->_getFirstCatchStatementInFunction(__METHOD__) |
|
164 |
+ ->getFirstChildOfType(PHP_Depend_Code_ASTVariable::CLAZZ); |
|
165 |
+ $this->assertEquals(10, $variable->getEndColumn()); |
|
166 |
+ } |
|
167 |
+ |
|
168 |
+ /** |
| 117 |
169 |
* Returns a node instance for the currently executed test case. |
| 118 |
170 |
* |
| 119 |
171 |
* @param string $testCase Name of the calling test case. |