NotOperatorWithSuccessorSpaceFixerTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 Javier Spagnoletti <phansys@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer>
  22. */
  23. final class NotOperatorWithSuccessorSpaceFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return iterable<int|string, array{string, string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [
  38. '<?php $i = 0; $i++; $foo = ! false || (! true || ! ! false && (2 === (7 -5)));',
  39. '<?php $i = 0; $i++; $foo = !false || (!true || !!false && (2 === (7 -5)));',
  40. ];
  41. yield [
  42. '<?php $i = 0; $i--; $foo = ! false || ($i && ! true);',
  43. '<?php $i = 0; $i--; $foo = !false || ($i && !true);',
  44. ];
  45. yield [
  46. '<?php $i = 0; $i--; $foo = ! false || ($i && ! /* some comment */true);',
  47. '<?php $i = 0; $i--; $foo = !false || ($i && !/* some comment */true);',
  48. ];
  49. yield [
  50. '<?php $i = 0; $i--; $foo = ! false || ($i && ! true);',
  51. '<?php $i = 0; $i--; $foo = !false || ($i && ! true);',
  52. ];
  53. yield [
  54. '<?php $i = 0; $i--; $foo = ! false || ($i && ! /* some comment */ true);',
  55. '<?php $i = 0; $i--; $foo = !false || ($i && ! /* some comment */ true);',
  56. ];
  57. yield 'comment case' => [
  58. '<?php
  59. $a=#
  60. ! #
  61. $b;
  62. ',
  63. '<?php
  64. $a=#
  65. !
  66. #
  67. $b;
  68. ',
  69. ];
  70. }
  71. }