CombineConsecutiveUnsetsFixerTest.php 3.9 KB

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