* 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 */ final class PhpdocReturnSelfReferenceFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixWithDefaultConfigurationCases */ public function testFixWithDefaultConfiguration(string $expected, ?string $input = null): void { $this->fixer->configure([]); $this->doTest($expected, $input); } public static function provideFixWithDefaultConfigurationCases(): iterable { return [ [ 'someTest();', 'someTest();', ], ]; } /** * @param array $configuration * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $configuration = []): void { $this->fixer->configure(['replacements' => $configuration]); $this->doTest($expected, $input); } public static function provideFixCases(): iterable { return [ [ ' 'static'], ], ]; } /** * @dataProvider provideGeneratedFixCases */ public function testGeneratedFix(string $expected, string $input): void { $config = ['replacements' => [$input => $expected]]; $this->fixer->configure($config); $expected = sprintf('doTest($expected, $input); } public static function provideGeneratedFixCases(): iterable { return [ ['$this', 'this'], ['$this', '@this'], ['self', '$self'], ['self', '@self'], ['static', '$static'], ['static', '@STATIC'], ]; } /** * @param array $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 { return [ [ ['replacements' => [1 => 'a']], 'Invalid configuration: Unknown key "integer#1", expected any of "this", "@this", "$self", "@self", "$static" and "@static".', ], [ ['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); } public static function provideFix81Cases(): iterable { yield [ 'test()); ', 'test()); ', ]; } }