2011-11-27 21:43:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class PHPParser_Tests_NodeAbstractTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testConstruct() {
|
2012-04-29 23:32:09 +02:00
|
|
|
$attributes = array(
|
2012-05-05 17:34:27 +02:00
|
|
|
'startLine' => 10,
|
2012-04-29 23:32:09 +02:00
|
|
|
'docComment' => '/** doc comment */',
|
|
|
|
);
|
|
|
|
|
2011-11-27 21:43:27 +01:00
|
|
|
$node = $this->getMockForAbstractClass(
|
|
|
|
'PHPParser_NodeAbstract',
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'subNode' => 'value'
|
|
|
|
),
|
2012-04-29 23:32:09 +02:00
|
|
|
$attributes
|
2011-11-27 21:43:27 +01:00
|
|
|
),
|
|
|
|
'PHPParser_Node_Dummy'
|
|
|
|
);
|
|
|
|
|
2011-12-02 17:52:03 +01:00
|
|
|
$this->assertEquals('Dummy', $node->getType());
|
|
|
|
$this->assertEquals(array('subNode'), $node->getSubNodeNames());
|
2011-11-27 21:43:27 +01:00
|
|
|
$this->assertEquals(10, $node->getLine());
|
|
|
|
$this->assertEquals('/** doc comment */', $node->getDocComment());
|
|
|
|
$this->assertEquals('value', $node->subNode);
|
|
|
|
$this->assertTrue(isset($node->subNode));
|
2012-04-29 23:32:09 +02:00
|
|
|
$this->assertEquals($attributes, $node->getAttributes());
|
2011-11-27 21:43:27 +01:00
|
|
|
|
|
|
|
return $node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testConstruct
|
|
|
|
*/
|
|
|
|
public function testChange(PHPParser_Node $node) {
|
2011-12-02 17:52:03 +01:00
|
|
|
// change of line
|
2011-11-27 21:43:27 +01:00
|
|
|
$node->setLine(15);
|
|
|
|
$this->assertEquals(15, $node->getLine());
|
|
|
|
|
2011-12-02 17:52:03 +01:00
|
|
|
// change of doc comment
|
2011-11-27 21:43:27 +01:00
|
|
|
$node->setDocComment('/** other doc comment */');
|
|
|
|
$this->assertEquals('/** other doc comment */', $node->getDocComment());
|
|
|
|
|
2011-12-02 17:52:03 +01:00
|
|
|
// direct modification
|
2011-11-27 21:43:27 +01:00
|
|
|
$node->subNode = 'newValue';
|
|
|
|
$this->assertEquals('newValue', $node->subNode);
|
|
|
|
|
2011-12-02 17:52:03 +01:00
|
|
|
// indirect modification
|
|
|
|
$subNode =& $node->subNode;
|
|
|
|
$subNode = 'newNewValue';
|
|
|
|
$this->assertEquals('newNewValue', $node->subNode);
|
|
|
|
|
|
|
|
// removal
|
2011-11-27 21:43:27 +01:00
|
|
|
unset($node->subNode);
|
|
|
|
$this->assertFalse(isset($node->subNode));
|
|
|
|
}
|
2012-04-09 12:37:47 +02:00
|
|
|
|
2012-04-29 23:32:09 +02:00
|
|
|
public function testAttributes() {
|
|
|
|
/** @var $node PHPParser_Node */
|
|
|
|
$node = $this->getMockForAbstractClass('PHPParser_NodeAbstract');
|
|
|
|
|
2012-04-09 12:37:47 +02:00
|
|
|
$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(
|
2012-04-29 23:32:09 +02:00
|
|
|
'key' => 'value',
|
2012-04-09 12:37:47 +02:00
|
|
|
'null' => null,
|
|
|
|
),
|
|
|
|
$node->getAttributes()
|
|
|
|
);
|
|
|
|
}
|
2011-11-27 21:43:27 +01:00
|
|
|
}
|