NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * @author John Kelly <wablam@gmail.com>
  16. * @author Graham Campbell <hello@gjcampbell.co.uk>
  17. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer
  22. *
  23. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer>
  24. */
  25. final class NoSinglelineWhitespaceBeforeSemicolonsFixerTest extends AbstractFixerTestCase
  26. {
  27. /**
  28. * @dataProvider provideFixCases
  29. */
  30. public function testFix(string $expected, ?string $input = null): void
  31. {
  32. $this->doTest($expected, $input);
  33. }
  34. /**
  35. * @return iterable<array{0: string, 1?: string}>
  36. */
  37. public static function provideFixCases(): iterable
  38. {
  39. yield [
  40. '<?php for ($uu = 0; ; ++$uu) {}',
  41. '<?php for ($uu = 0 ; ; ++$uu) {}',
  42. ];
  43. yield [
  44. '<?php
  45. $this
  46. ->setName(\'readme1\')
  47. ->setDescription(\'Generates the README content, based on the fix command help\')
  48. ;',
  49. ];
  50. yield [
  51. '<?php
  52. $this
  53. ->setName(\'readme2\')
  54. ->setDescription(\'Generates the README content, based on the fix command help\')
  55. ;',
  56. ];
  57. yield [
  58. '<?php echo "$this->foo(\'with param containing ;\') ;";',
  59. '<?php echo "$this->foo(\'with param containing ;\') ;" ;',
  60. ];
  61. yield [
  62. '<?php $this->foo();',
  63. '<?php $this->foo() ;',
  64. ];
  65. yield [
  66. '<?php $this->foo(\'with param containing ;\');',
  67. '<?php $this->foo(\'with param containing ;\') ;',
  68. ];
  69. yield [
  70. '<?php $this->foo(\'with param containing ) ; \');',
  71. '<?php $this->foo(\'with param containing ) ; \') ;',
  72. ];
  73. yield [
  74. '<?php $this->foo("with param containing ) ; ");',
  75. '<?php $this->foo("with param containing ) ; ") ;',
  76. ];
  77. yield [
  78. '<?php
  79. $foo
  80. ->bar(1)
  81. ->baz(2)
  82. ;',
  83. ];
  84. yield [
  85. '<?php
  86. $foo
  87. ->bar(1)
  88. //->baz(2)
  89. ;',
  90. ];
  91. yield [
  92. '<?php $this->foo("with semicolon in string) ; ");',
  93. ];
  94. }
  95. }