|
4 | 4 |
|
5 | 5 | namespace Symplify\EasyCodingStandard\Tests\FixerRunner\DependencyInjection; |
6 | 6 |
|
| 7 | +use Iterator; |
7 | 8 | use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; |
8 | 9 | use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer; |
| 10 | +use PhpCsFixer\Fixer\Import\OrderedImportsFixer; |
| 11 | +use PHPUnit\Framework\Attributes\DataProvider; |
9 | 12 | use Symplify\EasyCodingStandard\FixerRunner\Application\FixerFileProcessor; |
10 | 13 | use Symplify\EasyCodingStandard\Testing\PHPUnit\AbstractTestCase; |
11 | 14 | use Symplify\EasyCodingStandard\Utils\PrivatesAccessorHelper; |
@@ -43,4 +46,67 @@ public function test(): void |
43 | 46 | 'elements' => ['property'], |
44 | 47 | ], $visibilityRequiredConfiguration); |
45 | 48 | } |
| 49 | + |
| 50 | + /** |
| 51 | + * See https://github.com/easy-coding-standard/easy-coding-standard/discussions/198 |
| 52 | + * |
| 53 | + * @param array{ |
| 54 | + * case_sensitive: bool, |
| 55 | + * imports_order: list<string>|null, |
| 56 | + * sort_algorithm: string, |
| 57 | + * } $expectedConfiguration |
| 58 | + */ |
| 59 | + #[DataProvider('provideRuleOverrideInSetData')] |
| 60 | + public function testRuleOverrideInSet(string $filename, array $expectedConfiguration): void |
| 61 | + { |
| 62 | + $this->createContainerWithConfigs([__DIR__ . '/config/test-rule-override-in-set/' . $filename]); |
| 63 | + $fixerFileProcessor = $this->make(FixerFileProcessor::class); |
| 64 | + |
| 65 | + $checkers = $fixerFileProcessor->getCheckers(); |
| 66 | + $orderedImportsFixerInstances = []; |
| 67 | + |
| 68 | + foreach ($checkers as $checker) { |
| 69 | + if ($checker instanceof OrderedImportsFixer) { |
| 70 | + $orderedImportsFixerInstances[] = $checker; |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + $this->assertCount(2, $orderedImportsFixerInstances); |
| 75 | + |
| 76 | + foreach ($orderedImportsFixerInstances as $orderedImportFixerInstance) { |
| 77 | + $configuration = PrivatesAccessorHelper::getPropertyValue($orderedImportFixerInstance, 'configuration'); |
| 78 | + |
| 79 | + $this->assertSame($expectedConfiguration, $configuration); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + public static function provideRuleOverrideInSetData(): Iterator |
| 84 | + { |
| 85 | + yield [ |
| 86 | + 'with-rules.php', |
| 87 | + [ |
| 88 | + 'case_sensitive' => false, |
| 89 | + 'imports_order' => null, |
| 90 | + 'sort_algorithm' => OrderedImportsFixer::SORT_ALPHA, |
| 91 | + ], |
| 92 | + ]; |
| 93 | + |
| 94 | + yield [ |
| 95 | + 'with-configured-rule.php', |
| 96 | + [ |
| 97 | + 'case_sensitive' => true, |
| 98 | + 'imports_order' => ['const', 'class', 'function'], |
| 99 | + 'sort_algorithm' => 'alpha', |
| 100 | + ], |
| 101 | + ]; |
| 102 | + |
| 103 | + yield [ |
| 104 | + 'with-configured-rule-and-empty-config.php', |
| 105 | + [ |
| 106 | + 'case_sensitive' => false, |
| 107 | + 'imports_order' => null, |
| 108 | + 'sort_algorithm' => OrderedImportsFixer::SORT_ALPHA, |
| 109 | + ], |
| 110 | + ]; |
| 111 | + } |
46 | 112 | } |
0 commit comments