NoShortBoolCastFixerTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\CastNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\CastNotation\NoShortBoolCastFixer
  18. */
  19. final class NoShortBoolCastFixerTest 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 [
  31. '<?php
  32. $c = // lala
  33. // cc
  34. (bool)$content;',
  35. '<?php
  36. $c = ! // lala
  37. // cc
  38. !$content;',
  39. ];
  40. yield [
  41. '<?php
  42. $a = \'0\';
  43. $b = /*
  44. */(bool)$a;',
  45. '<?php
  46. $a = \'0\';
  47. $b = !/*
  48. */!$a;',
  49. ];
  50. yield [
  51. '<?php
  52. function foo($a, $b) {
  53. $c = (bool)$a;
  54. $d = !$a;
  55. $d1 = ! $a;
  56. $d2 = !$a;
  57. $b = !(!$foo);
  58. echo \'!!\'; // !! ! !
  59. $c = (bool) $b;
  60. $e = (bool) $d1;
  61. return (bool) $a;
  62. }
  63. ',
  64. '<?php
  65. function foo($a, $b) {
  66. $c = !!$a;
  67. $d = !$a;
  68. $d1 = ! $a;
  69. $d2 = !$a;
  70. $b = !(!$foo);
  71. echo \'!!\'; // !! ! !
  72. $c = ! ! $b;
  73. $e = !
  74. ! $d1;
  75. return !! $a;
  76. }
  77. ',
  78. ];
  79. }
  80. }