Dariusz Ruminski 4 лет назад
Родитель
Сommit
460a569196
3 измененных файлов с 245 добавлено и 318 удалено
  1. 1 1
      src/DocBlock/Annotation.php
  2. 8 0
      tests/DocBlock/AnnotationTest.php
  3. 236 317
      tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php

+ 1 - 1
src/DocBlock/Annotation.php

@@ -302,7 +302,7 @@ class Annotation
             }
             }
 
 
             $matchingResult = Preg::match(
             $matchingResult = Preg::match(
-                '{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.self::REGEX_TYPES.'(?:[*\h].*)?$}sx',
+                '{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.self::REGEX_TYPES.'(?:[*\h\v].*)?$}sx',
                 $this->lines[0]->getContent(),
                 $this->lines[0]->getContent(),
                 $matches
                 $matches
             );
             );

+ 8 - 0
tests/DocBlock/AnnotationTest.php

@@ -361,6 +361,14 @@ final class AnnotationTest extends TestCase
                 '/** @var array<string|int, string>',
                 '/** @var array<string|int, string>',
                 ['array<string|int, string>'],
                 ['array<string|int, string>'],
             ],
             ],
+            [
+                " * @return int\n",
+                ['int'],
+            ],
+            [
+                " * @return int\r\n",
+                ['int'],
+            ],
         ];
         ];
     }
     }
 
 

+ 236 - 317
tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php

@@ -24,330 +24,249 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  */
  */
 final class PhpdocScalarFixerTest extends AbstractFixerTestCase
 final class PhpdocScalarFixerTest extends AbstractFixerTestCase
 {
 {
-    public function testBasicFix()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @return int
-     */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-    /**
-     * @return integer
-     */
-
-EOF;
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testPropertyFix()
-    {
-        $expected = <<<'EOF'
-<?php
-/**
- * @method int foo()
- * @property int $foo
- * @property callback $foo
- * @property-read bool $bar
- * @property-write float $baz
- */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-/**
- * @method integer foo()
- * @property integer $foo
- * @property callback $foo
- * @property-read boolean $bar
- * @property-write double $baz
- */
-
-EOF;
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testDoNotModifyVariables()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @param int $integer
-     */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-    /**
-     * @param integer $integer
-     */
-
-EOF;
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testFixWithTabsOnOneLine()
-    {
-        $expected = "<?php /**\t@return\tbool\t*/";
-
-        $input = "<?php /**\t@return\tboolean\t*/";
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testFixMoreThings()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * Hello there mr integer!
-     *
-     * @param int|float $integer
-     * @param int|int[] $foo
-     * @param string|null $bar
-     *
-     * @return string|bool
-     */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-    /**
-     * Hello there mr integer!
-     *
-     * @param integer|real $integer
-     * @param int|integer[] $foo
-     * @param str|null $bar
-     *
-     * @return string|boolean
-     */
-
-EOF;
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testFixVar()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @var int Some integer value.
-     */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-    /**
-     * @var integer Some integer value.
-     */
-
-EOF;
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testFixVarWithMoreStuff()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @var bool|int|Double Booleans, integers and doubles.
-     */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-    /**
-     * @var boolean|integer|Double Booleans, integers and doubles.
-     */
-
-EOF;
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testFixType()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @type float
-     */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-    /**
-     * @type real
-     */
-
-EOF;
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testDoNotFix()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @var notaboolean
-     */
-
-EOF;
-
-        $this->doTest($expected);
-    }
-
-    public function testComplexMix()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @var notabooleanthistime|bool|integerr
-     */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-    /**
-     * @var notabooleanthistime|boolean|integerr
-     */
-
-EOF;
-
-        $this->doTest($expected, $input);
-    }
-
-    public function testDoNotModifyComplexTag()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @Type("boolean")
-     */
-EOF;
-
-        $this->doTest($expected);
-    }
-
-    public function testDoNotModifyStrings()
-    {
-        $expected = <<<'EOF'
-<?php
-
-$string = '
-    /**
-     * @var boolean
-     */
-';
-
-EOF;
-
-        $this->doTest($expected);
-    }
-
-    public function testEmptyDocBlock()
-    {
-        $expected = <<<'EOF'
-<?php
     /**
     /**
+     * @param string      $expected
+     * @param null|string $input
      *
      *
+     * @dataProvider provideFixCases
      */
      */
-
-EOF;
-
-        $this->doTest($expected);
-    }
-
-    public function testWrongCasedPhpdocTagIsNotAltered()
+    public function testFix($expected, $input = null, array $config = [])
     {
     {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * @Param boolean
-     *
-     * @Return int
-     */
-
-EOF;
-        $this->doTest($expected);
-    }
-
-    public function testInlineDoc()
-    {
-        $expected = <<<'EOF'
-<?php
-    /**
-     * Does stuffs with stuffs.
-     *
-     * @param array $stuffs {
-     *     @type bool $foo
-     *     @type int $bar
-     * }
-     */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-    /**
-     * Does stuffs with stuffs.
-     *
-     * @param array $stuffs {
-     *     @type boolean $foo
-     *     @type integer $bar
-     * }
-     */
-
-EOF;
-
+        $this->fixer->configure($config);
         $this->doTest($expected, $input);
         $this->doTest($expected, $input);
     }
     }
 
 
-    public function testFixCallback()
+    public static function provideFixCases()
     {
     {
-        $expected = <<<'EOF'
-<?php
-/**
- * @method int foo()
- * @property int $foo
- * @property callable $foo
- * @property-read bool $bar
- * @property-write float $baz
- */
-
-EOF;
-
-        $input = <<<'EOF'
-<?php
-/**
- * @method integer foo()
- * @property integer $foo
- * @property callback $foo
- * @property-read boolean $bar
- * @property-write double $baz
- */
-
-EOF;
-
-        $this->fixer->configure(['types' => ['boolean', 'callback', 'double', 'integer', 'real', 'str']]);
-
-        $this->doTest($expected, $input);
+        yield 'basic fix' => [
+            '<?php
+            /**
+             * @return int
+             */
+             ',
+            '<?php
+            /**
+             * @return integer
+             */
+             ',
+        ];
+
+        yield 'property fix' => [
+            '<?php
+            /**
+             * @method int foo()
+             * @property int $foo
+             * @property callback $foo
+             * @property-read bool $bar
+             * @property-write float $baz
+             */
+             ',
+            '<?php
+            /**
+             * @method integer foo()
+             * @property integer $foo
+             * @property callback $foo
+             * @property-read boolean $bar
+             * @property-write double $baz
+             */
+             ',
+        ];
+
+        yield 'do not modify variables' => [
+            '<?php
+            /**
+             * @param int $integer
+             */
+             ',
+            '<?php
+            /**
+             * @param integer $integer
+             */
+             ',
+        ];
+
+        yield 'fix with tabs on one line' => [
+            "<?php /**\t@return\tbool\t*/",
+            "<?php /**\t@return\tboolean\t*/",
+        ];
+
+        yield 'fix more things' => [
+            '<?php
+            /**
+             * Hello there mr integer!
+             *
+             * @param int|float $integer
+             * @param int|int[] $foo
+             * @param string|null $bar
+             *
+             * @return string|bool
+             */
+             ',
+            '<?php
+            /**
+             * Hello there mr integer!
+             *
+             * @param integer|real $integer
+             * @param int|integer[] $foo
+             * @param str|null $bar
+             *
+             * @return string|boolean
+             */
+             ',
+        ];
+
+        yield 'fix var' => [
+            '<?php
+            /**
+             * @var int Some integer value.
+             */
+             ',
+            '<?php
+            /**
+             * @var integer Some integer value.
+             */
+             ',
+        ];
+
+        yield 'fix var with more stuff' => [
+            '<?php
+            /**
+             * @var bool|int|Double Booleans, integers and doubles.
+             */
+             ',
+            '<?php
+            /**
+             * @var boolean|integer|Double Booleans, integers and doubles.
+             */
+             ',
+        ];
+
+        yield 'fix type' => [
+            '<?php
+            /**
+             * @type float
+             */
+             ',
+            '<?php
+            /**
+             * @type real
+             */
+             ',
+        ];
+
+        yield 'do not fix' => [
+            '<?php
+            /**
+             * @var notaboolean
+             */
+             ',
+        ];
+
+        yield 'complex mix' => [
+            '<?php
+            /**
+             * @var notabooleanthistime|bool|integerr
+             */
+             ',
+            '<?php
+            /**
+             * @var notabooleanthistime|boolean|integerr
+             */
+             ',
+        ];
+
+        yield 'do not modify complex tag' => [
+            '<?php
+            /**
+             * @Type("boolean")
+             */
+             ',
+        ];
+
+        yield 'do not modify strings' => [
+            "<?php
+            \$string = '
+                /**
+                 * @var boolean
+                 */
+            ';
+             ",
+        ];
+
+        yield 'empty DocBlock' => [
+            '<?php
+            /**
+             *
+             */
+             ',
+        ];
+
+        yield 'wrong cased Phpdoc tag is not altered' => [
+            '<?php
+            /**
+             * @Param boolean
+             *
+             * @Return int
+             */
+             ',
+        ];
+
+        yield 'inline doc' => [
+            '<?php
+            /**
+             * Does stuffs with stuffs.
+             *
+             * @param array $stuffs {
+             *     @type bool $foo
+             *     @type int $bar
+             * }
+             */
+             ',
+            '<?php
+            /**
+             * Does stuffs with stuffs.
+             *
+             * @param array $stuffs {
+             *     @type boolean $foo
+             *     @type integer $bar
+             * }
+             */
+             ',
+        ];
+
+        yield 'fix callback' => [
+            '<?php
+            /**
+             * @method int foo()
+             * @property int $foo
+             * @property callable $foo
+             * @property-read bool $bar
+             * @property-write float $baz
+             */
+             ',
+            '<?php
+            /**
+             * @method integer foo()
+             * @property integer $foo
+             * @property callback $foo
+             * @property-read boolean $bar
+             * @property-write double $baz
+             */
+             ',
+            ['types' => ['boolean', 'callback', 'double', 'integer', 'real', 'str']],
+        ];
+
+        yield 'fix Windows line endings' => [
+            str_replace("\n", "\r\n", '<?php
+            /**
+             * @return int
+             */
+             '),
+            str_replace("\n", "\r\n", '<?php
+            /**
+             * @return integer
+             */
+             '),
+        ];
     }
     }
 }
 }