Skip to content

Commit 83283d9

Browse files
committed
minor #4431 DX: test that default config is not passed in RuleSet (kubawerlos)
This PR was merged into the 2.12 branch. Discussion ---------- DX: test that default config is not passed in RuleSet Commits ------- 3654e58 DX: test that default config is not passed in RuleSet
2 parents d830c19 + 3654e58 commit 83283d9

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

src/RuleSet.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ final class RuleSet implements RuleSetInterface
6868
'cast_spaces' => true,
6969
'class_attributes_separation' => ['elements' => ['method']],
7070
'class_definition' => ['single_line' => true],
71-
'concat_space' => ['spacing' => 'none'],
71+
'concat_space' => true,
7272
'declare_equal_normalize' => true,
7373
'function_typehint_space' => true,
7474
'include' => true,
@@ -94,7 +94,7 @@ final class RuleSet implements RuleSetInterface
9494
]],
9595
'no_leading_import_slash' => true,
9696
'no_leading_namespace_whitespace' => true,
97-
'no_mixed_echo_print' => ['use' => 'echo'],
97+
'no_mixed_echo_print' => true,
9898
'no_multiline_whitespace_around_double_arrow' => true,
9999
'no_short_bool_cast' => true,
100100
'no_singleline_whitespace_before_semicolons' => true,
@@ -178,9 +178,7 @@ final class RuleSet implements RuleSetInterface
178178
],
179179
'no_alias_functions' => true,
180180
'no_homoglyph_names' => true,
181-
'non_printable_character' => [
182-
'use_escape_sequences_in_strings' => false,
183-
],
181+
'non_printable_character' => true,
184182
'php_unit_construct' => true,
185183
'psr4' => true,
186184
'self_accessor' => true,
@@ -322,7 +320,7 @@ final class RuleSet implements RuleSetInterface
322320
],
323321
'@PHPUnit50Migration:risky' => [
324322
'@PHPUnit48Migration:risky' => true,
325-
'php_unit_dedicate_assert' => ['target' => PhpUnitTargetVersion::VERSION_5_0],
323+
'php_unit_dedicate_assert' => true,
326324
],
327325
'@PHPUnit52Migration:risky' => [
328326
'@PHPUnit50Migration:risky' => true,

tests/RuleSetTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
1919
use PhpCsFixer\Fixer\FixerInterface;
2020
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
21+
use PhpCsFixer\FixerConfiguration\DeprecatedFixerOptionInterface;
2122
use PhpCsFixer\FixerFactory;
2223
use PhpCsFixer\RuleSet;
2324

@@ -71,6 +72,38 @@ public function testIfAllRulesInSetsExists($setName, $ruleName, $ruleConfig)
7172
}
7273
}
7374

75+
/**
76+
* @param string $setName
77+
* @param string $ruleName
78+
* @param array|bool $ruleConfig
79+
*
80+
* @dataProvider provideAllRulesFromSetsCases
81+
*/
82+
public function testThatDefaultConfigIsNotPassed($setName, $ruleName, $ruleConfig)
83+
{
84+
$factory = new FixerFactory();
85+
$factory->registerBuiltInFixers();
86+
$factory->useRuleSet(new RuleSet([$ruleName => true]));
87+
88+
$fixer = current($factory->getFixers());
89+
90+
if (!$fixer instanceof ConfigurableFixerInterface) {
91+
$this->addToAssertionCount(1);
92+
93+
return;
94+
}
95+
96+
$defaultConfig = [];
97+
foreach ($fixer->getConfigurationDefinition()->getOptions() as $option) {
98+
if ($option instanceof DeprecatedFixerOptionInterface) {
99+
continue;
100+
}
101+
$defaultConfig[$option->getName()] = $option->getDefault();
102+
}
103+
104+
static::assertNotSame($defaultConfig, $ruleConfig, sprintf('Rule "%s" (in RuleSet "%s") has default config passed.', $ruleName, $setName));
105+
}
106+
74107
/**
75108
* @param string $ruleName
76109
* @param string $setName

0 commit comments

Comments
 (0)