Просмотр исходного кода

Add tests for general_phpdoc_annotation_remove

Gert de Pagter 7 лет назад
Родитель
Сommit
249689dceb

+ 3 - 0
tests/AutoReview/FixerFactoryTest.php

@@ -75,6 +75,9 @@ final class FixerFactoryTest extends TestCase
             array($fixers['function_to_constant'], $fixers['no_singleline_whitespace_before_semicolons']),
             array($fixers['function_to_constant'], $fixers['no_trailing_whitespace']),
             array($fixers['function_to_constant'], $fixers['no_whitespace_in_blank_line']),
+            array($fixers['general_phpdoc_annotation_remove'], $fixers['phpdoc_separation']),
+            array($fixers['general_phpdoc_annotation_remove'], $fixers['phpdoc_trim']),
+            array($fixers['general_phpdoc_annotation_remove'], $fixers['no_empty_phpdoc']),
             array($fixers['indentation_type'], $fixers['phpdoc_indent']),
             array($fixers['line_ending'], $fixers['single_blank_line_at_eof']),
             array($fixers['method_separation'], $fixers['braces']),

+ 0 - 1
tests/AutoReview/ProjectCodeTest.php

@@ -43,7 +43,6 @@ final class ProjectCodeTest extends TestCase
         'PhpCsFixer\FileRemoval',
         'PhpCsFixer\Fixer\Operator\AlignDoubleArrowFixerHelper',
         'PhpCsFixer\Fixer\Operator\AlignEqualsFixerHelper',
-        'PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer',
         'PhpCsFixer\Runner\FileCachingLintingIterator',
         'PhpCsFixer\Runner\FileLintingIterator',
         'PhpCsFixer\StdinFileInfo',

+ 177 - 0
tests/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixerTest.php

@@ -0,0 +1,177 @@
+<?php
+
+/*
+ * 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
+ */
+final class GeneralPhpdocAnnotationRemoveFixerTest extends AbstractFixerTestCase
+{
+    /**
+     * @dataProvider provideFixCases
+     *
+     * @param string      $expected
+     * @param null|string $input
+     * @param null|array  $config
+     */
+    public function testFix($expected, $input = null, array $config = array())
+    {
+        $this->fixer->configure($config);
+        $this->doTest($expected, $input);
+    }
+
+    /**
+     * @return array
+     */
+    public function provideFixCases()
+    {
+        return array(
+            'An Annotation gets removed' => array(
+                '<?php
+/**
+ * @internal
+ */
+function hello($name)
+{
+    return "hello " . $name;
+}',
+                '<?php
+/**
+ * @internal
+ * @param string $name
+ */
+function hello($name)
+{
+    return "hello " . $name;
+}',
+                array('annotations' => array('param')),
+            ),
+            'It removes multiple annotations' => array(
+                '<?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;
+}',
+                array('annotations' => array('param', 'return', 'throws')),
+            ),
+            'It does nothing if no configuration is given' => array(
+                '<?php
+/**
+ * @author me
+ * @internal
+ * @param string $name
+ * @return string
+ * @throws \Exception
+ */
+function hello($name)
+{
+    return "hello " . $name;
+}',
+            ),
+            'It works on multiple functions' => array(
+                '<?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();
+}',
+                array('annotations' => array('author', 'return', 'internal')),
+            ),
+            'Nothing happens to non doc-block comments' => array(
+                '<?php
+/*
+ * @internal
+ * @param string $name
+ */
+function hello($name)
+{
+    return "hello " . $name;
+}',
+                null,
+                array('annotations' => array('internal', 'param', 'return')),
+            ),
+            'Nothing happens if to be deleted annotations are not present' => array(
+                '<?php
+/**
+ * @internal
+ * @param string $name
+ */
+function hello($name)
+{
+    return "hello " . $name;
+}',
+                null,
+                array('annotations' => array('author', 'test', 'return', 'deprecated')),
+            ),
+        );
+    }
+}

+ 26 - 0
tests/Fixtures/Integration/misc/general_phpdoc_annotation_remove,phpdoc_order.test

@@ -0,0 +1,26 @@
+--TEST--
+Integration of fixers: general_phpdoc_annotation_remove,phpdoc_order.
+--RULESET--
+{"general_phpdoc_annotation_remove": {"annotations": ["return"] }, "phpdoc_order": true}
+--EXPECT--
+<?php
+/**
+ * @param string $name
+ * @throws \Exception
+ */
+function hello($name)
+{
+    return 'hello'. $name;
+}
+
+--INPUT--
+<?php
+/**
+ * @throws \Exception
+ * @return string
+ * @param string $name
+ */
+function hello($name)
+{
+    return 'hello'. $name;
+}

+ 25 - 0
tests/Fixtures/Integration/priority/general_phpdoc_annotation_remove,no_empty_phpdoc.test

@@ -0,0 +1,25 @@
+--TEST--
+Integration of fixers: general_phpdoc_annotation_remove,no_empty_phpdoc.
+--RULESET--
+{"general_phpdoc_annotation_remove": {"annotations": ["test", "return", "param"] }, "no_empty_phpdoc": true}
+--EXPECT--
+<?php
+
+function hello($name)
+{
+    return 'hello'. $name;
+}
+
+--INPUT--
+<?php
+/**
+ *
+ *
+ * @return string
+ * @test
+ * @param string $name
+ */
+function hello($name)
+{
+    return 'hello'. $name;
+}

+ 29 - 0
tests/Fixtures/Integration/priority/general_phpdoc_annotation_remove,phpdoc_separation.test

@@ -0,0 +1,29 @@
+--TEST--
+Integration of fixers: general_phpdoc_annotation_remove,phpdoc_separation.
+--RULESET--
+{"general_phpdoc_annotation_remove": {"annotations": ["test"] }, "phpdoc_separation": true}
+--EXPECT--
+<?php
+/**
+ * @param string $name
+ *
+ * @return string
+ */
+function hello($name)
+{
+    return 'hello'. $name;
+}
+
+--INPUT--
+<?php
+/**
+ * @param string $name
+ *
+ * @test
+ *
+ * @return string
+ */
+function hello($name)
+{
+    return 'hello'. $name;
+}

+ 29 - 0
tests/Fixtures/Integration/priority/general_phpdoc_annotation_remove,phpdoc_trim.test

@@ -0,0 +1,29 @@
+--TEST--
+Integration of fixers: general_phpdoc_annotation_remove,phpdoc_trim.
+--RULESET--
+{"general_phpdoc_annotation_remove": {"annotations": ["test"] }, "phpdoc_trim": true}
+--EXPECT--
+<?php
+/**
+ * @return string
+ *
+ * @param string $name
+ */
+function hello($name)
+{
+    return 'hello'. $name;
+}
+
+--INPUT--
+<?php
+/**
+ * @test
+ *
+ * @return string
+ *
+ * @param string $name
+ */
+function hello($name)
+{
+    return 'hello'. $name;
+}