44
55namespace Narrowspark \CS \Config \Tests ;
66
7+ use Generator ;
78use Narrowspark \CS \Config \Config ;
89use Narrowspark \TestingHelper \Traits \AssertArrayTrait ;
910use PhpCsFixer \ConfigInterface ;
4041use PhpCsFixerCustomFixers \Fixer \SingleSpaceAfterStatementFixer ;
4142use PhpCsFixerCustomFixers \Fixer \SingleSpaceBeforeStatementFixer ;
4243use PHPUnit \Framework \TestCase ;
44+ use ReflectionException ;
45+ use const PHP_VERSION_ID ;
46+ use function array_diff ;
47+ use function array_keys ;
48+ use function array_map ;
49+ use function array_merge ;
50+ use function count ;
51+ use function implode ;
52+ use function sprintf ;
53+ use function trim ;
4354
4455/**
4556 * @internal
@@ -100,13 +111,14 @@ public function testHasContribRules(): void
100111
101112 public function testIfAllRulesAreTested (): void
102113 {
103- $ testRules = \array_merge (
114+ $ testRules = array_merge (
115+ $ this ->getNoGroupRules (),
104116 $ this ->getPsr2Rules (),
105117 $ this ->getPsr12Rules (),
106118 $ this ->getContribRules (),
107119 $ this ->getSymfonyRules (),
108120 $ this ->getPhp71Rules (),
109- \ PHP_VERSION_ID >= 70300 ? $ this ->getPhp73Rules () : [],
121+ PHP_VERSION_ID >= 70300 ? $ this ->getPhp73Rules () : [],
110122 $ this ->getPHPUnitRules (),
111123 $ this ->getPedroTrollerRules (),
112124 $ this ->getKubawerlosRules ()
@@ -117,7 +129,7 @@ public function testIfAllRulesAreTested(): void
117129 self ::assertTrue (isset ($ testRules [$ key ]), '[ ' . $ key . '] Rule is missing. ' );
118130 }
119131
120- self ::assertCount (\ count ($ testRules ), $ rules );
132+ self ::assertCount (count ($ testRules ), $ rules );
121133 }
122134
123135 public function testDoesNotHaveHeaderCommentFixerByDefault (): void
@@ -167,14 +179,14 @@ public function testAllConfiguredRulesAreBuiltIn(): void
167179 $ kubawerlosRules [] = $ fixer ->getName ();
168180 }
169181
170- $ fixersNotBuiltIn = \ array_diff (
182+ $ fixersNotBuiltIn = array_diff (
171183 $ this ->configuredFixers (),
172- \ array_merge ($ this ->builtInFixers (), $ pedroTrollerRules , $ kubawerlosRules )
184+ array_merge ($ this ->builtInFixers (), $ pedroTrollerRules , $ kubawerlosRules )
173185 );
174186
175- self ::assertEmpty ($ fixersNotBuiltIn , \ sprintf (
187+ self ::assertEmpty ($ fixersNotBuiltIn , sprintf (
176188 'Failed to assert that fixers for the rules "%s" are built in ' ,
177- \ implode ('", " ' , $ fixersNotBuiltIn )
189+ implode ('", " ' , $ fixersNotBuiltIn )
178190 ));
179191 }
180192
@@ -192,13 +204,13 @@ public function testDoesNotHaveRulesEnabled(string $fixer, $reason): void
192204 ];
193205
194206 if ($ fixer === 'array_syntax ' ) {
195- self ::assertNotSame (['syntax ' => 'long ' ], $ config ->getRules ()['array_syntax ' ], \ sprintf (
207+ self ::assertNotSame (['syntax ' => 'long ' ], $ config ->getRules ()['array_syntax ' ], sprintf (
196208 'Fixer "%s" should not be enabled, because "%s" ' ,
197209 $ fixer ,
198210 $ reason ['long ' ]
199211 ));
200212 } else {
201- self ::assertArraySubset ($ rule , $ config ->getRules (), true , \ sprintf (
213+ self ::assertArraySubset ($ rule , $ config ->getRules (), true , sprintf (
202214 'Fixer "%s" should not be enabled, because "%s" ' ,
203215 $ fixer ,
204216 $ reason
@@ -231,7 +243,7 @@ public function provideDoesNotHaveRulesEnabledCases(): iterable
231243 'fopen_flag_order ' => 'it changes r+b to b+r and w+b and b+w ' ,
232244 ];
233245
234- $ fixers = \ array_merge ($ contribFixers , $ symfonyFixers );
246+ $ fixers = array_merge ($ contribFixers , $ symfonyFixers );
235247
236248 $ data = [];
237249
@@ -265,15 +277,15 @@ public function testHeaderCommentFixerIsEnabledIfHeaderIsProvided($header): void
265277 self ::assertArrayHasKey ('header_comment ' , $ rules );
266278 $ expected = [
267279 'comment_type ' => 'PHPDoc ' ,
268- 'header ' => \ trim ($ header ),
280+ 'header ' => trim ($ header ),
269281 'location ' => 'after_declare_strict ' ,
270282 'separate ' => 'both ' ,
271283 ];
272284 self ::assertSame ($ expected , $ rules ['header_comment ' ]);
273285 }
274286
275287 /**
276- * @return \ Generator
288+ * @return Generator
277289 */
278290 public function provideHeaderCommentFixerIsEnabledIfHeaderIsProvidedCases (): iterable
279291 {
@@ -716,6 +728,7 @@ protected function getSymfonyRules(): array
716728 'single_quote ' => true ,
717729 'single_trait_insert_per_statement ' => true ,
718730 'single_line_comment_style ' => false ,
731+ 'single_line_throw ' => true ,
719732 'standardize_not_equals ' => true ,
720733 'ternary_operator_spaces ' => true ,
721734 'ternary_to_null_coalescing ' => true ,
@@ -726,6 +739,28 @@ protected function getSymfonyRules(): array
726739 ];
727740 }
728741
742+ public function getNoGroupRules (): array
743+ {
744+ return [
745+ 'final_static_access ' => true ,
746+ 'final_public_method_for_abstract_class ' => false ,
747+ 'lowercase_constants ' => false ,
748+ 'global_namespace_import ' => [
749+ 'import_classes ' => true ,
750+ 'import_constants ' => true ,
751+ 'import_functions ' => true ,
752+ ],
753+ 'nullable_type_declaration_for_default_null_value ' => true ,
754+ 'phpdoc_line_span ' => [
755+ 'const ' => 'multi ' ,
756+ 'method ' => 'multi ' ,
757+ 'property ' => 'multi ' ,
758+ ],
759+ 'phpdoc_to_param_type ' => false ,
760+ 'self_static_accessor ' => true ,
761+ ];
762+ }
763+
729764 /**
730765 * @param array $expected
731766 * @param array $actual
@@ -734,12 +769,12 @@ protected function getSymfonyRules(): array
734769 private function assertHasRules (array $ expected , array $ actual , string $ set ): void
735770 {
736771 foreach ($ expected as $ fixer => $ isEnabled ) {
737- self ::assertArrayHasKey ($ fixer , $ actual , \ sprintf (
772+ self ::assertArrayHasKey ($ fixer , $ actual , sprintf (
738773 'Failed to assert that a rule for fixer "%s" (in set "%s") exists., ' ,
739774 $ fixer ,
740775 $ set
741776 ));
742- self ::assertSame ($ isEnabled , $ actual [$ fixer ], \ sprintf (
777+ self ::assertSame ($ isEnabled , $ actual [$ fixer ], sprintf (
743778 'Failed to assert that fixer "%s" (in set "%s") is %s. ' ,
744779 $ fixer ,
745780 $ set ,
@@ -760,15 +795,15 @@ private function configuredFixers(): array
760795 *
761796 * @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/2361
762797 */
763- $ rules = \ array_map (static function () {
798+ $ rules = array_map (static function () {
764799 return true ;
765800 }, $ config ->getRules ());
766801
767- return \ array_keys (RuleSet::create ($ rules )->getRules ());
802+ return array_keys (RuleSet::create ($ rules )->getRules ());
768803 }
769804
770805 /**
771- * @throws \ ReflectionException
806+ * @throws ReflectionException
772807 *
773808 * @return string[]
774809 */
@@ -780,7 +815,7 @@ private function builtInFixers(): array
780815 $ fixerFactory = FixerFactory::create ();
781816 $ fixerFactory ->registerBuiltInFixers ();
782817
783- $ builtInFixers = \ array_map (static function (FixerInterface $ fixer ) {
818+ $ builtInFixers = array_map (static function (FixerInterface $ fixer ) {
784819 return $ fixer ->getName ();
785820 }, $ fixerFactory ->getFixers ());
786821 }
0 commit comments