* 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\Phpdoc; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer */ final class PhpdocReturnSelfReferenceFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixWithDefaultConfigurationCases */ public function testFixWithDefaultConfiguration(string $expected, ?string $input = null): void { $this->fixer->configure([]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixWithDefaultConfigurationCases(): iterable { yield [ 'someTest();', 'someTest();', ]; } /** * @param _AutogeneratedInputConfiguration['replacements'] $configurationReplacements * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $configurationReplacements = []): void { $this->fixer->configure(['replacements' => $configurationReplacements]); $this->doTest($expected, $input); } public static function provideFixCases(): iterable { yield [ ' 'static'], ]; } /** * @dataProvider provideGeneratedFixCases */ public function testGeneratedFix(string $expected, string $input): void { $config = ['replacements' => [$input => $expected]]; $this->fixer->configure($config); $expected = \sprintf('doTest($expected, $input); } /** * @return iterable */ public static function provideGeneratedFixCases(): iterable { yield ['$this', 'this']; yield ['$this', '@this']; yield ['self', '$self']; yield ['self', '@self']; yield ['static', '$static']; yield ['static', '@STATIC']; } /** * @param _AutogeneratedInputConfiguration $configuration * * @dataProvider provideInvalidConfigurationCases */ public function testInvalidConfiguration(array $configuration, string $message): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches(\sprintf('/^\[phpdoc_return_self_reference\] %s$/', preg_quote($message, '/'))); $this->fixer->configure($configuration); } public static function provideInvalidConfigurationCases(): iterable { yield [ ['replacements' => [1 => 'a']], 'Invalid configuration: Unknown key "integer#1", expected any of "this", "@this", "$self", "@self", "$static" and "@static".', ]; yield [ ['replacements' => [ 'this' => 'foo', ]], 'Invalid configuration: Unknown value "string#foo", expected any of "$this", "static" and "self".', ]; } public function testAnonymousClassFixing(): void { $this->doTest( 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield [ 'test()); ', 'test()); ', ]; } }