* 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; /** * @author Graham Campbell * @author Dariusz Rumiński * * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocNoAliasTagFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocNoAliasTagFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\PhpdocNoAliasTagFixer */ final class PhpdocNoAliasTagFixerTest extends AbstractFixerTestCase { /** * @param _AutogeneratedInputConfiguration $config * * @dataProvider provideInvalidConfigurationCases */ public function testInvalidConfiguration(array $config, string $expectedMessage): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches($expectedMessage); $this->fixer->configure($config); } /** * @return iterable, string}> */ public static function provideInvalidConfigurationCases(): iterable { yield [ ['replacements' => [1 => 'abc']], '#^\[phpdoc_no_alias_tag\] Invalid configuration: Tag to replace must be a string\.$#', ]; yield [ ['replacements' => ['a' => null]], '#^\[phpdoc_no_alias_tag\] Invalid configuration: The option "replacements" with value array is expected to be of type "string\[\]", but one of the elements is of type "null"\.$#', ]; yield [ ['replacements' => ['see' => 'link*/']], '#^\[phpdoc_no_alias_tag\] Invalid configuration: Tag "see" cannot be replaced by invalid tag "link\*\/"\.$#', ]; yield [ ['foo' => 123], '#^\[phpdoc_no_alias_tag\] Invalid configuration: The option "foo" does not exist. Defined options are: "replacements"\.$#', ]; yield [ ['replacements' => [ 'link' => 'see', 'a' => 'b', 'see' => 'link', ]], '#^\[phpdoc_no_alias_tag\] Invalid configuration: Cannot change tag "link" to tag "see", as the tag "see" is configured to be replaced to "link"\.$#', ]; yield [ ['replacements' => [ 'b' => 'see', 'see' => 'link', 'link' => 'b', ]], '#^\[phpdoc_no_alias_tag\] Invalid configuration: Cannot change tag "b" to tag "see", as the tag "see" is configured to be replaced to "link"\.$#', ]; yield [ ['replacements' => [ 'see' => 'link', 'link' => 'b', ]], '#^\[phpdoc_no_alias_tag\] Invalid configuration: Cannot change tag "see" to tag "link", as the tag "link" is configured to be replaced to "b"\.$#', ]; } /** * @param _AutogeneratedInputConfiguration $configuration * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $configuration = []): void { $this->fixer->configure($configuration); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixCases(): iterable { yield [ ' [ 'property-read' => 'property', 'property-write' => 'property', ]], ]; yield [ ' [ 'property-read' => 'property', 'property-write' => 'property', ]], ]; yield [ ' [ 'property-read' => 'property', 'property-write' => 'property', ]], ]; yield [ ' [ 'type' => 'var', ]], ]; yield [ ' [ 'type' => 'var', ]], ]; yield [ ' [ 'type' => 'var', ]], ]; yield [ ' [ 'type' => 'var', ]], ]; yield [ ' [ 'var' => 'type', ]], ]; yield [ ' [ 'var' => 'type', ]], ]; yield [ ' [ 'var' => 'type', ]], ]; yield [ ' [ 'var' => 'type', ]], ]; yield [ ' [ 'link' => 'see', ]], ]; } }