NoShortBoolCastFixerTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Fixer\CastNotation;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @internal
  15. *
  16. * @covers \PhpCsFixer\Fixer\CastNotation\NoShortBoolCastFixer
  17. */
  18. final class NoShortBoolCastFixerTest extends AbstractFixerTestCase
  19. {
  20. /**
  21. * @param string $expected
  22. * @param null|string $input
  23. *
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix($expected, $input = null)
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. public function provideFixCases()
  31. {
  32. return [
  33. [
  34. '<?php
  35. $c = // lala
  36. // cc
  37. (bool)$content;',
  38. '<?php
  39. $c = ! // lala
  40. // cc
  41. !$content;',
  42. ],
  43. [
  44. '<?php
  45. $a = \'0\';
  46. $b = /*
  47. */(bool)$a;',
  48. '<?php
  49. $a = \'0\';
  50. $b = !/*
  51. */!$a;',
  52. ],
  53. [
  54. '<?php
  55. function foo($a, $b) {
  56. $c = (bool)$a;
  57. $d = !$a;
  58. $d1 = ! $a;
  59. $d2 = !$a;
  60. $b = !(!$foo);
  61. echo \'!!\'; // !! ! !
  62. $c = (bool) $b;
  63. $e = (bool) $d1;
  64. return (bool) $a;
  65. }
  66. ',
  67. '<?php
  68. function foo($a, $b) {
  69. $c = !!$a;
  70. $d = !$a;
  71. $d1 = ! $a;
  72. $d2 = !$a;
  73. $b = !(!$foo);
  74. echo \'!!\'; // !! ! !
  75. $c = ! ! $b;
  76. $e = !
  77. ! $d1;
  78. return !! $a;
  79. }
  80. ',
  81. ],
  82. ];
  83. }
  84. }