* 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 Jakub Kwaśniewski * * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer */ final class PhpdocOrderFixerTest extends AbstractFixerTestCase { public function testEmptyOrderConfiguration(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage('The option "order" value is invalid. Minimum two tags are required.'); $this->fixer->configure(['order' => []]); } public function testInvalidOrderConfiguration(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage('The option "order" value is invalid. Minimum two tags are required.'); $this->fixer->configure(['order' => ['param']]); } public function testNoChanges(): void { $expected = <<<'EOF' doTest($expected); } /** * @dataProvider provideDifferentOrderCases * * @param _AutogeneratedInputConfiguration $config */ public function testOnlyParams(array $config): void { $this->fixer->configure($config); $expected = <<<'EOF' doTest($expected); } /** * @dataProvider provideDifferentOrderCases * * @param _AutogeneratedInputConfiguration $config */ public function testOnlyReturns(array $config): void { $this->fixer->configure($config); $expected = <<<'EOF' doTest($expected); } /** * @dataProvider provideDifferentOrderCases * * @param _AutogeneratedInputConfiguration $config */ public function testEmpty(array $config): void { $this->fixer->configure($config); $this->doTest('/***/'); } /** * @dataProvider provideDifferentOrderCases * * @param _AutogeneratedInputConfiguration $config */ public function testNoAnnotations(array $config): void { $this->fixer->configure($config); $expected = <<<'EOF' doTest($expected); } public function testFixBasicCase(): void { $expected = <<<'EOF' doTest($expected, $input); } public function testFixCompleteCase(): void { $expected = <<<'EOF' doTest($expected, $input); } public function testExampleFromSymfony(): void { $expected = <<<'EOF' doTest($expected, $input); } public function testNoChangesWithLaravelStyle(): void { $this->fixer->configure(['order' => ['param', 'return', 'throws']]); $expected = <<<'EOF' doTest($expected); } public function testFixBasicCaseWithLaravelStyle(): void { $this->fixer->configure(['order' => ['param', 'return', 'throws']]); $expected = <<<'EOF' doTest($expected, $input); } public function testFixCompleteCaseWithLaravelStyle(): void { $this->fixer->configure(['order' => ['param', 'return', 'throws']]); $expected = <<<'EOF' doTest($expected, $input); } public function testExampleFromSymfonyWithLaravelStyle(): void { $this->fixer->configure(['order' => ['param', 'return', 'throws']]); $input = <<<'EOF' doTest($input); } /** * @return iterable}> */ public static function provideDifferentOrderCases(): iterable { yield [['order' => ['param', 'throw', 'return']]]; yield [['order' => ['param', 'return', 'throw']]]; } /** * @dataProvider provideFixBasicCaseWithDifferentOrdersCases * * @param _AutogeneratedInputConfiguration $config */ public function testFixBasicCaseWithDifferentOrders(string $expected, ?string $input = null, ?array $config = null): void { $this->fixer->configure($config); $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFixBasicCaseWithDifferentOrdersCases(): iterable { $input = <<<'EOF' ['return', 'throws', 'param']], ]; yield [ <<<'EOF' ['throws', 'return', 'param']], ]; } public function testFixCompleteCaseWithCustomOrder(): void { $this->fixer->configure(['order' => [ 'throws', 'return', 'param', 'custom', 'internal', ]]); $expected = <<<'EOF' doTest($expected, $input); } /** * @dataProvider provideFixCompleteCasesWithCustomOrdersCases * * @param _AutogeneratedInputConfiguration $config */ public function testFixCompleteCasesWithCustomOrders(string $expected, string $input, array $config): void { $this->fixer->configure($config); $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFixCompleteCasesWithCustomOrdersCases(): iterable { yield 'intepacuthre' => [ <<<'EOF' $id * @custom Test! * asldnaksdkjasdasd * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd * @return bool Return false on failure * @return int Return the number of changes. **/ EOF, <<<'EOF' $id * @custom Test! * asldnaksdkjasdasd * @template T of Extension\Extension * @return bool Return false on failure * @return int Return the number of changes. * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd **/ EOF, ['order' => ['internal', 'template', 'param', 'custom', 'throws', 'return']], ]; yield 'pare' => [ <<<'EOF' $id * @return bool Return false on failure * @return int Return the number of changes. * @custom Test! * asldnaksdkjasdasd * @template T of Extension\Extension * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd **/ EOF, <<<'EOF' $id * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd **/ EOF, ['order' => ['param', 'return']], ]; yield 'pareth' => [ <<<'EOF' $id * @return bool Return false on failure * @return int Return the number of changes. * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd **/ EOF, <<<'EOF' $id * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd **/ EOF, ['order' => ['param', 'return', 'throws']], ]; yield 'pathre' => [ <<<'EOF' $id * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd * @return bool Return false on failure * @return int Return the number of changes. **/ EOF, <<<'EOF' $id * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd **/ EOF, ['order' => ['param', 'throws', 'return']], ]; yield 'tepathre' => [ <<<'EOF' $id * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd * @return bool Return false on failure * @return int Return the number of changes. * @custom Test! * asldnaksdkjasdasd **/ EOF, <<<'EOF' $id * @template T of Extension\Extension * @custom Test! * asldnaksdkjasdasd * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd **/ EOF, ['order' => ['template', 'param', 'throws', 'return']], ]; yield 'tepathre2' => [ <<<'EOF' $id * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd * @return bool Return false on failure * @return int Return the number of changes. * @custom Test! * asldnaksdkjasdasd **/ EOF, <<<'EOF' $id * @return bool Return false on failure * @return int Return the number of changes. * @template T of Extension\Extension * @custom Test! * asldnaksdkjasdasd * @throws Exception|RuntimeException dfsdf * jkaskdnaksdnkasndansdnansdajsdnkasd **/ EOF, ['order' => ['template', 'param', 'throws', 'return']], ]; } }