NoShortBoolCastFixerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\CastNotation\NoShortBoolCastFixer>
  20. */
  21. final class NoShortBoolCastFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. /**
  31. * @return iterable<array{string, string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield [
  36. '<?php
  37. $c = // lala
  38. // cc
  39. (bool)$content;',
  40. '<?php
  41. $c = ! // lala
  42. // cc
  43. !$content;',
  44. ];
  45. yield [
  46. '<?php
  47. $a = \'0\';
  48. $b = /*
  49. */(bool)$a;',
  50. '<?php
  51. $a = \'0\';
  52. $b = !/*
  53. */!$a;',
  54. ];
  55. yield [
  56. '<?php
  57. function foo($a, $b) {
  58. $c = (bool)$a;
  59. $d = !$a;
  60. $d1 = ! $a;
  61. $d2 = !$a;
  62. $b = !(!$foo);
  63. echo \'!!\'; // !! ! !
  64. $c = (bool) $b;
  65. $e = (bool) $d1;
  66. return (bool) $a;
  67. }
  68. ',
  69. '<?php
  70. function foo($a, $b) {
  71. $c = !!$a;
  72. $d = !$a;
  73. $d1 = ! $a;
  74. $d2 = !$a;
  75. $b = !(!$foo);
  76. echo \'!!\'; // !! ! !
  77. $c = ! ! $b;
  78. $e = !
  79. ! $d1;
  80. return !! $a;
  81. }
  82. ',
  83. ];
  84. }
  85. }