Browse Source

DX: use constants in tests for Fixer configuration

Dariusz Ruminski 3 years ago
parent
commit
4faf827e75

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

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Tests\Fixer\Basic;
 
+use PhpCsFixer\Fixer\Basic\BracesFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 use PhpCsFixer\WhitespacesFixerConfig;
 
@@ -24,9 +25,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()
     {

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

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Tests\Fixer\ClassNotation;
 
+use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -416,7 +417,7 @@ class Foo
 EOT
             ],
             [
-                ['sort_algorithm' => 'alpha'],
+                ['sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA],
                 <<<'EOT'
 <?php
 
@@ -1015,7 +1016,7 @@ EOT
                         'method_public',
                         'method_private',
                     ],
-                    'sort_algorithm' => 'alpha',
+                    'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
                 ],
                 <<<'EOT'
 <?php
@@ -1071,7 +1072,7 @@ EOT
                         'method_protected',
                         'method_private',
                     ],
-                    'sort_algorithm' => 'alpha',
+                    'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
                 ],
                 <<<'EOT'
 <?php
@@ -1181,7 +1182,7 @@ EOT
                         'method_protected_abstract',
                         'method_private',
                     ],
-                    'sort_algorithm' => 'alpha',
+                    'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
                 ],
                 <<<'EOT'
 <?php
@@ -1327,7 +1328,7 @@ EOT
                 public ?int $foo;
             }',
             [
-                'sort_algorithm' => 'alpha',
+                'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
             ],
         ];
     }
@@ -1354,7 +1355,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

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Tests\Fixer\ClassNotation;
 
+use PhpCsFixer\Fixer\ClassNotation\OrderedInterfacesFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -145,7 +146,7 @@ final class OrderedInterfacesFixerTest extends AbstractFixerTestCase
      */
     public function testFixAlphaDescend($expected, $input = null)
     {
-        $this->fixer->configure(['direction' => 'descend']);
+        $this->fixer->configure([OrderedInterfacesFixer::OPTION_DIRECTION => OrderedInterfacesFixer::DIRECTION_DESCEND]);
         $this->doTest($expected, $input);
     }
 
@@ -174,7 +175,7 @@ final class OrderedInterfacesFixerTest extends AbstractFixerTestCase
      */
     public function testFixLength($expected, $input = null)
     {
-        $this->fixer->configure(['order' => 'length']);
+        $this->fixer->configure([OrderedInterfacesFixer::OPTION_ORDER => OrderedInterfacesFixer::ORDER_LENGTH]);
         $this->doTest($expected, $input);
     }
 
@@ -218,8 +219,8 @@ final class OrderedInterfacesFixerTest extends AbstractFixerTestCase
     public function testFixLengthDescend($expected, $input = null)
     {
         $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

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Tests\Fixer\Comment;
 
 use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
+use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerWithAliasedOptionsTestCase;
 use PhpCsFixer\WhitespacesFixerConfig;
 
@@ -76,7 +77,7 @@ echo 1;',
                     'header' => 'tmp',
                     'location' => 'after_declare_strict',
                     'separate' => 'bottom',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 declare(strict_types=1);
@@ -120,7 +121,7 @@ echo 1;',
             [
                 [
                     'header' => 'new',
-                    'comment_type' => 'comment',
+                    'comment_type' => HeaderCommentFixer::HEADER_COMMENT,
                 ],
                 '<?php
 
@@ -135,7 +136,7 @@ echo 1;',
             [
                 [
                     'header' => 'new',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -150,7 +151,7 @@ echo 1;',
             [
                 [
                     'header' => 'def',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -189,7 +190,7 @@ echo 1;',
             [
                 [
                     'header' => 'abc',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -304,7 +305,7 @@ echo \'x\';',
                     'header' => 'foo',
                     'location' => 'after_open',
                     'separate' => 'bottom',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 /**
@@ -332,7 +333,7 @@ echo 1;',
                     'header' => 'foo',
                     'location' => 'after_open',
                     'separate' => 'bottom',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 /**
@@ -425,7 +426,7 @@ class Foo {}',
             [
                 [
                     'header' => 'tmp',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -447,7 +448,7 @@ class Foo {}',
             [
                 [
                     'header' => 'tmp',
-                    'comment_type' => 'PHPDoc',
+                    'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
                 ],
                 '<?php
 
@@ -663,14 +664,14 @@ echo 1;'
  * a
  */',
                 'a',
-                'comment',
+                HeaderCommentFixer::HEADER_COMMENT,
             ],
             [
                 '/**
  * a
  */',
                 'a',
-                'PHPDoc',
+                HeaderCommentFixer::HEADER_PHPDOC,
             ],
         ];
     }
@@ -731,7 +732,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;",
@@ -777,7 +778,7 @@ echo 1;'
 
         $this->fixer->configure([
             'header' => '/** test */',
-            'comment_type' => 'PHPDoc',
+            'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
         ]);
     }
 }

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

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Tests\Fixer\FunctionNotation;
 
+use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -24,7 +25,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()
     {

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

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Tests\Fixer\FunctionNotation;
 
 use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
+use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -105,8 +106,8 @@ final class NativeFunctionInvocationFixerTest extends AbstractFixerTestCase
     {
         return [
             [['foo', 'bar']],
-            [['@all']],
-            [['@all', 'bar']],
+            [[NativeFunctionInvocationFixer::SET_ALL]],
+            [[NativeFunctionInvocationFixer::SET_ALL, 'bar']],
             [
                 ['@xxx'],
                 InvalidFixerConfigurationException::class,
@@ -509,7 +510,7 @@ namespace {
                     not_me();
                 ',
                 [
-                    'include' => ['@internal', 'some_other'],
+                    'include' => [NativeFunctionInvocationFixer::SET_INTERNAL, 'some_other'],
                     'exclude' => ['strlen'],
                 ],
             ],
@@ -527,7 +528,7 @@ namespace {
                     me_as_well();
                 ',
                 [
-                    'include' => ['@all'],
+                    'include' => [NativeFunctionInvocationFixer::SET_ALL],
                 ],
             ],
             'include @compiler_optimized' => [
@@ -550,7 +551,7 @@ namespace {
                     $e = intval($f);
                 ',
                 [
-                    'include' => ['@compiler_optimized'],
+                    'include' => [NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED],
                 ],
             ],
             [
@@ -581,7 +582,7 @@ namespace {
                 ',
                 null,
                 [
-                    'include' => ['@all'],
+                    'include' => [NativeFunctionInvocationFixer::SET_ALL],
                 ],
             ],
         ];
@@ -603,7 +604,7 @@ namespace {
                         $c = intval($d);
                     ',
                 [
-                    'include' => ['@compiler_optimized'],
+                    'include' => [NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED],
                     'strict' => true,
                 ],
             ];

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

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Tests\Fixer\LanguageConstruct;
 
+use PhpCsFixer\Fixer\LanguageConstruct\ErrorSuppressionFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -56,7 +57,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); ?>',
@@ -87,32 +88,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

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Tests\Fixer\Operator;
 
+use PhpCsFixer\Fixer\Operator\IncrementStyleFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -33,7 +34,7 @@ final class IncrementStyleFixerTest extends AbstractFixerTestCase
      */
     public function testFixPreIncrement($expected, $input = null)
     {
-        $this->fixer->configure(['style' => 'pre']);
+        $this->fixer->configure(['style' => IncrementStyleFixer::STYLE_PRE]);
         $this->doTest($expected, $input);
     }
 
@@ -45,7 +46,7 @@ final class IncrementStyleFixerTest extends AbstractFixerTestCase
      */
     public function testFixPostIncrement($expected, $input = null)
     {
-        $this->fixer->configure(['style' => 'post']);
+        $this->fixer->configure(['style' => IncrementStyleFixer::STYLE_POST]);
         $this->doTest($expected, $input);
     }
 

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

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Tests\Fixer\PhpTag;
 
+use PhpCsFixer\Fixer\PhpTag\EchoTagSyntaxFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 
 /**
@@ -32,7 +33,7 @@ final class EchoTagSyntaxFixerTest extends AbstractFixerTestCase
      */
     public function testLongToShortFormat($expected, $input = null, $shortenSimpleStatementsOnly = true)
     {
-        $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);
     }
 
@@ -102,7 +103,7 @@ EOT
      */
     public function testShortToLongFormat($expected, $input, $function)
     {
-        $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);
     }
 
@@ -120,7 +121,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

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Tests\Fixer\Phpdoc;
 
+use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 use PhpCsFixer\WhitespacesFixerConfig;
 
@@ -55,7 +56,7 @@ EOF;
 
     public function testFixLeftAlign()
     {
-        $this->fixer->configure(['tags' => ['param'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -117,7 +118,7 @@ EOF;
 
     public function testFixPartiallyUntypedLeftAlign()
     {
-        $this->fixer->configure(['tags' => ['param'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -193,7 +194,7 @@ EOF;
 
     public function testFixMultiLineDescLeftAlign()
     {
-        $this->fixer->configure(['tags' => ['param', 'property', 'method'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param', 'property', 'method'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -285,7 +286,7 @@ EOF;
 
     public function testFixMultiLineDescWithThrowsLeftAlign()
     {
-        $this->fixer->configure(['tags' => ['param', 'return', 'throws'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param', 'return', 'throws'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -491,7 +492,7 @@ EOF;
 
     public function testFixTestLeftAlign()
     {
-        $this->fixer->configure(['tags' => ['param'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -732,7 +733,7 @@ EOF;
 
     public function testDifferentIndentationLeftAlign()
     {
-        $this->fixer->configure(['tags' => ['param', 'return'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['param', 'return'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -1020,7 +1021,7 @@ EOF;
 
     public function testAlignsMethodWithoutParametersLeftAlign()
     {
-        $this->fixer->configure(['tags' => ['method', 'property'], 'align' => 'left']);
+        $this->fixer->configure(['tags' => ['method', 'property'], 'align' => PhpdocAlignFixer::ALIGN_LEFT]);
 
         $expected = <<<'EOF'
 <?php
@@ -1198,7 +1199,7 @@ final class Sample
 ',
             ],
             [
-                ['tags' => ['param'], 'align' => 'left'],
+                ['tags' => ['param'], 'align' => PhpdocAlignFixer::ALIGN_LEFT],
                 '<?php
 final class Sample
 {