66
77use Cdn77 \TestCase ;
88
9+ use function array_keys ;
10+ use function is_array ;
11+ use function json_encode ;
12+
13+ use const JSON_THROW_ON_ERROR ;
14+
915class ValidVariableNameSniffTest extends TestCase
1016{
1117 public const CODE_NOT_CAMEL_CAPS = 'NotCamelCaps ' ;
@@ -18,43 +24,59 @@ public function testErrors(): void
1824 {
1925 $ file = self ::checkFile (__DIR__ . '/data/ValidVariableNameSniffTest.inc ' );
2026
21- self ::assertSame (36 , $ file ->getErrorCount ());
27+ $ errorTypesPerLine = [
28+ 3 => self ::CODE_NOT_CAMEL_CAPS ,
29+ 5 => self ::CODE_NOT_CAMEL_CAPS ,
30+ 10 => self ::CODE_MEMBER_NOT_CAMEL_CAPS ,
31+ 12 => self ::CODE_PUBLIC_HAS_UNDERSCORE ,
32+ 15 => self ::CODE_MEMBER_NOT_CAMEL_CAPS ,
33+ 17 => self ::CODE_PUBLIC_HAS_UNDERSCORE ,
34+ 20 => self ::CODE_MEMBER_NOT_CAMEL_CAPS ,
35+ 22 => self ::CODE_PUBLIC_HAS_UNDERSCORE ,
36+ 25 => self ::CODE_MEMBER_NOT_CAMEL_CAPS ,
37+ 27 => self ::CODE_PRIVATE_NO_UNDERSCORE ,
38+ 31 => self ::CODE_NOT_CAMEL_CAPS ,
39+ 33 => self ::CODE_NOT_CAMEL_CAPS ,
40+ 36 => self ::CODE_STRING_NOT_CAMEL_CAPS ,
41+ 37 => self ::CODE_STRING_NOT_CAMEL_CAPS ,
42+ 39 => self ::CODE_STRING_NOT_CAMEL_CAPS ,
43+ 42 => self ::CODE_NOT_CAMEL_CAPS ,
44+ 44 => self ::CODE_NOT_CAMEL_CAPS ,
45+ 53 => self ::CODE_MEMBER_NOT_CAMEL_CAPS ,
46+ 58 => self ::CODE_MEMBER_NOT_CAMEL_CAPS ,
47+ 62 => self ::CODE_MEMBER_NOT_CAMEL_CAPS ,
48+ 63 => self ::CODE_NOT_CAMEL_CAPS ,
49+ 64 => self ::CODE_NOT_CAMEL_CAPS ,
50+ 67 => self ::CODE_NOT_CAMEL_CAPS ,
51+ 81 => self ::CODE_STRING_NOT_CAMEL_CAPS ,
52+ 106 => self ::CODE_PUBLIC_HAS_UNDERSCORE ,
53+ 107 => [self ::CODE_PUBLIC_HAS_UNDERSCORE ,self ::CODE_MEMBER_NOT_CAMEL_CAPS ],
54+ 108 => self ::CODE_PUBLIC_HAS_UNDERSCORE ,
55+ 111 => self ::CODE_PRIVATE_NO_UNDERSCORE ,
56+ 112 => self ::CODE_PRIVATE_NO_UNDERSCORE ,
57+ 113 => self ::CODE_PRIVATE_NO_UNDERSCORE ,
58+ 114 => self ::CODE_PRIVATE_NO_UNDERSCORE ,
59+ 123 => self ::CODE_PUBLIC_HAS_UNDERSCORE ,
60+ 138 => self ::CODE_NOT_CAMEL_CAPS ,
61+ 141 => self ::CODE_NOT_CAMEL_CAPS ,
62+ 146 => self ::CODE_MEMBER_NOT_CAMEL_CAPS ,
63+ ];
64+ $ possibleLines = array_keys ($ errorTypesPerLine );
65+
66+ $ errors = $ file ->getErrors ();
67+ foreach ($ errors as $ line => $ error ) {
68+ self ::assertContains ($ line , $ possibleLines , json_encode ($ error , JSON_THROW_ON_ERROR ));
2269
23- self ::assertSniffError ($ file , 3 , self ::CODE_NOT_CAMEL_CAPS );
24- self ::assertSniffError ($ file , 5 , self ::CODE_NOT_CAMEL_CAPS );
25- self ::assertSniffError ($ file , 10 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
26- self ::assertSniffError ($ file , 12 , self ::CODE_PUBLIC_HAS_UNDERSCORE );
27- self ::assertSniffError ($ file , 15 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
28- self ::assertSniffError ($ file , 17 , self ::CODE_PUBLIC_HAS_UNDERSCORE );
29- self ::assertSniffError ($ file , 20 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
30- self ::assertSniffError ($ file , 22 , self ::CODE_PUBLIC_HAS_UNDERSCORE );
31- self ::assertSniffError ($ file , 25 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
32- self ::assertSniffError ($ file , 27 , self ::CODE_PRIVATE_NO_UNDERSCORE );
33- self ::assertSniffError ($ file , 31 , self ::CODE_NOT_CAMEL_CAPS );
34- self ::assertSniffError ($ file , 33 , self ::CODE_NOT_CAMEL_CAPS );
35- self ::assertSniffError ($ file , 36 , self ::CODE_STRING_NOT_CAMEL_CAPS );
36- self ::assertSniffError ($ file , 37 , self ::CODE_STRING_NOT_CAMEL_CAPS );
37- self ::assertSniffError ($ file , 39 , self ::CODE_STRING_NOT_CAMEL_CAPS );
38- self ::assertSniffError ($ file , 42 , self ::CODE_NOT_CAMEL_CAPS );
39- self ::assertSniffError ($ file , 44 , self ::CODE_NOT_CAMEL_CAPS );
40- self ::assertSniffError ($ file , 53 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
41- self ::assertSniffError ($ file , 58 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
42- self ::assertSniffError ($ file , 62 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
43- self ::assertSniffError ($ file , 63 , self ::CODE_NOT_CAMEL_CAPS );
44- self ::assertSniffError ($ file , 64 , self ::CODE_NOT_CAMEL_CAPS );
45- self ::assertSniffError ($ file , 67 , self ::CODE_NOT_CAMEL_CAPS );
46- self ::assertSniffError ($ file , 81 , self ::CODE_STRING_NOT_CAMEL_CAPS );
47- self ::assertSniffError ($ file , 106 , self ::CODE_PUBLIC_HAS_UNDERSCORE );
48- self ::assertSniffError ($ file , 107 , self ::CODE_PUBLIC_HAS_UNDERSCORE );
49- self ::assertSniffError ($ file , 107 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
50- self ::assertSniffError ($ file , 108 , self ::CODE_PUBLIC_HAS_UNDERSCORE );
51- self ::assertSniffError ($ file , 111 , self ::CODE_PRIVATE_NO_UNDERSCORE );
52- self ::assertSniffError ($ file , 112 , self ::CODE_PRIVATE_NO_UNDERSCORE );
53- self ::assertSniffError ($ file , 113 , self ::CODE_PRIVATE_NO_UNDERSCORE );
54- self ::assertSniffError ($ file , 114 , self ::CODE_PRIVATE_NO_UNDERSCORE );
55- self ::assertSniffError ($ file , 123 , self ::CODE_PUBLIC_HAS_UNDERSCORE );
56- self ::assertSniffError ($ file , 138 , self ::CODE_NOT_CAMEL_CAPS );
57- self ::assertSniffError ($ file , 141 , self ::CODE_NOT_CAMEL_CAPS );
58- self ::assertSniffError ($ file , 146 , self ::CODE_MEMBER_NOT_CAMEL_CAPS );
70+ $ errorTypes = $ errorTypesPerLine [$ line ];
71+ if (! is_array ($ errorTypes )) {
72+ $ errorTypes = [$ errorTypes ];
73+ }
74+
75+ foreach ($ errorTypes as $ errorType ) {
76+ self ::assertSniffError ($ file , $ line , $ errorType );
77+ }
78+ }
79+
80+ self ::assertSame (36 , $ file ->getErrorCount ());
5981 }
6082}
0 commit comments