NoTrailingWhitespaceInStringFixerTest.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\StringNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Gregor Harlan
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\StringNotation\NoTrailingWhitespaceInStringFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\StringNotation\NoTrailingWhitespaceInStringFixer>
  22. */
  23. final class NoTrailingWhitespaceInStringFixerTest 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. /**
  33. * @return iterable<int|string, array{string, string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [
  38. "<?php \$a = ' foo\r bar\r\n\nbaz\n ';",
  39. "<?php \$a = ' foo \r bar \r\n \nbaz \n ';",
  40. ];
  41. yield [
  42. "<?php \$a = \" foo\r bar\r\n\nbaz\n \";",
  43. "<?php \$a = \" foo \r bar \r\n \nbaz \n \";",
  44. ];
  45. yield [
  46. "<?php \$a = \" \$foo\n\";",
  47. "<?php \$a = \" \$foo \n\";",
  48. ];
  49. yield [
  50. " foo\r bar\r\nbaz\n",
  51. " foo \r bar \r\nbaz \n ",
  52. ];
  53. yield [
  54. "\n<?php foo() ?>\n foo",
  55. " \n<?php foo() ?> \n foo",
  56. ];
  57. yield [
  58. "<?php foo() ?>\n<?php foo() ?>\n",
  59. "<?php foo() ?> \n<?php foo() ?> \n",
  60. ];
  61. yield [
  62. "<?php foo() ?>\n\nfoo",
  63. "<?php foo() ?>\n \nfoo",
  64. ];
  65. yield [
  66. "<?php foo() ?>foo\n",
  67. "<?php foo() ?>foo \n",
  68. ];
  69. yield [
  70. '',
  71. ' ',
  72. ];
  73. yield [
  74. '<?php echo 1; ?>',
  75. '<?php echo 1; ?> ',
  76. ];
  77. yield [
  78. '
  79. <?php
  80. $a = <<<EOD
  81. foo
  82. bar
  83. $a
  84. $b
  85. baz
  86. EOD;
  87. ',
  88. '
  89. <?php
  90. $a = <<<EOD
  91. foo '.'
  92. bar
  93. $a '.'
  94. $b
  95. '.'
  96. baz '.'
  97. EOD;
  98. ',
  99. ];
  100. yield [
  101. '
  102. <?php
  103. $a = <<<\'EOD\'
  104. foo
  105. bar
  106. baz
  107. EOD;
  108. ',
  109. '
  110. <?php
  111. $a = <<<\'EOD\'
  112. foo '.'
  113. bar
  114. '.'
  115. baz '.'
  116. EOD;
  117. ',
  118. ];
  119. yield [
  120. '
  121. <?php
  122. $a = <<<\'EOD\'
  123. foo
  124. bar
  125. baz
  126. EOD;
  127. ',
  128. '
  129. <?php
  130. $a = <<<\'EOD\'
  131. foo '.'
  132. bar
  133. '.'
  134. baz '.'
  135. EOD;
  136. ',
  137. ];
  138. yield 'binary string' => [
  139. "<?php \$a = b\" \$foo\n\";",
  140. "<?php \$a = b\" \$foo \n\";",
  141. ];
  142. }
  143. }