NoMultipleStatementsPerLineFixerTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. final class NoMultipleStatementsPerLineFixerTest 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 'simple' => [
  31. '<?php
  32. foo();
  33. bar();',
  34. '<?php
  35. foo(); bar();',
  36. ];
  37. yield 'for loop' => [
  38. '<?php
  39. for ($i = 0; $i < 10; ++$i) {
  40. foo();
  41. }',
  42. ];
  43. yield 'mixed `;` and close tag' => [
  44. '<?php ++$a;
  45. ++$b ?>',
  46. '<?php ++$a; ++$b ?>',
  47. ];
  48. yield 'followed by closing brace' => [
  49. '<?php if ($foo) { foo(); }',
  50. ];
  51. yield 'followed by closing tag' => [
  52. '<?php foo(); ?>',
  53. ];
  54. yield 'if alternative syntax' => [
  55. '<?php if ($foo): foo(); endif;',
  56. ];
  57. yield 'for alternative syntax' => [
  58. '<?php for (;;): foo(); endfor;',
  59. ];
  60. yield 'foreach alternative syntax' => [
  61. '<?php foreach ($foo as $bar): foo(); endforeach;',
  62. ];
  63. yield 'while alternative syntax' => [
  64. '<?php while ($foo): foo(); endwhile;',
  65. ];
  66. yield 'switch alternative syntax' => [
  67. '<?php switch ($foo): case true: foo(); endswitch;',
  68. ];
  69. }
  70. }