mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-30 04:19:30 +01:00
a45360ccaf
Also fix the @inheritDoc declarations and do some whitespace normalization
82 lines
2.5 KiB
PHP
82 lines
2.5 KiB
PHP
<?php
|
|
|
|
class PHPParser_Tests_NodeAbstractTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
public function testConstruct() {
|
|
$node = $this->getMockForAbstractClass(
|
|
'PHPParser_NodeAbstract',
|
|
array(
|
|
array(
|
|
'subNode' => 'value'
|
|
),
|
|
10,
|
|
'/** doc comment */'
|
|
),
|
|
'PHPParser_Node_Dummy'
|
|
);
|
|
|
|
$this->assertEquals('Dummy', $node->getType());
|
|
$this->assertEquals(array('subNode'), $node->getSubNodeNames());
|
|
$this->assertEquals(10, $node->getLine());
|
|
$this->assertEquals('/** doc comment */', $node->getDocComment());
|
|
$this->assertEquals('value', $node->subNode);
|
|
$this->assertTrue(isset($node->subNode));
|
|
$this->assertEmpty($node->getAttributes());
|
|
|
|
return $node;
|
|
}
|
|
|
|
/**
|
|
* @depends testConstruct
|
|
*/
|
|
public function testChange(PHPParser_Node $node) {
|
|
// change of line
|
|
$node->setLine(15);
|
|
$this->assertEquals(15, $node->getLine());
|
|
|
|
// change of doc comment
|
|
$node->setDocComment('/** other doc comment */');
|
|
$this->assertEquals('/** other doc comment */', $node->getDocComment());
|
|
|
|
// direct modification
|
|
$node->subNode = 'newValue';
|
|
$this->assertEquals('newValue', $node->subNode);
|
|
|
|
// indirect modification
|
|
$subNode =& $node->subNode;
|
|
$subNode = 'newNewValue';
|
|
$this->assertEquals('newNewValue', $node->subNode);
|
|
|
|
// removal
|
|
unset($node->subNode);
|
|
$this->assertFalse(isset($node->subNode));
|
|
}
|
|
|
|
/**
|
|
* @depends testConstruct
|
|
*/
|
|
public function testAttributes(PHPParser_NodeAbstract $node) {
|
|
$this->assertEmpty($node->getAttributes());
|
|
|
|
$node->setAttribute('key', 'value');
|
|
$this->assertTrue($node->hasAttribute('key'));
|
|
$this->assertEquals('value', $node->getAttribute('key'));
|
|
|
|
$this->assertFalse($node->hasAttribute('doesNotExist'));
|
|
$this->assertNull($node->getAttribute('doesNotExist'));
|
|
$this->assertEquals('default', $node->getAttribute('doesNotExist', 'default'));
|
|
|
|
$node->setAttribute('null', null);
|
|
$this->assertTrue($node->hasAttribute('null'));
|
|
$this->assertNull($node->getAttribute('null'));
|
|
$this->assertNull($node->getAttribute('null', 'default'));
|
|
|
|
$this->assertEquals(
|
|
array(
|
|
'key' => 'value',
|
|
'null' => null,
|
|
),
|
|
$node->getAttributes()
|
|
);
|
|
}
|
|
} |