Permalink
Browse files

Make $line argument for Comment optional

Also add setLine() method.
  • Loading branch information...
1 parent 0911b2e commit 35ec185558ba6a8e735668a82d8f171a1c2be6fd @nikic nikic committed Jun 8, 2012
Showing with 18 additions and 7 deletions.
  1. +11 −3 lib/PHPParser/Comment.php
  2. +5 −2 test/PHPParser/Tests/CommentTest.php
  3. +2 −2 test/PHPParser/Tests/NodeAbstractTest.php
View
@@ -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;
}
@@ -45,6 +44,15 @@ public function getLine() {
}
/**
+ * Sets the line number the comment started on.
+ *
+ * @param int Line number
+ */
+ public function setLine($line) {
+ $this->line = $line;
+ }
+
+ /**
* Gets the comment text.
*
* @return string The comment text (including comment delimiters like /*)
@@ -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());
}
@@ -6,8 +6,8 @@ public function testConstruct() {
$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 */'),
),
);

0 comments on commit 35ec185

Please sign in to comment.