NoUnsetCastFixerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\CastNotation\NoUnsetCastFixer>
  22. */
  23. final class NoUnsetCastFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return iterable<int|string, array{0: string, 1?: string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield 'simple form I' => [
  38. "<?php\n\$a = null;",
  39. "<?php\n\$a =(unset)\$z;",
  40. ];
  41. yield 'simple form II' => [
  42. "<?php\n\$b = null;",
  43. "<?php\n\$b = (unset)\$z;",
  44. ];
  45. yield 'simple form III' => [
  46. "<?php\n\$c = null?>",
  47. "<?php\n\$c = (unset)\$z?>",
  48. ];
  49. yield 'lot of spaces' => [
  50. "<?php\n\$d = \t \t \t null;",
  51. "<?php\n\$d = \t (unset)\$z\t \t ;",
  52. ];
  53. yield 'comments' => [
  54. '<?php
  55. #0
  56. $a#1
  57. #2
  58. = null#3
  59. #4
  60. #5
  61. #6
  62. #7
  63. #8
  64. ;
  65. ',
  66. '<?php
  67. #0
  68. $a#1
  69. #2
  70. =#3
  71. #4
  72. (unset)#5
  73. #6
  74. $b#7
  75. #8
  76. ;
  77. ',
  78. ];
  79. yield [
  80. "<?php\n(unset) \$b;",
  81. ];
  82. yield [
  83. '<?php $r = (unset) f(1);',
  84. ];
  85. yield [
  86. '<?php $r = (unset) (new C())->mf(3);',
  87. ];
  88. yield [
  89. '<?php $r = (unset) $f(1);',
  90. ];
  91. yield [
  92. '<?php $r = (unset) $c::sf(2) ?>',
  93. ];
  94. yield [
  95. '<?php $r = (unset) $a[0];',
  96. ];
  97. yield [
  98. '<?php $r = (unset) $n**f($n);',
  99. ];
  100. }
  101. }