NoWhitespaceInBlankLineFixerTest.php 3.0 KB

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