* 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\Tests\Test\AbstractFixerTestCase; /** * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer */ final class PhpdocTypesOrderFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixWithAlphaAlgorithmAndNullAlwaysFirstCases */ public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @dataProvider provideFixWithNullFirstCases */ public function testFixWithNullFirst(string $expected, ?string $input = null): void { $this->fixer->configure([ 'sort_algorithm' => 'none', 'null_adjustment' => 'always_first', ]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixWithNullFirstCases(): iterable { yield [ ' Foo */', '|null Foo */', ]; yield [ '> Foo */', '>|null Foo */', ]; yield [ ' */', ' */', ]; yield [ ' */', ' */', ]; yield [ '> */', '> */', ]; yield [ ' */', ' */', ]; yield [ '>>>> */', '>>>> */', ]; yield [ ' $by) */', ' $by) */', ]; yield '@method with invalid 2nd phpdoc' => [ ', OutputInterface> */', ]; yield [ ', surname:string}> */', ]; yield [ '}> */', ]; yield [ '}> */', ]; yield [ '}> */', ]; yield [ ' , DateTime): bool> */', ]; yield [ '): array $callback */', ]; yield [ '): Generator> */', ]; yield [ '): Generator> $pipe */', ]; yield [ ', mixed, Identity> */', ]; yield [ ' $callback */', ' $callback */', ]; yield [ 'fixer->configure([ 'sort_algorithm' => 'none', 'null_adjustment' => 'always_last', ]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixWithNullLastCases(): iterable { yield [ '|null Foo */', ' Foo */', ]; yield [ '>|null Foo */', '> Foo */', ]; yield [ ' */', ' */', ]; yield [ ' */', ' */', ]; yield [ '> */', '> */', ]; yield [ ' */', ' */', ]; yield [ '>>>> */', '>>>> */', ]; yield [ ' , DateTime): bool> */', ' , DateTime): bool> */', ]; } /** * @dataProvider provideFixWithAlphaAlgorithmCases */ public function testFixWithAlphaAlgorithm(string $expected, ?string $input = null): void { $this->fixer->configure([ 'sort_algorithm' => 'alpha', 'null_adjustment' => 'none', ]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixWithAlphaAlgorithmCases(): iterable { yield [ '|null Foo */', ' Foo */', ]; yield [ '>|null Foo */', '> Foo */', ]; yield [ ' */', ' */', ]; yield [ ' */', ' */', ]; yield [ '> */', '> */', ]; yield [ ' */', ' */', ]; yield [ '>>>> */', '>>>> */', ]; yield [ ' , DateTime): bool> */', ]; yield [ ' */', ' */', ]; yield [ '|bool|string */', '|string */', ]; yield [ '&C&D */', '&C */', ]; yield [ '(T): T|null|string */', '(T): T|null */', ]; yield [ '(A|T, T3, T2): (T|T2)|null|string */', '(T|A, T3, T2): (T2|T)|null */', ]; yield [ '|null|string */', '|null */', ]; } /** * @dataProvider provideFixWithAlphaAlgorithmAndNullAlwaysFirstCases */ public function testFixWithAlphaAlgorithmAndNullAlwaysFirst(string $expected, ?string $input = null): void { $this->fixer->configure([ 'sort_algorithm' => 'alpha', 'null_adjustment' => 'always_first', ]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixWithAlphaAlgorithmAndNullAlwaysFirstCases(): iterable { yield [ ' Foo */', ]; yield [ '> Foo */', ]; yield [ ' */', ' */', ]; yield [ ' */', ' */', ]; yield [ '> */', '> */', ]; yield [ ' */', ' */', ]; yield [ '>>>> */', '>>>> */', ]; yield [ '> */', ]; yield [ ' , DateTime): bool> */', ]; } /** * @dataProvider provideFixWithAlphaAlgorithmAndNullAlwaysLastCases */ public function testFixWithAlphaAlgorithmAndNullAlwaysLast(string $expected, ?string $input = null): void { $this->fixer->configure([ 'sort_algorithm' => 'alpha', 'null_adjustment' => 'always_last', ]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixWithAlphaAlgorithmAndNullAlwaysLastCases(): iterable { yield [ '|null Foo */', ' Foo */', ]; yield [ '>|null Foo */', '> Foo */', ]; yield [ ' */', ' */', ]; yield [ ' */', ' */', ]; yield [ '> */', '> */', ]; yield [ ' */', ' */', ]; yield [ '>>>> */', '>>>> */', ]; yield [ ' , DateTime): bool> */', ' , DateTime): bool> */', ]; yield [ ' */', ]; } /** * @dataProvider provideFixWithCaseSensitiveCases */ public function testFixWithCaseSensitive(string $expected, ?string $input = null): void { $this->fixer->configure([ 'case_sensitive' => true, ]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixWithCaseSensitiveCases(): iterable { return [ [ '