NoUnsetCastFixerTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\NoUnsetCastFixer
  18. *
  19. * @requires PHP <8.0
  20. */
  21. final class NoUnsetCastFixerTest 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. public static function provideFixCases(): iterable
  31. {
  32. yield 'simple form I' => [
  33. "<?php\n\$a = null;",
  34. "<?php\n\$a =(unset)\$z;",
  35. ];
  36. yield 'simple form II' => [
  37. "<?php\n\$b = null;",
  38. "<?php\n\$b = (unset)\$z;",
  39. ];
  40. yield 'simple form III' => [
  41. "<?php\n\$c = null?>",
  42. "<?php\n\$c = (unset)\$z?>",
  43. ];
  44. yield 'lot of spaces' => [
  45. "<?php\n\$d = \t \t \t null;",
  46. "<?php\n\$d = \t (unset)\$z\t \t ;",
  47. ];
  48. yield 'comments' => [
  49. '<?php
  50. #0
  51. $a#1
  52. #2
  53. = null#3
  54. #4
  55. #5
  56. #6
  57. #7
  58. #8
  59. ;
  60. ',
  61. '<?php
  62. #0
  63. $a#1
  64. #2
  65. =#3
  66. #4
  67. (unset)#5
  68. #6
  69. $b#7
  70. #8
  71. ;
  72. ',
  73. ];
  74. yield [
  75. "<?php\n(unset) \$b;",
  76. ];
  77. yield [
  78. '<?php $r = (unset) f(1);',
  79. ];
  80. yield [
  81. '<?php $r = (unset) (new C())->mf(3);',
  82. ];
  83. yield [
  84. '<?php $r = (unset) $f(1);',
  85. ];
  86. yield [
  87. '<?php $r = (unset) $c::sf(2) ?>',
  88. ];
  89. yield [
  90. '<?php $r = (unset) $a[0];',
  91. ];
  92. yield [
  93. '<?php $r = (unset) $n**f($n);',
  94. ];
  95. }
  96. }