Skip to content

Commit

Permalink
Merge branches 'master' and 'release-2.6.1' of https://github.com/pde…
Browse files Browse the repository at this point in the history
…pend/pdepend into release-2.6.1
  • Loading branch information
kylekatarnls committed Dec 21, 2019
2 parents 66c822a + 9426ac9 commit 395b0f3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Expand Up @@ -351,4 +351,12 @@ protected function parseArgumentList(ASTArguments $arguments)

return $arguments;
}

protected function parseConstantDeclaratorValue()
{
$value = new ASTValue();
$value->setValue($this->parseOptionalExpression());

return $value;
}
}
Expand Up @@ -44,6 +44,10 @@
namespace PDepend\Source\Language\PHP;

use PDepend\AbstractTest;
use PDepend\Source\AST\ASTClass;
use PDepend\Source\AST\ASTConstantDeclarator;
use PDepend\Source\AST\ASTConstantDefinition;
use PDepend\Source\AST\ASTExpression;
use PDepend\Source\Builder\Builder;
use PDepend\Source\Tokenizer\Tokenizer;
use PDepend\Util\Cache\CacheDriver;
Expand Down Expand Up @@ -197,6 +201,47 @@ public function testParserThrowsUnexpectedTokenExceptionForInvalidTokenInPropert
$this->parseCodeResourceForTest();
}

/**
* Tests issue with constant array concatenation.
* https://github.com/pdepend/pdepend/issues/299
*
* @return void
*/
public function testConstantArrayConcatenation()
{
/** @var ASTClass $class */
$class = $this->getFirstClassForTestCase();

/** @var ASTConstantDefinition[] $sontants */
$constants = $class->getChildren();

$this->assertCount(2, $constants);
$this->assertInstanceOf('PDepend\\Source\\AST\\ASTConstantDefinition', $constants[0]);
$this->assertInstanceOf('PDepend\\Source\\AST\\ASTConstantDefinition', $constants[1]);

/** @var ASTConstantDeclarator[] $declarators */
$declarators = $constants[1]->getChildren();

$this->assertCount(1, $declarators);
$this->assertInstanceOf('PDepend\\Source\\AST\\ASTConstantDeclarator', $declarators[0]);

/** @var ASTExpression $expression */
$expression = $declarators[0]->getValue()->getValue();

$this->assertInstanceOf('PDepend\\Source\\AST\\ASTExpression', $expression);

$nodes = $expression->getChildren();
$this->assertInstanceOf('PDepend\\Source\\AST\\ASTMemberPrimaryPrefix', $nodes[0]);
$this->assertInstanceOf('PDepend\\Source\\AST\\ASTExpression', $nodes[1]);
$this->assertSame('+', $nodes[1]->getImage());
$this->assertInstanceOf('PDepend\\Source\\AST\\ASTArray', $nodes[2]);

$nodes = $nodes[0]->getChildren();
$this->assertInstanceOf('PDepend\\Source\\AST\\ASTSelfReference', $nodes[0]);
$this->assertInstanceOf('PDepend\\Source\\AST\\ASTConstantPostfix', $nodes[1]);
$this->assertSame('A', $nodes[1]->getImage());
}

/**
* @param \PDepend\Source\Tokenizer\Tokenizer $tokenizer
* @param \PDepend\Source\Builder\Builder $builder
Expand Down
@@ -0,0 +1,7 @@
<?php

class Test
{
const A = [];
const B = self::A + ['a' => 1];
}

0 comments on commit 395b0f3

Please sign in to comment.