* 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\PhpdocSeparationFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer */ final class PhpdocSeparationFixerTest extends AbstractFixerTestCase { public function testFix(): void { $this->doTest('doTest($expected, $input); } public function testFixMoreTags(): void { $expected = <<<'EOF' doTest($expected, $input); } public function testFixSpreadOut(): void { $expected = <<<'EOF' doTest($expected, $input); } public function testMultiLineComments(): void { $expected = <<<'EOF' doTest($expected, $input); } public function testCrazyMultiLineComments(): void { $expected = <<<'EOF' [ * 'https://www.foo.com/{version}/', * ['version' => '123'] * ], * 'defaults' => [ * 'timeout' => 10, * 'allow_redirects' => false, * 'proxy' => '192.168.16.1:10' * ] * ]); * * @param _AutogeneratedInputConfiguration $config Client configuration settings * - base_url: Base URL of the client that is merged into relative URLs. * Can be a string or an array that contains a URI template followed * by an associative array of expansion variables to inject into the * URI template. * - handler: callable RingPHP handler used to transfer requests * - message_factory: Factory used to create request and response object * - defaults: Default request options to apply to each request * - emitter: Event emitter used for request events * - fsm: (internal use only) The request finite state machine. A * function that accepts a transaction and optional final state. The * function is responsible for transitioning a request through its * lifecycle events. * @param string $foo */ EOF; $this->doTest($expected); } public function testDoctrineExample(): void { $expected = <<<'EOF' getId(); // method exists through __call * * @author Benjamin Eberlei */ EOF; $this->doTest($expected); } public function testSymfonyExample(): void { $expected = <<<'EOF' doTest($expected); } public function testDeprecatedAndSeeTags(): void { $expected = <<<'EOF' * * @deprecated As of some version. * @see Replacement * described here. * * @param string $foo test 123 * @param bool $bar qwerty * * @return void */ EOF; $input = <<<'EOF' * @deprecated As of some version. * * @see Replacement * described here. * @param string $foo test 123 * @param bool $bar qwerty * * @return void */ EOF; $this->doTest($expected, $input); } public function testPropertyTags(): void { $expected = <<<'EOF' * * @property int $foo * @property-read int $foo * @property-write int $bar */ EOF; $input = <<<'EOF' * @property int $foo * * @property-read int $foo * * @property-write int $bar */ EOF; $this->doTest($expected, $input); } public function testClassDocBlock(): void { $expected = <<<'EOF' * @author Graham Campbell * @copyright Foo Bar * @license MIT */ class Bar {} EOF; $input = <<<'EOF' * * @author Graham Campbell * * @copyright Foo Bar * * * @license MIT */ class Bar {} EOF; $this->doTest($expected, $input); } public function testPoorAlignment(): void { $expected = <<<'EOF' *@author Graham Campbell */ class Bar {} EOF; $input = <<<'EOF' * * *@author Graham Campbell */ class Bar {} EOF; $this->doTest($expected, $input); } public function testMoveUnknownAnnotations(): void { $expected = <<<'EOF' doTest($expected, $input); } /** * @dataProvider provideInheritDocCases */ public function testInheritDoc(string $expected, string $input): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideInheritDocCases(): iterable { yield [ 'doTest($expected); } public function testLargerEmptyDocBlock(): void { $expected = <<<'EOF' doTest($expected); } public function testOneLineDocBlock(): void { $expected = <<<'EOF' doTest($expected); } public function testMessyWhitespaces(): void { $expected = "doTest($expected, $input); } public function testWithSpacing(): void { $expected = 'doTest($expected, $input); } public function testTagInTwoGroupsConfiguration(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage( 'The option "groups" value is invalid. '. 'The "param" tag belongs to more than one group.' ); $this->fixer->configure(['groups' => [['param', 'return'], ['param', 'throws']]]); } public function testTagSpecifiedTwoTimesInGroupConfiguration(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage( 'The option "groups" value is invalid. '. 'The "param" tag is specified more than once.' ); $this->fixer->configure(['groups' => [['param', 'return', 'param', 'throws']]]); } public function testLaravelGroups(): void { $this->fixer->configure(['groups' => [ ['param', 'return'], ['throws'], ['deprecated', 'link', 'see', 'since'], ['author', 'copyright', 'license'], ['category', 'package', 'subpackage'], ['property', 'property-read', 'property-write'], ]]); $expected = <<<'EOF' doTest($expected, $input); } public function testVariousGroups(): void { $this->fixer->configure([ 'groups' => [ ['deprecated', 'link', 'see', 'since', 'author', 'copyright', 'license'], ['category', 'package', 'subpackage'], ['property', 'property-read', 'property-write'], ['return', 'param'], ], ]); $expected = <<<'EOF' doTest($expected, $input); } public function testVariousAdditionalGroups(): void { $this->fixer->configure([ 'groups' => [ ['deprecated', 'link', 'see', 'since', 'author', 'copyright', 'license'], ['category', 'package', 'subpackage'], ['property', 'property-read', 'property-write'], ['return', 'param'], ], ]); $expected = <<<'EOF' doTest($expected, $input); } /** * @dataProvider provideDocCodeCases * * @param _AutogeneratedInputConfiguration $config */ public function testDocCode(string $expected, ?string $input = null, ?array $config = null): void { if (null !== $config) { $this->fixer->configure($config); } $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideDocCodeCases(): iterable { $input = <<<'EOF' [ <<<'EOF' [ ['param', 'return'], ['throws'], ['deprecated', 'link', 'see', 'since'], ['author', 'copyright', 'license'], ['category', 'package', 'subpackage'], ['property', 'property-read', 'property-write'], ]], ]; yield 'all_tags' => [ <<<'EOF' [['author', 'throws', 'custom'], ['return', 'param']]], ]; yield 'default_groups_standard_tags' => [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [['in-group-1', 'in-group-1-too']], 'skip_unlisted_annotations' => true, ], ]; yield 'Doctrine annotations' => [ <<<'EOF' [ ['ORM\Id', 'ORM\Column', 'ORM\GeneratedValue'], ]], ]; yield 'With wildcard' => [ <<<'EOF' [ ['ORM\*'], ['Assert\*'], ]], ]; } }