123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * 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
- *
- * @author Gert de Pagter
- *
- * @covers \PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer>
- *
- * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer
- */
- final class GeneralPhpdocAnnotationRemoveFixerTest extends AbstractFixerTestCase
- {
- /**
- * @param _AutogeneratedInputConfiguration $config
- *
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null, array $config = []): void
- {
- $this->fixer->configure($config);
- $this->doTest($expected, $input);
- }
- public static function provideFixCases(): iterable
- {
- yield 'An Annotation gets removed' => [
- '<?php
- /**
- * @internal
- */
- function hello($name)
- {
- return "hello " . $name;
- }',
- '<?php
- /**
- * @internal
- * @param string $name
- */
- function hello($name)
- {
- return "hello " . $name;
- }',
- ['annotations' => ['param']],
- ];
- yield 'It removes multiple annotations' => [
- '<?php
- /**
- * @author me
- * @internal
- */
- function hello($name)
- {
- return "hello " . $name;
- }',
- '<?php
- /**
- * @author me
- * @internal
- * @param string $name
- * @return string
- * @throws \Exception
- */
- function hello($name)
- {
- return "hello " . $name;
- }',
- ['annotations' => ['param', 'return', 'throws']],
- ];
- yield 'It does nothing if no configuration is given' => [
- '<?php
- /**
- * @author me
- * @internal
- * @param string $name
- * @return string
- * @throws \Exception
- */
- function hello($name)
- {
- return "hello " . $name;
- }',
- ];
- yield 'It works on multiple functions' => [
- '<?php
- /**
- * @param string $name
- * @throws \Exception
- */
- function hello($name)
- {
- return "hello " . $name;
- }
- /**
- */
- function goodBye()
- {
- return 0;
- }
- function noComment()
- {
- callOtherFunction();
- }',
- '<?php
- /**
- * @author me
- * @internal
- * @param string $name
- * @return string
- * @throws \Exception
- */
- function hello($name)
- {
- return "hello " . $name;
- }
- /**
- * @internal
- * @author Piet-Henk
- * @return int
- */
- function goodBye()
- {
- return 0;
- }
- function noComment()
- {
- callOtherFunction();
- }',
- ['annotations' => ['author', 'return', 'internal']],
- ];
- yield 'Nothing happens to non doc-block comments' => [
- '<?php
- /*
- * @internal
- * @param string $name
- */
- function hello($name)
- {
- return "hello " . $name;
- }',
- null,
- ['annotations' => ['internal', 'param', 'return']],
- ];
- yield 'Nothing happens if to be deleted annotations are not present' => [
- '<?php
- /**
- * @internal
- * @param string $name
- */
- function hello($name)
- {
- return "hello " . $name;
- }',
- null,
- ['annotations' => ['author', 'test', 'return', 'deprecated']],
- ];
- yield [
- '<?php
- while ($something = myFunction($foo)) {}
- ',
- '<?php
- /** @noinspection PhpAssignmentInConditionInspection */
- while ($something = myFunction($foo)) {}
- ',
- ['annotations' => ['noinspection']],
- ];
- yield [
- '<?php
- /**
- * @internal
- * @AuThOr Jane Doe
- */
- function foo() {}',
- '<?php
- /**
- * @internal
- * @author John Doe
- * @AuThOr Jane Doe
- */
- function foo() {}',
- ['annotations' => ['author'], 'case_sensitive' => true],
- ];
- yield [
- '<?php
- /**
- * @internal
- */
- function foo() {}',
- '<?php
- /**
- * @internal
- * @author John Doe
- * @AuThOr Jane Doe
- */
- function foo() {}',
- ['annotations' => ['author'], 'case_sensitive' => false],
- ];
- }
- }
|