NoWhitespaceInBlankLineFixerTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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\Whitespace;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. use PhpCsFixer\WhitespacesFixerConfig;
  15. /**
  16. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer
  21. *
  22. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer>
  23. */
  24. final class NoWhitespaceInBlankLineFixerTest extends AbstractFixerTestCase
  25. {
  26. /**
  27. * @dataProvider provideFixCases
  28. */
  29. public function testFix(string $expected, ?string $input = null): void
  30. {
  31. $this->doTest($expected, $input);
  32. }
  33. /**
  34. * @return iterable<array{0: string, 1?: string}>
  35. */
  36. public static function provideFixCases(): iterable
  37. {
  38. yield [
  39. "<?php\n",
  40. ];
  41. yield [
  42. '<?php ',
  43. ];
  44. yield [
  45. '<?php
  46. ',
  47. '<?php
  48. ',
  49. ];
  50. yield [
  51. '<?php
  52. ',
  53. '<?php
  54. '.'
  55. ',
  56. ];
  57. yield [
  58. '<?php
  59. $a = 1; ',
  60. '<?php
  61. '.'
  62. $a = 1; ',
  63. ];
  64. yield [
  65. '<?php
  66. $r = 5 +6; '.'
  67. $t = true> 9; '.'
  68. ',
  69. ];
  70. yield [
  71. '<?php
  72. $a = 1; ',
  73. ];
  74. yield [
  75. "<?php
  76. \t\$b = 1;\t\t",
  77. ];
  78. yield [
  79. '<?php
  80. $b = 2;
  81. ',
  82. '<?php
  83. $b = 2;
  84. ',
  85. ];
  86. yield [
  87. '<?php
  88. $b = 3;
  89. ',
  90. '<?php
  91. $b = 3;
  92. '.'
  93. '.'
  94. ',
  95. ];
  96. yield [
  97. '<?php
  98. $b = 4;
  99. $b += 4;',
  100. '<?php
  101. $b = 4;
  102. '.'
  103. '.'
  104. '.'
  105. $b += 4;',
  106. ];
  107. yield [
  108. "<?php\n\n\n\$b = 5;",
  109. "<?php\n \n\t\n\$b = 5;",
  110. ];
  111. yield [
  112. "<?php\necho 1;\n?>\n\n\n\n",
  113. ];
  114. yield [
  115. "<?php\necho <<<HTML\ndata \n \n \t \n \nHTML\n;\n//a",
  116. ];
  117. yield [
  118. "<?php\n\$sql = 'SELECT * FROM products WHERE description = \"This product\n \nis nice\"';",
  119. ];
  120. yield [
  121. '<?php
  122. /**
  123. * @const Foo.
  124. */
  125. const FOO = "BAR";
  126. ',
  127. ];
  128. yield [
  129. "<?php\n\n \$a = 1;\n\n \$b = 2;",
  130. "<?php\n\n \$a = 1;\n \n \$b = 2;",
  131. ];
  132. }
  133. /**
  134. * @dataProvider provideWithWhitespacesConfigCases
  135. */
  136. public function testWithWhitespacesConfig(string $expected, ?string $input = null): void
  137. {
  138. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
  139. $this->doTest($expected, $input);
  140. }
  141. /**
  142. * @return iterable<array{string, string}>
  143. */
  144. public static function provideWithWhitespacesConfigCases(): iterable
  145. {
  146. yield [
  147. "<?php\r\n\r\n \$a = 1;\r\n\r\n \$b = 2;",
  148. "<?php\r\n\r\n \$a = 1;\r\n \r\n \$b = 2;",
  149. ];
  150. }
  151. }