* 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\ConstructorPromotionTransformer * * @phpstan-import-type _TransformerTestExpectedTokens from AbstractTransformerTestCase */ final class ConstructorPromotionTransformerTest extends AbstractTransformerTestCase { /** * @param _TransformerTestExpectedTokens $expectedTokens * * @dataProvider provideProcessCases * * @requires PHP 8.0 */ public function testProcess(array $expectedTokens, string $source): void { $this->doTest( $source, $expectedTokens, [ CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, ] ); } public static function provideProcessCases(): iterable { yield [ [ 14 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, 25 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, 36 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, ], ' CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, 22 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, 28 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, ], 'isGivenKind([ CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, ])); } } /** * @param _TransformerTestExpectedTokens $expectedTokens * * @dataProvider provideFix81Cases * * @requires PHP 8.1 */ public function testFix81(array $expectedTokens, string $source): void { $this->doTest( $source, $expectedTokens, [ CT::T_TYPE_ALTERNATION, ] ); } public static function provideFix81Cases(): iterable { yield 'readonly' => [ [ 14 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, 23 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, 36 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, 52 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, ], '