* Dariusz RumiƄski * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Tests\Fixer\Import; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @internal * * @covers \PhpCsFixer\Fixer\Import\NoUnusedImportsFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Import\NoUnusedImportsFixer> */ final class NoUnusedImportsFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixCases(): iterable { yield 'simple' => [ <<<'EOF' toArray(); /** @var ArrayInterface $bar */ } } EOF, <<<'EOF' toArray(); /** @var ArrayInterface $bar */ } } EOF, ]; yield 'with_indents' => [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' repo = $repo; } } EOF, <<<'EOF' repo = $repo; } } EOF, ]; yield 'variable_name' => [ <<<'EOF' [ <<<'EOF' bar = null; $foo->bar(); $foo::bar(); $foo::bar; EOF, <<<'EOF' bar = null; $foo->bar(); $foo::bar(); $foo::bar; EOF, ]; yield 'constant_name' => [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ 'inline content', 'inline content', ]; yield 'close_tag_2' => [ '', '', ]; yield 'close_tag_3' => [ '', '', ]; yield 'case_mismatch_typo' => [ ' [ ' [ ' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ ' [ ' [ ' [' [' ['ABC::Test; ', ]; yield 'imported_class_name_is_prefix_with_dash_of_constant' => [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ $expected = <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ ' [ ' [ " [ " [ " [ " [ " [ "doTest( 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield [ 'bar; $y = foo?->bar(); ', 'bar; $y = foo?->bar(); ', ]; yield 'with union type in non-capturing catch' => [ ' [ ' [ " '%regex.uuid%'], methods: ['POST']), IsGranted('ROLE_USER'), JsonSchema('Public/Basket/addItem.json'), ] class Foo {} ", ]; yield 'attribute 2' => [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield 'final const' => [ ' [ ' [ '