UnaryOperatorSpacesFixerTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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\Operator;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Gregor Harlan <gharlan@web.de>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer>
  22. *
  23. * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer
  24. */
  25. final class UnaryOperatorSpacesFixerTest extends AbstractFixerTestCase
  26. {
  27. /**
  28. * @param _AutogeneratedInputConfiguration $configuration
  29. *
  30. * @dataProvider provideFixCases
  31. */
  32. public function testFix(string $expected, ?string $input = null, array $configuration = []): void
  33. {
  34. $this->fixer->configure($configuration);
  35. $this->doTest($expected, $input);
  36. }
  37. public static function provideFixCases(): iterable
  38. {
  39. yield [
  40. '<?php $a= 1;$a#
  41. ++#
  42. ;#',
  43. ];
  44. yield [
  45. '<?php $a++;',
  46. '<?php $a ++;',
  47. ];
  48. yield [
  49. '<?php $a--;',
  50. '<?php $a --;',
  51. ];
  52. yield [
  53. '<?php ++$a;',
  54. '<?php ++ $a;',
  55. ];
  56. yield [
  57. '<?php --$a;',
  58. '<?php -- $a;',
  59. ];
  60. yield [
  61. '<?php $a = !$b;',
  62. '<?php $a = ! $b;',
  63. ];
  64. yield [
  65. '<?php $a = !!$b;',
  66. '<?php $a = ! ! $b;',
  67. ];
  68. yield [
  69. '<?php $a = ~$b;',
  70. '<?php $a = ~ $b;',
  71. ];
  72. yield [
  73. '<?php $a = &$b;',
  74. '<?php $a = & $b;',
  75. ];
  76. yield [
  77. '<?php $a=&$b;',
  78. ];
  79. yield [
  80. '<?php $a * -$b;',
  81. '<?php $a * - $b;',
  82. ];
  83. yield [
  84. '<?php $a *-$b;',
  85. '<?php $a *- $b;',
  86. ];
  87. yield [
  88. '<?php $a*-$b;',
  89. ];
  90. yield [
  91. '<?php function &foo(){}',
  92. '<?php function & foo(){}',
  93. ];
  94. yield [
  95. '<?php function &foo(){}',
  96. '<?php function & foo(){}',
  97. ];
  98. yield [
  99. '<?php function foo(&$a, array &$b, Bar &$c) {}',
  100. '<?php function foo(& $a, array & $b, Bar & $c) {}',
  101. ];
  102. yield [
  103. '<?php function foo($a, ...$b) {}',
  104. '<?php function foo($a, ... $b) {}',
  105. ];
  106. yield [
  107. '<?php function foo(&...$a) {}',
  108. '<?php function foo(& ... $a) {}',
  109. ];
  110. yield [
  111. '<?php function foo(array ...$a) {}',
  112. ];
  113. yield [
  114. '<?php foo(...$a);',
  115. '<?php foo(... $a);',
  116. ];
  117. yield [
  118. '<?php foo($a, ...$b);',
  119. '<?php foo($a, ... $b);',
  120. ];
  121. yield [
  122. '<?php function foo($a, ...$b) { return (--$a) * ($b++);}',
  123. '<?php function foo($a, ... $b) { return (-- $a) * ($b ++);}',
  124. ['only_dec_inc' => false],
  125. ];
  126. yield [
  127. '<?php function foo($a, ... $b) { return (--$a) * ($b++);}',
  128. '<?php function foo($a, ... $b) { return (-- $a) * ($b ++);}',
  129. ['only_dec_inc' => true],
  130. ];
  131. yield [
  132. '<?php static fn(Token $t): bool => 8 === ($t->flags & 8);',
  133. ];
  134. }
  135. }