BlankLineAfterOpeningTagFixerTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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\PhpTag;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. use PhpCsFixer\WhitespacesFixerConfig;
  15. /**
  16. * @author Ceeram <ceeram@cakephp.org>
  17. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer
  22. */
  23. final class BlankLineAfterOpeningTagFixerTest 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. public static function provideFixCases(): iterable
  33. {
  34. yield [
  35. '<?php
  36. $a = 0;
  37. echo 1;',
  38. '<?php
  39. $a = 0;
  40. echo 1;',
  41. ];
  42. yield [
  43. '<?php
  44. $b = 2;
  45. echo 3;',
  46. '<?php $b = 2;
  47. echo 3;',
  48. ];
  49. yield [
  50. '<?php
  51. '.'
  52. $c = 4;
  53. echo 5;',
  54. ];
  55. yield [
  56. '<?php
  57. $a = function(){
  58. echo 1;
  59. };',
  60. '<?php $a = function(){
  61. echo 1;
  62. };',
  63. ];
  64. yield [
  65. '<?php
  66. class SomeClass
  67. {
  68. const VERSION = "1.1.1";
  69. const FOO = "bar";
  70. }
  71. ',
  72. ];
  73. yield [
  74. '<?php $foo = true; ?>',
  75. ];
  76. yield [
  77. '<?php $foo = true; ?>
  78. ',
  79. ];
  80. yield [
  81. '<?php
  82. $foo = true;
  83. ?>',
  84. '<?php
  85. $foo = true;
  86. ?>',
  87. ];
  88. yield [
  89. '<?php
  90. $foo = true;
  91. $bar = false;
  92. ',
  93. '<?php $foo = true;
  94. $bar = false;
  95. ',
  96. ];
  97. yield [
  98. '<?php
  99. $foo = true;
  100. ?>
  101. Html here
  102. <?php $bar = false;',
  103. ];
  104. yield [
  105. '<?php
  106. $foo = true;
  107. ?>
  108. Html here
  109. <?php $bar = false;
  110. ',
  111. ];
  112. yield [
  113. '<?= $bar;
  114. $foo = $bar;
  115. ?>',
  116. ];
  117. }
  118. /**
  119. * @dataProvider provideMessyWhitespacesCases
  120. */
  121. public function testMessyWhitespaces(string $expected, ?string $input = null): void
  122. {
  123. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
  124. $this->doTest($expected, $input);
  125. }
  126. public static function provideMessyWhitespacesCases(): iterable
  127. {
  128. yield [
  129. "<?php\r\n\r\n\$foo = true;\r\n",
  130. "<?php \$foo = true;\r\n",
  131. ];
  132. yield [
  133. "<?php\r\n\r\n\$foo = true;\r\n",
  134. "<?php\r\n\$foo = true;\r\n",
  135. ];
  136. }
  137. }