NoTrailingWhitespaceInCommentFixerTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\Comment;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer>
  22. */
  23. final class NoTrailingWhitespaceInCommentFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return iterable<array{string, string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [
  38. '<?php
  39. /*
  40. //
  41. //
  42. //
  43. //
  44. //
  45. //
  46. //
  47. //
  48. */
  49. ',
  50. '<?php
  51. /*
  52. //
  53. //
  54. '.'
  55. //
  56. //
  57. //
  58. '.'
  59. //
  60. //
  61. '.'
  62. //
  63. */
  64. ',
  65. ];
  66. yield [
  67. '<?php
  68. // This is'.'
  69. //'.'
  70. //'.'
  71. // multiline comment.
  72. //',
  73. '<?php
  74. // This is '.'
  75. // '.'
  76. // '.'
  77. // multiline comment. '.'
  78. // ',
  79. ];
  80. yield [
  81. '<?php
  82. /*
  83. * This is another'.'
  84. *'.'
  85. *'.'
  86. * multiline comment.'.'
  87. */',
  88. '<?php
  89. /* '.'
  90. * This is another '.'
  91. * '.'
  92. * '.'
  93. * multiline comment. '.'
  94. */',
  95. ];
  96. yield [
  97. '<?php
  98. /**
  99. * Summary'.'
  100. *'.'
  101. *'.'
  102. * Description.'.'
  103. *
  104. * @annotation
  105. * Foo
  106. */',
  107. '<?php
  108. /** '.'
  109. * Summary '.'
  110. * '.'
  111. * '.'
  112. * Description. '.'
  113. * '.'
  114. * @annotation '.'
  115. * Foo '.'
  116. */',
  117. ];
  118. yield [
  119. str_replace(
  120. "\n",
  121. "\r\n",
  122. '<?php
  123. /**
  124. * Summary
  125. *'.'
  126. * Description
  127. */'
  128. ),
  129. str_replace(
  130. "\n",
  131. "\r\n",
  132. '<?php
  133. /**
  134. * Summary
  135. * '.'
  136. * Description
  137. */'
  138. ),
  139. ];
  140. yield [
  141. str_replace(
  142. "\n",
  143. "\r",
  144. '<?php
  145. /**
  146. * Summary
  147. *'.'
  148. * Description
  149. */'
  150. ),
  151. str_replace(
  152. "\n",
  153. "\r",
  154. '<?php
  155. /**
  156. * Summary
  157. * '.'
  158. * Description
  159. */'
  160. ),
  161. ];
  162. }
  163. }