NoMultipleStatementsPerLineFixerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. }