Arbit - project tracking

PHP Depend

History

Diff

1114 1115 /tests/PHP/Depend/_code/code/ASTForeachStatement/testForeachStatementContainsExpressionAsFirstChild.php
2 +<?php
3 +function testForeachStatementContainsListExpressionAsFirstChild()
4 +{
5 + foreach (array($expr) as $foo) {
6 +
7 + }
8 +}
1114 1115 /tests/PHP/Depend/_code/code/ASTForeachStatement/testForeachStatementWithKeyAndValueByReference.php
2 +<?php
3 +function testForeachStatementWithKeyAndValueByReference()
4 +{
5 + foreach ($expr as $key => &$value) {}
6 +}
1114 1115 /tests/PHP/Depend/_code/code/ASTForeachStatement/testForeachStatementThrowsExpectedExceptionForKeyByReference.php
2 +<?php
3 +function testForeachStatementThrowsExpectedExceptionForKeyByReference()
4 +{
5 + foreach ($expr as &$key => &$value) {}
6 +}
1114 1115 /tests/PHP/Depend/_code/code/ASTForeachStatement/testForeachStatementWithoutKeyAndWithValueByReference.php
2 +<?php
3 +function testForeachStatementWithoutKeyAndWithValueByReference()
4 +{
5 + foreach ($expr as &$value) {}
6 +}
1114 1115 /tests/PHP/Depend/_code/code/ASTForeachStatement/testForeachStatementWithKeyAndValue.php
2 +<?php
3 +function testForeachStatementWithKeyAndValue()
4 +{
5 + foreach ($expr as $key => $value) {}
6 +}
1114 1115 /tests/PHP/Depend/_code/code/ASTForeachStatement/testForeachStatementWithoutKeyAndWithValue.php
2 +<?php
3 +function testForeachStatementWithoutKeyAndWithValue()
4 +{
5 + foreach ($expr as $foo) {
6 +
7 + }
8 +}
1114 1115 /tests/PHP/Depend/Code/ASTForeachStatementTest.php
69 69 * Tests the start line value.
70 70 *
71 71 * @return void
72 - * @group ast
72 + * @covers PHP_Depend_Code_ASTForeachStatement
73 + * @covers PHP_Depend_Parser
74 + * @group pdepend
75 + * @group pdepend::ast
76 + * @group unittest
73 77 */
74 78 public function testForeachStatementHasExpectedStartLine()
75 79 {
76 80 $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
77 - $this->assertSame(4, $statement->getStartLine());
81 + $this->assertEquals(4, $statement->getStartLine());
78 82 }
79 83
80 84 /**
81 85 * Tests the start column value.
82 86 *
83 87 * @return void
84 - * @group ast
88 + * @covers PHP_Depend_Code_ASTForeachStatement
89 + * @covers PHP_Depend_Parser
90 + * @group pdepend
91 + * @group pdepend::ast
92 + * @group unittest
85 93 */
86 94 public function testForeachStatementHasExpectedStartColumn()
87 95 {
88 96 $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
89 - $this->assertSame(5, $statement->getStartColumn());
97 + $this->assertEquals(5, $statement->getStartColumn());
90 98 }
91 99
92 100 /**
93 101 * Tests the end line value.
94 102 *
95 103 * @return void
96 - * @group ast
104 + * @covers PHP_Depend_Code_ASTForeachStatement
105 + * @covers PHP_Depend_Parser
106 + * @group pdepend
107 + * @group pdepend::ast
108 + * @group unittest
97 109 */
98 110 public function testForeachStatementHasExpectedEndLine()
99 111 {
100 112 $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
101 - $this->assertSame(4, $statement->getEndLine());
113 + $this->assertEquals(4, $statement->getEndLine());
102 114 }
103 115
104 116 /**
105 117 * Tests the end column value.
106 118 *
107 119 * @return void
108 - * @group ast
120 + * @covers PHP_Depend_Code_ASTForeachStatement
121 + * @covers PHP_Depend_Parser
122 + * @group pdepend
123 + * @group pdepend::ast
124 + * @group unittest
109 125 */
110 126 public function testForeachStatementHasExpectedEndColumn()
111 127 {
112 128 $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
113 - $this->assertSame(11, $statement->getEndColumn());
129 + $this->assertEquals(26, $statement->getEndColumn());
114 130 }
115 131
116 132 /**
133 + * testForeachStatementContainsListExpressionAsFirstChild
134 + *
135 + * @return void
136 + * @covers PHP_Depend_Code_ASTForeachStatement
137 + * @covers PHP_Depend_Parser
138 + * @group pdepend
139 + * @group pdepend::ast
140 + * @group unittest
141 + */
142 + public function testForeachStatementContainsExpressionAsFirstChild()
143 + {
144 + $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
145 + $this->assertType(PHP_Depend_Code_ASTExpression::CLAZZ, $statement->getChild(0));
146 + }
147 +
148 + /**
149 + * testForeachStatementWithoutKeyAndWithValue
150 + *
151 + * @return void
152 + * @covers PHP_Depend_Code_ASTForeachStatement
153 + * @covers PHP_Depend_Parser
154 + * @group pdepend
155 + * @group pdepend::ast
156 + * @group unittest
157 + */
158 + public function testForeachStatementWithoutKeyAndWithValue()
159 + {
160 + $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
161 + $this->assertType(PHP_Depend_Code_ASTVariable::CLAZZ, $statement->getChild(1));
162 + }
163 +
164 + /**
165 + * testForeachStatementWithoutKeyAndWithValueByReference
166 + *
167 + * @return void
168 + * @covers PHP_Depend_Code_ASTForeachStatement
169 + * @covers PHP_Depend_Parser
170 + * @group pdepend
171 + * @group pdepend::ast
172 + * @group unittest
173 + */
174 + public function testForeachStatementWithoutKeyAndWithValueByReference()
175 + {
176 + $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
177 + $this->assertType(PHP_Depend_Code_ASTUnaryExpression::CLAZZ, $statement->getChild(1));
178 + }
179 +
180 + /**
181 + * testForeachStatementWithKeyAndValue
182 + *
183 + * @return void
184 + * @covers PHP_Depend_Code_ASTForeachStatement
185 + * @covers PHP_Depend_Parser
186 + * @group pdepend
187 + * @group pdepend::ast
188 + * @group unittest
189 + */
190 + public function testForeachStatementWithKeyAndValue()
191 + {
192 + $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
193 + $this->assertType(PHP_Depend_Code_ASTVariable::CLAZZ, $statement->getChild(2));
194 + }
195 +
196 + /**
197 + * testForeachStatementWithKeyAndValueByReference
198 + *
199 + * @return void
200 + * @covers PHP_Depend_Code_ASTForeachStatement
201 + * @covers PHP_Depend_Parser
202 + * @group pdepend
203 + * @group pdepend::ast
204 + * @group unittest
205 + */
206 + public function testForeachStatementWithKeyAndValueByReference()
207 + {
208 + $statement = $this->_getFirstForeachStatementInFunction(__METHOD__);
209 + $this->assertType(PHP_Depend_Code_ASTUnaryExpression::CLAZZ, $statement->getChild(2));
210 + }
211 +
212 + /**
213 + * testForeachStatementThrowsExpectedExceptionForKeyByReference
214 + *
215 + * @return void
216 + * @covers PHP_Depend_Code_ASTForeachStatement
217 + * @covers PHP_Depend_Parser
218 + * @group pdepend
219 + * @group pdepend::ast
220 + * @group unittest
221 + * @expectedException PHP_Depend_Parser_UnexpectedTokenException
222 + */
223 + public function testForeachStatementThrowsExpectedExceptionForKeyByReference()
224 + {
225 + $this->_getFirstForeachStatementInFunction(__METHOD__);
226 + }
227 +
228 + /**
117 229 * Returns a node instance for the currently executed test case.
118 230 *
119 231 * @param string $testCase Name of the calling test case.
1114 1115 /pdepend.php
54 54
55 55 require_once 'PHP/Depend/TextUI/Command.php';
56 56
57 +ini_set('memory_limit', -1);
58 +
57 59 exit(PHP_Depend_TextUI_Command::main());
1114 1115 /PHP/Depend/Parser.php
1702 1702 {
1703 1703 $this->_tokenStack->push();
1704 1704 $token = $this->_consumeToken(self::T_FOREACH);
1705 +
1706 + $foreach = $this->_builder->buildASTForeachStatement($token->image);
1707 +
1708 + $this->_consumeComments();
1709 + $this->_consumeToken(self::T_PARENTHESIS_OPEN);
1710 +
1711 + $foreach->addChild($this->_parseExpressionUntil(self::T_AS));
1712 +
1713 + $this->_consumeToken(self::T_AS);
1714 + $this->_consumeComments();
1715 +
1716 + if ($this->_tokenizer->peek() === self::T_BITWISE_AND) {
1717 + $foreach->addChild($this->_parseVariableByReference());
1718 + } else {
1719 + $foreach->addChild($this->_parseVariable());
1720 +
1721 + if ($this->_tokenizer->peek() === self::T_DOUBLE_ARROW) {
1722 + $this->_consumeToken(self::T_DOUBLE_ARROW);
1723 + $foreach->addChild($this->_parseVariableOptionalByReference());
1724 + }
1725 + }
1705 1726
1706 - return $this->_setNodePositionsAndReturn(
1707 - $this->_builder->buildASTForeachStatement($token->image)
1708 - );
1727 + $this->_consumeToken(self::T_PARENTHESIS_CLOSE);
1728 +
1729 + return $this->_setNodePositionsAndReturn($foreach);
1709 1730 }
1710 1731
1711 1732 /**
1724 1745
1725 1746 return $this->_setNodePositionsAndReturn($while);
1726 1747 }
1748 +
1749 + /**
1750 + * Parses an expression until the first token of <b>$stopTokenType</b>
1751 + * occures.
1752 + *
1753 + * This method is temporary solution until the parser supports the complete
1754 + * PHP syntax, so that this method will/must be removed in future versions
1755 + * of PHP_Depend.
1756 + *
1757 + * @param integer $stopTokenType The stop token which will not be part of
1758 + * the parsed and returns ASTExpression node.
1759 + *
1760 + * @return PHP_Depend_Code_ASTExpression
1761 + * @since 0.9.11
1762 + * @todo Remove this method when PHP_Depend supports the complete PHP syntax
1763 + */
1764 + private function _parseExpressionUntil($stopTokenType)
1765 + {
1766 + $this->_tokenStack->push();
1767 +
1768 + $expression = $this->_builder->buildASTExpression();
1769 +
1770 + $tokenType = $this->_tokenizer->peek();
1771 + while ($tokenType !== self::T_EOF) {
1772 + if ($stopTokenType === $tokenType) {
1773 + return $this->_setNodePositionsAndReturn($expression);
1774 + }
1775 + if (is_object($expr = $this->_parseOptionalExpression())) {
1776 + $expression->addChild($expr);
1777 + } else {
1778 + $this->_consumeToken($tokenType);
1779 + }
1780 + $tokenType = $this->_tokenizer->peek();
1781 + }
1782 + throw new PHP_Depend_Parser_TokenStreamEndException($this->_tokenizer);
1783 + }
1727 1784
1728 1785 /**
1729 1786 * Parses any expression that is surrounded by an opening and a closing
2285 2342 *
2286 2343 * @param PHP_Depend_Token $token The "self" keyword token.
2287 2344 *
2288 - * @return PHP_Depend_Code_AST_Node
2345 + * @return PHP_Depend_Code_ASTNode
2289 2346 * @throws PHP_Depend_Parser_Exception When an error occured during the
2290 2347 * parsing process.
2291 2348 * @throws PHP_Depend_Parser_InvalidStateException When the keyword parent
2325 2382 * reference as its first child when the self token is followed by a
2326 2383 * double colon token.
2327 2384 *
2328 - * @return PHP_Depend_Code_AST_Node
2385 + * @return PHP_Depend_Code_ASTNode
2329 2386 * @throws PHP_Depend_Parser_Exception When an error occured during the
2330 2387 * parsing process.
2331 2388 * @throws PHP_Depend_Parser_InvalidStateException When the keyword parent
2350 2407 }
2351 2408 return $this->_builder->buildASTConstant($token->image);
2352 2409 }
2410 +
2411 + /**
2412 + * Parses a variable node, optionally prefixed by an unary expression that
2413 + * represents php's by reference operator.
2414 + *
2415 + * @return PHP_Depend_Code_ASTNode
2416 + * @since 0.9.11
2417 + */
2418 + private function _parseVariableOptionalByReference()
2419 + {
2420 + $this->_consumeComments();
2421 + if ($this->_tokenizer->peek() === self::T_BITWISE_AND) {
2422 + return $this->_parseVariableByReference();
2423 + }
2424 + return $this->_parseVariable();
2425 + }
2426 +
2427 + /**
2428 + * Parses a unary expression which represents php's by reference operator,
2429 + * that is followed by a variable node.
2430 + *
2431 + * @return PHP_Depend_Code_ASTUnaryExpression
2432 + * @since 0.9.11
2433 + */
2434 + private function _parseVariableByReference()
2435 + {
2436 + $this->_consumeComments();
2437 +
2438 + $this->_tokenStack->push();
2439 +
2440 + $token = $this->_consumeToken(self::T_BITWISE_AND);
2353 2441
2442 + $expression = $this->_builder->buildASTUnaryExpression($token->image);
2443 + $expression->addChild($this->_parseVariable());
2444 +
2445 + return $this->_setNodePositionsAndReturn($expression);
2446 + }
2447 +
2354 2448 /**
2355 2449 * This method parses a simple PHP variable.
2356 2450 *
2361 2455 */
2362 2456 private function _parseVariable()
2363 2457 {
2458 + $this->_consumeComments();
2459 +
2364 2460 $this->_tokenStack->push();
2365 2461
2366 - // Read variable token
2367 - $this->_consumeComments();
2368 2462 $token = $this->_consumeToken(self::T_VARIABLE);
2369 2463
2370 2464 // TODO: ASTThisVariable
2371 -
2372 2465 return $this->_setNodePositionsAndReturn(
2373 2466 $this->_builder->buildASTVariable($token->image)
2374 2467 );
1114 1115 /PHP/Depend/Builder/Default.php
43 43 * @author Manuel Pichler <mapi@pdepend.org>
44 44 * @copyright 2008-2010 Manuel Pichler. All rights reserved.
45 45 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id: Default.php 675 2009-03-05 07:40:28Z mapi $
46 + * @version SVN: $Id$
47 47 * @link http://pdepend.org/
48 48 */
49 49
1391 1391 }
1392 1392
1393 1393 /**
1394 + * Builds a new unary expression node instance.
1395 + *
1396 + * @param string $image The unary expression image/character.
1397 + *
1398 + * @return PHP_Depend_Code_ASTUnaryExpression
1399 + * @since 0.9.11
1400 + */
1401 + public function buildASTUnaryExpression($image)
1402 + {
1403 + include_once 'PHP/Depend/Code/ASTUnaryExpression.php';
1404 +
1405 + PHP_Depend_Util_Log::debug('Creating: PHP_Depend_Code_ASTUnaryExpression()');
1406 +
1407 + return new PHP_Depend_Code_ASTUnaryExpression($image);
1408 + }
1409 +
1410 + /**
1394 1411 * Returns an iterator with all generated {@link PHP_Depend_Code_Package}
1395 1412 * objects.
1396 1413 *
1114 1115 /PHP/Depend/Code/ASTUnaryExpression.php
2 +<?php
3 +/**
4 + * This file is part of PHP_Depend.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2008-2010, 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-2010 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 + * @since 0.9.11
49 + */
50 +
51 +/**
52 + * This class represents an unary expression node.
53 + *
54 + * <code>
55 + * // -
56 + * -$foo
57 + * // -
58 + *
59 + * // -
60 + * +$foo
61 + * // -
62 + *
63 + * // -
64 + * &$foo
65 + * // -
66 + * </code>
67 + *
68 + * @category PHP
69 + * @package PHP_Depend
70 + * @subpackage Code
71 + * @author Manuel Pichler <mapi@pdepend.org>
72 + * @copyright 2008-2010 Manuel Pichler. All rights reserved.
73 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
74 + * @version Release: @package_version@
75 + * @link http://www.pdepend.org/
76 + * @since 0.9.11
77 + */
78 +class PHP_Depend_Code_ASTUnaryExpression extends PHP_Depend_Code_ASTNode
79 +{
80 + /**
81 + * Type of this node class.
82 + */
83 + const CLAZZ = __CLASS__;
84 +}