NoMultipleStatementsPerLineFixerTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\Basic;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\Basic\NoMultipleStatementsPerLineFixer
  18. *
  19. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Basic\NoMultipleStatementsPerLineFixer>
  20. */
  21. final class NoMultipleStatementsPerLineFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. /**
  31. * @return iterable<string, array{0: string, 1?: string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield 'simple' => [
  36. '<?php
  37. foo();
  38. bar();',
  39. '<?php
  40. foo(); bar();',
  41. ];
  42. yield 'for loop' => [
  43. '<?php
  44. for ($i = 0; $i < 10; ++$i) {
  45. foo();
  46. }',
  47. ];
  48. yield 'mixed `;` and close tag' => [
  49. '<?php ++$a;
  50. ++$b ?>',
  51. '<?php ++$a; ++$b ?>',
  52. ];
  53. yield 'followed by closing brace' => [
  54. '<?php if ($foo) { foo(); }',
  55. ];
  56. yield 'followed by closing tag' => [
  57. '<?php foo(); ?>',
  58. ];
  59. yield 'if alternative syntax' => [
  60. '<?php if ($foo): foo(); endif;',
  61. ];
  62. yield 'for alternative syntax' => [
  63. '<?php for (;;): foo(); endfor;',
  64. ];
  65. yield 'foreach alternative syntax' => [
  66. '<?php foreach ($foo as $bar): foo(); endforeach;',
  67. ];
  68. yield 'while alternative syntax' => [
  69. '<?php while ($foo): foo(); endwhile;',
  70. ];
  71. yield 'switch alternative syntax' => [
  72. '<?php switch ($foo): case true: foo(); endswitch;',
  73. ];
  74. }
  75. /**
  76. * @dataProvider provideFix84Cases
  77. *
  78. * @requires PHP 8.4
  79. */
  80. public function testFix84(string $expected, ?string $input = null): void
  81. {
  82. $this->doTest($expected, $input);
  83. }
  84. /**
  85. * @return iterable<string, array{string, 1?: string}>
  86. */
  87. public static function provideFix84Cases(): iterable
  88. {
  89. yield "don't touch property hooks" => [
  90. '<?php interface I {
  91. public string $readable { get; }
  92. public string $writeable { set; }
  93. public string $both { get; set; }
  94. }',
  95. ];
  96. }
  97. }