CommentTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. class PHPParser_Tests_CommentTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testGetSet() {
  5. $comment = new PHPParser_Comment('/* Some comment */', 1);
  6. $this->assertEquals('/* Some comment */', $comment->getText());
  7. $this->assertEquals('/* Some comment */', (string) $comment);
  8. $this->assertEquals(1, $comment->getLine());
  9. $comment->setText('/* Some other comment */');
  10. $comment->setLine(10);
  11. $this->assertEquals('/* Some other comment */', $comment->getText());
  12. $this->assertEquals('/* Some other comment */', (string) $comment);
  13. $this->assertEquals(10, $comment->getLine());
  14. }
  15. /**
  16. * @dataProvider provideTestReformatting
  17. */
  18. public function testReformatting($commentText, $reformattedText) {
  19. $comment = new PHPParser_Comment($commentText);
  20. $this->assertEquals($reformattedText, $comment->getReformattedText());
  21. }
  22. public function provideTestReformatting() {
  23. return array(
  24. array('// Some text' . "\n", '// Some text'),
  25. array('/* Some text */', '/* Some text */'),
  26. array(
  27. '/**
  28. * Some text.
  29. * Some more text.
  30. */',
  31. '/**
  32. * Some text.
  33. * Some more text.
  34. */'
  35. ),
  36. array(
  37. '/*
  38. Some text.
  39. Some more text.
  40. */',
  41. '/*
  42. Some text.
  43. Some more text.
  44. */'
  45. ),
  46. array(
  47. '/* Some text.
  48. More text.
  49. Even more text. */',
  50. '/* Some text.
  51. More text.
  52. Even more text. */'
  53. ),
  54. // invalid comment -> no reformatting
  55. array(
  56. 'hallo
  57. world',
  58. 'hallo
  59. world',
  60. ),
  61. );
  62. }
  63. }