LogicalOperatorsFixerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 Haralan Dobrev <hkdobrev@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Operator\LogicalOperatorsFixer
  20. */
  21. final class LogicalOperatorsFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, string $input): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. public static function provideFixCases(): iterable
  31. {
  32. yield [
  33. '<?php if ($a == "foo" && $b == "bar") {}',
  34. '<?php if ($a == "foo" and $b == "bar") {}',
  35. ];
  36. yield [
  37. '<?php if ($a == "foo" || $b == "bar") {}',
  38. '<?php if ($a == "foo" or $b == "bar") {}',
  39. ];
  40. yield [
  41. '<?php if ($a == "foo" && ($b == "bar" || $c == "baz")) {}',
  42. '<?php if ($a == "foo" and ($b == "bar" or $c == "baz")) {}',
  43. ];
  44. yield [
  45. '<?php if ($a == "foo" && ($b == "bar" || $c == "baz")) {}',
  46. '<?php if ($a == "foo" and ($b == "bar" || $c == "baz")) {}',
  47. ];
  48. yield [
  49. '<?php if ($a == "foo" && ($b == "bar" || $c == "baz")) {}',
  50. '<?php if ($a == "foo" && ($b == "bar" or $c == "baz")) {}',
  51. ];
  52. yield [
  53. '<?php if ($a == "foo" && ($b == "bar" || $c == "baz")) {}',
  54. '<?php if ($a == "foo" AND ($b == "bar" OR $c == "baz")) {}',
  55. ];
  56. yield [
  57. '<?php if ($a == "foo" && ($b == "bar" || $c == "baz")) {}',
  58. '<?php if ($a == "foo" and ($b == "bar" OR $c == "baz")) {}',
  59. ];
  60. yield [
  61. '<?php if ($a == "foo" && ($b == "bar" || $c == "baz")) {}',
  62. '<?php if ($a == "foo" AND ($b == "bar" or $c == "baz")) {}',
  63. ];
  64. }
  65. }