Skip to content

Commit

Permalink
DX: use constants in tests for Fixer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Apr 24, 2021
1 parent fe2e08f commit 4faf827
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 54 deletions.
7 changes: 4 additions & 3 deletions tests/Fixer/Basic/BracesFixerTest.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\Tests\Fixer\Basic;

use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
use PhpCsFixer\WhitespacesFixerConfig;

Expand All @@ -24,9 +25,9 @@
*/
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()
{
Expand Down
13 changes: 7 additions & 6 deletions tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\Tests\Fixer\ClassNotation;

use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;

/**
Expand Down Expand Up @@ -416,7 +417,7 @@ class Foo
EOT
],
[
['sort_algorithm' => 'alpha'],
['sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA],
<<<'EOT'
<?php
Expand Down Expand Up @@ -1015,7 +1016,7 @@ public function provideSortingConfigurationCases()
'method_public',
'method_private',
],
'sort_algorithm' => 'alpha',
'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
],
<<<'EOT'
<?php
Expand Down Expand Up @@ -1071,7 +1072,7 @@ public function C1(){}
'method_protected',
'method_private',
],
'sort_algorithm' => 'alpha',
'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
],
<<<'EOT'
<?php
Expand Down Expand Up @@ -1181,7 +1182,7 @@ protected static function protStatFunc() {}
'method_protected_abstract',
'method_private',
],
'sort_algorithm' => 'alpha',
'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
],
<<<'EOT'
<?php
Expand Down Expand Up @@ -1327,7 +1328,7 @@ class Foo {
public ?int $foo;
}',
[
'sort_algorithm' => 'alpha',
'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA,
],
];
}
Expand All @@ -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),
Expand Down
9 changes: 5 additions & 4 deletions tests/Fixer/ClassNotation/OrderedInterfacesFixerTest.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\Tests\Fixer\ClassNotation;

use PhpCsFixer\Fixer\ClassNotation\OrderedInterfacesFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;

/**
Expand Down Expand Up @@ -145,7 +146,7 @@ public function getNestedAnonymousClassObject()
*/
public function testFixAlphaDescend($expected, $input = null)
{
$this->fixer->configure(['direction' => 'descend']);
$this->fixer->configure([OrderedInterfacesFixer::OPTION_DIRECTION => OrderedInterfacesFixer::DIRECTION_DESCEND]);
$this->doTest($expected, $input);
}

Expand Down Expand Up @@ -174,7 +175,7 @@ public function provideFixAlphaDescendCases()
*/
public function testFixLength($expected, $input = null)
{
$this->fixer->configure(['order' => 'length']);
$this->fixer->configure([OrderedInterfacesFixer::OPTION_ORDER => OrderedInterfacesFixer::ORDER_LENGTH]);
$this->doTest($expected, $input);
}

Expand Down Expand Up @@ -218,8 +219,8 @@ class A implements
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);
}
Expand Down
27 changes: 14 additions & 13 deletions tests/Fixer/Comment/HeaderCommentFixerTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -76,7 +77,7 @@ public function provideFixCases()
'header' => 'tmp',
'location' => 'after_declare_strict',
'separate' => 'bottom',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
],
'<?php
declare(strict_types=1);
Expand Down Expand Up @@ -120,7 +121,7 @@ public function provideFixCases()
[
[
'header' => 'new',
'comment_type' => 'comment',
'comment_type' => HeaderCommentFixer::HEADER_COMMENT,
],
'<?php
Expand All @@ -135,7 +136,7 @@ public function provideFixCases()
[
[
'header' => 'new',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
],
'<?php
Expand All @@ -150,7 +151,7 @@ public function provideFixCases()
[
[
'header' => 'def',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
],
'<?php
Expand Down Expand Up @@ -189,7 +190,7 @@ public function provideFixCases()
[
[
'header' => 'abc',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
],
'<?php
Expand Down Expand Up @@ -304,7 +305,7 @@ public function provideFixCases()
'header' => 'foo',
'location' => 'after_open',
'separate' => 'bottom',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
],
'<?php
/**
Expand Down Expand Up @@ -332,7 +333,7 @@ public function provideFixCases()
'header' => 'foo',
'location' => 'after_open',
'separate' => 'bottom',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
],
'<?php
/**
Expand Down Expand Up @@ -425,7 +426,7 @@ class Foo {}',
[
[
'header' => 'tmp',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
],
'<?php
Expand All @@ -447,7 +448,7 @@ class Foo {}',
[
[
'header' => 'tmp',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
],
'<?php
Expand Down Expand Up @@ -663,14 +664,14 @@ public function provideHeaderGenerationCases()
* a
*/',
'a',
'comment',
HeaderCommentFixer::HEADER_COMMENT,
],
[
'/**
* a
*/',
'a',
'PHPDoc',
HeaderCommentFixer::HEADER_PHPDOC,
],
];
}
Expand Down Expand Up @@ -731,7 +732,7 @@ public function provideMessyWhitespacesCases()
'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;",
Expand Down Expand Up @@ -777,7 +778,7 @@ public function testInvalidHeaderConfiguration()

$this->fixer->configure([
'header' => '/** test */',
'comment_type' => 'PHPDoc',
'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
]);
}
}
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\Tests\Fixer\FunctionNotation;

use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;

/**
Expand All @@ -24,7 +25,7 @@
*/
final class FunctionDeclarationFixerTest extends AbstractFixerTestCase
{
private static $configurationClosureSpacingNone = ['closure_function_spacing' => 'none'];
private static $configurationClosureSpacingNone = ['closure_function_spacing' => FunctionDeclarationFixer::SPACING_NONE];

public function testInvalidConfigurationClosureFunctionSpacing()
{
Expand Down
Expand Up @@ -13,6 +13,7 @@
namespace PhpCsFixer\Tests\Fixer\FunctionNotation;

use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;

/**
Expand Down Expand Up @@ -105,8 +106,8 @@ public function provideConfigureIncludeSetsCases()
{
return [
[['foo', 'bar']],
[['@all']],
[['@all', 'bar']],
[[NativeFunctionInvocationFixer::SET_ALL]],
[[NativeFunctionInvocationFixer::SET_ALL, 'bar']],
[
['@xxx'],
InvalidFixerConfigurationException::class,
Expand Down Expand Up @@ -509,7 +510,7 @@ public function provideFixWithConfiguredIncludeCases()
not_me();
',
[
'include' => ['@internal', 'some_other'],
'include' => [NativeFunctionInvocationFixer::SET_INTERNAL, 'some_other'],
'exclude' => ['strlen'],
],
],
Expand All @@ -527,7 +528,7 @@ public function provideFixWithConfiguredIncludeCases()
me_as_well();
',
[
'include' => ['@all'],
'include' => [NativeFunctionInvocationFixer::SET_ALL],
],
],
'include @compiler_optimized' => [
Expand All @@ -550,7 +551,7 @@ public function provideFixWithConfiguredIncludeCases()
$e = intval($f);
',
[
'include' => ['@compiler_optimized'],
'include' => [NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED],
],
],
[
Expand Down Expand Up @@ -581,7 +582,7 @@ public function & strlen($name) {
',
null,
[
'include' => ['@all'],
'include' => [NativeFunctionInvocationFixer::SET_ALL],
],
],
];
Expand All @@ -603,7 +604,7 @@ public function & strlen($name) {
$c = intval($d);
',
[
'include' => ['@compiler_optimized'],
'include' => [NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED],
'strict' => true,
],
];
Expand Down
15 changes: 8 additions & 7 deletions tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\Tests\Fixer\LanguageConstruct;

use PhpCsFixer\Fixer\LanguageConstruct\ErrorSuppressionFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ public function provideFixCases()
[
'<?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); ?>',
Expand Down Expand Up @@ -87,32 +88,32 @@ public function provideFixCases()
[
'<?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']],
],
];

Expand Down

0 comments on commit 4faf827

Please sign in to comment.