Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Fixed #189: Invalid Start/End Line/Column for object method invocat…
…ion.
  • Loading branch information
manuelpichler committed Dec 28, 2010
1 parent debb5fa commit c6cc9dd
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 26 deletions.
36 changes: 29 additions & 7 deletions PHP/Depend/Parser.php
Expand Up @@ -3475,18 +3475,40 @@ private function _parseMethodOrPropertyPostfix(PHP_Depend_Code_ASTNode $node)
switch ($this->tokenizer->peek()) {

case self::T_PARENTHESIS_OPEN:
$postfix = $this->_builder->buildASTMethodPostfix($node->getImage());
$postfix->addChild($node);
$postfix->addChild($this->_parseArguments());

return $this->_parseOptionalMemberPrimaryPrefix($postfix);
$postfix = $this->_parseMethodPostfix($node);
break;

default:
$postfix = $this->_builder->buildASTPropertyPostfix($node->getImage());
$postfix->addChild($node);

return $this->_parseOptionalMemberPrimaryPrefix($postfix);
break;
}
return $this->_parseOptionalMemberPrimaryPrefix($postfix);
}

/**
* Parses a method postfix node instance.
*
* @param PHP_Depend_Code_ASTNode $node Node that represents the image of
* the method postfix node.
*
* @return PHP_Depend_Code_ASTMethodPostfix
* @since 0.11.0
*/
private function _parseMethodPostfix(PHP_Depend_Code_ASTNode $node)
{
$args = $this->_parseArguments();

$postfix = $this->_builder->buildASTMethodPostfix($node->getImage());
$postfix->addChild($node);
$postfix->addChild($args);

$postfix->setEndLine($args->getEndLine());
$postfix->setEndColumn($args->getEndColumn());
$postfix->setStartLine($node->getStartLine());
$postfix->setStartColumn($node->getStartColumn());

return $postfix;
}

/**
Expand Down
184 changes: 165 additions & 19 deletions tests/PHP/Depend/Code/ASTMethodPostfixTest.php
Expand Up @@ -48,9 +48,6 @@

require_once dirname(__FILE__) . '/ASTNodeTest.php';

require_once 'PHP/Depend/Code/ASTMethodPostfix.php';
require_once 'PHP/Depend/ConstantsI.php';

/**
* Test case for the {@link PHP_Depend_Code_ASTMethodPostfix} class.
*
Expand All @@ -65,6 +62,142 @@
*/
class PHP_Depend_Code_ASTMethodPostfixTest extends PHP_Depend_Code_ASTNodeTest
{
/**
* testObjectMethodPostfixHasExpectedStartLine
*
* @return void
* @covers PHP_Depend_Parser
* @covers PHP_Depend_Builder_Default
* @covers PHP_Depend_Code_ASTMethodPostfix
* @group pdepend
* @group pdepend::ast
* @group unittest
*/
public function testObjectMethodPostfixHasExpectedStartLine()
{
$postfix = $this->_getFirstMethodPostfixInFunction();
self::assertEquals(6, $postfix->getStartLine());
}

/**
* testObjectMethodPostfixHasExpectedStartColumn
*
* @return void
* @covers PHP_Depend_Parser
* @covers PHP_Depend_Builder_Default
* @covers PHP_Depend_Code_ASTMethodPostfix
* @group pdepend
* @group pdepend::ast
* @group unittest
*/
public function testObjectMethodPostfixHasExpectedStartColumn()
{
$postfix = $this->_getFirstMethodPostfixInFunction();
self::assertEquals(13, $postfix->getStartColumn());
}

/**
* testObjectMethodPostfixHasExpectedEndLine
*
* @return void
* @covers PHP_Depend_Parser
* @covers PHP_Depend_Builder_Default
* @covers PHP_Depend_Code_ASTMethodPostfix
* @group pdepend
* @group pdepend::ast
* @group unittest
*/
public function testObjectMethodPostfixHasExpectedEndLine()
{
$postfix = $this->_getFirstMethodPostfixInFunction();
self::assertEquals(7, $postfix->getEndLine());
}

/**
* testObjectMethodPostfixHasExpectedEndColumn
*
* @return void
* @covers PHP_Depend_Parser
* @covers PHP_Depend_Builder_Default
* @covers PHP_Depend_Code_ASTMethodPostfix
* @group pdepend
* @group pdepend::ast
* @group unittest
*/
public function testObjectMethodPostfixHasExpectedEndColumn()
{
$postfix = $this->_getFirstMethodPostfixInFunction();
self::assertEquals(17, $postfix->getEndColumn());
}

/**
* testClassMethodPostfixHasExpectedStartLine
*
* @return void
* @covers PHP_Depend_Parser
* @covers PHP_Depend_Builder_Default
* @covers PHP_Depend_Code_ASTMethodPostfix
* @group pdepend
* @group pdepend::ast
* @group unittest
*/
public function testClassMethodPostfixHasExpectedStartLine()
{
$postfix = $this->_getFirstMethodPostfixInFunction();
self::assertEquals(6, $postfix->getStartLine());
}

/**
* testClassMethodPostfixHasExpectedStartColumn
*
* @return void
* @covers PHP_Depend_Parser
* @covers PHP_Depend_Builder_Default
* @covers PHP_Depend_Code_ASTMethodPostfix
* @group pdepend
* @group pdepend::ast
* @group unittest
*/
public function testClassMethodPostfixHasExpectedStartColumn()
{
$postfix = $this->_getFirstMethodPostfixInFunction();
self::assertEquals(13, $postfix->getStartColumn());
}

/**
* testClassMethodPostfixHasExpectedEndLine
*
* @return void
* @covers PHP_Depend_Parser
* @covers PHP_Depend_Builder_Default
* @covers PHP_Depend_Code_ASTMethodPostfix
* @group pdepend
* @group pdepend::ast
* @group unittest
*/
public function testClassMethodPostfixHasExpectedEndLine()
{
$postfix = $this->_getFirstMethodPostfixInFunction();
self::assertEquals(7, $postfix->getEndLine());
}

/**
* testClassMethodPostfixHasExpectedEndColumn
*
* @return void
* @covers PHP_Depend_Parser
* @covers PHP_Depend_Builder_Default
* @covers PHP_Depend_Code_ASTMethodPostfix
* @group pdepend
* @group pdepend::ast
* @group unittest
*/
public function testClassMethodPostfixHasExpectedEndColumn()
{
$postfix = $this->_getFirstMethodPostfixInFunction();
self::assertEquals(17, $postfix->getEndColumn());
}

/**
* testAcceptInvokesVisitOnGivenVisitor
*
Expand Down Expand Up @@ -129,7 +262,7 @@ public function testMethodPostfixStructureForSimpleInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -153,7 +286,7 @@ public function testMethodPostfixStructureForVariableInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -178,7 +311,7 @@ public function testMethodPostfixStructureForVariableVariableInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -203,7 +336,7 @@ public function testMethodPostfixStructureForCompoundVariableInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -227,7 +360,7 @@ public function testMethodPostfixStructureForSimpleStaticInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -251,7 +384,7 @@ public function testMethodPostfixStructureForVariableStaticInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -276,7 +409,7 @@ public function testMethodPostfixStructureForVariableVariableStaticInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -301,7 +434,7 @@ public function testMethodPostfixStructureForCompoundVariableStaticInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ,
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -328,7 +461,7 @@ public function testMethodPostfixStructureForVariableCompoundVariableStaticInvoc
PHP_Depend_Code_ASTArguments::CLAZZ,
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand Down Expand Up @@ -356,7 +489,7 @@ public function testMethodPostfixStructureForStaticInvocationWithConsecutiveInvo
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -380,7 +513,7 @@ public function testMethodPostfixStructureForStaticInvocationOnVariable()
PHP_Depend_Code_ASTArguments::CLAZZ
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -404,7 +537,7 @@ public function testMethodPostfixStructureForSelfInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ,
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -428,7 +561,7 @@ public function testMethodPostfixStructureForParentInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ,
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand All @@ -452,7 +585,7 @@ public function testMethodPostfixGraphForStaticReferenceInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ,
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand Down Expand Up @@ -482,7 +615,7 @@ public function testMethodPostfixGraphForVariableArrayElementInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ,
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
Expand Down Expand Up @@ -512,7 +645,20 @@ public function testMethodPostfixGraphForPropertyArrayElementInvocation()
PHP_Depend_Code_ASTArguments::CLAZZ,
);

$this->assertGraphEquals($prefix, $expected);
self::assertGraphEquals($prefix, $expected);
}

/**
* Returns a node instance for the currently executed test case.
*
* @return PHP_Depend_Code_ASTMethodPostfix
*/
private function _getFirstMethodPostfixInFunction()
{
return $this->getFirstNodeOfTypeInFunction(
self::getCallingTestMethod(),
PHP_Depend_Code_ASTMethodPostfix::CLAZZ
);
}

/**
Expand Down
@@ -0,0 +1,8 @@
<?php
function testClassMethodPostfixHasExpectedEndColumn()
{
return ClassMethodPostfix
::
foo(
);
}
@@ -0,0 +1,8 @@
<?php
function testClassMethodPostfixHasExpectedEndLine()
{
return ClassMethodPostfix
::
foo(
);
}
@@ -0,0 +1,8 @@
<?php
function testClassMethodPostfixHasExpectedStartColumn()
{
return ClassMethodPostfix
::
foo(
);
}
@@ -0,0 +1,8 @@
<?php
function testClassMethodPostfixHasExpectedStartLine()
{
return ClassMethodPostfix
::
foo(
);
}

0 comments on commit c6cc9dd

Please sign in to comment.