/* Decoded by unphp.net */ * 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\Tokenizer\Processor; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\Tokenizer\Processor\ImportProcessor; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\WhitespacesFixerConfig; /** * @internal * * @covers \PhpCsFixer\Tokenizer\Processor\ImportProcessor */ final class ImportProcessorTest extends TestCase { /** * @param class-string $symbol * * @dataProvider provideTokenizeNameCases */ public function testTokenizeName(string $symbol): void { self::assertSame( $symbol, implode( '', array_map( static fn (Token $token): string => $token->getContent(), ImportProcessor::tokenizeName($symbol) ) ) ); } /** * @return iterable */ public static function provideTokenizeNameCases(): iterable { yield [__CLASS__]; yield ['Foo\Bar']; yield ['\Foo\Bar']; yield ['FooBar']; yield ['\FooBar']; yield ['\Foo\Bar\Baz\Buzz']; yield ['\Foo1\Bar_azuzz']; } /** * @param array{ * const?: array, * class?: array, * function?: array * } $imports * * @dataProvider provideInsertImportsCases */ public function testInsertImports(string $expected, string $input, array $imports, int $atIndex): void { $processor = new ImportProcessor(new WhitespacesFixerConfig()); $tokens = Tokens::fromCode($input); $processor->insertImports($tokens, $imports, $atIndex); self::assertSame($expected, $tokens->generateCode()); } /** * @return iterable, const?: list, function?: list}, 3: int}> */ public static function provideInsertImportsCases(): iterable { yield 'class import in single namespace' => [ ' ['Other\A', 'Other\B'], ], 6, ]; yield 'class import in single {} namespace' => [ ' ['Other\A', 'Other\B'], ], 7, ]; } } ?>