CombineConsecutiveUnsetsFixerTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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\LanguageConstruct;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer
  18. */
  19. final class CombineConsecutiveUnsetsFixerTest extends AbstractFixerTestCase
  20. {
  21. /**
  22. * @dataProvider provideFixCases
  23. */
  24. public function testFix(string $expected, ?string $input = null): void
  25. {
  26. $this->doTest($expected, $input);
  27. }
  28. public function provideFixCases(): \Generator
  29. {
  30. yield from [
  31. [
  32. '<?php //1
  33. unset($foo/*;*/, /*;*/$bar, $c , $foobar , $foobar2);
  34. //test
  35. /* more comment test*/
  36. '.'
  37. ',
  38. '<?php //1
  39. unset($foo/*;*/);
  40. unset(/*;*/$bar, $c ); //test
  41. unset($foobar ); /* more comment test*/
  42. unset( $foobar2);
  43. ',
  44. ],
  45. [
  46. '<?php unset($d , $e);/*unset( $d2);unset($e );;*/ ',
  47. '<?php unset($d );/*unset( $d2);unset($e );;*/ uNseT($e);',
  48. ],
  49. [
  50. '<?php UNSET($a, $b,$c/**/); ',
  51. '<?php UNSET($a); unset($b,$c/**/);',
  52. ],
  53. [
  54. '<?php
  55. $config = array();
  56. if ($config) {
  57. }
  58. unset($config[\'autoescape_service\'], $config[\'autoescape_service_method\']);
  59. ',
  60. ],
  61. [
  62. '<?php //2
  63. unset($foo, $bar, $foobar, $foobar2, $foobar3);/*1*/
  64. /*2*/
  65. //3
  66. /*4*/
  67. /*5*/ '.'
  68. ',
  69. '<?php //2
  70. unset($foo);/*1*/
  71. unset($bar);/*2*/
  72. unset($foobar);//3
  73. unset($foobar2);/*4*/
  74. /*5*/ unset($foobar3);
  75. ',
  76. ],
  77. [
  78. '<?php
  79. unset($foo3, $bar, $test,$test1);
  80. /* c1 */
  81. '.'
  82. '.'
  83. // c2
  84. '.'
  85. ',
  86. '<?php
  87. unset($foo3);
  88. /* c1 */
  89. unset($bar);
  90. '.'
  91. // c2
  92. unset($test,$test1);
  93. ',
  94. ],
  95. [
  96. '<?php unset($x, $b , $d); /**/ ?> b',
  97. '<?php unset($x); /**/ unset ($b , $d) ?> b',
  98. ],
  99. [
  100. '<?php unset($x) ?>',
  101. ],
  102. [
  103. '<?php unset($y, $u); ?>',
  104. '<?php unset($y);unset($u) ?>',
  105. ],
  106. [
  107. '<?php
  108. unset($a[0], $a[\'a\'], $a["b"], $a->b, $a->b->c, $a->b[0]->c[\'a\']);
  109. '.'
  110. '.'
  111. '.'
  112. '.'
  113. '.'
  114. ',
  115. '<?php
  116. unset($a[0]);
  117. unset($a[\'a\']);
  118. unset($a["b"]);
  119. unset($a->b);
  120. unset($a->b->c);
  121. unset($a->b[0]->c[\'a\']);
  122. ',
  123. ],
  124. ];
  125. }
  126. /**
  127. * @dataProvider provideFixPre80Cases
  128. * @requires PHP <8.0
  129. */
  130. public function testFixPre80(string $expected, string $input = null): void
  131. {
  132. $this->doTest($expected, $input);
  133. }
  134. public function provideFixPre80Cases(): \Generator
  135. {
  136. yield [
  137. '<?php (unset)$f;',
  138. ];
  139. }
  140. }