* 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; use PhpCsFixer\Tokenizer\Tokens; /** * @internal * * @covers \PhpCsFixer\Tokenizer\Transformer\NamedArgumentTransformer * * @phpstan-import-type _TransformerTestExpectedTokens from AbstractTransformerTestCase */ final class NamedArgumentTransformerTest extends AbstractTransformerTestCase { /** * @param _TransformerTestExpectedTokens $expectedTokens * * @dataProvider provideProcessCases * * @requires PHP 8.0 */ public function testProcess(string $source, array $expectedTokens): void { $this->doTest($source, $expectedTokens); } public static function provideProcessCases(): iterable { yield 'function call' => [ ' CT::T_NAMED_ARGUMENT_NAME, 4 => CT::T_NAMED_ARGUMENT_COLON, ], ]; yield 'dynamic function 2x' => [ ' CT::T_NAMED_ARGUMENT_NAME, 4 => CT::T_NAMED_ARGUMENT_COLON, 9 => CT::T_NAMED_ARGUMENT_NAME, 10 => CT::T_NAMED_ARGUMENT_COLON, ], ]; yield 'method' => [ 'a(foo: 1); ', [ 36 => CT::T_NAMED_ARGUMENT_NAME, 37 => CT::T_NAMED_ARGUMENT_COLON, ], ]; yield 'nested' => [ ' CT::T_NAMED_ARGUMENT_NAME, 5 => CT::T_NAMED_ARGUMENT_COLON, 17 => CT::T_NAMED_ARGUMENT_NAME, 18 => CT::T_NAMED_ARGUMENT_COLON, ], ]; } /** * @dataProvider provideDoNotChangeCases */ public function testDoNotChange(string $source): void { self::assertNotChange($source); } /** * @return iterable */ public static function provideDoNotChangeCases(): iterable { yield 'switch/case/constants' => [ ' [ ' ['isGivenKind([ CT::T_NAMED_ARGUMENT_NAME, CT::T_NAMED_ARGUMENT_COLON, ])); } } }