Skip to content

Commit a5096b3

Browse files
committed
Add testing for deprecated fixers
1 parent 1693844 commit a5096b3

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

src/Ruleset/Nexus73.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function __construct()
112112
'final_class' => false, // risky
113113
'final_internal_class' => true, // risky
114114
'final_public_method_for_abstract_class' => false, // risky
115-
'final_static_access' => true,
115+
'final_static_access' => false, // deprecated
116116
'fopen_flag_order' => true, // risky
117117
'fopen_flags' => ['b_mode' => true], // risky
118118
'full_opening_tag' => true,
@@ -308,7 +308,7 @@ public function __construct()
308308
'php_unit_mock_short_will_return' => true, // risky
309309
'php_unit_namespaced' => true, // risky
310310
'php_unit_no_expectation_annotation' => true, // risky
311-
'php_unit_ordered_covers' => true,
311+
'php_unit_ordered_covers' => false, // deprecated
312312
'php_unit_set_up_tear_down_visibility' => true, // risky
313313
'php_unit_size_class' => false,
314314
'php_unit_strict' => true, // risky
@@ -328,7 +328,7 @@ public function __construct()
328328
'phpdoc_no_package' => true,
329329
'phpdoc_no_useless_inheritdoc' => true,
330330
'phpdoc_order' => true,
331-
'phpdoc_order_by_value' => false,
331+
'phpdoc_order_by_value' => true,
332332
'phpdoc_return_self_reference' => true,
333333
'phpdoc_scalar' => true,
334334
'phpdoc_separation' => true,
@@ -349,7 +349,7 @@ public function __construct()
349349
'pre_increment' => false, // deprecated
350350
'protected_to_private' => true,
351351
'psr0' => false,
352-
'psr4' => true, // deprecated
352+
'psr4' => false, // deprecated
353353
'psr_autoloading' => ['dir' => null],
354354
'random_api_migration' => true,
355355
'regular_callable_call' => true, // risky

src/Test/AbstractRulesetTestCase.php

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
namespace Nexus\CsConfig\Test;
1515

1616
use Nexus\CsConfig\Ruleset\RulesetInterface;
17+
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
1718
use PhpCsFixer\Fixer\FixerInterface;
1819
use PhpCsFixer\FixerFactory;
19-
use PhpCsFixer\RuleSet;
20+
use PhpCsFixer\RuleSet\RuleSet;
2021
use PHPUnit\Framework\TestCase;
2122

2223
abstract class AbstractRulesetTestCase extends TestCase
@@ -29,10 +30,36 @@ abstract class AbstractRulesetTestCase extends TestCase
2930
final public static function ruleNamesProvider(): iterable
3031
{
3132
$ruleset = static::createRuleset();
33+
$name = $ruleset->getName();
3234

33-
return [
34-
[$ruleset->getName(), array_keys($ruleset->getRules())],
35-
];
35+
yield $name => [$name, array_keys($ruleset->getRules())];
36+
}
37+
38+
/**
39+
* @codeCoverageIgnore
40+
*
41+
* @return iterable
42+
*/
43+
public static function deprecatedBuiltInFixersProvider(): iterable
44+
{
45+
static $deprecatedFixers;
46+
47+
if (null === $deprecatedFixers) {
48+
$fixerFactory = FixerFactory::create();
49+
$fixerFactory->registerBuiltInFixers();
50+
51+
$deprecatedFixers = array_map(static function (FixerInterface $fixer): string {
52+
return $fixer->getName();
53+
}, array_filter($fixerFactory->getFixers(), static function (FixerInterface $fixer): bool {
54+
return $fixer instanceof DeprecatedFixerInterface;
55+
}));
56+
57+
sort($deprecatedFixers);
58+
}
59+
60+
foreach ($deprecatedFixers as $fixer) {
61+
yield $fixer => [$fixer];
62+
}
3663
}
3764

3865
protected static function createRuleset(): RulesetInterface
@@ -107,6 +134,28 @@ final public function testHeaderCommentFixerIsDisabledByDefault(): void
107134
self::assertFalse($rules['header_comment']);
108135
}
109136

137+
/**
138+
* @dataProvider deprecatedBuiltInFixersProvider
139+
*
140+
* @param string $fixer
141+
*
142+
* @return void
143+
*/
144+
final public function testDeprecatedFixersAreTurnedOff(string $fixer): void
145+
{
146+
static $rules;
147+
148+
if (null === $rules) {
149+
$rules = self::createRuleset()->getRules();
150+
}
151+
152+
self::assertArrayHasKey($fixer, $rules);
153+
self::assertFalse($rules[$fixer], sprintf(
154+
'Failed asserting that the deprecated "%s" fixer is set to false.',
155+
$fixer
156+
));
157+
}
158+
110159
/**
111160
* Rules defined by PhpCsFixer.
112161
*
@@ -139,6 +188,6 @@ private function configuredFixers(): array
139188
return true;
140189
}, static::createRuleset()->getRules());
141190

142-
return array_keys(RuleSet::create($rules)->getRules());
191+
return array_keys((new RuleSet($rules))->getRules());
143192
}
144193
}

0 commit comments

Comments
 (0)