Make $line argument for Comment optional

Also add setLine() method.
This commit is contained in:
nikic 2012-06-08 17:55:35 +02:00
parent 0911b2e1ce
commit 35ec185558
3 changed files with 18 additions and 7 deletions

View File

@ -3,16 +3,15 @@
class PHPParser_Comment
{
protected $text;
protected $line;
/**
* Constructs a comment node.
*
* @param string $text Comment text (including comment delimiters like /*)
* @param int $line Line number the comment started on
* @param int $line Line number the comment started on
*/
public function __construct($text, $line) {
public function __construct($text, $line = -1) {
$this->text = $text;
$this->line = $line;
}
@ -44,6 +43,15 @@ class PHPParser_Comment
return $this->line;
}
/**
* Sets the line number the comment started on.
*
* @param int Line number
*/
public function setLine($line) {
$this->line = $line;
}
/**
* Gets the comment text.
*

View File

@ -2,23 +2,26 @@
class PHPParser_Tests_CommentTest extends PHPUnit_Framework_TestCase
{
public function testGetSetText() {
public function testGetSet() {
$comment = new PHPParser_Comment('/* Some comment */', 1);
$this->assertEquals('/* Some comment */', $comment->getText());
$this->assertEquals('/* Some comment */', (string) $comment);
$this->assertEquals(1, $comment->getLine());
$comment->setText('/* Some other comment */');
$comment->setLine(10);
$this->assertEquals('/* Some other comment */', $comment->getText());
$this->assertEquals('/* Some other comment */', (string) $comment);
$this->assertEquals(10, $comment->getLine());
}
/**
* @dataProvider provideTestReformatting
*/
public function testReformatting($commentText, $reformattedText) {
$comment = new PHPParser_Comment($commentText, 1);
$comment = new PHPParser_Comment($commentText);
$this->assertEquals($reformattedText, $comment->getReformattedText());
}

View File

@ -6,8 +6,8 @@ class PHPParser_Tests_NodeAbstractTest extends PHPUnit_Framework_TestCase
$attributes = array(
'startLine' => 10,
'comments' => array(
new PHPParser_Comment('// Comment' . "\n", 8),
new PHPParser_Comment_Doc('/** doc comment */', 9),
new PHPParser_Comment('// Comment' . "\n"),
new PHPParser_Comment_Doc('/** doc comment */'),
),
);