NoBinaryStringFixerTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 ntzm
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\StringNotation\NoBinaryStringFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\StringNotation\NoBinaryStringFixer>
  22. */
  23. final class NoBinaryStringFixerTest 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<array{0: string, 1?: string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [
  38. '<?php echo \'hello world\';',
  39. '<?php echo b\'hello world\';',
  40. ];
  41. yield [
  42. '<?php $a=\'hello world\';',
  43. '<?php $a=b\'hello world\';',
  44. ];
  45. yield [
  46. '<?php echo (\'hello world\');',
  47. '<?php echo (b\'hello world\');',
  48. ];
  49. yield [
  50. '<?php echo "hi".\'hello world\';',
  51. '<?php echo "hi".b\'hello world\';',
  52. ];
  53. yield [
  54. '<?php echo "hello world";',
  55. '<?php echo b"hello world";',
  56. ];
  57. yield [
  58. '<?php echo \'hello world\';',
  59. '<?php echo B\'hello world\';',
  60. ];
  61. yield [
  62. '<?php echo "hello world";',
  63. '<?php echo B"hello world";',
  64. ];
  65. yield [
  66. '<?php echo /* foo */"hello world";',
  67. '<?php echo /* foo */B"hello world";',
  68. ];
  69. yield [
  70. "<?php echo <<<EOT\nfoo\nEOT;\n",
  71. "<?php echo b<<<EOT\nfoo\nEOT;\n",
  72. ];
  73. yield [
  74. "<?php echo <<<EOT\nfoo\nEOT;\n",
  75. "<?php echo B<<<EOT\nfoo\nEOT;\n",
  76. ];
  77. yield [
  78. "<?php echo <<<'EOT'\nfoo\nEOT;\n",
  79. "<?php echo b<<<'EOT'\nfoo\nEOT;\n",
  80. ];
  81. yield [
  82. "<?php echo <<<'EOT'\nfoo\nEOT;\n",
  83. "<?php echo B<<<'EOT'\nfoo\nEOT;\n",
  84. ];
  85. yield [
  86. "<?php echo <<<\"EOT\"\nfoo\nEOT;\n",
  87. "<?php echo b<<<\"EOT\"\nfoo\nEOT;\n",
  88. ];
  89. yield [
  90. "<?php echo <<<\"EOT\"\nfoo\nEOT;\n",
  91. "<?php echo B<<<\"EOT\"\nfoo\nEOT;\n",
  92. ];
  93. yield [
  94. '<?php
  95. echo "{$fruit}";
  96. echo " {$fruit}";
  97. ',
  98. '<?php
  99. echo b"{$fruit}";
  100. echo b" {$fruit}";
  101. ',
  102. ];
  103. yield ['<?php echo Bar::foo();'];
  104. yield ['<?php echo bar::foo();'];
  105. yield ['<?php echo "b";'];
  106. yield ['<?php echo b;'];
  107. yield ['<?php echo b."a";'];
  108. yield ['<?php echo b("a");'];
  109. }
  110. }