CommentTest.php 1.8 KB

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