Arbit - project tracking

PHP Depend

History

Diff

1014 1015 /tests/PHP/Depend/_code/code/ASTVariable/testVariableHasExpectedStartLine.php
2 +<?php
3 +function testVariableHasExpectedStartLine()
4 +{
5 + private function foo()
6 + {
7 + $x = 1;
8 + }
9 +}
1014 1015 /tests/PHP/Depend/_code/code/ASTVariable/testVariableHasExpectedStartColumn.php
2 +<?php
3 +function testVariableHasExpectedStartColumn()
4 +{
5 + private function foo()
6 + {
7 + $x = 1;
8 + }
9 +}
1014 1015 /tests/PHP/Depend/_code/code/ASTVariable/testVariableHasExpectedEndLine.php
2 +<?php
3 +function testVariableHasExpectedEndLine()
4 +{
5 + private function foo()
6 + {
7 + $x = 1;
8 + }
9 +}
1014 1015 /tests/PHP/Depend/_code/code/ASTVariable/testVariableHasExpectedEndColumn.php
2 +<?php
3 +function testVariableHasExpectedEndColumn()
4 +{
5 + private function foo()
6 + {
7 + $x = 1;
8 + }
9 +}
1014 1015 /tests/PHP/Depend/_code/code/ASTCatchStatement/testCatchStatementVariableHasExpectedEndLine.php
2 +<?php
3 +function testCatchStatementVariableHasExpectedStartLine()
4 +{
5 + try {
6 + x();
7 + } catch (
8 + Exception
9 + $e
10 + ) {}
11 +}
1014 1015 /tests/PHP/Depend/_code/code/ASTCatchStatement/testCatchStatementVariableHasExpectedEndColumn.php
2 +<?php
3 +function testCatchStatementVariableHasExpectedStartLine()
4 +{
5 + try {
6 + x();
7 + } catch (
8 + Exception
9 + $e
10 + ) {}
11 +}
1014 1015 /tests/PHP/Depend/_code/code/ASTCatchStatement/testCatchStatementVariableHasExpectedStartLine.php
2 +<?php
3 +function testCatchStatementVariableHasExpectedStartLine()
4 +{
5 + try {
6 + x();
7 + } catch (
8 + Exception
9 + $e
10 + ) {}
11 +}
1014 1015 /tests/PHP/Depend/_code/code/ASTCatchStatement/testCatchStatementVariableHasExpectedStartColumn.php
2 +<?php
3 +function testCatchStatementVariableHasExpectedStartLine()
4 +{
5 + try {
6 + x();
7 + } catch (
8 + Exception
9 + $e
10 + ) {}
11 +}
1014 1015 /tests/PHP/Depend/Code/ASTVariableTest.php
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 +}
1014 1015 /tests/PHP/Depend/Code/ASTCatchStatementTest.php
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.
1014 1015 /tests/PHP/Depend/Code/AllTests.php
89 89 require_once dirname(__FILE__) . '/ASTStaticVariableDeclarationTest.php';
90 90 require_once dirname(__FILE__) . '/ASTSwitchStatementTest.php';
91 91 require_once dirname(__FILE__) . '/ASTSwitchLabelTest.php';
92 +require_once dirname(__FILE__) . '/ASTVariableTest.php';
92 93 require_once dirname(__FILE__) . '/ASTVariableDeclaratorTest.php';
93 94 require_once dirname(__FILE__) . '/ASTWhileStatementTest.php';
94 95
188 189 $suite->addTestSuite('PHP_Depend_Code_ASTStaticVariableDeclarationTest');
189 190 $suite->addTestSuite('PHP_Depend_Code_ASTSwitchStatementTest');
190 191 $suite->addTestSuite('PHP_Depend_Code_ASTSwitchLabelTest');
192 + $suite->addTestSuite('PHP_Depend_Code_ASTVariableTest');
191 193 $suite->addTestSuite('PHP_Depend_Code_ASTVariableDeclaratorTest');
192 194 $suite->addTestSuite('PHP_Depend_Code_ASTWhileStatementTest');
193 195
1014 1015 /PHP/Depend/Parser.php
1595 1595 $this->_parseQualifiedName()
1596 1596 )
1597 1597 );
1598 + $catch->addChild($this->_parseVariable());
1598 1599
1599 1600 $this->_consumeComments();
1600 - $token = $this->_consumeToken(self::T_VARIABLE);
1601 -
1602 - $catch->addChild($this->_builder->buildASTVariable($token->image));
1603 -
1604 - $this->_consumeComments();
1605 1601 $this->_consumeToken(self::T_PARENTHESIS_CLOSE);
1606 1602
1607 1603 return $this->_setNodePositionsAndReturn($catch);
2358 2354 */
2359 2355 private function _parseVariable()
2360 2356 {
2357 + $this->_tokenStack->push();
2358 +
2361 2359 // Read variable token
2360 + $this->_consumeComments();
2362 2361 $token = $this->_consumeToken(self::T_VARIABLE);
2363 2362 $this->_consumeComments();
2364 2363
2365 2364 // TODO: ASTThisVariable
2366 -
2367 - return $this->_builder->buildASTVariable($token->image);
2365 +
2366 + return $this->_setNodePositionsAndReturn(
2367 + $this->_builder->buildASTVariable($token->image)
2368 + );
2368 2369 }
2369 2370
2370 2371 /**