NoShortBoolCastFixerTest.php 1.7 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. return [
  31. [
  32. '<?php
  33. $c = // lala
  34. // cc
  35. (bool)$content;',
  36. '<?php
  37. $c = ! // lala
  38. // cc
  39. !$content;',
  40. ],
  41. [
  42. '<?php
  43. $a = \'0\';
  44. $b = /*
  45. */(bool)$a;',
  46. '<?php
  47. $a = \'0\';
  48. $b = !/*
  49. */!$a;',
  50. ],
  51. [
  52. '<?php
  53. function foo($a, $b) {
  54. $c = (bool)$a;
  55. $d = !$a;
  56. $d1 = ! $a;
  57. $d2 = !$a;
  58. $b = !(!$foo);
  59. echo \'!!\'; // !! ! !
  60. $c = (bool) $b;
  61. $e = (bool) $d1;
  62. return (bool) $a;
  63. }
  64. ',
  65. '<?php
  66. function foo($a, $b) {
  67. $c = !!$a;
  68. $d = !$a;
  69. $d1 = ! $a;
  70. $d2 = !$a;
  71. $b = !(!$foo);
  72. echo \'!!\'; // !! ! !
  73. $c = ! ! $b;
  74. $e = !
  75. ! $d1;
  76. return !! $a;
  77. }
  78. ',
  79. ],
  80. ];
  81. }
  82. }