NoEmptyPhpdocFixerTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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\Phpdoc;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer
  18. *
  19. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer>
  20. */
  21. final class NoEmptyPhpdocFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. /**
  31. * @return iterable<string, array{string, string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield 'multiple PHPdocs' => [
  36. '<?php
  37. /** a */
  38. '.'
  39. '.'
  40. '.'
  41. '.'
  42. /**
  43. * test
  44. */
  45. /** *test* */
  46. ',
  47. '<?php
  48. /** *//** a *//** */
  49. /**
  50. */
  51. /**
  52. *
  53. */
  54. /** ***
  55. *
  56. ******/
  57. /**
  58. **/
  59. /**
  60. * test
  61. */
  62. /** *test* */
  63. ',
  64. ];
  65. yield 'PHPDoc on its own line' => [
  66. <<<'PHP'
  67. <?php
  68. echo $a;
  69. echo $b;
  70. PHP,
  71. <<<'PHP'
  72. <?php
  73. echo $a;
  74. /** */
  75. echo $b;
  76. PHP,
  77. ];
  78. yield 'PHPDoc on its own line with empty line before' => [
  79. <<<'PHP'
  80. <?php
  81. function f() {
  82. echo $a;
  83. echo $b;
  84. }
  85. PHP,
  86. <<<'PHP'
  87. <?php
  88. function f() {
  89. echo $a;
  90. /** */
  91. echo $b;
  92. }
  93. PHP,
  94. ];
  95. yield 'PHPDoc on its own line with empty line after' => [
  96. <<<'PHP'
  97. <?php
  98. echo $a;
  99. echo $b;
  100. PHP,
  101. <<<'PHP'
  102. <?php
  103. echo $a;
  104. /** */
  105. echo $b;
  106. PHP,
  107. ];
  108. yield 'PHPDoc on its own line with empty line before and after' => [
  109. <<<'PHP'
  110. <?php
  111. echo $a;
  112. echo $b;
  113. PHP,
  114. <<<'PHP'
  115. <?php
  116. echo $a;
  117. /** */
  118. echo $b;
  119. PHP,
  120. ];
  121. yield 'PHPDoc with empty line before and content after' => [
  122. <<<'PHP'
  123. <?php
  124. function f() {
  125. echo $a;
  126. echo $b;
  127. }
  128. PHP,
  129. <<<'PHP'
  130. <?php
  131. function f() {
  132. echo $a;
  133. /** */echo $b;
  134. }
  135. PHP,
  136. ];
  137. yield 'PHPDoc with content before and empty line after' => [
  138. <<<'PHP'
  139. <?php
  140. function f() {
  141. echo $a;
  142. echo $b;
  143. }
  144. PHP,
  145. <<<'PHP'
  146. <?php
  147. function f() {
  148. echo $a;/** */
  149. echo $b;
  150. }
  151. PHP,
  152. ];
  153. yield 'PHPDoc after open tag - the same line' => [
  154. '<?php '.'
  155. foo();
  156. ',
  157. '<?php /** */
  158. foo();
  159. ',
  160. ];
  161. yield 'PHPDoc after open tag - next line' => [
  162. <<<'PHP'
  163. <?php
  164. foo();
  165. PHP,
  166. <<<'PHP'
  167. <?php
  168. /** */
  169. foo();
  170. PHP,
  171. ];
  172. yield 'PHPDoc after open tag - next next next line' => [
  173. <<<'PHP'
  174. <?php
  175. foo();
  176. PHP,
  177. <<<'PHP'
  178. <?php
  179. /** */
  180. foo();
  181. PHP,
  182. ];
  183. }
  184. }