123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Fixer\LanguageConstruct;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer>
- */
- final class CombineConsecutiveUnsetsFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{0: string, 1?: string}>
- */
- public static function provideFixCases(): iterable
- {
- yield [
- '<?php //1
- unset($foo/*;*/, /*;*/$bar, $c , $foobar , $foobar2);
- //test
- /* more comment test*/
- '.'
- ',
- '<?php //1
- unset($foo/*;*/);
- unset(/*;*/$bar, $c ); //test
- unset($foobar ); /* more comment test*/
- unset( $foobar2);
- ',
- ];
- yield [
- '<?php unset($d , $e);/*unset( $d2);unset($e );;*/ ',
- '<?php unset($d );/*unset( $d2);unset($e );;*/ uNseT($e);',
- ];
- yield [
- '<?php UNSET($a, $b,$c/**/); ',
- '<?php UNSET($a); unset($b,$c/**/);',
- ];
- yield [
- '<?php
- $config = array();
- if ($config) {
- }
- unset($config[\'autoescape_service\'], $config[\'autoescape_service_method\']);
- ',
- ];
- yield [
- '<?php //2
- unset($foo, $bar, $foobar, $foobar2, $foobar3);/*1*/
- /*2*/
- //3
- /*4*/
- /*5*/ '.'
- ',
- '<?php //2
- unset($foo);/*1*/
- unset($bar);/*2*/
- unset($foobar);//3
- unset($foobar2);/*4*/
- /*5*/ unset($foobar3);
- ',
- ];
- yield [
- '<?php
- unset($foo3, $bar, $test,$test1);
- /* c1 */
- '.'
- '.'
- // c2
- '.'
- ',
- '<?php
- unset($foo3);
- /* c1 */
- unset($bar);
- '.'
- // c2
- unset($test,$test1);
- ',
- ];
- yield [
- '<?php unset($x, $b , $d); /**/ ?> b',
- '<?php unset($x); /**/ unset ($b , $d) ?> b',
- ];
- yield [
- '<?php unset($x) ?>',
- ];
- yield [
- '<?php unset($y, $u); ?>',
- '<?php unset($y);unset($u) ?>',
- ];
- yield [
- '<?php
- unset($a[0], $a[\'a\'], $a["b"], $a->b, $a->b->c, $a->b[0]->c[\'a\']);
- '.'
- '.'
- '.'
- '.'
- '.'
- ',
- '<?php
- unset($a[0]);
- unset($a[\'a\']);
- unset($a["b"]);
- unset($a->b);
- unset($a->b->c);
- unset($a->b[0]->c[\'a\']);
- ',
- ];
- }
- /**
- * @dataProvider provideFixPre80Cases
- *
- * @requires PHP <8.0
- */
- public function testFixPre80(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{string}>
- */
- public static function provideFixPre80Cases(): iterable
- {
- yield [
- '<?php (unset)$f;',
- ];
- }
- }
|