LinebreakAfterOpeningTagFixerTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\LinebreakAfterOpeningTagFixer
  22. */
  23. final class LinebreakAfterOpeningTagFixerTest 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 = function(){
  37. echo 1;
  38. };',
  39. '<?php $a = function(){
  40. echo 1;
  41. };',
  42. ];
  43. yield [
  44. '<?php $foo = true; ?>',
  45. ];
  46. yield [
  47. '<?php $foo = true; ?>
  48. ',
  49. ];
  50. yield [
  51. '<?php
  52. $foo = true;
  53. ?>',
  54. ];
  55. yield [
  56. '<?php
  57. $foo = true;
  58. $bar = false;
  59. ?>',
  60. '<?php $foo = true;
  61. $bar = false;
  62. ?>',
  63. ];
  64. yield [
  65. '<?php $foo = true; ?>
  66. Html here
  67. <?php $bar = false; ?>',
  68. ];
  69. yield [
  70. '<?= $bar;
  71. $foo = $bar;
  72. ?>',
  73. ];
  74. yield [
  75. str_replace("\n", "\r\n", '<?php
  76. // linebreak already present in file with Windows line endings
  77. '),
  78. ];
  79. }
  80. /**
  81. * @dataProvider provideMessyWhitespacesCases
  82. */
  83. public function testMessyWhitespaces(string $expected, ?string $input = null): void
  84. {
  85. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
  86. $this->doTest($expected, $input);
  87. }
  88. public static function provideMessyWhitespacesCases(): iterable
  89. {
  90. yield [
  91. "<?php\r\n\$foo = true;\n",
  92. "<?php \$foo = true;\n",
  93. ];
  94. }
  95. }