* 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\Transformer; use PhpCsFixer\Tests\Test\AbstractTransformerTestCase; use PhpCsFixer\Tokenizer\CT; /** * @author Dariusz Rumiński * * @internal * * @covers \PhpCsFixer\Tokenizer\Transformer\UseTransformer * * @phpstan-import-type _TransformerTestExpectedTokens from AbstractTransformerTestCase * @phpstan-import-type _TransformerTestObservedKindsOrPrototypes from AbstractTransformerTestCase */ final class UseTransformerTest extends AbstractTransformerTestCase { /** * @param _TransformerTestExpectedTokens $expectedTokens * * @dataProvider provideProcessCases */ public function testProcess(string $source, array $expectedTokens = []): void { $this->doTest( $source, $expectedTokens, [ T_USE, CT::T_USE_LAMBDA, CT::T_USE_TRAIT, ] ); } /** * @return iterable */ public static function provideProcessCases(): iterable { yield [ ' T_USE, ], ]; yield [ ' CT::T_USE_LAMBDA, ], ]; yield [ ' CT::T_USE_TRAIT, ], ]; yield [ ' T_USE, 17 => CT::T_USE_TRAIT, 42 => CT::T_USE_LAMBDA, ], ]; yield [ ' T_USE, ], ]; yield [ ' T_USE, ], ]; yield 'nested anonymous classes' => [ 'test(); $a(); } }; ', [ 38 => CT::T_USE_LAMBDA, 76 => CT::T_USE_TRAIT, ], ]; yield [ ' T_USE, 11 => T_USE, 18 => T_USE, ], ]; } /** * @param _TransformerTestExpectedTokens $expectedTokens * * @requires PHP 8.1 * * @dataProvider provideProcessPhp81Cases */ public function testProcessPhp81(string $source, array $expectedTokens = []): void { $this->doTest($source, $expectedTokens, [CT::T_USE_TRAIT]); } /** * @return iterable */ public static function provideProcessPhp81Cases(): iterable { yield [ ' CT::T_USE_TRAIT, ], ]; } }