Browse Source

Merge branch 'master' into 3.0

# Conflicts:
#	tests/Fixer/Comment/HeaderCommentFixerTest.php
Dariusz Ruminski 3 years ago
parent
commit
8c5943b38e

+ 4 - 3
tests/Fixer/Basic/BracesFixerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Fixer\Basic;
 
+use PhpCsFixer\Fixer\Basic\BracesFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 use PhpCsFixer\WhitespacesFixerConfig;
 
@@ -26,9 +27,9 @@ use PhpCsFixer\WhitespacesFixerConfig;
  */
 final class BracesFixerTest extends AbstractFixerTestCase
 {
-    private static $configurationOopPositionSameLine = ['position_after_functions_and_oop_constructs' => 'same'];
-    private static $configurationCtrlStructPositionNextLine = ['position_after_control_structures' => 'next'];
-    private static $configurationAnonymousPositionNextLine = ['position_after_anonymous_constructs' => 'next'];
+    private static $configurationOopPositionSameLine = ['position_after_functions_and_oop_constructs' => BracesFixer::LINE_SAME];
+    private static $configurationCtrlStructPositionNextLine = ['position_after_control_structures' => BracesFixer::LINE_NEXT];
+    private static $configurationAnonymousPositionNextLine = ['position_after_anonymous_constructs' => BracesFixer::LINE_NEXT];
 
     public function testInvalidConfigurationClassyConstructs(): void
     {

+ 7 - 6
tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Fixer\ClassNotation;
 
+use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -404,7 +405,7 @@ class Foo
 EOT
             ],
             [
-                ['sort_algorithm' => 'alpha'],
+                ['sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA],
                 <<<'EOT'
 <?php
 
@@ -983,7 +984,7 @@ EOT
                         'method_public',
                         'method_private',
                     ],
-                    'sort_algorithm' => 'alpha',
+                    'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
                 ],
                 <<<'EOT'
 <?php
@@ -1039,7 +1040,7 @@ EOT
                         'method_protected',
                         'method_private',
                     ],
-                    'sort_algorithm' => 'alpha',
+                    'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
                 ],
                 <<<'EOT'
 <?php
@@ -1149,7 +1150,7 @@ EOT
                         'method_protected_abstract',
                         'method_private',
                     ],
-                    'sort_algorithm' => 'alpha',
+                    'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
                 ],
                 <<<'EOT'
 <?php
@@ -1292,7 +1293,7 @@ EOT
                 public ?int $foo;
             }',
             [
-                'sort_algorithm' => 'alpha',
+                'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
             ],
         ];
     }
@@ -1316,7 +1317,7 @@ class TestClass
     public function %s(){}
     public function %s(){}
 }';
-        $this->fixer->configure(['order' => ['use_trait'], 'sort_algorithm' => 'alpha']);
+        $this->fixer->configure(['order' => ['use_trait'], 'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA]);
 
         $this->doTest(
             sprintf($template, $methodName2, $methodName1),

+ 5 - 4
tests/Fixer/ClassNotation/OrderedInterfacesFixerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Fixer\ClassNotation;
 
+use PhpCsFixer\Fixer\ClassNotation\OrderedInterfacesFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -138,7 +139,7 @@ final class OrderedInterfacesFixerTest extends AbstractFixerTestCase
      */
     public function testFixAlphaDescend(string $expected, ?string $input = null): void
     {
-        $this->fixer->configure(['direction' => 'descend']);
+        $this->fixer->configure([OrderedInterfacesFixer::OPTION_DIRECTION => OrderedInterfacesFixer::DIRECTION_DESCEND]);
         $this->doTest($expected, $input);
     }
 
@@ -164,7 +165,7 @@ final class OrderedInterfacesFixerTest extends AbstractFixerTestCase
      */
     public function testFixLength(string $expected, ?string $input = null): void
     {
-        $this->fixer->configure(['order' => 'length']);
+        $this->fixer->configure([OrderedInterfacesFixer::OPTION_ORDER => OrderedInterfacesFixer::ORDER_LENGTH]);
         $this->doTest($expected, $input);
     }
 
@@ -205,8 +206,8 @@ final class OrderedInterfacesFixerTest extends AbstractFixerTestCase
     public function testFixLengthDescend(string $expected, ?string $input = null): void
     {
         $this->fixer->configure([
-            'order' => 'length',
-            'direction' => 'descend',
+            OrderedInterfacesFixer::OPTION_ORDER => OrderedInterfacesFixer::ORDER_LENGTH,
+            OrderedInterfacesFixer::OPTION_DIRECTION => OrderedInterfacesFixer::DIRECTION_DESCEND,
         ]);
         $this->doTest($expected, $input);
     }

+ 14 - 13
tests/Fixer/Comment/HeaderCommentFixerTest.php

@@ -15,6 +15,7 @@ declare(strict_types=1);
 namespace PhpCsFixer\Tests\Fixer\Comment;
 
 use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
+use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 use PhpCsFixer\WhitespacesFixerConfig;
 
@@ -75,7 +76,7 @@ echo 1;',
                     'header' => 'tmp',
                     'location' => 'after_declare_strict',
                     'separate' => 'bottom',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 declare(strict_types=1);
@@ -119,7 +120,7 @@ echo 1;',
             [
                 [
                     'header' => 'new',
-                    'comment_type' => 'comment',
+                    'comment_type' => HeaderCommentFixer::HEADER_COMMENT,
                 ],
                 '<?php
 
@@ -134,7 +135,7 @@ echo 1;',
             [
                 [
                     'header' => 'new',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -149,7 +150,7 @@ echo 1;',
             [
                 [
                     'header' => 'def',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -188,7 +189,7 @@ echo 1;',
             [
                 [
                     'header' => 'abc',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -303,7 +304,7 @@ echo \'x\';',
                     'header' => 'foo',
                     'location' => 'after_open',
                     'separate' => 'bottom',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 /**
@@ -331,7 +332,7 @@ echo 1;',
                     'header' => 'foo',
                     'location' => 'after_open',
                     'separate' => 'bottom',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 /**
@@ -424,7 +425,7 @@ class Foo {}',
             [
                 [
                     'header' => 'tmp',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -446,7 +447,7 @@ class Foo {}',
             [
                 [
                     'header' => 'tmp',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -643,14 +644,14 @@ echo 1;'
  * a
  */',
                 'a',
-                'comment',
+                HeaderCommentFixer::HEADER_COMMENT,
             ],
             [
                 '/**
  * a
  */',
                 'a',
-                'PHPDoc',
+                HeaderCommentFixer::HEADER_PHPDOC,
             ],
         ];
     }
@@ -706,7 +707,7 @@ echo 1;'
                     'header' => 'whitemess',
                     'location' => 'after_declare_strict',
                     'separate' => 'bottom',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 "<?php\r\ndeclare(strict_types=1);\r\n/**\r\n * whitemess\r\n */\r\n\r\nnamespace A\\B;\r\n\r\necho 1;",
                 "<?php\r\ndeclare(strict_types=1);\r\n\r\nnamespace A\\B;\r\n\r\necho 1;",
@@ -752,7 +753,7 @@ echo 1;'
 
         $this->fixer->configure([
             'header' => '/** test */',
-            'comment_type' => 'PHPDoc',
+            'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
         ]);
     }
 }

+ 2 - 1
tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Fixer\FunctionNotation;
 
+use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -26,7 +27,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  */
 final class FunctionDeclarationFixerTest extends AbstractFixerTestCase
 {
-    private static $configurationClosureSpacingNone = ['closure_function_spacing' => 'none'];
+    private static $configurationClosureSpacingNone = ['closure_function_spacing' => FunctionDeclarationFixer::SPACING_NONE];
 
     public function testInvalidConfigurationClosureFunctionSpacing(): void
     {

+ 8 - 7
tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php

@@ -15,6 +15,7 @@ declare(strict_types=1);
 namespace PhpCsFixer\Tests\Fixer\FunctionNotation;
 
 use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
+use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -102,8 +103,8 @@ final class NativeFunctionInvocationFixerTest extends AbstractFixerTestCase
     {
         return [
             [['foo', 'bar']],
-            [['@all']],
-            [['@all', 'bar']],
+            [[NativeFunctionInvocationFixer::SET_ALL]],
+            [[NativeFunctionInvocationFixer::SET_ALL, 'bar']],
             [
                 ['@xxx'],
                 InvalidFixerConfigurationException::class,
@@ -487,7 +488,7 @@ namespace {
                     not_me();
                 ',
                 [
-                    'include' => ['@internal', 'some_other'],
+                    'include' => [NativeFunctionInvocationFixer::SET_INTERNAL, 'some_other'],
                     'exclude' => ['strlen'],
                 ],
             ],
@@ -505,7 +506,7 @@ namespace {
                     me_as_well();
                 ',
                 [
-                    'include' => ['@all'],
+                    'include' => [NativeFunctionInvocationFixer::SET_ALL],
                 ],
             ],
             'include @compiler_optimized' => [
@@ -528,7 +529,7 @@ namespace {
                     $e = intval($f);
                 ',
                 [
-                    'include' => ['@compiler_optimized'],
+                    'include' => [NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED],
                 ],
             ],
             [
@@ -559,7 +560,7 @@ namespace {
                 ',
                 null,
                 [
-                    'include' => ['@all'],
+                    'include' => [NativeFunctionInvocationFixer::SET_ALL],
                 ],
             ],
         ];
@@ -581,7 +582,7 @@ namespace {
                         $c = intval($d);
                     ',
                 [
-                    'include' => ['@compiler_optimized'],
+                    'include' => [NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED],
                     'strict' => true,
                 ],
             ];

+ 8 - 7
tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Fixer\LanguageConstruct;
 
+use PhpCsFixer\Fixer\LanguageConstruct\ErrorSuppressionFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -55,7 +56,7 @@ final class ErrorSuppressionFixerTest extends AbstractFixerTestCase
             [
                 '<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); ?>',
                 null,
-                ['mute_deprecation_error' => false],
+                [ErrorSuppressionFixer::OPTION_MUTE_DEPRECATION_ERROR => false],
             ],
             [
                 '<?php @\trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); ?>',
@@ -86,32 +87,32 @@ Trigger_Error/**/("This is a deprecation warning.", E_USER_DEPRECATED/***/); ?>'
             [
                 '<?php @trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); mkdir("dir"); ?>',
                 '<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); @mkdir("dir"); ?>',
-                ['mute_deprecation_error' => true, 'noise_remaining_usages' => true],
+                [ErrorSuppressionFixer::OPTION_MUTE_DEPRECATION_ERROR => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES => true],
             ],
             [
                 '<?php $foo->isBar(); ?>',
                 '<?php @$foo->isBar(); ?>',
-                ['noise_remaining_usages' => true],
+                [ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES => true],
             ],
             [
                 '<?php Foo::isBar(); ?>',
                 '<?php @Foo::isBar(); ?>',
-                ['noise_remaining_usages' => true],
+                [ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES => true],
             ],
             [
                 '<?php @trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); @mkdir("dir"); ?>',
                 '<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); @mkdir("dir"); ?>',
-                ['mute_deprecation_error' => true, 'noise_remaining_usages' => true, 'noise_remaining_usages_exclude' => ['mkdir']],
+                [ErrorSuppressionFixer::OPTION_MUTE_DEPRECATION_ERROR => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES_EXCLUDE => ['mkdir']],
             ],
             [
                 '<?php @trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); @mkdir("dir"); unlink($path); ?>',
                 '<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); @mkdir("dir"); @unlink($path); ?>',
-                ['mute_deprecation_error' => true, 'noise_remaining_usages' => true, 'noise_remaining_usages_exclude' => ['mkdir']],
+                [ErrorSuppressionFixer::OPTION_MUTE_DEPRECATION_ERROR => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES_EXCLUDE => ['mkdir']],
             ],
             [
                 '<?php @trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); @trigger_error("This is not a deprecation warning.", E_USER_WARNING); ?>',
                 '<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED); @trigger_error("This is not a deprecation warning.", E_USER_WARNING); ?>',
-                ['mute_deprecation_error' => true, 'noise_remaining_usages' => true, 'noise_remaining_usages_exclude' => ['trigger_error']],
+                [ErrorSuppressionFixer::OPTION_MUTE_DEPRECATION_ERROR => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES_EXCLUDE => ['trigger_error']],
             ],
         ];
 

+ 3 - 2
tests/Fixer/Operator/IncrementStyleFixerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Fixer\Operator;
 
+use PhpCsFixer\Fixer\Operator\IncrementStyleFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -32,7 +33,7 @@ final class IncrementStyleFixerTest extends AbstractFixerTestCase
      */
     public function testFixPreIncrement(string $expected, ?string $input = null): void
     {
-        $this->fixer->configure(['style' => 'pre']);
+        $this->fixer->configure(['style' => IncrementStyleFixer::STYLE_PRE]);
         $this->doTest($expected, $input);
     }
 
@@ -41,7 +42,7 @@ final class IncrementStyleFixerTest extends AbstractFixerTestCase
      */
     public function testFixPostIncrement(string $expected, ?string $input = null): void
     {
-        $this->fixer->configure(['style' => 'post']);
+        $this->fixer->configure(['style' => IncrementStyleFixer::STYLE_POST]);
         $this->doTest($expected, $input);
     }
 

+ 4 - 3
tests/Fixer/PhpTag/EchoTagSyntaxFixerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Fixer\PhpTag;
 
+use PhpCsFixer\Fixer\PhpTag\EchoTagSyntaxFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -30,7 +31,7 @@ final class EchoTagSyntaxFixerTest extends AbstractFixerTestCase
      */
     public function testLongToShortFormat(string $expected, ?string $input = null, bool $shortenSimpleStatementsOnly = true): void
     {
-        $this->fixer->configure(['format' => 'short', 'shorten_simple_statements_only' => $shortenSimpleStatementsOnly]);
+        $this->fixer->configure([EchoTagSyntaxFixer::OPTION_FORMAT => EchoTagSyntaxFixer::FORMAT_SHORT, EchoTagSyntaxFixer::OPTION_SHORTEN_SIMPLE_STATEMENTS_ONLY => $shortenSimpleStatementsOnly]);
         $this->doTest($expected, $input);
     }
 
@@ -96,7 +97,7 @@ EOT
      */
     public function testShortToLongFormat(string $expected, ?string $input, string $function): void
     {
-        $this->fixer->configure(['format' => 'long', 'long_function' => $function]);
+        $this->fixer->configure([EchoTagSyntaxFixer::OPTION_FORMAT => EchoTagSyntaxFixer::FORMAT_LONG, EchoTagSyntaxFixer::OPTION_LONG_FUNCTION => $function]);
         $this->doTest($expected, $input);
     }
 
@@ -114,7 +115,7 @@ EOT
             ['<?php <fn> foo();', '<?=foo();'],
         ];
         $result = [];
-        foreach (['echo', 'print'] as $fn) {
+        foreach ([EchoTagSyntaxFixer::LONG_FUNCTION_ECHO, EchoTagSyntaxFixer::LONG_FUNCTION_PRINT] as $fn) {
             foreach ($cases as $case) {
                 $result[] = [str_replace('<fn>', $fn, $case[0]), str_replace('<fn>', $fn, $case[1]), $fn];
             }

+ 9 - 8
tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Fixer\Phpdoc;
 
+use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 use PhpCsFixer\WhitespacesFixerConfig;
 
@@ -57,7 +58,7 @@ EOF;
 
     public function testFixLeftAlign(): void
     {
-        $this->fixer->configure(['tags' => ['param'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -119,7 +120,7 @@ EOF;
 
     public function testFixPartiallyUntypedLeftAlign(): void
     {
-        $this->fixer->configure(['tags' => ['param'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -195,7 +196,7 @@ EOF;
 
     public function testFixMultiLineDescLeftAlign(): void
     {
-        $this->fixer->configure(['tags' => ['param', 'property', 'method'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param', 'property', 'method'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -287,7 +288,7 @@ EOF;
 
     public function testFixMultiLineDescWithThrowsLeftAlign(): void
     {
-        $this->fixer->configure(['tags' => ['param', 'return', 'throws'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param', 'return', 'throws'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -493,7 +494,7 @@ EOF;
 
     public function testFixTestLeftAlign(): void
     {
-        $this->fixer->configure(['tags' => ['param'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -734,7 +735,7 @@ EOF;
 
     public function testDifferentIndentationLeftAlign(): void
     {
-        $this->fixer->configure(['tags' => ['param', 'return'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param', 'return'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -1019,7 +1020,7 @@ EOF;
 
     public function testAlignsMethodWithoutParametersLeftAlign(): void
     {
-        $this->fixer->configure(['tags' => ['method', 'property'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['method', 'property'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -1194,7 +1195,7 @@ final class Sample
 ',
             ],
             [
-                ['tags' => ['param'], 'align' => 'left'],
+                ['tags' => ['param'], 'align' => PhpdocAlignFixer::ALIGN_LEFT],
                 '<?php
 final class Sample
 {