* 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\InvalidConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; /** * @author Dariusz Rumiński * * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer */ final class PhpdocAddMissingParamAnnotationFixerTest extends AbstractFixerTestCase { public function testConfigureRejectsUnknownConfigurationKey(): void { $key = 'foo'; $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(\sprintf( '[phpdoc_add_missing_param_annotation] Invalid configuration: The option "%s" does not exist.', $key )); $this->fixer->configure([ $key => 'bar', ]); } /** * @dataProvider provideConfigureRejectsInvalidConfigurationValueCases * * @param mixed $value */ public function testConfigureRejectsInvalidConfigurationValue($value, string $expectedMessage): void { $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessageMatches($expectedMessage); $this->fixer->configure([ 'only_untyped' => $value, ]); } /** * @return iterable */ public static function provideConfigureRejectsInvalidConfigurationValueCases(): iterable { yield 'null' => [ null, '#expected to be of type "bool", but is of type "(null|NULL)"\.$#', ]; yield 'int' => [ 1, '#expected to be of type "bool", but is of type "(int|integer)"\.$#', ]; yield 'array' => [ [], '#expected to be of type "bool", but is of type "array"\.$#', ]; yield 'float' => [ 0.1, '#expected to be of type "bool", but is of type "(float|double)"\.$#', ]; yield 'object' => [ new \stdClass(), '#expected to be of type "bool", but is of type "stdClass"\.$#', ]; } /** * @param _AutogeneratedInputConfiguration $config * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, ?array $config = null): void { $this->fixer->configure($config ?? ['only_untyped' => false]); $this->doTest($expected, $input); } public static function provideFixCases(): iterable { yield [ ' true], ]; yield [ ' false], ]; yield [ ' true], ]; yield [ ' true], ]; } /** * @param _AutogeneratedInputConfiguration $config * * @dataProvider provideMessyWhitespacesCases */ public function testMessyWhitespaces(string $expected, ?string $input = null, ?array $config = null): void { $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure($config ?? ['only_untyped' => false]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideMessyWhitespacesCases(): iterable { yield [ "fixer->configure(['only_untyped' => false]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideByReferenceCases(): iterable { yield [ 'fixer->configure(['only_untyped' => false]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideVariableNumberOfArgumentsCases(): iterable { yield [ 'fixer->configure(['only_untyped' => false]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield [ 'fixer->configure(['only_untyped' => false]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield [ '