NoUnsetCastFixerTest.php 2.0 KB

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