Skip to content

Commit ff457be

Browse files
committed
Rule sets must appear in the order present in PhpCsFixer\RuleSet
1 parent 1cc36ca commit ff457be

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

lib/Config.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
final class Config extends PhpCsFixerConfig
1212
{
13-
const APP_V1 = 'APP_V1';
14-
const APP_V2 = 'APP_V2';
15-
const LIB = 'LIB';
13+
public const APP_V1 = 'APP_V1';
14+
public const APP_V2 = 'APP_V2';
15+
public const LIB = 'LIB';
1616

1717
public function __construct(string $type = self::APP_V2, array $overriddenRules = [])
1818
{
@@ -36,12 +36,12 @@ public function __construct(string $type = self::APP_V2, array $overriddenRules
3636
]);
3737

3838
$rules = [
39+
'@Symfony' => true,
40+
'@Symfony:risky' => true,
3941
'@DoctrineAnnotation' => true,
4042
'@PHP71Migration' => true,
4143
'@PHP71Migration:risky' => true,
42-
'@PHPUnit60Migration:risky' => true,
43-
'@Symfony' => true,
44-
'@Symfony:risky' => true,
44+
'@PHPUnit75Migration:risky' => true,
4545
'Slam/final_abstract_public' => self::APP_V1 !== $type,
4646
'Slam/final_internal_class' => self::APP_V1 !== $type,
4747
'Slam/function_reference_space' => true,
@@ -110,7 +110,6 @@ public function __construct(string $type = self::APP_V2, array $overriddenRules
110110
'ordered_class_elements' => ['order' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property', 'construct', 'destruct', 'magic', 'phpunit', 'method']],
111111
'ordered_imports' => true,
112112
'ordered_interfaces' => true,
113-
'php_unit_dedicate_assert_internal_type' => true,
114113
'php_unit_internal_class' => false,
115114
'php_unit_method_casing' => true,
116115
'php_unit_ordered_covers' => true,

tests/ConfigTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testAllDefaultRulesAreSpecified()
4848
$fixerFactory->registerCustomFixers($config->getCustomFixers());
4949
$fixers = $fixerFactory->getFixers();
5050

51-
$availableRules = \array_filter($fixers, function (FixerInterface $fixer) {
51+
$availableRules = \array_filter($fixers, static function (FixerInterface $fixer) {
5252
return ! $fixer instanceof DeprecatedFixerInterface;
5353
});
5454
$availableRules = \array_map(function (FixerInterface $fixer) {
@@ -62,7 +62,17 @@ public function testAllDefaultRulesAreSpecified()
6262
$diff = \array_diff($currentRules, $availableRules);
6363
static::assertEmpty($diff, \sprintf("I seguenti fixer sono di troppo:\n- %s", \implode(\PHP_EOL . '- ', $diff)));
6464

65-
$currentRules = \array_keys($configRules);
65+
$currentSets = \array_values(\array_filter(\array_keys($configRules), static function (string $fixerName): bool {
66+
return isset($fixerName[0]) && '@' === $fixerName[0];
67+
}));
68+
$defaultSets = $ruleSet->getSetDefinitionNames();
69+
$intersectSets = \array_values(\array_intersect($defaultSets, $currentSets));
70+
static::assertEquals($intersectSets, $currentSets, \sprintf('Rule sets must be ordered as the appear in %s', RuleSet::class));
71+
72+
$currentRules = \array_values(\array_filter(\array_keys($configRules), static function (string $fixerName): bool {
73+
return isset($fixerName[0]) && '@' !== $fixerName[0];
74+
}));
75+
6676
$orderedCurrentRules = $currentRules;
6777
\sort($orderedCurrentRules);
6878
static::assertEquals($orderedCurrentRules, $currentRules, 'Order the rules alphabetically please');

0 commit comments

Comments
 (0)