SemicolonAfterInstructionFixerTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\Semicolon;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer
  18. */
  19. final class SemicolonAfterInstructionFixerTest extends AbstractFixerTestCase
  20. {
  21. /**
  22. * @dataProvider provideFixCases
  23. */
  24. public function testFix(string $expected, ?string $input = null): void
  25. {
  26. $this->doTest($expected, $input);
  27. }
  28. public static function provideFixCases(): iterable
  29. {
  30. yield 'comment' => [
  31. '<?php $a++;//a ?>',
  32. '<?php $a++//a ?>',
  33. ];
  34. yield 'comment II' => [
  35. '<?php $b++; /**/ ?>',
  36. '<?php $b++ /**/ ?>',
  37. ];
  38. yield 'no space' => [
  39. '<?php $b++;?>',
  40. '<?php $b++?>',
  41. ];
  42. yield [
  43. '<?php echo 123; ?>',
  44. '<?php echo 123 ?>',
  45. ];
  46. yield [
  47. "<?php echo 123;\n\t?>",
  48. "<?php echo 123\n\t?>",
  49. ];
  50. yield ['<?php ?>'];
  51. yield ['<?php ; ?>'];
  52. yield ['<?php if($a){}'];
  53. yield ['<?php while($a > $b){}'];
  54. yield [
  55. '<?php if ($a == 5): ?>
  56. A is equal to 5
  57. <?php endif; ?>
  58. <?php switch ($foo): ?>
  59. <?php case 1: ?>
  60. ...
  61. <?php endswitch; ?>',
  62. '<?php if ($a == 5): ?>
  63. A is equal to 5
  64. <?php endif; ?>
  65. <?php switch ($foo): ?>
  66. <?php case 1: ?>
  67. ...
  68. <?php endswitch ?>',
  69. ];
  70. yield [
  71. '<?php if ($a == 5) { ?>
  72. A is equal to 5
  73. <?php } ?>',
  74. ];
  75. }
  76. /**
  77. * @dataProvider provideFixPre80Cases
  78. *
  79. * @requires PHP <8.0
  80. */
  81. public function testFixPre80(string $expected, string $input = null): void
  82. {
  83. $this->doTest($expected, $input);
  84. }
  85. public static function provideFixPre80Cases(): iterable
  86. {
  87. yield [
  88. '<?php $a = [1,2,3]; echo $a{1}; ?>',
  89. '<?php $a = [1,2,3]; echo $a{1} ?>',
  90. ];
  91. }
  92. public function testOpenWithEcho(): void
  93. {
  94. if (!\ini_get('short_open_tag')) {
  95. self::markTestSkipped('The short_open_tag option is required to be enabled.');
  96. }
  97. $this->doTest(
  98. "<?= '1_'; ?> <?php ?><?= 1; ?>",
  99. "<?= '1_' ?> <?php ?><?= 1; ?>"
  100. );
  101. }
  102. }