NoWhitespaceInBlankLineFixerTest.php 3.2 KB

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