@@ -17,126 +17,126 @@ |
||
17 | 17 | class FindImplementedInterfaceNamesTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The \PHP_CodeSniffer\Files\File object containing parsed contents of the test case file. |
|
22 | - * |
|
23 | - * @var \PHP_CodeSniffer\Files\File |
|
24 | - */ |
|
25 | - private $phpcsFile; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file. |
|
30 | - * |
|
31 | - * Methods used for these tests can be found in a test case file in the same |
|
32 | - * directory and with the same name, using the .inc extension. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setUp() |
|
37 | - { |
|
38 | - $config = new Config(); |
|
39 | - $config->standards = ['Generic']; |
|
40 | - |
|
41 | - $ruleset = new Ruleset($config); |
|
42 | - |
|
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | - $this->phpcsFile->process(); |
|
46 | - |
|
47 | - }//end setUp() |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Clean up after finished test. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function tearDown() |
|
56 | - { |
|
57 | - unset($this->phpcsFile); |
|
58 | - |
|
59 | - }//end tearDown() |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Test retrieving the name(s) of the interfaces being implemented by a class. |
|
64 | - * |
|
65 | - * @param string $identifier Comment which precedes the test case. |
|
66 | - * @param bool $expected Expected function output. |
|
67 | - * |
|
68 | - * @dataProvider dataImplementedInterface |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function testFindImplementedInterfaceNames($identifier, $expected) |
|
73 | - { |
|
74 | - $start = ($this->phpcsFile->numTokens - 1); |
|
75 | - $delim = $this->phpcsFile->findPrevious( |
|
76 | - T_COMMENT, |
|
77 | - $start, |
|
78 | - null, |
|
79 | - false, |
|
80 | - $identifier |
|
81 | - ); |
|
82 | - $OOToken = $this->phpcsFile->findNext([T_CLASS, T_ANON_CLASS, T_INTERFACE], ($delim + 1)); |
|
83 | - |
|
84 | - $result = $this->phpcsFile->findImplementedInterfaceNames($OOToken); |
|
85 | - $this->assertSame($expected, $result); |
|
86 | - |
|
87 | - }//end testFindImplementedInterfaceNames() |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Data provider for the FindImplementedInterfaceNames test. |
|
92 | - * |
|
93 | - * @see testFindImplementedInterfaceNames() |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function dataImplementedInterface() |
|
98 | - { |
|
99 | - return [ |
|
100 | - [ |
|
101 | - '/* testImplementedClass */', |
|
102 | - ['testFIINInterface'], |
|
103 | - ], |
|
104 | - [ |
|
105 | - '/* testMultiImplementedClass */', |
|
106 | - [ |
|
107 | - 'testFIINInterface', |
|
108 | - 'testFIINInterface2', |
|
109 | - ], |
|
110 | - ], |
|
111 | - [ |
|
112 | - '/* testNamespacedClass */', |
|
113 | - ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface'], |
|
114 | - ], |
|
115 | - [ |
|
116 | - '/* testNonImplementedClass */', |
|
117 | - false, |
|
118 | - ], |
|
119 | - [ |
|
120 | - '/* testInterface */', |
|
121 | - false, |
|
122 | - ], |
|
123 | - [ |
|
124 | - '/* testClassThatExtendsAndImplements */', |
|
125 | - [ |
|
126 | - 'InterfaceA', |
|
127 | - '\NameSpaced\Cat\InterfaceB', |
|
128 | - ], |
|
129 | - ], |
|
130 | - [ |
|
131 | - '/* testClassThatImplementsAndExtends */', |
|
132 | - [ |
|
133 | - '\InterfaceA', |
|
134 | - 'InterfaceB', |
|
135 | - ], |
|
136 | - ], |
|
137 | - ]; |
|
138 | - |
|
139 | - }//end dataImplementedInterface() |
|
20 | + /** |
|
21 | + * The \PHP_CodeSniffer\Files\File object containing parsed contents of the test case file. |
|
22 | + * |
|
23 | + * @var \PHP_CodeSniffer\Files\File |
|
24 | + */ |
|
25 | + private $phpcsFile; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file. |
|
30 | + * |
|
31 | + * Methods used for these tests can be found in a test case file in the same |
|
32 | + * directory and with the same name, using the .inc extension. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setUp() |
|
37 | + { |
|
38 | + $config = new Config(); |
|
39 | + $config->standards = ['Generic']; |
|
40 | + |
|
41 | + $ruleset = new Ruleset($config); |
|
42 | + |
|
43 | + $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | + $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | + $this->phpcsFile->process(); |
|
46 | + |
|
47 | + }//end setUp() |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Clean up after finished test. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function tearDown() |
|
56 | + { |
|
57 | + unset($this->phpcsFile); |
|
58 | + |
|
59 | + }//end tearDown() |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Test retrieving the name(s) of the interfaces being implemented by a class. |
|
64 | + * |
|
65 | + * @param string $identifier Comment which precedes the test case. |
|
66 | + * @param bool $expected Expected function output. |
|
67 | + * |
|
68 | + * @dataProvider dataImplementedInterface |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function testFindImplementedInterfaceNames($identifier, $expected) |
|
73 | + { |
|
74 | + $start = ($this->phpcsFile->numTokens - 1); |
|
75 | + $delim = $this->phpcsFile->findPrevious( |
|
76 | + T_COMMENT, |
|
77 | + $start, |
|
78 | + null, |
|
79 | + false, |
|
80 | + $identifier |
|
81 | + ); |
|
82 | + $OOToken = $this->phpcsFile->findNext([T_CLASS, T_ANON_CLASS, T_INTERFACE], ($delim + 1)); |
|
83 | + |
|
84 | + $result = $this->phpcsFile->findImplementedInterfaceNames($OOToken); |
|
85 | + $this->assertSame($expected, $result); |
|
86 | + |
|
87 | + }//end testFindImplementedInterfaceNames() |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Data provider for the FindImplementedInterfaceNames test. |
|
92 | + * |
|
93 | + * @see testFindImplementedInterfaceNames() |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function dataImplementedInterface() |
|
98 | + { |
|
99 | + return [ |
|
100 | + [ |
|
101 | + '/* testImplementedClass */', |
|
102 | + ['testFIINInterface'], |
|
103 | + ], |
|
104 | + [ |
|
105 | + '/* testMultiImplementedClass */', |
|
106 | + [ |
|
107 | + 'testFIINInterface', |
|
108 | + 'testFIINInterface2', |
|
109 | + ], |
|
110 | + ], |
|
111 | + [ |
|
112 | + '/* testNamespacedClass */', |
|
113 | + ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface'], |
|
114 | + ], |
|
115 | + [ |
|
116 | + '/* testNonImplementedClass */', |
|
117 | + false, |
|
118 | + ], |
|
119 | + [ |
|
120 | + '/* testInterface */', |
|
121 | + false, |
|
122 | + ], |
|
123 | + [ |
|
124 | + '/* testClassThatExtendsAndImplements */', |
|
125 | + [ |
|
126 | + 'InterfaceA', |
|
127 | + '\NameSpaced\Cat\InterfaceB', |
|
128 | + ], |
|
129 | + ], |
|
130 | + [ |
|
131 | + '/* testClassThatImplementsAndExtends */', |
|
132 | + [ |
|
133 | + '\InterfaceA', |
|
134 | + 'InterfaceB', |
|
135 | + ], |
|
136 | + ], |
|
137 | + ]; |
|
138 | + |
|
139 | + }//end dataImplementedInterface() |
|
140 | 140 | |
141 | 141 | |
142 | 142 | }//end class |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | public function setUp() |
37 | 37 | { |
38 | 38 | $config = new Config(); |
39 | - $config->standards = ['Generic']; |
|
39 | + $config->standards = [ 'Generic' ]; |
|
40 | 40 | |
41 | - $ruleset = new Ruleset($config); |
|
41 | + $ruleset = new Ruleset( $config ); |
|
42 | 42 | |
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
43 | + $pathToTestFile = dirname( __FILE__ ) . '/' . basename( __FILE__, '.php' ) . '.inc'; |
|
44 | + $this->phpcsFile = new DummyFile( file_get_contents( $pathToTestFile ), $ruleset, $config ); |
|
45 | 45 | $this->phpcsFile->process(); |
46 | 46 | |
47 | 47 | }//end setUp() |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function tearDown() |
56 | 56 | { |
57 | - unset($this->phpcsFile); |
|
57 | + unset( $this->phpcsFile ); |
|
58 | 58 | |
59 | 59 | }//end tearDown() |
60 | 60 | |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function testFindImplementedInterfaceNames($identifier, $expected) |
|
72 | + public function testFindImplementedInterfaceNames( $identifier, $expected ) |
|
73 | 73 | { |
74 | - $start = ($this->phpcsFile->numTokens - 1); |
|
74 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
75 | 75 | $delim = $this->phpcsFile->findPrevious( |
76 | 76 | T_COMMENT, |
77 | 77 | $start, |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | false, |
80 | 80 | $identifier |
81 | 81 | ); |
82 | - $OOToken = $this->phpcsFile->findNext([T_CLASS, T_ANON_CLASS, T_INTERFACE], ($delim + 1)); |
|
82 | + $OOToken = $this->phpcsFile->findNext( [ T_CLASS, T_ANON_CLASS, T_INTERFACE ], ( $delim + 1 ) ); |
|
83 | 83 | |
84 | - $result = $this->phpcsFile->findImplementedInterfaceNames($OOToken); |
|
85 | - $this->assertSame($expected, $result); |
|
84 | + $result = $this->phpcsFile->findImplementedInterfaceNames( $OOToken ); |
|
85 | + $this->assertSame( $expected, $result ); |
|
86 | 86 | |
87 | 87 | }//end testFindImplementedInterfaceNames() |
88 | 88 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | return [ |
100 | 100 | [ |
101 | 101 | '/* testImplementedClass */', |
102 | - ['testFIINInterface'], |
|
102 | + [ 'testFIINInterface' ], |
|
103 | 103 | ], |
104 | 104 | [ |
105 | 105 | '/* testMultiImplementedClass */', |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | ], |
111 | 111 | [ |
112 | 112 | '/* testNamespacedClass */', |
113 | - ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface'], |
|
113 | + [ '\PHP_CodeSniffer\Tests\Core\File\testFIINInterface' ], |
|
114 | 114 | ], |
115 | 115 | [ |
116 | 116 | '/* testNonImplementedClass */', |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | use PHP_CodeSniffer\Files\DummyFile; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | 16 | |
17 | -class FindImplementedInterfaceNamesTest extends TestCase |
|
18 | -{ |
|
17 | +class FindImplementedInterfaceNamesTest extends TestCase { |
|
19 | 18 | |
20 | 19 | /** |
21 | 20 | * The \PHP_CodeSniffer\Files\File object containing parsed contents of the test case file. |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | * |
34 | 33 | * @return void |
35 | 34 | */ |
36 | - public function setUp() |
|
37 | - { |
|
35 | + public function setUp() { |
|
38 | 36 | $config = new Config(); |
39 | 37 | $config->standards = ['Generic']; |
40 | 38 | |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | * |
53 | 51 | * @return void |
54 | 52 | */ |
55 | - public function tearDown() |
|
56 | - { |
|
53 | + public function tearDown() { |
|
57 | 54 | unset($this->phpcsFile); |
58 | 55 | |
59 | 56 | }//end tearDown() |
@@ -69,8 +66,7 @@ discard block |
||
69 | 66 | * |
70 | 67 | * @return void |
71 | 68 | */ |
72 | - public function testFindImplementedInterfaceNames($identifier, $expected) |
|
73 | - { |
|
69 | + public function testFindImplementedInterfaceNames($identifier, $expected) { |
|
74 | 70 | $start = ($this->phpcsFile->numTokens - 1); |
75 | 71 | $delim = $this->phpcsFile->findPrevious( |
76 | 72 | T_COMMENT, |
@@ -94,8 +90,7 @@ discard block |
||
94 | 90 | * |
95 | 91 | * @return array |
96 | 92 | */ |
97 | - public function dataImplementedInterface() |
|
98 | - { |
|
93 | + public function dataImplementedInterface() { |
|
99 | 94 | return [ |
100 | 95 | [ |
101 | 96 | '/* testImplementedClass */', |
@@ -6,56 +6,56 @@ |
||
6 | 6 | /* testReturnFunction */ |
7 | 7 | function myFunction(array ...$arrays): array |
8 | 8 | { |
9 | - return array_map(/* testNestedClosure */function(array $array): int { |
|
10 | - return array_sum($array); |
|
11 | - }, $arrays); |
|
9 | + return array_map(/* testNestedClosure */function(array $array): int { |
|
10 | + return array_sum($array); |
|
11 | + }, $arrays); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class MyClass { |
15 | - /* testBasicMethod */ |
|
16 | - function myFunction() {} |
|
15 | + /* testBasicMethod */ |
|
16 | + function myFunction() {} |
|
17 | 17 | |
18 | - /* testPrivateStaticMethod */ |
|
19 | - private static function myFunction() {} |
|
18 | + /* testPrivateStaticMethod */ |
|
19 | + private static function myFunction() {} |
|
20 | 20 | |
21 | - /* testFinalMethod */ |
|
22 | - final public function myFunction() {} |
|
21 | + /* testFinalMethod */ |
|
22 | + final public function myFunction() {} |
|
23 | 23 | |
24 | - /* testProtectedReturnMethod */ |
|
25 | - protected function myFunction() : int {} |
|
24 | + /* testProtectedReturnMethod */ |
|
25 | + protected function myFunction() : int {} |
|
26 | 26 | |
27 | - /* testPublicReturnMethod */ |
|
28 | - public function myFunction(): array {} |
|
27 | + /* testPublicReturnMethod */ |
|
28 | + public function myFunction(): array {} |
|
29 | 29 | |
30 | - /* testNullableReturnMethod */ |
|
31 | - public function myFunction(): ?array {} |
|
30 | + /* testNullableReturnMethod */ |
|
31 | + public function myFunction(): ?array {} |
|
32 | 32 | |
33 | - /* testMessyNullableReturnMethod */ |
|
34 | - public function myFunction() /* comment |
|
33 | + /* testMessyNullableReturnMethod */ |
|
34 | + public function myFunction() /* comment |
|
35 | 35 | */ : |
36 | - /* comment */ ? //comment |
|
37 | - array {} |
|
36 | + /* comment */ ? //comment |
|
37 | + array {} |
|
38 | 38 | |
39 | - /* testReturnNamespace */ |
|
40 | - function myFunction(): \MyNamespace\MyClass {} |
|
39 | + /* testReturnNamespace */ |
|
40 | + function myFunction(): \MyNamespace\MyClass {} |
|
41 | 41 | |
42 | - /* testReturnMultilineNamespace */ |
|
43 | - function myFunction(): \MyNamespace /** comment *\/ comment */ |
|
44 | - \MyClass /* comment */ |
|
45 | - \Foo {} |
|
42 | + /* testReturnMultilineNamespace */ |
|
43 | + function myFunction(): \MyNamespace /** comment *\/ comment */ |
|
44 | + \MyClass /* comment */ |
|
45 | + \Foo {} |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | abstract class MyClass |
49 | 49 | { |
50 | - /* testAbstractMethod */ |
|
51 | - abstract function myFunction(); |
|
50 | + /* testAbstractMethod */ |
|
51 | + abstract function myFunction(); |
|
52 | 52 | |
53 | - /* testAbstractReturnMethod */ |
|
54 | - abstract protected function myFunction(): bool; |
|
53 | + /* testAbstractReturnMethod */ |
|
54 | + abstract protected function myFunction(): bool; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | interface MyInterface |
58 | 58 | { |
59 | - /* testInterfaceMethod */ |
|
60 | - function myFunction(); |
|
59 | + /* testInterfaceMethod */ |
|
60 | + function myFunction(); |
|
61 | 61 | } |
@@ -4,10 +4,10 @@ |
||
4 | 4 | function myFunction() {} |
5 | 5 | |
6 | 6 | /* testReturnFunction */ |
7 | -function myFunction(array ...$arrays): array |
|
7 | +function myFunction( array ...$arrays ): array |
|
8 | 8 | { |
9 | - return array_map(/* testNestedClosure */function(array $array): int { |
|
10 | - return array_sum($array); |
|
9 | + return array_map(/* testNestedClosure */function( array $array ): int { |
|
10 | + return array_sum( $array ); |
|
11 | 11 | }, $arrays); |
12 | 12 | } |
13 | 13 |
@@ -45,8 +45,7 @@ discard block |
||
45 | 45 | \Foo {} |
46 | 46 | } |
47 | 47 | |
48 | -abstract class MyClass |
|
49 | -{ |
|
48 | +abstract class MyClass { |
|
50 | 49 | /* testAbstractMethod */ |
51 | 50 | abstract function myFunction(); |
52 | 51 | |
@@ -54,8 +53,7 @@ discard block |
||
54 | 53 | abstract protected function myFunction(): bool; |
55 | 54 | } |
56 | 55 | |
57 | -interface MyInterface |
|
58 | -{ |
|
56 | +interface MyInterface { |
|
59 | 57 | /* testInterfaceMethod */ |
60 | 58 | function myFunction(); |
61 | 59 | } |
@@ -17,388 +17,388 @@ |
||
17 | 17 | class GetMethodParametersTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
|
22 | - * |
|
23 | - * @var \PHP_CodeSniffer\Files\File |
|
24 | - */ |
|
25 | - private $phpcsFile; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Initialize & tokenize PHP_CodeSniffer_File with code from the test case file. |
|
30 | - * |
|
31 | - * Methods used for these tests can be found in a test case file in the same |
|
32 | - * directory and with the same name, using the .inc extension. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setUp() |
|
37 | - { |
|
38 | - $config = new Config(); |
|
39 | - $config->standards = ['Generic']; |
|
40 | - |
|
41 | - $ruleset = new Ruleset($config); |
|
42 | - |
|
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | - $this->phpcsFile->process(); |
|
46 | - |
|
47 | - }//end setUp() |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Clean up after finished test. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function tearDown() |
|
56 | - { |
|
57 | - unset($this->phpcsFile); |
|
58 | - |
|
59 | - }//end tearDown() |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Verify pass-by-reference parsing. |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function testPassByReference() |
|
68 | - { |
|
69 | - $expected = []; |
|
70 | - $expected[0] = [ |
|
71 | - 'name' => '$var', |
|
72 | - 'content' => '&$var', |
|
73 | - 'pass_by_reference' => true, |
|
74 | - 'variable_length' => false, |
|
75 | - 'type_hint' => '', |
|
76 | - 'nullable_type' => false, |
|
77 | - ]; |
|
78 | - |
|
79 | - $start = ($this->phpcsFile->numTokens - 1); |
|
80 | - $function = $this->phpcsFile->findPrevious( |
|
81 | - T_COMMENT, |
|
82 | - $start, |
|
83 | - null, |
|
84 | - false, |
|
85 | - '/* testPassByReference */' |
|
86 | - ); |
|
87 | - |
|
88 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
89 | - unset($found[0]['token']); |
|
90 | - unset($found[0]['type_hint_token']); |
|
91 | - $this->assertSame($expected, $found); |
|
92 | - |
|
93 | - }//end testPassByReference() |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Verify array hint parsing. |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public function testArrayHint() |
|
102 | - { |
|
103 | - $expected = []; |
|
104 | - $expected[0] = [ |
|
105 | - 'name' => '$var', |
|
106 | - 'content' => 'array $var', |
|
107 | - 'pass_by_reference' => false, |
|
108 | - 'variable_length' => false, |
|
109 | - 'type_hint' => 'array', |
|
110 | - 'nullable_type' => false, |
|
111 | - ]; |
|
112 | - |
|
113 | - $start = ($this->phpcsFile->numTokens - 1); |
|
114 | - $function = $this->phpcsFile->findPrevious( |
|
115 | - T_COMMENT, |
|
116 | - $start, |
|
117 | - null, |
|
118 | - false, |
|
119 | - '/* testArrayHint */' |
|
120 | - ); |
|
121 | - |
|
122 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
123 | - unset($found[0]['token']); |
|
124 | - unset($found[0]['type_hint_token']); |
|
125 | - $this->assertSame($expected, $found); |
|
126 | - |
|
127 | - }//end testArrayHint() |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Verify type hint parsing. |
|
132 | - * |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - public function testTypeHint() |
|
136 | - { |
|
137 | - $expected = []; |
|
138 | - $expected[0] = [ |
|
139 | - 'name' => '$var1', |
|
140 | - 'content' => 'foo $var1', |
|
141 | - 'pass_by_reference' => false, |
|
142 | - 'variable_length' => false, |
|
143 | - 'type_hint' => 'foo', |
|
144 | - 'nullable_type' => false, |
|
145 | - ]; |
|
146 | - |
|
147 | - $expected[1] = [ |
|
148 | - 'name' => '$var2', |
|
149 | - 'content' => 'bar $var2', |
|
150 | - 'pass_by_reference' => false, |
|
151 | - 'variable_length' => false, |
|
152 | - 'type_hint' => 'bar', |
|
153 | - 'nullable_type' => false, |
|
154 | - ]; |
|
155 | - |
|
156 | - $start = ($this->phpcsFile->numTokens - 1); |
|
157 | - $function = $this->phpcsFile->findPrevious( |
|
158 | - T_COMMENT, |
|
159 | - $start, |
|
160 | - null, |
|
161 | - false, |
|
162 | - '/* testTypeHint */' |
|
163 | - ); |
|
164 | - |
|
165 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
166 | - unset($found[0]['token']); |
|
167 | - unset($found[1]['token']); |
|
168 | - unset($found[0]['type_hint_token']); |
|
169 | - unset($found[1]['type_hint_token']); |
|
170 | - $this->assertSame($expected, $found); |
|
171 | - |
|
172 | - }//end testTypeHint() |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * Verify self type hint parsing. |
|
177 | - * |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - public function testSelfTypeHint() |
|
181 | - { |
|
182 | - $expected = []; |
|
183 | - $expected[0] = [ |
|
184 | - 'name' => '$var', |
|
185 | - 'content' => 'self $var', |
|
186 | - 'pass_by_reference' => false, |
|
187 | - 'variable_length' => false, |
|
188 | - 'type_hint' => 'self', |
|
189 | - 'nullable_type' => false, |
|
190 | - ]; |
|
191 | - |
|
192 | - $start = ($this->phpcsFile->numTokens - 1); |
|
193 | - $function = $this->phpcsFile->findPrevious( |
|
194 | - T_COMMENT, |
|
195 | - $start, |
|
196 | - null, |
|
197 | - false, |
|
198 | - '/* testSelfTypeHint */' |
|
199 | - ); |
|
200 | - |
|
201 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
202 | - unset($found[0]['token']); |
|
203 | - unset($found[0]['type_hint_token']); |
|
204 | - $this->assertSame($expected, $found); |
|
205 | - |
|
206 | - }//end testSelfTypeHint() |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * Verify nullable type hint parsing. |
|
211 | - * |
|
212 | - * @return void |
|
213 | - */ |
|
214 | - public function testNullableTypeHint() |
|
215 | - { |
|
216 | - $expected = []; |
|
217 | - $expected[0] = [ |
|
218 | - 'name' => '$var1', |
|
219 | - 'content' => '?int $var1', |
|
220 | - 'pass_by_reference' => false, |
|
221 | - 'variable_length' => false, |
|
222 | - 'type_hint' => '?int', |
|
223 | - 'nullable_type' => true, |
|
224 | - ]; |
|
225 | - |
|
226 | - $expected[1] = [ |
|
227 | - 'name' => '$var2', |
|
228 | - 'content' => '?\bar $var2', |
|
229 | - 'pass_by_reference' => false, |
|
230 | - 'variable_length' => false, |
|
231 | - 'type_hint' => '?\bar', |
|
232 | - 'nullable_type' => true, |
|
233 | - ]; |
|
234 | - |
|
235 | - $start = ($this->phpcsFile->numTokens - 1); |
|
236 | - $function = $this->phpcsFile->findPrevious( |
|
237 | - T_COMMENT, |
|
238 | - $start, |
|
239 | - null, |
|
240 | - false, |
|
241 | - '/* testNullableTypeHint */' |
|
242 | - ); |
|
243 | - |
|
244 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
245 | - unset($found[0]['token']); |
|
246 | - unset($found[1]['token']); |
|
247 | - unset($found[0]['type_hint_token']); |
|
248 | - unset($found[1]['type_hint_token']); |
|
249 | - $this->assertSame($expected, $found); |
|
250 | - |
|
251 | - }//end testNullableTypeHint() |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Verify variable. |
|
256 | - * |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function testVariable() |
|
260 | - { |
|
261 | - $expected = []; |
|
262 | - $expected[0] = [ |
|
263 | - 'name' => '$var', |
|
264 | - 'content' => '$var', |
|
265 | - 'pass_by_reference' => false, |
|
266 | - 'variable_length' => false, |
|
267 | - 'type_hint' => '', |
|
268 | - 'nullable_type' => false, |
|
269 | - ]; |
|
270 | - |
|
271 | - $start = ($this->phpcsFile->numTokens - 1); |
|
272 | - $function = $this->phpcsFile->findPrevious( |
|
273 | - T_COMMENT, |
|
274 | - $start, |
|
275 | - null, |
|
276 | - false, |
|
277 | - '/* testVariable */' |
|
278 | - ); |
|
279 | - |
|
280 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
281 | - unset($found[0]['token']); |
|
282 | - unset($found[0]['type_hint_token']); |
|
283 | - $this->assertSame($expected, $found); |
|
284 | - |
|
285 | - }//end testVariable() |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * Verify default value parsing with a single function param. |
|
290 | - * |
|
291 | - * @return void |
|
292 | - */ |
|
293 | - public function testSingleDefaultValue() |
|
294 | - { |
|
295 | - $expected = []; |
|
296 | - $expected[0] = [ |
|
297 | - 'name' => '$var1', |
|
298 | - 'content' => '$var1=self::CONSTANT', |
|
299 | - 'default' => 'self::CONSTANT', |
|
300 | - 'pass_by_reference' => false, |
|
301 | - 'variable_length' => false, |
|
302 | - 'type_hint' => '', |
|
303 | - 'nullable_type' => false, |
|
304 | - ]; |
|
305 | - |
|
306 | - $start = ($this->phpcsFile->numTokens - 1); |
|
307 | - $function = $this->phpcsFile->findPrevious( |
|
308 | - T_COMMENT, |
|
309 | - $start, |
|
310 | - null, |
|
311 | - false, |
|
312 | - '/* testSingleDefaultValue */' |
|
313 | - ); |
|
314 | - |
|
315 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
316 | - unset($found[0]['token']); |
|
317 | - unset($found[0]['type_hint_token']); |
|
318 | - $this->assertSame($expected, $found); |
|
319 | - |
|
320 | - }//end testSingleDefaultValue() |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * Verify default value parsing. |
|
325 | - * |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - public function testDefaultValues() |
|
329 | - { |
|
330 | - $expected = []; |
|
331 | - $expected[0] = [ |
|
332 | - 'name' => '$var1', |
|
333 | - 'content' => '$var1=1', |
|
334 | - 'default' => '1', |
|
335 | - 'pass_by_reference' => false, |
|
336 | - 'variable_length' => false, |
|
337 | - 'type_hint' => '', |
|
338 | - 'nullable_type' => false, |
|
339 | - ]; |
|
340 | - $expected[1] = [ |
|
341 | - 'name' => '$var2', |
|
342 | - 'content' => "\$var2='value'", |
|
343 | - 'default' => "'value'", |
|
344 | - 'pass_by_reference' => false, |
|
345 | - 'variable_length' => false, |
|
346 | - 'type_hint' => '', |
|
347 | - 'nullable_type' => false, |
|
348 | - ]; |
|
349 | - |
|
350 | - $start = ($this->phpcsFile->numTokens - 1); |
|
351 | - $function = $this->phpcsFile->findPrevious( |
|
352 | - T_COMMENT, |
|
353 | - $start, |
|
354 | - null, |
|
355 | - false, |
|
356 | - '/* testDefaultValues */' |
|
357 | - ); |
|
358 | - |
|
359 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
360 | - unset($found[0]['token']); |
|
361 | - unset($found[1]['token']); |
|
362 | - unset($found[0]['type_hint_token']); |
|
363 | - unset($found[1]['type_hint_token']); |
|
364 | - $this->assertSame($expected, $found); |
|
365 | - |
|
366 | - }//end testDefaultValues() |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Verify "bitwise and" in default value !== pass-by-reference. |
|
371 | - * |
|
372 | - * @return void |
|
373 | - */ |
|
374 | - public function testBitwiseAndConstantExpressionDefaultValue() |
|
375 | - { |
|
376 | - $expected = []; |
|
377 | - $expected[0] = [ |
|
378 | - 'name' => '$a', |
|
379 | - 'content' => '$a = 10 & 20', |
|
380 | - 'default' => '10 & 20', |
|
381 | - 'pass_by_reference' => false, |
|
382 | - 'variable_length' => false, |
|
383 | - 'type_hint' => '', |
|
384 | - 'nullable_type' => false, |
|
385 | - ]; |
|
386 | - |
|
387 | - $start = ($this->phpcsFile->numTokens - 1); |
|
388 | - $function = $this->phpcsFile->findPrevious( |
|
389 | - T_COMMENT, |
|
390 | - $start, |
|
391 | - null, |
|
392 | - false, |
|
393 | - '/* testBitwiseAndConstantExpressionDefaultValue */' |
|
394 | - ); |
|
395 | - |
|
396 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
397 | - unset($found[0]['token']); |
|
398 | - unset($found[0]['type_hint_token']); |
|
399 | - $this->assertSame($expected, $found); |
|
400 | - |
|
401 | - }//end testBitwiseAndConstantExpressionDefaultValue() |
|
20 | + /** |
|
21 | + * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
|
22 | + * |
|
23 | + * @var \PHP_CodeSniffer\Files\File |
|
24 | + */ |
|
25 | + private $phpcsFile; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Initialize & tokenize PHP_CodeSniffer_File with code from the test case file. |
|
30 | + * |
|
31 | + * Methods used for these tests can be found in a test case file in the same |
|
32 | + * directory and with the same name, using the .inc extension. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setUp() |
|
37 | + { |
|
38 | + $config = new Config(); |
|
39 | + $config->standards = ['Generic']; |
|
40 | + |
|
41 | + $ruleset = new Ruleset($config); |
|
42 | + |
|
43 | + $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | + $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | + $this->phpcsFile->process(); |
|
46 | + |
|
47 | + }//end setUp() |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Clean up after finished test. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function tearDown() |
|
56 | + { |
|
57 | + unset($this->phpcsFile); |
|
58 | + |
|
59 | + }//end tearDown() |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Verify pass-by-reference parsing. |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function testPassByReference() |
|
68 | + { |
|
69 | + $expected = []; |
|
70 | + $expected[0] = [ |
|
71 | + 'name' => '$var', |
|
72 | + 'content' => '&$var', |
|
73 | + 'pass_by_reference' => true, |
|
74 | + 'variable_length' => false, |
|
75 | + 'type_hint' => '', |
|
76 | + 'nullable_type' => false, |
|
77 | + ]; |
|
78 | + |
|
79 | + $start = ($this->phpcsFile->numTokens - 1); |
|
80 | + $function = $this->phpcsFile->findPrevious( |
|
81 | + T_COMMENT, |
|
82 | + $start, |
|
83 | + null, |
|
84 | + false, |
|
85 | + '/* testPassByReference */' |
|
86 | + ); |
|
87 | + |
|
88 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
89 | + unset($found[0]['token']); |
|
90 | + unset($found[0]['type_hint_token']); |
|
91 | + $this->assertSame($expected, $found); |
|
92 | + |
|
93 | + }//end testPassByReference() |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Verify array hint parsing. |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public function testArrayHint() |
|
102 | + { |
|
103 | + $expected = []; |
|
104 | + $expected[0] = [ |
|
105 | + 'name' => '$var', |
|
106 | + 'content' => 'array $var', |
|
107 | + 'pass_by_reference' => false, |
|
108 | + 'variable_length' => false, |
|
109 | + 'type_hint' => 'array', |
|
110 | + 'nullable_type' => false, |
|
111 | + ]; |
|
112 | + |
|
113 | + $start = ($this->phpcsFile->numTokens - 1); |
|
114 | + $function = $this->phpcsFile->findPrevious( |
|
115 | + T_COMMENT, |
|
116 | + $start, |
|
117 | + null, |
|
118 | + false, |
|
119 | + '/* testArrayHint */' |
|
120 | + ); |
|
121 | + |
|
122 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
123 | + unset($found[0]['token']); |
|
124 | + unset($found[0]['type_hint_token']); |
|
125 | + $this->assertSame($expected, $found); |
|
126 | + |
|
127 | + }//end testArrayHint() |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Verify type hint parsing. |
|
132 | + * |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + public function testTypeHint() |
|
136 | + { |
|
137 | + $expected = []; |
|
138 | + $expected[0] = [ |
|
139 | + 'name' => '$var1', |
|
140 | + 'content' => 'foo $var1', |
|
141 | + 'pass_by_reference' => false, |
|
142 | + 'variable_length' => false, |
|
143 | + 'type_hint' => 'foo', |
|
144 | + 'nullable_type' => false, |
|
145 | + ]; |
|
146 | + |
|
147 | + $expected[1] = [ |
|
148 | + 'name' => '$var2', |
|
149 | + 'content' => 'bar $var2', |
|
150 | + 'pass_by_reference' => false, |
|
151 | + 'variable_length' => false, |
|
152 | + 'type_hint' => 'bar', |
|
153 | + 'nullable_type' => false, |
|
154 | + ]; |
|
155 | + |
|
156 | + $start = ($this->phpcsFile->numTokens - 1); |
|
157 | + $function = $this->phpcsFile->findPrevious( |
|
158 | + T_COMMENT, |
|
159 | + $start, |
|
160 | + null, |
|
161 | + false, |
|
162 | + '/* testTypeHint */' |
|
163 | + ); |
|
164 | + |
|
165 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
166 | + unset($found[0]['token']); |
|
167 | + unset($found[1]['token']); |
|
168 | + unset($found[0]['type_hint_token']); |
|
169 | + unset($found[1]['type_hint_token']); |
|
170 | + $this->assertSame($expected, $found); |
|
171 | + |
|
172 | + }//end testTypeHint() |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * Verify self type hint parsing. |
|
177 | + * |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + public function testSelfTypeHint() |
|
181 | + { |
|
182 | + $expected = []; |
|
183 | + $expected[0] = [ |
|
184 | + 'name' => '$var', |
|
185 | + 'content' => 'self $var', |
|
186 | + 'pass_by_reference' => false, |
|
187 | + 'variable_length' => false, |
|
188 | + 'type_hint' => 'self', |
|
189 | + 'nullable_type' => false, |
|
190 | + ]; |
|
191 | + |
|
192 | + $start = ($this->phpcsFile->numTokens - 1); |
|
193 | + $function = $this->phpcsFile->findPrevious( |
|
194 | + T_COMMENT, |
|
195 | + $start, |
|
196 | + null, |
|
197 | + false, |
|
198 | + '/* testSelfTypeHint */' |
|
199 | + ); |
|
200 | + |
|
201 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
202 | + unset($found[0]['token']); |
|
203 | + unset($found[0]['type_hint_token']); |
|
204 | + $this->assertSame($expected, $found); |
|
205 | + |
|
206 | + }//end testSelfTypeHint() |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * Verify nullable type hint parsing. |
|
211 | + * |
|
212 | + * @return void |
|
213 | + */ |
|
214 | + public function testNullableTypeHint() |
|
215 | + { |
|
216 | + $expected = []; |
|
217 | + $expected[0] = [ |
|
218 | + 'name' => '$var1', |
|
219 | + 'content' => '?int $var1', |
|
220 | + 'pass_by_reference' => false, |
|
221 | + 'variable_length' => false, |
|
222 | + 'type_hint' => '?int', |
|
223 | + 'nullable_type' => true, |
|
224 | + ]; |
|
225 | + |
|
226 | + $expected[1] = [ |
|
227 | + 'name' => '$var2', |
|
228 | + 'content' => '?\bar $var2', |
|
229 | + 'pass_by_reference' => false, |
|
230 | + 'variable_length' => false, |
|
231 | + 'type_hint' => '?\bar', |
|
232 | + 'nullable_type' => true, |
|
233 | + ]; |
|
234 | + |
|
235 | + $start = ($this->phpcsFile->numTokens - 1); |
|
236 | + $function = $this->phpcsFile->findPrevious( |
|
237 | + T_COMMENT, |
|
238 | + $start, |
|
239 | + null, |
|
240 | + false, |
|
241 | + '/* testNullableTypeHint */' |
|
242 | + ); |
|
243 | + |
|
244 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
245 | + unset($found[0]['token']); |
|
246 | + unset($found[1]['token']); |
|
247 | + unset($found[0]['type_hint_token']); |
|
248 | + unset($found[1]['type_hint_token']); |
|
249 | + $this->assertSame($expected, $found); |
|
250 | + |
|
251 | + }//end testNullableTypeHint() |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Verify variable. |
|
256 | + * |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function testVariable() |
|
260 | + { |
|
261 | + $expected = []; |
|
262 | + $expected[0] = [ |
|
263 | + 'name' => '$var', |
|
264 | + 'content' => '$var', |
|
265 | + 'pass_by_reference' => false, |
|
266 | + 'variable_length' => false, |
|
267 | + 'type_hint' => '', |
|
268 | + 'nullable_type' => false, |
|
269 | + ]; |
|
270 | + |
|
271 | + $start = ($this->phpcsFile->numTokens - 1); |
|
272 | + $function = $this->phpcsFile->findPrevious( |
|
273 | + T_COMMENT, |
|
274 | + $start, |
|
275 | + null, |
|
276 | + false, |
|
277 | + '/* testVariable */' |
|
278 | + ); |
|
279 | + |
|
280 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
281 | + unset($found[0]['token']); |
|
282 | + unset($found[0]['type_hint_token']); |
|
283 | + $this->assertSame($expected, $found); |
|
284 | + |
|
285 | + }//end testVariable() |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * Verify default value parsing with a single function param. |
|
290 | + * |
|
291 | + * @return void |
|
292 | + */ |
|
293 | + public function testSingleDefaultValue() |
|
294 | + { |
|
295 | + $expected = []; |
|
296 | + $expected[0] = [ |
|
297 | + 'name' => '$var1', |
|
298 | + 'content' => '$var1=self::CONSTANT', |
|
299 | + 'default' => 'self::CONSTANT', |
|
300 | + 'pass_by_reference' => false, |
|
301 | + 'variable_length' => false, |
|
302 | + 'type_hint' => '', |
|
303 | + 'nullable_type' => false, |
|
304 | + ]; |
|
305 | + |
|
306 | + $start = ($this->phpcsFile->numTokens - 1); |
|
307 | + $function = $this->phpcsFile->findPrevious( |
|
308 | + T_COMMENT, |
|
309 | + $start, |
|
310 | + null, |
|
311 | + false, |
|
312 | + '/* testSingleDefaultValue */' |
|
313 | + ); |
|
314 | + |
|
315 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
316 | + unset($found[0]['token']); |
|
317 | + unset($found[0]['type_hint_token']); |
|
318 | + $this->assertSame($expected, $found); |
|
319 | + |
|
320 | + }//end testSingleDefaultValue() |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * Verify default value parsing. |
|
325 | + * |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + public function testDefaultValues() |
|
329 | + { |
|
330 | + $expected = []; |
|
331 | + $expected[0] = [ |
|
332 | + 'name' => '$var1', |
|
333 | + 'content' => '$var1=1', |
|
334 | + 'default' => '1', |
|
335 | + 'pass_by_reference' => false, |
|
336 | + 'variable_length' => false, |
|
337 | + 'type_hint' => '', |
|
338 | + 'nullable_type' => false, |
|
339 | + ]; |
|
340 | + $expected[1] = [ |
|
341 | + 'name' => '$var2', |
|
342 | + 'content' => "\$var2='value'", |
|
343 | + 'default' => "'value'", |
|
344 | + 'pass_by_reference' => false, |
|
345 | + 'variable_length' => false, |
|
346 | + 'type_hint' => '', |
|
347 | + 'nullable_type' => false, |
|
348 | + ]; |
|
349 | + |
|
350 | + $start = ($this->phpcsFile->numTokens - 1); |
|
351 | + $function = $this->phpcsFile->findPrevious( |
|
352 | + T_COMMENT, |
|
353 | + $start, |
|
354 | + null, |
|
355 | + false, |
|
356 | + '/* testDefaultValues */' |
|
357 | + ); |
|
358 | + |
|
359 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
360 | + unset($found[0]['token']); |
|
361 | + unset($found[1]['token']); |
|
362 | + unset($found[0]['type_hint_token']); |
|
363 | + unset($found[1]['type_hint_token']); |
|
364 | + $this->assertSame($expected, $found); |
|
365 | + |
|
366 | + }//end testDefaultValues() |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Verify "bitwise and" in default value !== pass-by-reference. |
|
371 | + * |
|
372 | + * @return void |
|
373 | + */ |
|
374 | + public function testBitwiseAndConstantExpressionDefaultValue() |
|
375 | + { |
|
376 | + $expected = []; |
|
377 | + $expected[0] = [ |
|
378 | + 'name' => '$a', |
|
379 | + 'content' => '$a = 10 & 20', |
|
380 | + 'default' => '10 & 20', |
|
381 | + 'pass_by_reference' => false, |
|
382 | + 'variable_length' => false, |
|
383 | + 'type_hint' => '', |
|
384 | + 'nullable_type' => false, |
|
385 | + ]; |
|
386 | + |
|
387 | + $start = ($this->phpcsFile->numTokens - 1); |
|
388 | + $function = $this->phpcsFile->findPrevious( |
|
389 | + T_COMMENT, |
|
390 | + $start, |
|
391 | + null, |
|
392 | + false, |
|
393 | + '/* testBitwiseAndConstantExpressionDefaultValue */' |
|
394 | + ); |
|
395 | + |
|
396 | + $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
397 | + unset($found[0]['token']); |
|
398 | + unset($found[0]['type_hint_token']); |
|
399 | + $this->assertSame($expected, $found); |
|
400 | + |
|
401 | + }//end testBitwiseAndConstantExpressionDefaultValue() |
|
402 | 402 | |
403 | 403 | |
404 | 404 | }//end class |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | public function setUp() |
37 | 37 | { |
38 | 38 | $config = new Config(); |
39 | - $config->standards = ['Generic']; |
|
39 | + $config->standards = [ 'Generic' ]; |
|
40 | 40 | |
41 | - $ruleset = new Ruleset($config); |
|
41 | + $ruleset = new Ruleset( $config ); |
|
42 | 42 | |
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
43 | + $pathToTestFile = dirname( __FILE__ ) . '/' . basename( __FILE__, '.php' ) . '.inc'; |
|
44 | + $this->phpcsFile = new DummyFile( file_get_contents( $pathToTestFile ), $ruleset, $config ); |
|
45 | 45 | $this->phpcsFile->process(); |
46 | 46 | |
47 | 47 | }//end setUp() |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function tearDown() |
56 | 56 | { |
57 | - unset($this->phpcsFile); |
|
57 | + unset( $this->phpcsFile ); |
|
58 | 58 | |
59 | 59 | }//end tearDown() |
60 | 60 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function testPassByReference() |
68 | 68 | { |
69 | - $expected = []; |
|
70 | - $expected[0] = [ |
|
69 | + $expected = [ ]; |
|
70 | + $expected[ 0 ] = [ |
|
71 | 71 | 'name' => '$var', |
72 | 72 | 'content' => '&$var', |
73 | 73 | 'pass_by_reference' => true, |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | 'nullable_type' => false, |
77 | 77 | ]; |
78 | 78 | |
79 | - $start = ($this->phpcsFile->numTokens - 1); |
|
79 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
80 | 80 | $function = $this->phpcsFile->findPrevious( |
81 | 81 | T_COMMENT, |
82 | 82 | $start, |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | '/* testPassByReference */' |
86 | 86 | ); |
87 | 87 | |
88 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
89 | - unset($found[0]['token']); |
|
90 | - unset($found[0]['type_hint_token']); |
|
91 | - $this->assertSame($expected, $found); |
|
88 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
89 | + unset( $found[ 0 ][ 'token' ] ); |
|
90 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
91 | + $this->assertSame( $expected, $found ); |
|
92 | 92 | |
93 | 93 | }//end testPassByReference() |
94 | 94 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function testArrayHint() |
102 | 102 | { |
103 | - $expected = []; |
|
104 | - $expected[0] = [ |
|
103 | + $expected = [ ]; |
|
104 | + $expected[ 0 ] = [ |
|
105 | 105 | 'name' => '$var', |
106 | 106 | 'content' => 'array $var', |
107 | 107 | 'pass_by_reference' => false, |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | 'nullable_type' => false, |
111 | 111 | ]; |
112 | 112 | |
113 | - $start = ($this->phpcsFile->numTokens - 1); |
|
113 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
114 | 114 | $function = $this->phpcsFile->findPrevious( |
115 | 115 | T_COMMENT, |
116 | 116 | $start, |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | '/* testArrayHint */' |
120 | 120 | ); |
121 | 121 | |
122 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
123 | - unset($found[0]['token']); |
|
124 | - unset($found[0]['type_hint_token']); |
|
125 | - $this->assertSame($expected, $found); |
|
122 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
123 | + unset( $found[ 0 ][ 'token' ] ); |
|
124 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
125 | + $this->assertSame( $expected, $found ); |
|
126 | 126 | |
127 | 127 | }//end testArrayHint() |
128 | 128 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function testTypeHint() |
136 | 136 | { |
137 | - $expected = []; |
|
138 | - $expected[0] = [ |
|
137 | + $expected = [ ]; |
|
138 | + $expected[ 0 ] = [ |
|
139 | 139 | 'name' => '$var1', |
140 | 140 | 'content' => 'foo $var1', |
141 | 141 | 'pass_by_reference' => false, |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | 'nullable_type' => false, |
145 | 145 | ]; |
146 | 146 | |
147 | - $expected[1] = [ |
|
147 | + $expected[ 1 ] = [ |
|
148 | 148 | 'name' => '$var2', |
149 | 149 | 'content' => 'bar $var2', |
150 | 150 | 'pass_by_reference' => false, |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | 'nullable_type' => false, |
154 | 154 | ]; |
155 | 155 | |
156 | - $start = ($this->phpcsFile->numTokens - 1); |
|
156 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
157 | 157 | $function = $this->phpcsFile->findPrevious( |
158 | 158 | T_COMMENT, |
159 | 159 | $start, |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | '/* testTypeHint */' |
163 | 163 | ); |
164 | 164 | |
165 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
166 | - unset($found[0]['token']); |
|
167 | - unset($found[1]['token']); |
|
168 | - unset($found[0]['type_hint_token']); |
|
169 | - unset($found[1]['type_hint_token']); |
|
170 | - $this->assertSame($expected, $found); |
|
165 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
166 | + unset( $found[ 0 ][ 'token' ] ); |
|
167 | + unset( $found[ 1 ][ 'token' ] ); |
|
168 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
169 | + unset( $found[ 1 ][ 'type_hint_token' ] ); |
|
170 | + $this->assertSame( $expected, $found ); |
|
171 | 171 | |
172 | 172 | }//end testTypeHint() |
173 | 173 | |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function testSelfTypeHint() |
181 | 181 | { |
182 | - $expected = []; |
|
183 | - $expected[0] = [ |
|
182 | + $expected = [ ]; |
|
183 | + $expected[ 0 ] = [ |
|
184 | 184 | 'name' => '$var', |
185 | 185 | 'content' => 'self $var', |
186 | 186 | 'pass_by_reference' => false, |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'nullable_type' => false, |
190 | 190 | ]; |
191 | 191 | |
192 | - $start = ($this->phpcsFile->numTokens - 1); |
|
192 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
193 | 193 | $function = $this->phpcsFile->findPrevious( |
194 | 194 | T_COMMENT, |
195 | 195 | $start, |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | '/* testSelfTypeHint */' |
199 | 199 | ); |
200 | 200 | |
201 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
202 | - unset($found[0]['token']); |
|
203 | - unset($found[0]['type_hint_token']); |
|
204 | - $this->assertSame($expected, $found); |
|
201 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
202 | + unset( $found[ 0 ][ 'token' ] ); |
|
203 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
204 | + $this->assertSame( $expected, $found ); |
|
205 | 205 | |
206 | 206 | }//end testSelfTypeHint() |
207 | 207 | |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | */ |
214 | 214 | public function testNullableTypeHint() |
215 | 215 | { |
216 | - $expected = []; |
|
217 | - $expected[0] = [ |
|
216 | + $expected = [ ]; |
|
217 | + $expected[ 0 ] = [ |
|
218 | 218 | 'name' => '$var1', |
219 | 219 | 'content' => '?int $var1', |
220 | 220 | 'pass_by_reference' => false, |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | 'nullable_type' => true, |
224 | 224 | ]; |
225 | 225 | |
226 | - $expected[1] = [ |
|
226 | + $expected[ 1 ] = [ |
|
227 | 227 | 'name' => '$var2', |
228 | 228 | 'content' => '?\bar $var2', |
229 | 229 | 'pass_by_reference' => false, |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | 'nullable_type' => true, |
233 | 233 | ]; |
234 | 234 | |
235 | - $start = ($this->phpcsFile->numTokens - 1); |
|
235 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
236 | 236 | $function = $this->phpcsFile->findPrevious( |
237 | 237 | T_COMMENT, |
238 | 238 | $start, |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | '/* testNullableTypeHint */' |
242 | 242 | ); |
243 | 243 | |
244 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
245 | - unset($found[0]['token']); |
|
246 | - unset($found[1]['token']); |
|
247 | - unset($found[0]['type_hint_token']); |
|
248 | - unset($found[1]['type_hint_token']); |
|
249 | - $this->assertSame($expected, $found); |
|
244 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
245 | + unset( $found[ 0 ][ 'token' ] ); |
|
246 | + unset( $found[ 1 ][ 'token' ] ); |
|
247 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
248 | + unset( $found[ 1 ][ 'type_hint_token' ] ); |
|
249 | + $this->assertSame( $expected, $found ); |
|
250 | 250 | |
251 | 251 | }//end testNullableTypeHint() |
252 | 252 | |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function testVariable() |
260 | 260 | { |
261 | - $expected = []; |
|
262 | - $expected[0] = [ |
|
261 | + $expected = [ ]; |
|
262 | + $expected[ 0 ] = [ |
|
263 | 263 | 'name' => '$var', |
264 | 264 | 'content' => '$var', |
265 | 265 | 'pass_by_reference' => false, |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | 'nullable_type' => false, |
269 | 269 | ]; |
270 | 270 | |
271 | - $start = ($this->phpcsFile->numTokens - 1); |
|
271 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
272 | 272 | $function = $this->phpcsFile->findPrevious( |
273 | 273 | T_COMMENT, |
274 | 274 | $start, |
@@ -277,10 +277,10 @@ discard block |
||
277 | 277 | '/* testVariable */' |
278 | 278 | ); |
279 | 279 | |
280 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
281 | - unset($found[0]['token']); |
|
282 | - unset($found[0]['type_hint_token']); |
|
283 | - $this->assertSame($expected, $found); |
|
280 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
281 | + unset( $found[ 0 ][ 'token' ] ); |
|
282 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
283 | + $this->assertSame( $expected, $found ); |
|
284 | 284 | |
285 | 285 | }//end testVariable() |
286 | 286 | |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function testSingleDefaultValue() |
294 | 294 | { |
295 | - $expected = []; |
|
296 | - $expected[0] = [ |
|
295 | + $expected = [ ]; |
|
296 | + $expected[ 0 ] = [ |
|
297 | 297 | 'name' => '$var1', |
298 | 298 | 'content' => '$var1=self::CONSTANT', |
299 | 299 | 'default' => 'self::CONSTANT', |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | 'nullable_type' => false, |
304 | 304 | ]; |
305 | 305 | |
306 | - $start = ($this->phpcsFile->numTokens - 1); |
|
306 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
307 | 307 | $function = $this->phpcsFile->findPrevious( |
308 | 308 | T_COMMENT, |
309 | 309 | $start, |
@@ -312,10 +312,10 @@ discard block |
||
312 | 312 | '/* testSingleDefaultValue */' |
313 | 313 | ); |
314 | 314 | |
315 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
316 | - unset($found[0]['token']); |
|
317 | - unset($found[0]['type_hint_token']); |
|
318 | - $this->assertSame($expected, $found); |
|
315 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
316 | + unset( $found[ 0 ][ 'token' ] ); |
|
317 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
318 | + $this->assertSame( $expected, $found ); |
|
319 | 319 | |
320 | 320 | }//end testSingleDefaultValue() |
321 | 321 | |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | */ |
328 | 328 | public function testDefaultValues() |
329 | 329 | { |
330 | - $expected = []; |
|
331 | - $expected[0] = [ |
|
330 | + $expected = [ ]; |
|
331 | + $expected[ 0 ] = [ |
|
332 | 332 | 'name' => '$var1', |
333 | 333 | 'content' => '$var1=1', |
334 | 334 | 'default' => '1', |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | 'type_hint' => '', |
338 | 338 | 'nullable_type' => false, |
339 | 339 | ]; |
340 | - $expected[1] = [ |
|
340 | + $expected[ 1 ] = [ |
|
341 | 341 | 'name' => '$var2', |
342 | 342 | 'content' => "\$var2='value'", |
343 | 343 | 'default' => "'value'", |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | 'nullable_type' => false, |
348 | 348 | ]; |
349 | 349 | |
350 | - $start = ($this->phpcsFile->numTokens - 1); |
|
350 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
351 | 351 | $function = $this->phpcsFile->findPrevious( |
352 | 352 | T_COMMENT, |
353 | 353 | $start, |
@@ -356,12 +356,12 @@ discard block |
||
356 | 356 | '/* testDefaultValues */' |
357 | 357 | ); |
358 | 358 | |
359 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
360 | - unset($found[0]['token']); |
|
361 | - unset($found[1]['token']); |
|
362 | - unset($found[0]['type_hint_token']); |
|
363 | - unset($found[1]['type_hint_token']); |
|
364 | - $this->assertSame($expected, $found); |
|
359 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
360 | + unset( $found[ 0 ][ 'token' ] ); |
|
361 | + unset( $found[ 1 ][ 'token' ] ); |
|
362 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
363 | + unset( $found[ 1 ][ 'type_hint_token' ] ); |
|
364 | + $this->assertSame( $expected, $found ); |
|
365 | 365 | |
366 | 366 | }//end testDefaultValues() |
367 | 367 | |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | */ |
374 | 374 | public function testBitwiseAndConstantExpressionDefaultValue() |
375 | 375 | { |
376 | - $expected = []; |
|
377 | - $expected[0] = [ |
|
376 | + $expected = [ ]; |
|
377 | + $expected[ 0 ] = [ |
|
378 | 378 | 'name' => '$a', |
379 | 379 | 'content' => '$a = 10 & 20', |
380 | 380 | 'default' => '10 & 20', |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | 'nullable_type' => false, |
385 | 385 | ]; |
386 | 386 | |
387 | - $start = ($this->phpcsFile->numTokens - 1); |
|
387 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
388 | 388 | $function = $this->phpcsFile->findPrevious( |
389 | 389 | T_COMMENT, |
390 | 390 | $start, |
@@ -393,10 +393,10 @@ discard block |
||
393 | 393 | '/* testBitwiseAndConstantExpressionDefaultValue */' |
394 | 394 | ); |
395 | 395 | |
396 | - $found = $this->phpcsFile->getMethodParameters(($function + 2)); |
|
397 | - unset($found[0]['token']); |
|
398 | - unset($found[0]['type_hint_token']); |
|
399 | - $this->assertSame($expected, $found); |
|
396 | + $found = $this->phpcsFile->getMethodParameters( ( $function + 2 ) ); |
|
397 | + unset( $found[ 0 ][ 'token' ] ); |
|
398 | + unset( $found[ 0 ][ 'type_hint_token' ] ); |
|
399 | + $this->assertSame( $expected, $found ); |
|
400 | 400 | |
401 | 401 | }//end testBitwiseAndConstantExpressionDefaultValue() |
402 | 402 |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | use PHP_CodeSniffer\Files\DummyFile; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | 16 | |
17 | -class GetMethodParametersTest extends TestCase |
|
18 | -{ |
|
17 | +class GetMethodParametersTest extends TestCase { |
|
19 | 18 | |
20 | 19 | /** |
21 | 20 | * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | * |
34 | 33 | * @return void |
35 | 34 | */ |
36 | - public function setUp() |
|
37 | - { |
|
35 | + public function setUp() { |
|
38 | 36 | $config = new Config(); |
39 | 37 | $config->standards = ['Generic']; |
40 | 38 | |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | * |
53 | 51 | * @return void |
54 | 52 | */ |
55 | - public function tearDown() |
|
56 | - { |
|
53 | + public function tearDown() { |
|
57 | 54 | unset($this->phpcsFile); |
58 | 55 | |
59 | 56 | }//end tearDown() |
@@ -64,8 +61,7 @@ discard block |
||
64 | 61 | * |
65 | 62 | * @return void |
66 | 63 | */ |
67 | - public function testPassByReference() |
|
68 | - { |
|
64 | + public function testPassByReference() { |
|
69 | 65 | $expected = []; |
70 | 66 | $expected[0] = [ |
71 | 67 | 'name' => '$var', |
@@ -98,8 +94,7 @@ discard block |
||
98 | 94 | * |
99 | 95 | * @return void |
100 | 96 | */ |
101 | - public function testArrayHint() |
|
102 | - { |
|
97 | + public function testArrayHint() { |
|
103 | 98 | $expected = []; |
104 | 99 | $expected[0] = [ |
105 | 100 | 'name' => '$var', |
@@ -132,8 +127,7 @@ discard block |
||
132 | 127 | * |
133 | 128 | * @return void |
134 | 129 | */ |
135 | - public function testTypeHint() |
|
136 | - { |
|
130 | + public function testTypeHint() { |
|
137 | 131 | $expected = []; |
138 | 132 | $expected[0] = [ |
139 | 133 | 'name' => '$var1', |
@@ -177,8 +171,7 @@ discard block |
||
177 | 171 | * |
178 | 172 | * @return void |
179 | 173 | */ |
180 | - public function testSelfTypeHint() |
|
181 | - { |
|
174 | + public function testSelfTypeHint() { |
|
182 | 175 | $expected = []; |
183 | 176 | $expected[0] = [ |
184 | 177 | 'name' => '$var', |
@@ -211,8 +204,7 @@ discard block |
||
211 | 204 | * |
212 | 205 | * @return void |
213 | 206 | */ |
214 | - public function testNullableTypeHint() |
|
215 | - { |
|
207 | + public function testNullableTypeHint() { |
|
216 | 208 | $expected = []; |
217 | 209 | $expected[0] = [ |
218 | 210 | 'name' => '$var1', |
@@ -256,8 +248,7 @@ discard block |
||
256 | 248 | * |
257 | 249 | * @return void |
258 | 250 | */ |
259 | - public function testVariable() |
|
260 | - { |
|
251 | + public function testVariable() { |
|
261 | 252 | $expected = []; |
262 | 253 | $expected[0] = [ |
263 | 254 | 'name' => '$var', |
@@ -290,8 +281,7 @@ discard block |
||
290 | 281 | * |
291 | 282 | * @return void |
292 | 283 | */ |
293 | - public function testSingleDefaultValue() |
|
294 | - { |
|
284 | + public function testSingleDefaultValue() { |
|
295 | 285 | $expected = []; |
296 | 286 | $expected[0] = [ |
297 | 287 | 'name' => '$var1', |
@@ -325,8 +315,7 @@ discard block |
||
325 | 315 | * |
326 | 316 | * @return void |
327 | 317 | */ |
328 | - public function testDefaultValues() |
|
329 | - { |
|
318 | + public function testDefaultValues() { |
|
330 | 319 | $expected = []; |
331 | 320 | $expected[0] = [ |
332 | 321 | 'name' => '$var1', |
@@ -371,8 +360,7 @@ discard block |
||
371 | 360 | * |
372 | 361 | * @return void |
373 | 362 | */ |
374 | - public function testBitwiseAndConstantExpressionDefaultValue() |
|
375 | - { |
|
363 | + public function testBitwiseAndConstantExpressionDefaultValue() { |
|
376 | 364 | $expected = []; |
377 | 365 | $expected[0] = [ |
378 | 366 | 'name' => '$a', |
@@ -17,556 +17,556 @@ |
||
17 | 17 | class GetMethodPropertiesTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
|
22 | - * |
|
23 | - * @var \PHP_CodeSniffer\Files\File |
|
24 | - */ |
|
25 | - private $phpcsFile; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Initialize & tokenize PHP_CodeSniffer_File with code from the test case file. |
|
30 | - * |
|
31 | - * Methods used for these tests can be found in a test case file in the same |
|
32 | - * directory and with the same name, using the .inc extension. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setUp() |
|
37 | - { |
|
38 | - $config = new Config(); |
|
39 | - $config->standards = ['Generic']; |
|
40 | - |
|
41 | - $ruleset = new Ruleset($config); |
|
42 | - |
|
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | - $this->phpcsFile->process(); |
|
46 | - |
|
47 | - }//end setUp() |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Clean up after finished test. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function tearDown() |
|
56 | - { |
|
57 | - unset($this->phpcsFile); |
|
58 | - |
|
59 | - }//end tearDown() |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Test a basic function. |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function testBasicFunction() |
|
68 | - { |
|
69 | - $expected = [ |
|
70 | - 'scope' => 'public', |
|
71 | - 'scope_specified' => false, |
|
72 | - 'return_type' => '', |
|
73 | - 'nullable_return_type' => false, |
|
74 | - 'is_abstract' => false, |
|
75 | - 'is_final' => false, |
|
76 | - 'is_static' => false, |
|
77 | - 'has_body' => true, |
|
78 | - ]; |
|
79 | - |
|
80 | - $start = ($this->phpcsFile->numTokens - 1); |
|
81 | - $function = $this->phpcsFile->findPrevious( |
|
82 | - T_COMMENT, |
|
83 | - $start, |
|
84 | - null, |
|
85 | - false, |
|
86 | - '/* testBasicFunction */' |
|
87 | - ); |
|
88 | - |
|
89 | - $found = $this->phpcsFile->getMethodProperties(($function + 2)); |
|
90 | - unset($found['return_type_token']); |
|
91 | - $this->assertSame($expected, $found); |
|
92 | - |
|
93 | - }//end testBasicFunction() |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Test a function with a return type. |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public function testReturnFunction() |
|
102 | - { |
|
103 | - $expected = [ |
|
104 | - 'scope' => 'public', |
|
105 | - 'scope_specified' => false, |
|
106 | - 'return_type' => 'array', |
|
107 | - 'nullable_return_type' => false, |
|
108 | - 'is_abstract' => false, |
|
109 | - 'is_final' => false, |
|
110 | - 'is_static' => false, |
|
111 | - 'has_body' => true, |
|
112 | - ]; |
|
113 | - |
|
114 | - $start = ($this->phpcsFile->numTokens - 1); |
|
115 | - $function = $this->phpcsFile->findPrevious( |
|
116 | - T_COMMENT, |
|
117 | - $start, |
|
118 | - null, |
|
119 | - false, |
|
120 | - '/* testReturnFunction */' |
|
121 | - ); |
|
122 | - |
|
123 | - $found = $this->phpcsFile->getMethodProperties(($function + 2)); |
|
124 | - unset($found['return_type_token']); |
|
125 | - $this->assertSame($expected, $found); |
|
126 | - |
|
127 | - }//end testReturnFunction() |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Test a closure used as a function argument. |
|
132 | - * |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - public function testNestedClosure() |
|
136 | - { |
|
137 | - $expected = [ |
|
138 | - 'scope' => 'public', |
|
139 | - 'scope_specified' => false, |
|
140 | - 'return_type' => 'int', |
|
141 | - 'nullable_return_type' => false, |
|
142 | - 'is_abstract' => false, |
|
143 | - 'is_final' => false, |
|
144 | - 'is_static' => false, |
|
145 | - 'has_body' => true, |
|
146 | - ]; |
|
147 | - |
|
148 | - $start = ($this->phpcsFile->numTokens - 1); |
|
149 | - $function = $this->phpcsFile->findPrevious( |
|
150 | - T_COMMENT, |
|
151 | - $start, |
|
152 | - null, |
|
153 | - false, |
|
154 | - '/* testNestedClosure */' |
|
155 | - ); |
|
156 | - |
|
157 | - $found = $this->phpcsFile->getMethodProperties(($function + 1)); |
|
158 | - unset($found['return_type_token']); |
|
159 | - $this->assertSame($expected, $found); |
|
160 | - |
|
161 | - }//end testNestedClosure() |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Test a basic method. |
|
166 | - * |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - public function testBasicMethod() |
|
170 | - { |
|
171 | - $expected = [ |
|
172 | - 'scope' => 'public', |
|
173 | - 'scope_specified' => false, |
|
174 | - 'return_type' => '', |
|
175 | - 'nullable_return_type' => false, |
|
176 | - 'is_abstract' => false, |
|
177 | - 'is_final' => false, |
|
178 | - 'is_static' => false, |
|
179 | - 'has_body' => true, |
|
180 | - ]; |
|
181 | - |
|
182 | - $start = ($this->phpcsFile->numTokens - 1); |
|
183 | - $function = $this->phpcsFile->findPrevious( |
|
184 | - T_COMMENT, |
|
185 | - $start, |
|
186 | - null, |
|
187 | - false, |
|
188 | - '/* testBasicMethod */' |
|
189 | - ); |
|
190 | - |
|
191 | - $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
192 | - unset($found['return_type_token']); |
|
193 | - $this->assertSame($expected, $found); |
|
194 | - |
|
195 | - }//end testBasicMethod() |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Test a private static method. |
|
200 | - * |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public function testPrivateStaticMethod() |
|
204 | - { |
|
205 | - $expected = [ |
|
206 | - 'scope' => 'private', |
|
207 | - 'scope_specified' => true, |
|
208 | - 'return_type' => '', |
|
209 | - 'nullable_return_type' => false, |
|
210 | - 'is_abstract' => false, |
|
211 | - 'is_final' => false, |
|
212 | - 'is_static' => true, |
|
213 | - 'has_body' => true, |
|
214 | - ]; |
|
215 | - |
|
216 | - $start = ($this->phpcsFile->numTokens - 1); |
|
217 | - $function = $this->phpcsFile->findPrevious( |
|
218 | - T_COMMENT, |
|
219 | - $start, |
|
220 | - null, |
|
221 | - false, |
|
222 | - '/* testPrivateStaticMethod */' |
|
223 | - ); |
|
224 | - |
|
225 | - $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
226 | - unset($found['return_type_token']); |
|
227 | - $this->assertSame($expected, $found); |
|
228 | - |
|
229 | - }//end testPrivateStaticMethod() |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * Test a basic final method. |
|
234 | - * |
|
235 | - * @return void |
|
236 | - */ |
|
237 | - public function testFinalMethod() |
|
238 | - { |
|
239 | - $expected = [ |
|
240 | - 'scope' => 'public', |
|
241 | - 'scope_specified' => true, |
|
242 | - 'return_type' => '', |
|
243 | - 'nullable_return_type' => false, |
|
244 | - 'is_abstract' => false, |
|
245 | - 'is_final' => true, |
|
246 | - 'is_static' => false, |
|
247 | - 'has_body' => true, |
|
248 | - ]; |
|
249 | - |
|
250 | - $start = ($this->phpcsFile->numTokens - 1); |
|
251 | - $function = $this->phpcsFile->findPrevious( |
|
252 | - T_COMMENT, |
|
253 | - $start, |
|
254 | - null, |
|
255 | - false, |
|
256 | - '/* testFinalMethod */' |
|
257 | - ); |
|
258 | - |
|
259 | - $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
260 | - unset($found['return_type_token']); |
|
261 | - $this->assertSame($expected, $found); |
|
262 | - |
|
263 | - }//end testFinalMethod() |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * Test a protected method with a return type. |
|
268 | - * |
|
269 | - * @return void |
|
270 | - */ |
|
271 | - public function testProtectedReturnMethod() |
|
272 | - { |
|
273 | - $expected = [ |
|
274 | - 'scope' => 'protected', |
|
275 | - 'scope_specified' => true, |
|
276 | - 'return_type' => 'int', |
|
277 | - 'nullable_return_type' => false, |
|
278 | - 'is_abstract' => false, |
|
279 | - 'is_final' => false, |
|
280 | - 'is_static' => false, |
|
281 | - 'has_body' => true, |
|
282 | - ]; |
|
283 | - |
|
284 | - $start = ($this->phpcsFile->numTokens - 1); |
|
285 | - $function = $this->phpcsFile->findPrevious( |
|
286 | - T_COMMENT, |
|
287 | - $start, |
|
288 | - null, |
|
289 | - false, |
|
290 | - '/* testProtectedReturnMethod */' |
|
291 | - ); |
|
292 | - |
|
293 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
294 | - unset($found['return_type_token']); |
|
295 | - $this->assertSame($expected, $found); |
|
296 | - |
|
297 | - }//end testProtectedReturnMethod() |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Test a public method with a return type. |
|
302 | - * |
|
303 | - * @return void |
|
304 | - */ |
|
305 | - public function testPublicReturnMethod() |
|
306 | - { |
|
307 | - $expected = [ |
|
308 | - 'scope' => 'public', |
|
309 | - 'scope_specified' => true, |
|
310 | - 'return_type' => 'array', |
|
311 | - 'nullable_return_type' => false, |
|
312 | - 'is_abstract' => false, |
|
313 | - 'is_final' => false, |
|
314 | - 'is_static' => false, |
|
315 | - 'has_body' => true, |
|
316 | - ]; |
|
317 | - |
|
318 | - $start = ($this->phpcsFile->numTokens - 1); |
|
319 | - $function = $this->phpcsFile->findPrevious( |
|
320 | - T_COMMENT, |
|
321 | - $start, |
|
322 | - null, |
|
323 | - false, |
|
324 | - '/* testPublicReturnMethod */' |
|
325 | - ); |
|
326 | - |
|
327 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
328 | - unset($found['return_type_token']); |
|
329 | - $this->assertSame($expected, $found); |
|
330 | - |
|
331 | - }//end testPublicReturnMethod() |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Test a public method with a nullable return type. |
|
336 | - * |
|
337 | - * @return void |
|
338 | - */ |
|
339 | - public function testNullableReturnMethod() |
|
340 | - { |
|
341 | - $expected = [ |
|
342 | - 'scope' => 'public', |
|
343 | - 'scope_specified' => true, |
|
344 | - 'return_type' => '?array', |
|
345 | - 'nullable_return_type' => true, |
|
346 | - 'is_abstract' => false, |
|
347 | - 'is_final' => false, |
|
348 | - 'is_static' => false, |
|
349 | - 'has_body' => true, |
|
350 | - ]; |
|
351 | - |
|
352 | - $start = ($this->phpcsFile->numTokens - 1); |
|
353 | - $function = $this->phpcsFile->findPrevious( |
|
354 | - T_COMMENT, |
|
355 | - $start, |
|
356 | - null, |
|
357 | - false, |
|
358 | - '/* testNullableReturnMethod */' |
|
359 | - ); |
|
360 | - |
|
361 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
362 | - unset($found['return_type_token']); |
|
363 | - $this->assertSame($expected, $found); |
|
364 | - |
|
365 | - }//end testNullableReturnMethod() |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Test a public method with a nullable return type. |
|
370 | - * |
|
371 | - * @return void |
|
372 | - */ |
|
373 | - public function testMessyNullableReturnMethod() |
|
374 | - { |
|
375 | - $expected = [ |
|
376 | - 'scope' => 'public', |
|
377 | - 'scope_specified' => true, |
|
378 | - 'return_type' => '?array', |
|
379 | - 'nullable_return_type' => true, |
|
380 | - 'is_abstract' => false, |
|
381 | - 'is_final' => false, |
|
382 | - 'is_static' => false, |
|
383 | - 'has_body' => true, |
|
384 | - ]; |
|
385 | - |
|
386 | - $start = ($this->phpcsFile->numTokens - 1); |
|
387 | - $function = $this->phpcsFile->findPrevious( |
|
388 | - T_COMMENT, |
|
389 | - $start, |
|
390 | - null, |
|
391 | - false, |
|
392 | - '/* testMessyNullableReturnMethod */' |
|
393 | - ); |
|
394 | - |
|
395 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
396 | - unset($found['return_type_token']); |
|
397 | - $this->assertSame($expected, $found); |
|
398 | - |
|
399 | - }//end testMessyNullableReturnMethod() |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * Test a method with a namespaced return type. |
|
404 | - * |
|
405 | - * @return void |
|
406 | - */ |
|
407 | - public function testReturnNamespace() |
|
408 | - { |
|
409 | - $expected = [ |
|
410 | - 'scope' => 'public', |
|
411 | - 'scope_specified' => false, |
|
412 | - 'return_type' => '\MyNamespace\MyClass', |
|
413 | - 'nullable_return_type' => false, |
|
414 | - 'is_abstract' => false, |
|
415 | - 'is_final' => false, |
|
416 | - 'is_static' => false, |
|
417 | - 'has_body' => true, |
|
418 | - ]; |
|
419 | - |
|
420 | - $start = ($this->phpcsFile->numTokens - 1); |
|
421 | - $function = $this->phpcsFile->findPrevious( |
|
422 | - T_COMMENT, |
|
423 | - $start, |
|
424 | - null, |
|
425 | - false, |
|
426 | - '/* testReturnNamespace */' |
|
427 | - ); |
|
428 | - |
|
429 | - $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
430 | - unset($found['return_type_token']); |
|
431 | - $this->assertSame($expected, $found); |
|
432 | - |
|
433 | - }//end testReturnNamespace() |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Test a method with a messy namespaces return type. |
|
438 | - * |
|
439 | - * @return void |
|
440 | - */ |
|
441 | - public function testReturnMultilineNamespace() |
|
442 | - { |
|
443 | - $expected = [ |
|
444 | - 'scope' => 'public', |
|
445 | - 'scope_specified' => false, |
|
446 | - 'return_type' => '\MyNamespace\MyClass\Foo', |
|
447 | - 'nullable_return_type' => false, |
|
448 | - 'is_abstract' => false, |
|
449 | - 'is_final' => false, |
|
450 | - 'is_static' => false, |
|
451 | - 'has_body' => true, |
|
452 | - ]; |
|
453 | - |
|
454 | - $start = ($this->phpcsFile->numTokens - 1); |
|
455 | - $function = $this->phpcsFile->findPrevious( |
|
456 | - T_COMMENT, |
|
457 | - $start, |
|
458 | - null, |
|
459 | - false, |
|
460 | - '/* testReturnMultilineNamespace */' |
|
461 | - ); |
|
462 | - |
|
463 | - $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
464 | - unset($found['return_type_token']); |
|
465 | - $this->assertSame($expected, $found); |
|
466 | - |
|
467 | - }//end testReturnMultilineNamespace() |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Test a basic abstract method. |
|
472 | - * |
|
473 | - * @return void |
|
474 | - */ |
|
475 | - public function testAbstractMethod() |
|
476 | - { |
|
477 | - $expected = [ |
|
478 | - 'scope' => 'public', |
|
479 | - 'scope_specified' => false, |
|
480 | - 'return_type' => '', |
|
481 | - 'nullable_return_type' => false, |
|
482 | - 'is_abstract' => true, |
|
483 | - 'is_final' => false, |
|
484 | - 'is_static' => false, |
|
485 | - 'has_body' => false, |
|
486 | - ]; |
|
487 | - |
|
488 | - $start = ($this->phpcsFile->numTokens - 1); |
|
489 | - $function = $this->phpcsFile->findPrevious( |
|
490 | - T_COMMENT, |
|
491 | - $start, |
|
492 | - null, |
|
493 | - false, |
|
494 | - '/* testAbstractMethod */' |
|
495 | - ); |
|
496 | - |
|
497 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
498 | - unset($found['return_type_token']); |
|
499 | - $this->assertSame($expected, $found); |
|
500 | - |
|
501 | - }//end testAbstractMethod() |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * Test an abstract method with a return type. |
|
506 | - * |
|
507 | - * @return void |
|
508 | - */ |
|
509 | - public function testAbstractReturnMethod() |
|
510 | - { |
|
511 | - $expected = [ |
|
512 | - 'scope' => 'protected', |
|
513 | - 'scope_specified' => true, |
|
514 | - 'return_type' => 'bool', |
|
515 | - 'nullable_return_type' => false, |
|
516 | - 'is_abstract' => true, |
|
517 | - 'is_final' => false, |
|
518 | - 'is_static' => false, |
|
519 | - 'has_body' => false, |
|
520 | - ]; |
|
521 | - |
|
522 | - $start = ($this->phpcsFile->numTokens - 1); |
|
523 | - $function = $this->phpcsFile->findPrevious( |
|
524 | - T_COMMENT, |
|
525 | - $start, |
|
526 | - null, |
|
527 | - false, |
|
528 | - '/* testAbstractReturnMethod */' |
|
529 | - ); |
|
530 | - |
|
531 | - $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
532 | - unset($found['return_type_token']); |
|
533 | - $this->assertSame($expected, $found); |
|
534 | - |
|
535 | - }//end testAbstractReturnMethod() |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * Test a basic interface method. |
|
540 | - * |
|
541 | - * @return void |
|
542 | - */ |
|
543 | - public function testInterfaceMethod() |
|
544 | - { |
|
545 | - $expected = [ |
|
546 | - 'scope' => 'public', |
|
547 | - 'scope_specified' => false, |
|
548 | - 'return_type' => '', |
|
549 | - 'nullable_return_type' => false, |
|
550 | - 'is_abstract' => false, |
|
551 | - 'is_final' => false, |
|
552 | - 'is_static' => false, |
|
553 | - 'has_body' => false, |
|
554 | - ]; |
|
555 | - |
|
556 | - $start = ($this->phpcsFile->numTokens - 1); |
|
557 | - $function = $this->phpcsFile->findPrevious( |
|
558 | - T_COMMENT, |
|
559 | - $start, |
|
560 | - null, |
|
561 | - false, |
|
562 | - '/* testInterfaceMethod */' |
|
563 | - ); |
|
564 | - |
|
565 | - $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
566 | - unset($found['return_type_token']); |
|
567 | - $this->assertSame($expected, $found); |
|
568 | - |
|
569 | - }//end testInterfaceMethod() |
|
20 | + /** |
|
21 | + * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
|
22 | + * |
|
23 | + * @var \PHP_CodeSniffer\Files\File |
|
24 | + */ |
|
25 | + private $phpcsFile; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Initialize & tokenize PHP_CodeSniffer_File with code from the test case file. |
|
30 | + * |
|
31 | + * Methods used for these tests can be found in a test case file in the same |
|
32 | + * directory and with the same name, using the .inc extension. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setUp() |
|
37 | + { |
|
38 | + $config = new Config(); |
|
39 | + $config->standards = ['Generic']; |
|
40 | + |
|
41 | + $ruleset = new Ruleset($config); |
|
42 | + |
|
43 | + $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | + $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | + $this->phpcsFile->process(); |
|
46 | + |
|
47 | + }//end setUp() |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Clean up after finished test. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function tearDown() |
|
56 | + { |
|
57 | + unset($this->phpcsFile); |
|
58 | + |
|
59 | + }//end tearDown() |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Test a basic function. |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function testBasicFunction() |
|
68 | + { |
|
69 | + $expected = [ |
|
70 | + 'scope' => 'public', |
|
71 | + 'scope_specified' => false, |
|
72 | + 'return_type' => '', |
|
73 | + 'nullable_return_type' => false, |
|
74 | + 'is_abstract' => false, |
|
75 | + 'is_final' => false, |
|
76 | + 'is_static' => false, |
|
77 | + 'has_body' => true, |
|
78 | + ]; |
|
79 | + |
|
80 | + $start = ($this->phpcsFile->numTokens - 1); |
|
81 | + $function = $this->phpcsFile->findPrevious( |
|
82 | + T_COMMENT, |
|
83 | + $start, |
|
84 | + null, |
|
85 | + false, |
|
86 | + '/* testBasicFunction */' |
|
87 | + ); |
|
88 | + |
|
89 | + $found = $this->phpcsFile->getMethodProperties(($function + 2)); |
|
90 | + unset($found['return_type_token']); |
|
91 | + $this->assertSame($expected, $found); |
|
92 | + |
|
93 | + }//end testBasicFunction() |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Test a function with a return type. |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public function testReturnFunction() |
|
102 | + { |
|
103 | + $expected = [ |
|
104 | + 'scope' => 'public', |
|
105 | + 'scope_specified' => false, |
|
106 | + 'return_type' => 'array', |
|
107 | + 'nullable_return_type' => false, |
|
108 | + 'is_abstract' => false, |
|
109 | + 'is_final' => false, |
|
110 | + 'is_static' => false, |
|
111 | + 'has_body' => true, |
|
112 | + ]; |
|
113 | + |
|
114 | + $start = ($this->phpcsFile->numTokens - 1); |
|
115 | + $function = $this->phpcsFile->findPrevious( |
|
116 | + T_COMMENT, |
|
117 | + $start, |
|
118 | + null, |
|
119 | + false, |
|
120 | + '/* testReturnFunction */' |
|
121 | + ); |
|
122 | + |
|
123 | + $found = $this->phpcsFile->getMethodProperties(($function + 2)); |
|
124 | + unset($found['return_type_token']); |
|
125 | + $this->assertSame($expected, $found); |
|
126 | + |
|
127 | + }//end testReturnFunction() |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Test a closure used as a function argument. |
|
132 | + * |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + public function testNestedClosure() |
|
136 | + { |
|
137 | + $expected = [ |
|
138 | + 'scope' => 'public', |
|
139 | + 'scope_specified' => false, |
|
140 | + 'return_type' => 'int', |
|
141 | + 'nullable_return_type' => false, |
|
142 | + 'is_abstract' => false, |
|
143 | + 'is_final' => false, |
|
144 | + 'is_static' => false, |
|
145 | + 'has_body' => true, |
|
146 | + ]; |
|
147 | + |
|
148 | + $start = ($this->phpcsFile->numTokens - 1); |
|
149 | + $function = $this->phpcsFile->findPrevious( |
|
150 | + T_COMMENT, |
|
151 | + $start, |
|
152 | + null, |
|
153 | + false, |
|
154 | + '/* testNestedClosure */' |
|
155 | + ); |
|
156 | + |
|
157 | + $found = $this->phpcsFile->getMethodProperties(($function + 1)); |
|
158 | + unset($found['return_type_token']); |
|
159 | + $this->assertSame($expected, $found); |
|
160 | + |
|
161 | + }//end testNestedClosure() |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Test a basic method. |
|
166 | + * |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + public function testBasicMethod() |
|
170 | + { |
|
171 | + $expected = [ |
|
172 | + 'scope' => 'public', |
|
173 | + 'scope_specified' => false, |
|
174 | + 'return_type' => '', |
|
175 | + 'nullable_return_type' => false, |
|
176 | + 'is_abstract' => false, |
|
177 | + 'is_final' => false, |
|
178 | + 'is_static' => false, |
|
179 | + 'has_body' => true, |
|
180 | + ]; |
|
181 | + |
|
182 | + $start = ($this->phpcsFile->numTokens - 1); |
|
183 | + $function = $this->phpcsFile->findPrevious( |
|
184 | + T_COMMENT, |
|
185 | + $start, |
|
186 | + null, |
|
187 | + false, |
|
188 | + '/* testBasicMethod */' |
|
189 | + ); |
|
190 | + |
|
191 | + $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
192 | + unset($found['return_type_token']); |
|
193 | + $this->assertSame($expected, $found); |
|
194 | + |
|
195 | + }//end testBasicMethod() |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Test a private static method. |
|
200 | + * |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public function testPrivateStaticMethod() |
|
204 | + { |
|
205 | + $expected = [ |
|
206 | + 'scope' => 'private', |
|
207 | + 'scope_specified' => true, |
|
208 | + 'return_type' => '', |
|
209 | + 'nullable_return_type' => false, |
|
210 | + 'is_abstract' => false, |
|
211 | + 'is_final' => false, |
|
212 | + 'is_static' => true, |
|
213 | + 'has_body' => true, |
|
214 | + ]; |
|
215 | + |
|
216 | + $start = ($this->phpcsFile->numTokens - 1); |
|
217 | + $function = $this->phpcsFile->findPrevious( |
|
218 | + T_COMMENT, |
|
219 | + $start, |
|
220 | + null, |
|
221 | + false, |
|
222 | + '/* testPrivateStaticMethod */' |
|
223 | + ); |
|
224 | + |
|
225 | + $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
226 | + unset($found['return_type_token']); |
|
227 | + $this->assertSame($expected, $found); |
|
228 | + |
|
229 | + }//end testPrivateStaticMethod() |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * Test a basic final method. |
|
234 | + * |
|
235 | + * @return void |
|
236 | + */ |
|
237 | + public function testFinalMethod() |
|
238 | + { |
|
239 | + $expected = [ |
|
240 | + 'scope' => 'public', |
|
241 | + 'scope_specified' => true, |
|
242 | + 'return_type' => '', |
|
243 | + 'nullable_return_type' => false, |
|
244 | + 'is_abstract' => false, |
|
245 | + 'is_final' => true, |
|
246 | + 'is_static' => false, |
|
247 | + 'has_body' => true, |
|
248 | + ]; |
|
249 | + |
|
250 | + $start = ($this->phpcsFile->numTokens - 1); |
|
251 | + $function = $this->phpcsFile->findPrevious( |
|
252 | + T_COMMENT, |
|
253 | + $start, |
|
254 | + null, |
|
255 | + false, |
|
256 | + '/* testFinalMethod */' |
|
257 | + ); |
|
258 | + |
|
259 | + $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
260 | + unset($found['return_type_token']); |
|
261 | + $this->assertSame($expected, $found); |
|
262 | + |
|
263 | + }//end testFinalMethod() |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * Test a protected method with a return type. |
|
268 | + * |
|
269 | + * @return void |
|
270 | + */ |
|
271 | + public function testProtectedReturnMethod() |
|
272 | + { |
|
273 | + $expected = [ |
|
274 | + 'scope' => 'protected', |
|
275 | + 'scope_specified' => true, |
|
276 | + 'return_type' => 'int', |
|
277 | + 'nullable_return_type' => false, |
|
278 | + 'is_abstract' => false, |
|
279 | + 'is_final' => false, |
|
280 | + 'is_static' => false, |
|
281 | + 'has_body' => true, |
|
282 | + ]; |
|
283 | + |
|
284 | + $start = ($this->phpcsFile->numTokens - 1); |
|
285 | + $function = $this->phpcsFile->findPrevious( |
|
286 | + T_COMMENT, |
|
287 | + $start, |
|
288 | + null, |
|
289 | + false, |
|
290 | + '/* testProtectedReturnMethod */' |
|
291 | + ); |
|
292 | + |
|
293 | + $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
294 | + unset($found['return_type_token']); |
|
295 | + $this->assertSame($expected, $found); |
|
296 | + |
|
297 | + }//end testProtectedReturnMethod() |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Test a public method with a return type. |
|
302 | + * |
|
303 | + * @return void |
|
304 | + */ |
|
305 | + public function testPublicReturnMethod() |
|
306 | + { |
|
307 | + $expected = [ |
|
308 | + 'scope' => 'public', |
|
309 | + 'scope_specified' => true, |
|
310 | + 'return_type' => 'array', |
|
311 | + 'nullable_return_type' => false, |
|
312 | + 'is_abstract' => false, |
|
313 | + 'is_final' => false, |
|
314 | + 'is_static' => false, |
|
315 | + 'has_body' => true, |
|
316 | + ]; |
|
317 | + |
|
318 | + $start = ($this->phpcsFile->numTokens - 1); |
|
319 | + $function = $this->phpcsFile->findPrevious( |
|
320 | + T_COMMENT, |
|
321 | + $start, |
|
322 | + null, |
|
323 | + false, |
|
324 | + '/* testPublicReturnMethod */' |
|
325 | + ); |
|
326 | + |
|
327 | + $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
328 | + unset($found['return_type_token']); |
|
329 | + $this->assertSame($expected, $found); |
|
330 | + |
|
331 | + }//end testPublicReturnMethod() |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Test a public method with a nullable return type. |
|
336 | + * |
|
337 | + * @return void |
|
338 | + */ |
|
339 | + public function testNullableReturnMethod() |
|
340 | + { |
|
341 | + $expected = [ |
|
342 | + 'scope' => 'public', |
|
343 | + 'scope_specified' => true, |
|
344 | + 'return_type' => '?array', |
|
345 | + 'nullable_return_type' => true, |
|
346 | + 'is_abstract' => false, |
|
347 | + 'is_final' => false, |
|
348 | + 'is_static' => false, |
|
349 | + 'has_body' => true, |
|
350 | + ]; |
|
351 | + |
|
352 | + $start = ($this->phpcsFile->numTokens - 1); |
|
353 | + $function = $this->phpcsFile->findPrevious( |
|
354 | + T_COMMENT, |
|
355 | + $start, |
|
356 | + null, |
|
357 | + false, |
|
358 | + '/* testNullableReturnMethod */' |
|
359 | + ); |
|
360 | + |
|
361 | + $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
362 | + unset($found['return_type_token']); |
|
363 | + $this->assertSame($expected, $found); |
|
364 | + |
|
365 | + }//end testNullableReturnMethod() |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Test a public method with a nullable return type. |
|
370 | + * |
|
371 | + * @return void |
|
372 | + */ |
|
373 | + public function testMessyNullableReturnMethod() |
|
374 | + { |
|
375 | + $expected = [ |
|
376 | + 'scope' => 'public', |
|
377 | + 'scope_specified' => true, |
|
378 | + 'return_type' => '?array', |
|
379 | + 'nullable_return_type' => true, |
|
380 | + 'is_abstract' => false, |
|
381 | + 'is_final' => false, |
|
382 | + 'is_static' => false, |
|
383 | + 'has_body' => true, |
|
384 | + ]; |
|
385 | + |
|
386 | + $start = ($this->phpcsFile->numTokens - 1); |
|
387 | + $function = $this->phpcsFile->findPrevious( |
|
388 | + T_COMMENT, |
|
389 | + $start, |
|
390 | + null, |
|
391 | + false, |
|
392 | + '/* testMessyNullableReturnMethod */' |
|
393 | + ); |
|
394 | + |
|
395 | + $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
396 | + unset($found['return_type_token']); |
|
397 | + $this->assertSame($expected, $found); |
|
398 | + |
|
399 | + }//end testMessyNullableReturnMethod() |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * Test a method with a namespaced return type. |
|
404 | + * |
|
405 | + * @return void |
|
406 | + */ |
|
407 | + public function testReturnNamespace() |
|
408 | + { |
|
409 | + $expected = [ |
|
410 | + 'scope' => 'public', |
|
411 | + 'scope_specified' => false, |
|
412 | + 'return_type' => '\MyNamespace\MyClass', |
|
413 | + 'nullable_return_type' => false, |
|
414 | + 'is_abstract' => false, |
|
415 | + 'is_final' => false, |
|
416 | + 'is_static' => false, |
|
417 | + 'has_body' => true, |
|
418 | + ]; |
|
419 | + |
|
420 | + $start = ($this->phpcsFile->numTokens - 1); |
|
421 | + $function = $this->phpcsFile->findPrevious( |
|
422 | + T_COMMENT, |
|
423 | + $start, |
|
424 | + null, |
|
425 | + false, |
|
426 | + '/* testReturnNamespace */' |
|
427 | + ); |
|
428 | + |
|
429 | + $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
430 | + unset($found['return_type_token']); |
|
431 | + $this->assertSame($expected, $found); |
|
432 | + |
|
433 | + }//end testReturnNamespace() |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Test a method with a messy namespaces return type. |
|
438 | + * |
|
439 | + * @return void |
|
440 | + */ |
|
441 | + public function testReturnMultilineNamespace() |
|
442 | + { |
|
443 | + $expected = [ |
|
444 | + 'scope' => 'public', |
|
445 | + 'scope_specified' => false, |
|
446 | + 'return_type' => '\MyNamespace\MyClass\Foo', |
|
447 | + 'nullable_return_type' => false, |
|
448 | + 'is_abstract' => false, |
|
449 | + 'is_final' => false, |
|
450 | + 'is_static' => false, |
|
451 | + 'has_body' => true, |
|
452 | + ]; |
|
453 | + |
|
454 | + $start = ($this->phpcsFile->numTokens - 1); |
|
455 | + $function = $this->phpcsFile->findPrevious( |
|
456 | + T_COMMENT, |
|
457 | + $start, |
|
458 | + null, |
|
459 | + false, |
|
460 | + '/* testReturnMultilineNamespace */' |
|
461 | + ); |
|
462 | + |
|
463 | + $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
464 | + unset($found['return_type_token']); |
|
465 | + $this->assertSame($expected, $found); |
|
466 | + |
|
467 | + }//end testReturnMultilineNamespace() |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Test a basic abstract method. |
|
472 | + * |
|
473 | + * @return void |
|
474 | + */ |
|
475 | + public function testAbstractMethod() |
|
476 | + { |
|
477 | + $expected = [ |
|
478 | + 'scope' => 'public', |
|
479 | + 'scope_specified' => false, |
|
480 | + 'return_type' => '', |
|
481 | + 'nullable_return_type' => false, |
|
482 | + 'is_abstract' => true, |
|
483 | + 'is_final' => false, |
|
484 | + 'is_static' => false, |
|
485 | + 'has_body' => false, |
|
486 | + ]; |
|
487 | + |
|
488 | + $start = ($this->phpcsFile->numTokens - 1); |
|
489 | + $function = $this->phpcsFile->findPrevious( |
|
490 | + T_COMMENT, |
|
491 | + $start, |
|
492 | + null, |
|
493 | + false, |
|
494 | + '/* testAbstractMethod */' |
|
495 | + ); |
|
496 | + |
|
497 | + $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
498 | + unset($found['return_type_token']); |
|
499 | + $this->assertSame($expected, $found); |
|
500 | + |
|
501 | + }//end testAbstractMethod() |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * Test an abstract method with a return type. |
|
506 | + * |
|
507 | + * @return void |
|
508 | + */ |
|
509 | + public function testAbstractReturnMethod() |
|
510 | + { |
|
511 | + $expected = [ |
|
512 | + 'scope' => 'protected', |
|
513 | + 'scope_specified' => true, |
|
514 | + 'return_type' => 'bool', |
|
515 | + 'nullable_return_type' => false, |
|
516 | + 'is_abstract' => true, |
|
517 | + 'is_final' => false, |
|
518 | + 'is_static' => false, |
|
519 | + 'has_body' => false, |
|
520 | + ]; |
|
521 | + |
|
522 | + $start = ($this->phpcsFile->numTokens - 1); |
|
523 | + $function = $this->phpcsFile->findPrevious( |
|
524 | + T_COMMENT, |
|
525 | + $start, |
|
526 | + null, |
|
527 | + false, |
|
528 | + '/* testAbstractReturnMethod */' |
|
529 | + ); |
|
530 | + |
|
531 | + $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
532 | + unset($found['return_type_token']); |
|
533 | + $this->assertSame($expected, $found); |
|
534 | + |
|
535 | + }//end testAbstractReturnMethod() |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * Test a basic interface method. |
|
540 | + * |
|
541 | + * @return void |
|
542 | + */ |
|
543 | + public function testInterfaceMethod() |
|
544 | + { |
|
545 | + $expected = [ |
|
546 | + 'scope' => 'public', |
|
547 | + 'scope_specified' => false, |
|
548 | + 'return_type' => '', |
|
549 | + 'nullable_return_type' => false, |
|
550 | + 'is_abstract' => false, |
|
551 | + 'is_final' => false, |
|
552 | + 'is_static' => false, |
|
553 | + 'has_body' => false, |
|
554 | + ]; |
|
555 | + |
|
556 | + $start = ($this->phpcsFile->numTokens - 1); |
|
557 | + $function = $this->phpcsFile->findPrevious( |
|
558 | + T_COMMENT, |
|
559 | + $start, |
|
560 | + null, |
|
561 | + false, |
|
562 | + '/* testInterfaceMethod */' |
|
563 | + ); |
|
564 | + |
|
565 | + $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
566 | + unset($found['return_type_token']); |
|
567 | + $this->assertSame($expected, $found); |
|
568 | + |
|
569 | + }//end testInterfaceMethod() |
|
570 | 570 | |
571 | 571 | |
572 | 572 | }//end class |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | public function setUp() |
37 | 37 | { |
38 | 38 | $config = new Config(); |
39 | - $config->standards = ['Generic']; |
|
39 | + $config->standards = [ 'Generic' ]; |
|
40 | 40 | |
41 | - $ruleset = new Ruleset($config); |
|
41 | + $ruleset = new Ruleset( $config ); |
|
42 | 42 | |
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
43 | + $pathToTestFile = dirname( __FILE__ ) . '/' . basename( __FILE__, '.php' ) . '.inc'; |
|
44 | + $this->phpcsFile = new DummyFile( file_get_contents( $pathToTestFile ), $ruleset, $config ); |
|
45 | 45 | $this->phpcsFile->process(); |
46 | 46 | |
47 | 47 | }//end setUp() |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function tearDown() |
56 | 56 | { |
57 | - unset($this->phpcsFile); |
|
57 | + unset( $this->phpcsFile ); |
|
58 | 58 | |
59 | 59 | }//end tearDown() |
60 | 60 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'has_body' => true, |
78 | 78 | ]; |
79 | 79 | |
80 | - $start = ($this->phpcsFile->numTokens - 1); |
|
80 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
81 | 81 | $function = $this->phpcsFile->findPrevious( |
82 | 82 | T_COMMENT, |
83 | 83 | $start, |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | '/* testBasicFunction */' |
87 | 87 | ); |
88 | 88 | |
89 | - $found = $this->phpcsFile->getMethodProperties(($function + 2)); |
|
90 | - unset($found['return_type_token']); |
|
91 | - $this->assertSame($expected, $found); |
|
89 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 2 ) ); |
|
90 | + unset( $found[ 'return_type_token' ] ); |
|
91 | + $this->assertSame( $expected, $found ); |
|
92 | 92 | |
93 | 93 | }//end testBasicFunction() |
94 | 94 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | 'has_body' => true, |
112 | 112 | ]; |
113 | 113 | |
114 | - $start = ($this->phpcsFile->numTokens - 1); |
|
114 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
115 | 115 | $function = $this->phpcsFile->findPrevious( |
116 | 116 | T_COMMENT, |
117 | 117 | $start, |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | '/* testReturnFunction */' |
121 | 121 | ); |
122 | 122 | |
123 | - $found = $this->phpcsFile->getMethodProperties(($function + 2)); |
|
124 | - unset($found['return_type_token']); |
|
125 | - $this->assertSame($expected, $found); |
|
123 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 2 ) ); |
|
124 | + unset( $found[ 'return_type_token' ] ); |
|
125 | + $this->assertSame( $expected, $found ); |
|
126 | 126 | |
127 | 127 | }//end testReturnFunction() |
128 | 128 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | 'has_body' => true, |
146 | 146 | ]; |
147 | 147 | |
148 | - $start = ($this->phpcsFile->numTokens - 1); |
|
148 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
149 | 149 | $function = $this->phpcsFile->findPrevious( |
150 | 150 | T_COMMENT, |
151 | 151 | $start, |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | '/* testNestedClosure */' |
155 | 155 | ); |
156 | 156 | |
157 | - $found = $this->phpcsFile->getMethodProperties(($function + 1)); |
|
158 | - unset($found['return_type_token']); |
|
159 | - $this->assertSame($expected, $found); |
|
157 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 1 ) ); |
|
158 | + unset( $found[ 'return_type_token' ] ); |
|
159 | + $this->assertSame( $expected, $found ); |
|
160 | 160 | |
161 | 161 | }//end testNestedClosure() |
162 | 162 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | 'has_body' => true, |
180 | 180 | ]; |
181 | 181 | |
182 | - $start = ($this->phpcsFile->numTokens - 1); |
|
182 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
183 | 183 | $function = $this->phpcsFile->findPrevious( |
184 | 184 | T_COMMENT, |
185 | 185 | $start, |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | '/* testBasicMethod */' |
189 | 189 | ); |
190 | 190 | |
191 | - $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
192 | - unset($found['return_type_token']); |
|
193 | - $this->assertSame($expected, $found); |
|
191 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 3 ) ); |
|
192 | + unset( $found[ 'return_type_token' ] ); |
|
193 | + $this->assertSame( $expected, $found ); |
|
194 | 194 | |
195 | 195 | }//end testBasicMethod() |
196 | 196 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | 'has_body' => true, |
214 | 214 | ]; |
215 | 215 | |
216 | - $start = ($this->phpcsFile->numTokens - 1); |
|
216 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
217 | 217 | $function = $this->phpcsFile->findPrevious( |
218 | 218 | T_COMMENT, |
219 | 219 | $start, |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | '/* testPrivateStaticMethod */' |
223 | 223 | ); |
224 | 224 | |
225 | - $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
226 | - unset($found['return_type_token']); |
|
227 | - $this->assertSame($expected, $found); |
|
225 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 7 ) ); |
|
226 | + unset( $found[ 'return_type_token' ] ); |
|
227 | + $this->assertSame( $expected, $found ); |
|
228 | 228 | |
229 | 229 | }//end testPrivateStaticMethod() |
230 | 230 | |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | 'has_body' => true, |
248 | 248 | ]; |
249 | 249 | |
250 | - $start = ($this->phpcsFile->numTokens - 1); |
|
250 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
251 | 251 | $function = $this->phpcsFile->findPrevious( |
252 | 252 | T_COMMENT, |
253 | 253 | $start, |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | '/* testFinalMethod */' |
257 | 257 | ); |
258 | 258 | |
259 | - $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
260 | - unset($found['return_type_token']); |
|
261 | - $this->assertSame($expected, $found); |
|
259 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 7 ) ); |
|
260 | + unset( $found[ 'return_type_token' ] ); |
|
261 | + $this->assertSame( $expected, $found ); |
|
262 | 262 | |
263 | 263 | }//end testFinalMethod() |
264 | 264 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | 'has_body' => true, |
282 | 282 | ]; |
283 | 283 | |
284 | - $start = ($this->phpcsFile->numTokens - 1); |
|
284 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
285 | 285 | $function = $this->phpcsFile->findPrevious( |
286 | 286 | T_COMMENT, |
287 | 287 | $start, |
@@ -290,9 +290,9 @@ discard block |
||
290 | 290 | '/* testProtectedReturnMethod */' |
291 | 291 | ); |
292 | 292 | |
293 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
294 | - unset($found['return_type_token']); |
|
295 | - $this->assertSame($expected, $found); |
|
293 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 5 ) ); |
|
294 | + unset( $found[ 'return_type_token' ] ); |
|
295 | + $this->assertSame( $expected, $found ); |
|
296 | 296 | |
297 | 297 | }//end testProtectedReturnMethod() |
298 | 298 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | 'has_body' => true, |
316 | 316 | ]; |
317 | 317 | |
318 | - $start = ($this->phpcsFile->numTokens - 1); |
|
318 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
319 | 319 | $function = $this->phpcsFile->findPrevious( |
320 | 320 | T_COMMENT, |
321 | 321 | $start, |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | '/* testPublicReturnMethod */' |
325 | 325 | ); |
326 | 326 | |
327 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
328 | - unset($found['return_type_token']); |
|
329 | - $this->assertSame($expected, $found); |
|
327 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 5 ) ); |
|
328 | + unset( $found[ 'return_type_token' ] ); |
|
329 | + $this->assertSame( $expected, $found ); |
|
330 | 330 | |
331 | 331 | }//end testPublicReturnMethod() |
332 | 332 | |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | 'has_body' => true, |
350 | 350 | ]; |
351 | 351 | |
352 | - $start = ($this->phpcsFile->numTokens - 1); |
|
352 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
353 | 353 | $function = $this->phpcsFile->findPrevious( |
354 | 354 | T_COMMENT, |
355 | 355 | $start, |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | '/* testNullableReturnMethod */' |
359 | 359 | ); |
360 | 360 | |
361 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
362 | - unset($found['return_type_token']); |
|
363 | - $this->assertSame($expected, $found); |
|
361 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 5 ) ); |
|
362 | + unset( $found[ 'return_type_token' ] ); |
|
363 | + $this->assertSame( $expected, $found ); |
|
364 | 364 | |
365 | 365 | }//end testNullableReturnMethod() |
366 | 366 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | 'has_body' => true, |
384 | 384 | ]; |
385 | 385 | |
386 | - $start = ($this->phpcsFile->numTokens - 1); |
|
386 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
387 | 387 | $function = $this->phpcsFile->findPrevious( |
388 | 388 | T_COMMENT, |
389 | 389 | $start, |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | '/* testMessyNullableReturnMethod */' |
393 | 393 | ); |
394 | 394 | |
395 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
396 | - unset($found['return_type_token']); |
|
397 | - $this->assertSame($expected, $found); |
|
395 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 5 ) ); |
|
396 | + unset( $found[ 'return_type_token' ] ); |
|
397 | + $this->assertSame( $expected, $found ); |
|
398 | 398 | |
399 | 399 | }//end testMessyNullableReturnMethod() |
400 | 400 | |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | 'has_body' => true, |
418 | 418 | ]; |
419 | 419 | |
420 | - $start = ($this->phpcsFile->numTokens - 1); |
|
420 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
421 | 421 | $function = $this->phpcsFile->findPrevious( |
422 | 422 | T_COMMENT, |
423 | 423 | $start, |
@@ -426,9 +426,9 @@ discard block |
||
426 | 426 | '/* testReturnNamespace */' |
427 | 427 | ); |
428 | 428 | |
429 | - $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
430 | - unset($found['return_type_token']); |
|
431 | - $this->assertSame($expected, $found); |
|
429 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 3 ) ); |
|
430 | + unset( $found[ 'return_type_token' ] ); |
|
431 | + $this->assertSame( $expected, $found ); |
|
432 | 432 | |
433 | 433 | }//end testReturnNamespace() |
434 | 434 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | 'has_body' => true, |
452 | 452 | ]; |
453 | 453 | |
454 | - $start = ($this->phpcsFile->numTokens - 1); |
|
454 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
455 | 455 | $function = $this->phpcsFile->findPrevious( |
456 | 456 | T_COMMENT, |
457 | 457 | $start, |
@@ -460,9 +460,9 @@ discard block |
||
460 | 460 | '/* testReturnMultilineNamespace */' |
461 | 461 | ); |
462 | 462 | |
463 | - $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
464 | - unset($found['return_type_token']); |
|
465 | - $this->assertSame($expected, $found); |
|
463 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 3 ) ); |
|
464 | + unset( $found[ 'return_type_token' ] ); |
|
465 | + $this->assertSame( $expected, $found ); |
|
466 | 466 | |
467 | 467 | }//end testReturnMultilineNamespace() |
468 | 468 | |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | 'has_body' => false, |
486 | 486 | ]; |
487 | 487 | |
488 | - $start = ($this->phpcsFile->numTokens - 1); |
|
488 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
489 | 489 | $function = $this->phpcsFile->findPrevious( |
490 | 490 | T_COMMENT, |
491 | 491 | $start, |
@@ -494,9 +494,9 @@ discard block |
||
494 | 494 | '/* testAbstractMethod */' |
495 | 495 | ); |
496 | 496 | |
497 | - $found = $this->phpcsFile->getMethodProperties(($function + 5)); |
|
498 | - unset($found['return_type_token']); |
|
499 | - $this->assertSame($expected, $found); |
|
497 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 5 ) ); |
|
498 | + unset( $found[ 'return_type_token' ] ); |
|
499 | + $this->assertSame( $expected, $found ); |
|
500 | 500 | |
501 | 501 | }//end testAbstractMethod() |
502 | 502 | |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | 'has_body' => false, |
520 | 520 | ]; |
521 | 521 | |
522 | - $start = ($this->phpcsFile->numTokens - 1); |
|
522 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
523 | 523 | $function = $this->phpcsFile->findPrevious( |
524 | 524 | T_COMMENT, |
525 | 525 | $start, |
@@ -528,9 +528,9 @@ discard block |
||
528 | 528 | '/* testAbstractReturnMethod */' |
529 | 529 | ); |
530 | 530 | |
531 | - $found = $this->phpcsFile->getMethodProperties(($function + 7)); |
|
532 | - unset($found['return_type_token']); |
|
533 | - $this->assertSame($expected, $found); |
|
531 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 7 ) ); |
|
532 | + unset( $found[ 'return_type_token' ] ); |
|
533 | + $this->assertSame( $expected, $found ); |
|
534 | 534 | |
535 | 535 | }//end testAbstractReturnMethod() |
536 | 536 | |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | 'has_body' => false, |
554 | 554 | ]; |
555 | 555 | |
556 | - $start = ($this->phpcsFile->numTokens - 1); |
|
556 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
557 | 557 | $function = $this->phpcsFile->findPrevious( |
558 | 558 | T_COMMENT, |
559 | 559 | $start, |
@@ -562,9 +562,9 @@ discard block |
||
562 | 562 | '/* testInterfaceMethod */' |
563 | 563 | ); |
564 | 564 | |
565 | - $found = $this->phpcsFile->getMethodProperties(($function + 3)); |
|
566 | - unset($found['return_type_token']); |
|
567 | - $this->assertSame($expected, $found); |
|
565 | + $found = $this->phpcsFile->getMethodProperties( ( $function + 3 ) ); |
|
566 | + unset( $found[ 'return_type_token' ] ); |
|
567 | + $this->assertSame( $expected, $found ); |
|
568 | 568 | |
569 | 569 | }//end testInterfaceMethod() |
570 | 570 |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | use PHP_CodeSniffer\Files\DummyFile; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | 16 | |
17 | -class GetMethodPropertiesTest extends TestCase |
|
18 | -{ |
|
17 | +class GetMethodPropertiesTest extends TestCase { |
|
19 | 18 | |
20 | 19 | /** |
21 | 20 | * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | * |
34 | 33 | * @return void |
35 | 34 | */ |
36 | - public function setUp() |
|
37 | - { |
|
35 | + public function setUp() { |
|
38 | 36 | $config = new Config(); |
39 | 37 | $config->standards = ['Generic']; |
40 | 38 | |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | * |
53 | 51 | * @return void |
54 | 52 | */ |
55 | - public function tearDown() |
|
56 | - { |
|
53 | + public function tearDown() { |
|
57 | 54 | unset($this->phpcsFile); |
58 | 55 | |
59 | 56 | }//end tearDown() |
@@ -64,8 +61,7 @@ discard block |
||
64 | 61 | * |
65 | 62 | * @return void |
66 | 63 | */ |
67 | - public function testBasicFunction() |
|
68 | - { |
|
64 | + public function testBasicFunction() { |
|
69 | 65 | $expected = [ |
70 | 66 | 'scope' => 'public', |
71 | 67 | 'scope_specified' => false, |
@@ -98,8 +94,7 @@ discard block |
||
98 | 94 | * |
99 | 95 | * @return void |
100 | 96 | */ |
101 | - public function testReturnFunction() |
|
102 | - { |
|
97 | + public function testReturnFunction() { |
|
103 | 98 | $expected = [ |
104 | 99 | 'scope' => 'public', |
105 | 100 | 'scope_specified' => false, |
@@ -132,8 +127,7 @@ discard block |
||
132 | 127 | * |
133 | 128 | * @return void |
134 | 129 | */ |
135 | - public function testNestedClosure() |
|
136 | - { |
|
130 | + public function testNestedClosure() { |
|
137 | 131 | $expected = [ |
138 | 132 | 'scope' => 'public', |
139 | 133 | 'scope_specified' => false, |
@@ -166,8 +160,7 @@ discard block |
||
166 | 160 | * |
167 | 161 | * @return void |
168 | 162 | */ |
169 | - public function testBasicMethod() |
|
170 | - { |
|
163 | + public function testBasicMethod() { |
|
171 | 164 | $expected = [ |
172 | 165 | 'scope' => 'public', |
173 | 166 | 'scope_specified' => false, |
@@ -200,8 +193,7 @@ discard block |
||
200 | 193 | * |
201 | 194 | * @return void |
202 | 195 | */ |
203 | - public function testPrivateStaticMethod() |
|
204 | - { |
|
196 | + public function testPrivateStaticMethod() { |
|
205 | 197 | $expected = [ |
206 | 198 | 'scope' => 'private', |
207 | 199 | 'scope_specified' => true, |
@@ -234,8 +226,7 @@ discard block |
||
234 | 226 | * |
235 | 227 | * @return void |
236 | 228 | */ |
237 | - public function testFinalMethod() |
|
238 | - { |
|
229 | + public function testFinalMethod() { |
|
239 | 230 | $expected = [ |
240 | 231 | 'scope' => 'public', |
241 | 232 | 'scope_specified' => true, |
@@ -268,8 +259,7 @@ discard block |
||
268 | 259 | * |
269 | 260 | * @return void |
270 | 261 | */ |
271 | - public function testProtectedReturnMethod() |
|
272 | - { |
|
262 | + public function testProtectedReturnMethod() { |
|
273 | 263 | $expected = [ |
274 | 264 | 'scope' => 'protected', |
275 | 265 | 'scope_specified' => true, |
@@ -302,8 +292,7 @@ discard block |
||
302 | 292 | * |
303 | 293 | * @return void |
304 | 294 | */ |
305 | - public function testPublicReturnMethod() |
|
306 | - { |
|
295 | + public function testPublicReturnMethod() { |
|
307 | 296 | $expected = [ |
308 | 297 | 'scope' => 'public', |
309 | 298 | 'scope_specified' => true, |
@@ -336,8 +325,7 @@ discard block |
||
336 | 325 | * |
337 | 326 | * @return void |
338 | 327 | */ |
339 | - public function testNullableReturnMethod() |
|
340 | - { |
|
328 | + public function testNullableReturnMethod() { |
|
341 | 329 | $expected = [ |
342 | 330 | 'scope' => 'public', |
343 | 331 | 'scope_specified' => true, |
@@ -370,8 +358,7 @@ discard block |
||
370 | 358 | * |
371 | 359 | * @return void |
372 | 360 | */ |
373 | - public function testMessyNullableReturnMethod() |
|
374 | - { |
|
361 | + public function testMessyNullableReturnMethod() { |
|
375 | 362 | $expected = [ |
376 | 363 | 'scope' => 'public', |
377 | 364 | 'scope_specified' => true, |
@@ -404,8 +391,7 @@ discard block |
||
404 | 391 | * |
405 | 392 | * @return void |
406 | 393 | */ |
407 | - public function testReturnNamespace() |
|
408 | - { |
|
394 | + public function testReturnNamespace() { |
|
409 | 395 | $expected = [ |
410 | 396 | 'scope' => 'public', |
411 | 397 | 'scope_specified' => false, |
@@ -438,8 +424,7 @@ discard block |
||
438 | 424 | * |
439 | 425 | * @return void |
440 | 426 | */ |
441 | - public function testReturnMultilineNamespace() |
|
442 | - { |
|
427 | + public function testReturnMultilineNamespace() { |
|
443 | 428 | $expected = [ |
444 | 429 | 'scope' => 'public', |
445 | 430 | 'scope_specified' => false, |
@@ -472,8 +457,7 @@ discard block |
||
472 | 457 | * |
473 | 458 | * @return void |
474 | 459 | */ |
475 | - public function testAbstractMethod() |
|
476 | - { |
|
460 | + public function testAbstractMethod() { |
|
477 | 461 | $expected = [ |
478 | 462 | 'scope' => 'public', |
479 | 463 | 'scope_specified' => false, |
@@ -506,8 +490,7 @@ discard block |
||
506 | 490 | * |
507 | 491 | * @return void |
508 | 492 | */ |
509 | - public function testAbstractReturnMethod() |
|
510 | - { |
|
493 | + public function testAbstractReturnMethod() { |
|
511 | 494 | $expected = [ |
512 | 495 | 'scope' => 'protected', |
513 | 496 | 'scope_specified' => true, |
@@ -540,8 +523,7 @@ discard block |
||
540 | 523 | * |
541 | 524 | * @return void |
542 | 525 | */ |
543 | - public function testInterfaceMethod() |
|
544 | - { |
|
526 | + public function testInterfaceMethod() { |
|
545 | 527 | $expected = [ |
546 | 528 | 'scope' => 'public', |
547 | 529 | 'scope_specified' => false, |
@@ -17,269 +17,269 @@ |
||
17 | 17 | class IsReferenceTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
|
22 | - * |
|
23 | - * @var \PHP_CodeSniffer\Files\File |
|
24 | - */ |
|
25 | - private $phpcsFile; |
|
20 | + /** |
|
21 | + * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
|
22 | + * |
|
23 | + * @var \PHP_CodeSniffer\Files\File |
|
24 | + */ |
|
25 | + private $phpcsFile; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file. |
|
30 | - * |
|
31 | - * Methods used for these tests can be found in a test case file in the same |
|
32 | - * directory and with the same name, using the .inc extension. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setUp() |
|
37 | - { |
|
38 | - $config = new Config(); |
|
39 | - $config->standards = ['Generic']; |
|
28 | + /** |
|
29 | + * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file. |
|
30 | + * |
|
31 | + * Methods used for these tests can be found in a test case file in the same |
|
32 | + * directory and with the same name, using the .inc extension. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setUp() |
|
37 | + { |
|
38 | + $config = new Config(); |
|
39 | + $config->standards = ['Generic']; |
|
40 | 40 | |
41 | - $ruleset = new Ruleset($config); |
|
41 | + $ruleset = new Ruleset($config); |
|
42 | 42 | |
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | - $this->phpcsFile->process(); |
|
43 | + $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | + $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | + $this->phpcsFile->process(); |
|
46 | 46 | |
47 | - }//end setUp() |
|
47 | + }//end setUp() |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Clean up after finished test. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function tearDown() |
|
56 | - { |
|
57 | - unset($this->phpcsFile); |
|
50 | + /** |
|
51 | + * Clean up after finished test. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function tearDown() |
|
56 | + { |
|
57 | + unset($this->phpcsFile); |
|
58 | 58 | |
59 | - }//end tearDown() |
|
59 | + }//end tearDown() |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Test a class that extends another. |
|
64 | - * |
|
65 | - * @param string $identifier Comment which precedes the test case. |
|
66 | - * @param bool $expected Expected function output. |
|
67 | - * |
|
68 | - * @dataProvider dataIsReference |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function testIsReference($identifier, $expected) |
|
73 | - { |
|
74 | - $start = ($this->phpcsFile->numTokens - 1); |
|
75 | - $delim = $this->phpcsFile->findPrevious( |
|
76 | - T_COMMENT, |
|
77 | - $start, |
|
78 | - null, |
|
79 | - false, |
|
80 | - $identifier |
|
81 | - ); |
|
82 | - $bitwiseAnd = $this->phpcsFile->findNext(T_BITWISE_AND, ($delim + 1)); |
|
62 | + /** |
|
63 | + * Test a class that extends another. |
|
64 | + * |
|
65 | + * @param string $identifier Comment which precedes the test case. |
|
66 | + * @param bool $expected Expected function output. |
|
67 | + * |
|
68 | + * @dataProvider dataIsReference |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function testIsReference($identifier, $expected) |
|
73 | + { |
|
74 | + $start = ($this->phpcsFile->numTokens - 1); |
|
75 | + $delim = $this->phpcsFile->findPrevious( |
|
76 | + T_COMMENT, |
|
77 | + $start, |
|
78 | + null, |
|
79 | + false, |
|
80 | + $identifier |
|
81 | + ); |
|
82 | + $bitwiseAnd = $this->phpcsFile->findNext(T_BITWISE_AND, ($delim + 1)); |
|
83 | 83 | |
84 | - $result = $this->phpcsFile->isReference($bitwiseAnd); |
|
85 | - $this->assertSame($expected, $result); |
|
84 | + $result = $this->phpcsFile->isReference($bitwiseAnd); |
|
85 | + $this->assertSame($expected, $result); |
|
86 | 86 | |
87 | - }//end testIsReference() |
|
87 | + }//end testIsReference() |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * Data provider for the IsReference test. |
|
92 | - * |
|
93 | - * @see testIsReference() |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function dataIsReference() |
|
98 | - { |
|
99 | - return [ |
|
100 | - [ |
|
101 | - '/* bitwiseAndA */', |
|
102 | - false, |
|
103 | - ], |
|
104 | - [ |
|
105 | - '/* bitwiseAndB */', |
|
106 | - false, |
|
107 | - ], |
|
108 | - [ |
|
109 | - '/* bitwiseAndC */', |
|
110 | - false, |
|
111 | - ], |
|
112 | - [ |
|
113 | - '/* bitwiseAndD */', |
|
114 | - false, |
|
115 | - ], |
|
116 | - [ |
|
117 | - '/* bitwiseAndE */', |
|
118 | - false, |
|
119 | - ], |
|
120 | - [ |
|
121 | - '/* bitwiseAndF */', |
|
122 | - false, |
|
123 | - ], |
|
124 | - [ |
|
125 | - '/* bitwiseAndG */', |
|
126 | - false, |
|
127 | - ], |
|
128 | - [ |
|
129 | - '/* bitwiseAndH */', |
|
130 | - false, |
|
131 | - ], |
|
132 | - [ |
|
133 | - '/* bitwiseAndI */', |
|
134 | - false, |
|
135 | - ], |
|
136 | - [ |
|
137 | - '/* functionReturnByReference */', |
|
138 | - true, |
|
139 | - ], |
|
140 | - [ |
|
141 | - '/* functionPassByReferenceA */', |
|
142 | - true, |
|
143 | - ], |
|
144 | - [ |
|
145 | - '/* functionPassByReferenceB */', |
|
146 | - true, |
|
147 | - ], |
|
148 | - [ |
|
149 | - '/* functionPassByReferenceC */', |
|
150 | - true, |
|
151 | - ], |
|
152 | - [ |
|
153 | - '/* functionPassByReferenceD */', |
|
154 | - true, |
|
155 | - ], |
|
156 | - [ |
|
157 | - '/* functionPassByReferenceE */', |
|
158 | - true, |
|
159 | - ], |
|
160 | - [ |
|
161 | - '/* functionPassByReferenceF */', |
|
162 | - true, |
|
163 | - ], |
|
164 | - [ |
|
165 | - '/* functionPassByReferenceG */', |
|
166 | - true, |
|
167 | - ], |
|
168 | - [ |
|
169 | - '/* foreachValueByReference */', |
|
170 | - true, |
|
171 | - ], |
|
172 | - [ |
|
173 | - '/* foreachKeyByReference */', |
|
174 | - true, |
|
175 | - ], |
|
176 | - [ |
|
177 | - '/* arrayValueByReferenceA */', |
|
178 | - true, |
|
179 | - ], |
|
180 | - [ |
|
181 | - '/* arrayValueByReferenceB */', |
|
182 | - true, |
|
183 | - ], |
|
184 | - [ |
|
185 | - '/* arrayValueByReferenceC */', |
|
186 | - true, |
|
187 | - ], |
|
188 | - [ |
|
189 | - '/* arrayValueByReferenceD */', |
|
190 | - true, |
|
191 | - ], |
|
192 | - [ |
|
193 | - '/* arrayValueByReferenceE */', |
|
194 | - true, |
|
195 | - ], |
|
196 | - [ |
|
197 | - '/* arrayValueByReferenceF */', |
|
198 | - true, |
|
199 | - ], |
|
200 | - [ |
|
201 | - '/* arrayValueByReferenceG */', |
|
202 | - true, |
|
203 | - ], |
|
204 | - [ |
|
205 | - '/* arrayValueByReferenceH */', |
|
206 | - true, |
|
207 | - ], |
|
208 | - [ |
|
209 | - '/* assignByReferenceA */', |
|
210 | - true, |
|
211 | - ], |
|
212 | - [ |
|
213 | - '/* assignByReferenceB */', |
|
214 | - true, |
|
215 | - ], |
|
216 | - [ |
|
217 | - '/* assignByReferenceC */', |
|
218 | - true, |
|
219 | - ], |
|
220 | - [ |
|
221 | - '/* assignByReferenceD */', |
|
222 | - true, |
|
223 | - ], |
|
224 | - [ |
|
225 | - '/* assignByReferenceE */', |
|
226 | - true, |
|
227 | - ], |
|
228 | - [ |
|
229 | - '/* passByReferenceA */', |
|
230 | - true, |
|
231 | - ], |
|
232 | - [ |
|
233 | - '/* passByReferenceB */', |
|
234 | - true, |
|
235 | - ], |
|
236 | - [ |
|
237 | - '/* passByReferenceC */', |
|
238 | - true, |
|
239 | - ], |
|
240 | - [ |
|
241 | - '/* passByReferenceD */', |
|
242 | - true, |
|
243 | - ], |
|
244 | - [ |
|
245 | - '/* passByReferenceE */', |
|
246 | - true, |
|
247 | - ], |
|
248 | - [ |
|
249 | - '/* passByReferenceF */', |
|
250 | - true, |
|
251 | - ], |
|
252 | - [ |
|
253 | - '/* passByReferenceG */', |
|
254 | - true, |
|
255 | - ], |
|
256 | - [ |
|
257 | - '/* passByReferenceH */', |
|
258 | - true, |
|
259 | - ], |
|
260 | - [ |
|
261 | - '/* passByReferenceI */', |
|
262 | - true, |
|
263 | - ], |
|
264 | - [ |
|
265 | - '/* passByReferenceJ */', |
|
266 | - true, |
|
267 | - ], |
|
268 | - [ |
|
269 | - '/* newByReferenceA */', |
|
270 | - true, |
|
271 | - ], |
|
272 | - [ |
|
273 | - '/* newByReferenceB */', |
|
274 | - true, |
|
275 | - ], |
|
276 | - [ |
|
277 | - '/* useByReference */', |
|
278 | - true, |
|
279 | - ], |
|
280 | - ]; |
|
90 | + /** |
|
91 | + * Data provider for the IsReference test. |
|
92 | + * |
|
93 | + * @see testIsReference() |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function dataIsReference() |
|
98 | + { |
|
99 | + return [ |
|
100 | + [ |
|
101 | + '/* bitwiseAndA */', |
|
102 | + false, |
|
103 | + ], |
|
104 | + [ |
|
105 | + '/* bitwiseAndB */', |
|
106 | + false, |
|
107 | + ], |
|
108 | + [ |
|
109 | + '/* bitwiseAndC */', |
|
110 | + false, |
|
111 | + ], |
|
112 | + [ |
|
113 | + '/* bitwiseAndD */', |
|
114 | + false, |
|
115 | + ], |
|
116 | + [ |
|
117 | + '/* bitwiseAndE */', |
|
118 | + false, |
|
119 | + ], |
|
120 | + [ |
|
121 | + '/* bitwiseAndF */', |
|
122 | + false, |
|
123 | + ], |
|
124 | + [ |
|
125 | + '/* bitwiseAndG */', |
|
126 | + false, |
|
127 | + ], |
|
128 | + [ |
|
129 | + '/* bitwiseAndH */', |
|
130 | + false, |
|
131 | + ], |
|
132 | + [ |
|
133 | + '/* bitwiseAndI */', |
|
134 | + false, |
|
135 | + ], |
|
136 | + [ |
|
137 | + '/* functionReturnByReference */', |
|
138 | + true, |
|
139 | + ], |
|
140 | + [ |
|
141 | + '/* functionPassByReferenceA */', |
|
142 | + true, |
|
143 | + ], |
|
144 | + [ |
|
145 | + '/* functionPassByReferenceB */', |
|
146 | + true, |
|
147 | + ], |
|
148 | + [ |
|
149 | + '/* functionPassByReferenceC */', |
|
150 | + true, |
|
151 | + ], |
|
152 | + [ |
|
153 | + '/* functionPassByReferenceD */', |
|
154 | + true, |
|
155 | + ], |
|
156 | + [ |
|
157 | + '/* functionPassByReferenceE */', |
|
158 | + true, |
|
159 | + ], |
|
160 | + [ |
|
161 | + '/* functionPassByReferenceF */', |
|
162 | + true, |
|
163 | + ], |
|
164 | + [ |
|
165 | + '/* functionPassByReferenceG */', |
|
166 | + true, |
|
167 | + ], |
|
168 | + [ |
|
169 | + '/* foreachValueByReference */', |
|
170 | + true, |
|
171 | + ], |
|
172 | + [ |
|
173 | + '/* foreachKeyByReference */', |
|
174 | + true, |
|
175 | + ], |
|
176 | + [ |
|
177 | + '/* arrayValueByReferenceA */', |
|
178 | + true, |
|
179 | + ], |
|
180 | + [ |
|
181 | + '/* arrayValueByReferenceB */', |
|
182 | + true, |
|
183 | + ], |
|
184 | + [ |
|
185 | + '/* arrayValueByReferenceC */', |
|
186 | + true, |
|
187 | + ], |
|
188 | + [ |
|
189 | + '/* arrayValueByReferenceD */', |
|
190 | + true, |
|
191 | + ], |
|
192 | + [ |
|
193 | + '/* arrayValueByReferenceE */', |
|
194 | + true, |
|
195 | + ], |
|
196 | + [ |
|
197 | + '/* arrayValueByReferenceF */', |
|
198 | + true, |
|
199 | + ], |
|
200 | + [ |
|
201 | + '/* arrayValueByReferenceG */', |
|
202 | + true, |
|
203 | + ], |
|
204 | + [ |
|
205 | + '/* arrayValueByReferenceH */', |
|
206 | + true, |
|
207 | + ], |
|
208 | + [ |
|
209 | + '/* assignByReferenceA */', |
|
210 | + true, |
|
211 | + ], |
|
212 | + [ |
|
213 | + '/* assignByReferenceB */', |
|
214 | + true, |
|
215 | + ], |
|
216 | + [ |
|
217 | + '/* assignByReferenceC */', |
|
218 | + true, |
|
219 | + ], |
|
220 | + [ |
|
221 | + '/* assignByReferenceD */', |
|
222 | + true, |
|
223 | + ], |
|
224 | + [ |
|
225 | + '/* assignByReferenceE */', |
|
226 | + true, |
|
227 | + ], |
|
228 | + [ |
|
229 | + '/* passByReferenceA */', |
|
230 | + true, |
|
231 | + ], |
|
232 | + [ |
|
233 | + '/* passByReferenceB */', |
|
234 | + true, |
|
235 | + ], |
|
236 | + [ |
|
237 | + '/* passByReferenceC */', |
|
238 | + true, |
|
239 | + ], |
|
240 | + [ |
|
241 | + '/* passByReferenceD */', |
|
242 | + true, |
|
243 | + ], |
|
244 | + [ |
|
245 | + '/* passByReferenceE */', |
|
246 | + true, |
|
247 | + ], |
|
248 | + [ |
|
249 | + '/* passByReferenceF */', |
|
250 | + true, |
|
251 | + ], |
|
252 | + [ |
|
253 | + '/* passByReferenceG */', |
|
254 | + true, |
|
255 | + ], |
|
256 | + [ |
|
257 | + '/* passByReferenceH */', |
|
258 | + true, |
|
259 | + ], |
|
260 | + [ |
|
261 | + '/* passByReferenceI */', |
|
262 | + true, |
|
263 | + ], |
|
264 | + [ |
|
265 | + '/* passByReferenceJ */', |
|
266 | + true, |
|
267 | + ], |
|
268 | + [ |
|
269 | + '/* newByReferenceA */', |
|
270 | + true, |
|
271 | + ], |
|
272 | + [ |
|
273 | + '/* newByReferenceB */', |
|
274 | + true, |
|
275 | + ], |
|
276 | + [ |
|
277 | + '/* useByReference */', |
|
278 | + true, |
|
279 | + ], |
|
280 | + ]; |
|
281 | 281 | |
282 | - }//end dataIsReference() |
|
282 | + }//end dataIsReference() |
|
283 | 283 | |
284 | 284 | |
285 | 285 | }//end class |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | public function setUp() |
37 | 37 | { |
38 | 38 | $config = new Config(); |
39 | - $config->standards = ['Generic']; |
|
39 | + $config->standards = [ 'Generic' ]; |
|
40 | 40 | |
41 | - $ruleset = new Ruleset($config); |
|
41 | + $ruleset = new Ruleset( $config ); |
|
42 | 42 | |
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
43 | + $pathToTestFile = dirname( __FILE__ ) . '/' . basename( __FILE__, '.php' ) . '.inc'; |
|
44 | + $this->phpcsFile = new DummyFile( file_get_contents( $pathToTestFile ), $ruleset, $config ); |
|
45 | 45 | $this->phpcsFile->process(); |
46 | 46 | |
47 | 47 | }//end setUp() |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function tearDown() |
56 | 56 | { |
57 | - unset($this->phpcsFile); |
|
57 | + unset( $this->phpcsFile ); |
|
58 | 58 | |
59 | 59 | }//end tearDown() |
60 | 60 | |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function testIsReference($identifier, $expected) |
|
72 | + public function testIsReference( $identifier, $expected ) |
|
73 | 73 | { |
74 | - $start = ($this->phpcsFile->numTokens - 1); |
|
74 | + $start = ( $this->phpcsFile->numTokens - 1 ); |
|
75 | 75 | $delim = $this->phpcsFile->findPrevious( |
76 | 76 | T_COMMENT, |
77 | 77 | $start, |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | false, |
80 | 80 | $identifier |
81 | 81 | ); |
82 | - $bitwiseAnd = $this->phpcsFile->findNext(T_BITWISE_AND, ($delim + 1)); |
|
82 | + $bitwiseAnd = $this->phpcsFile->findNext( T_BITWISE_AND, ( $delim + 1 ) ); |
|
83 | 83 | |
84 | - $result = $this->phpcsFile->isReference($bitwiseAnd); |
|
85 | - $this->assertSame($expected, $result); |
|
84 | + $result = $this->phpcsFile->isReference( $bitwiseAnd ); |
|
85 | + $this->assertSame( $expected, $result ); |
|
86 | 86 | |
87 | 87 | }//end testIsReference() |
88 | 88 |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | use PHP_CodeSniffer\Files\DummyFile; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | 16 | |
17 | -class IsReferenceTest extends TestCase |
|
18 | -{ |
|
17 | +class IsReferenceTest extends TestCase { |
|
19 | 18 | |
20 | 19 | /** |
21 | 20 | * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | * |
34 | 33 | * @return void |
35 | 34 | */ |
36 | - public function setUp() |
|
37 | - { |
|
35 | + public function setUp() { |
|
38 | 36 | $config = new Config(); |
39 | 37 | $config->standards = ['Generic']; |
40 | 38 | |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | * |
53 | 51 | * @return void |
54 | 52 | */ |
55 | - public function tearDown() |
|
56 | - { |
|
53 | + public function tearDown() { |
|
57 | 54 | unset($this->phpcsFile); |
58 | 55 | |
59 | 56 | }//end tearDown() |
@@ -69,8 +66,7 @@ discard block |
||
69 | 66 | * |
70 | 67 | * @return void |
71 | 68 | */ |
72 | - public function testIsReference($identifier, $expected) |
|
73 | - { |
|
69 | + public function testIsReference($identifier, $expected) { |
|
74 | 70 | $start = ($this->phpcsFile->numTokens - 1); |
75 | 71 | $delim = $this->phpcsFile->findPrevious( |
76 | 72 | T_COMMENT, |
@@ -94,8 +90,7 @@ discard block |
||
94 | 90 | * |
95 | 91 | * @return array |
96 | 92 | */ |
97 | - public function dataIsReference() |
|
98 | - { |
|
93 | + public function dataIsReference() { |
|
99 | 94 | return [ |
100 | 95 | [ |
101 | 96 | '/* bitwiseAndA */', |
@@ -17,10 +17,10 @@ |
||
17 | 17 | interface testFECNInterface {} |
18 | 18 | |
19 | 19 | /* testInterfaceThatExtendsInterface */ |
20 | -interface testInterfaceThatExtendsInterface extends testFECNInterface{} |
|
20 | +interface testInterfaceThatExtendsInterface extends testFECNInterface {} |
|
21 | 21 | |
22 | 22 | /* testInterfaceThatExtendsFQCNInterface */ |
23 | -interface testInterfaceThatExtendsFQCNInterface extends \PHP_CodeSniffer\Tests\Core\File\testFECNInterface{} |
|
23 | +interface testInterfaceThatExtendsFQCNInterface extends \PHP_CodeSniffer\Tests\Core\File\testFECNInterface {} |
|
24 | 24 | |
25 | 25 | /* testNestedExtendedClass */ |
26 | 26 | class testFECNNestedExtendedClass { |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | $a = $something & $somethingElse; |
25 | 25 | |
26 | 26 | /* bitwiseAndH */ |
27 | -function myFunction($a = 10 & 20) {} |
|
27 | +function myFunction( $a = 10 & 20 ) {} |
|
28 | 28 | |
29 | 29 | /* bitwiseAndI */ |
30 | -$closure = function ($a = MY_CONSTANT & parent::OTHER_CONSTANT) {}; |
|
30 | +$closure = function( $a = MY_CONSTANT & parent::OTHER_CONSTANT ) {}; |
|
31 | 31 | |
32 | 32 | /* functionReturnByReference */ |
33 | 33 | function &myFunction() {} |
@@ -39,25 +39,25 @@ discard block |
||
39 | 39 | function myFunction( $a, &$b ) {} |
40 | 40 | |
41 | 41 | /* functionPassByReferenceC */ |
42 | -$closure = function ( &$a ) {}; |
|
42 | +$closure = function( &$a ) {}; |
|
43 | 43 | |
44 | 44 | /* functionPassByReferenceD */ |
45 | -$closure = function ( $a, &$b ) {}; |
|
45 | +$closure = function( $a, &$b ) {}; |
|
46 | 46 | |
47 | 47 | /* functionPassByReferenceE */ |
48 | -function myFunction(array &$one) {} |
|
48 | +function myFunction( array &$one ) {} |
|
49 | 49 | |
50 | 50 | /* functionPassByReferenceF */ |
51 | -$closure = function (\MyClass &$one) {}; |
|
51 | +$closure = function( \MyClass &$one ) {}; |
|
52 | 52 | |
53 | 53 | /* functionPassByReferenceG */ |
54 | -$closure = function myFunc($param, &...$moreParams) {}; |
|
54 | +$closure = function myFunc( $param, &...$moreParams ) {}; |
|
55 | 55 | |
56 | 56 | /* foreachValueByReference */ |
57 | -foreach( $array as $key => &$value ) {} |
|
57 | +foreach ( $array as $key => &$value ) {} |
|
58 | 58 | |
59 | 59 | /* foreachKeyByReference */ |
60 | -foreach( $array as &$key => $value ) {} |
|
60 | +foreach ( $array as &$key => $value ) {} |
|
61 | 61 | |
62 | 62 | /* arrayValueByReferenceA */ |
63 | 63 | $a = [ 'a' => &$something ]; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $b = &$something; |
88 | 88 | |
89 | 89 | /* assignByReferenceB */ |
90 | -$b =& $something; |
|
90 | +$b = & $something; |
|
91 | 91 | |
92 | 92 | /* assignByReferenceC */ |
93 | 93 | $b .= &$something; |
@@ -99,40 +99,40 @@ discard block |
||
99 | 99 | $collection = &collector(); |
100 | 100 | |
101 | 101 | /* passByReferenceA */ |
102 | -functionCall(&$something, $somethingElse); |
|
102 | +functionCall( &$something, $somethingElse ); |
|
103 | 103 | |
104 | 104 | /* passByReferenceB */ |
105 | -functionCall($something, &$somethingElse); |
|
105 | +functionCall( $something, &$somethingElse ); |
|
106 | 106 | |
107 | 107 | /* passByReferenceC */ |
108 | -functionCall($something, &$this->somethingElse); |
|
108 | +functionCall( $something, &$this->somethingElse ); |
|
109 | 109 | |
110 | 110 | /* passByReferenceD */ |
111 | -functionCall($something, &self::$somethingElse); |
|
111 | +functionCall( $something, &self::$somethingElse ); |
|
112 | 112 | |
113 | 113 | /* passByReferenceE */ |
114 | -functionCall($something, &parent::$somethingElse); |
|
114 | +functionCall( $something, &parent::$somethingElse ); |
|
115 | 115 | |
116 | 116 | /* passByReferenceF */ |
117 | -functionCall($something, &static::$somethingElse); |
|
117 | +functionCall( $something, &static::$somethingElse ); |
|
118 | 118 | |
119 | 119 | /* passByReferenceG */ |
120 | -functionCall($something, &SomeClass::$somethingElse); |
|
120 | +functionCall( $something, &SomeClass::$somethingElse ); |
|
121 | 121 | |
122 | 122 | /* passByReferenceH */ |
123 | -functionCall(&\SomeClass::$somethingElse); |
|
123 | +functionCall( &\SomeClass::$somethingElse ); |
|
124 | 124 | |
125 | 125 | /* passByReferenceI */ |
126 | -functionCall($something, &\SomeNS\SomeClass::$somethingElse); |
|
126 | +functionCall( $something, &\SomeNS\SomeClass::$somethingElse ); |
|
127 | 127 | |
128 | 128 | /* passByReferenceJ */ |
129 | -functionCall($something, &namespace\SomeClass::$somethingElse); |
|
129 | +functionCall( $something, &namespace\SomeClass::$somethingElse ); |
|
130 | 130 | |
131 | 131 | /* newByReferenceA */ |
132 | 132 | $foobar2 = &new Foobar(); |
133 | 133 | |
134 | 134 | /* newByReferenceB */ |
135 | -functionCall( $something , &new Foobar() ); |
|
135 | +functionCall( $something, &new Foobar() ); |
|
136 | 136 | |
137 | 137 | /* useByReference */ |
138 | -$closure = function() use (&$var){}; |
|
138 | +$closure = function() use ( &$var ){}; |
@@ -26,38 +26,38 @@ |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * Prepare the test runner. |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function main() |
|
35 | - { |
|
36 | - TestRunner::run(self::suite()); |
|
37 | - |
|
38 | - }//end main() |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Add all core unit tests into a test suite. |
|
43 | - * |
|
44 | - * @return \PHPUnit\Framework\TestSuite |
|
45 | - */ |
|
46 | - public static function suite() |
|
47 | - { |
|
48 | - $suite = new TestSuite('PHP CodeSniffer Core'); |
|
49 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\IsCamelCapsTest'); |
|
50 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\ErrorSuppressionTest'); |
|
51 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindEndOfStatementTest'); |
|
52 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindExtendedClassNameTest'); |
|
53 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindImplementedInterfaceNamesTest'); |
|
54 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMemberPropertiesTest'); |
|
55 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodParametersTest'); |
|
56 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodPropertiesTest'); |
|
57 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\IsReferenceTest'); |
|
58 | - return $suite; |
|
59 | - |
|
60 | - }//end suite() |
|
29 | + /** |
|
30 | + * Prepare the test runner. |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function main() |
|
35 | + { |
|
36 | + TestRunner::run(self::suite()); |
|
37 | + |
|
38 | + }//end main() |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Add all core unit tests into a test suite. |
|
43 | + * |
|
44 | + * @return \PHPUnit\Framework\TestSuite |
|
45 | + */ |
|
46 | + public static function suite() |
|
47 | + { |
|
48 | + $suite = new TestSuite('PHP CodeSniffer Core'); |
|
49 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\IsCamelCapsTest'); |
|
50 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\ErrorSuppressionTest'); |
|
51 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindEndOfStatementTest'); |
|
52 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindExtendedClassNameTest'); |
|
53 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindImplementedInterfaceNamesTest'); |
|
54 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMemberPropertiesTest'); |
|
55 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodParametersTest'); |
|
56 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodPropertiesTest'); |
|
57 | + $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\IsReferenceTest'); |
|
58 | + return $suite; |
|
59 | + |
|
60 | + }//end suite() |
|
61 | 61 | |
62 | 62 | |
63 | 63 | }//end class |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public static function main() |
35 | 35 | { |
36 | - TestRunner::run(self::suite()); |
|
36 | + TestRunner::run( self::suite() ); |
|
37 | 37 | |
38 | 38 | }//end main() |
39 | 39 | |
@@ -45,16 +45,16 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public static function suite() |
47 | 47 | { |
48 | - $suite = new TestSuite('PHP CodeSniffer Core'); |
|
49 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\IsCamelCapsTest'); |
|
50 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\ErrorSuppressionTest'); |
|
51 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindEndOfStatementTest'); |
|
52 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindExtendedClassNameTest'); |
|
53 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\FindImplementedInterfaceNamesTest'); |
|
54 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMemberPropertiesTest'); |
|
55 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodParametersTest'); |
|
56 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodPropertiesTest'); |
|
57 | - $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\IsReferenceTest'); |
|
48 | + $suite = new TestSuite( 'PHP CodeSniffer Core' ); |
|
49 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\IsCamelCapsTest' ); |
|
50 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\ErrorSuppressionTest' ); |
|
51 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\File\FindEndOfStatementTest' ); |
|
52 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\File\FindExtendedClassNameTest' ); |
|
53 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\File\FindImplementedInterfaceNamesTest' ); |
|
54 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\File\GetMemberPropertiesTest' ); |
|
55 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\File\GetMethodParametersTest' ); |
|
56 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\File\GetMethodPropertiesTest' ); |
|
57 | + $suite->addTestSuite( 'PHP_CodeSniffer\Tests\Core\File\IsReferenceTest' ); |
|
58 | 58 | return $suite; |
59 | 59 | |
60 | 60 | }//end suite() |
@@ -22,8 +22,7 @@ discard block |
||
22 | 22 | require_once 'File/GetMethodPropertiesTest.php'; |
23 | 23 | require_once 'File/IsReferenceTest.php'; |
24 | 24 | |
25 | -class AllTests |
|
26 | -{ |
|
25 | +class AllTests { |
|
27 | 26 | |
28 | 27 | |
29 | 28 | /** |
@@ -31,8 +30,7 @@ discard block |
||
31 | 30 | * |
32 | 31 | * @return void |
33 | 32 | */ |
34 | - public static function main() |
|
35 | - { |
|
33 | + public static function main() { |
|
36 | 34 | TestRunner::run(self::suite()); |
37 | 35 | |
38 | 36 | }//end main() |
@@ -43,8 +41,7 @@ discard block |
||
43 | 41 | * |
44 | 42 | * @return \PHPUnit\Framework\TestSuite |
45 | 43 | */ |
46 | - public static function suite() |
|
47 | - { |
|
44 | + public static function suite() { |
|
48 | 45 | $suite = new TestSuite('PHP CodeSniffer Core'); |
49 | 46 | $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\IsCamelCapsTest'); |
50 | 47 | $suite->addTestSuite('PHP_CodeSniffer\Tests\Core\ErrorSuppressionTest'); |
@@ -18,1235 +18,1235 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * Test suppressing a single error. |
|
23 | - * |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function testSuppressError() |
|
27 | - { |
|
28 | - $config = new Config(); |
|
29 | - $config->standards = ['Generic']; |
|
30 | - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
31 | - |
|
32 | - $ruleset = new Ruleset($config); |
|
33 | - |
|
34 | - // Process without suppression. |
|
35 | - $content = '<?php '.PHP_EOL.'$var = FALSE;'; |
|
36 | - $file = new DummyFile($content, $ruleset, $config); |
|
37 | - $file->process(); |
|
38 | - |
|
39 | - $errors = $file->getErrors(); |
|
40 | - $numErrors = $file->getErrorCount(); |
|
41 | - $this->assertEquals(1, $numErrors); |
|
42 | - $this->assertCount(1, $errors); |
|
43 | - |
|
44 | - // Process with inline comment suppression. |
|
45 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable'; |
|
46 | - $file = new DummyFile($content, $ruleset, $config); |
|
47 | - $file->process(); |
|
48 | - |
|
49 | - $errors = $file->getErrors(); |
|
50 | - $numErrors = $file->getErrorCount(); |
|
51 | - $this->assertEquals(0, $numErrors); |
|
52 | - $this->assertCount(0, $errors); |
|
53 | - |
|
54 | - // Process with multi-line inline comment suppression, tab-indented. |
|
55 | - $content = '<?php '.PHP_EOL."\t".'// For reasons'.PHP_EOL."\t".'// phpcs:disable'.PHP_EOL."\t".'$var = FALSE;'.PHP_EOL."\t".'// phpcs:enable'; |
|
56 | - $file = new DummyFile($content, $ruleset, $config); |
|
57 | - $file->process(); |
|
58 | - |
|
59 | - $errors = $file->getErrors(); |
|
60 | - $numErrors = $file->getErrorCount(); |
|
61 | - $this->assertEquals(0, $numErrors); |
|
62 | - $this->assertCount(0, $errors); |
|
63 | - |
|
64 | - // Process with inline @ comment suppression. |
|
65 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @phpcs:enable'; |
|
66 | - $file = new DummyFile($content, $ruleset, $config); |
|
67 | - $file->process(); |
|
68 | - |
|
69 | - $errors = $file->getErrors(); |
|
70 | - $numErrors = $file->getErrorCount(); |
|
71 | - $this->assertEquals(0, $numErrors); |
|
72 | - $this->assertCount(0, $errors); |
|
73 | - |
|
74 | - // Process with inline comment suppression mixed case. |
|
75 | - $content = '<?php '.PHP_EOL.'// PHPCS:Disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// pHPcs:enabLE'; |
|
76 | - $file = new DummyFile($content, $ruleset, $config); |
|
77 | - $file->process(); |
|
78 | - |
|
79 | - $errors = $file->getErrors(); |
|
80 | - $numErrors = $file->getErrorCount(); |
|
81 | - $this->assertEquals(0, $numErrors); |
|
82 | - $this->assertCount(0, $errors); |
|
83 | - |
|
84 | - // Process with inline comment suppression (deprecated syntax). |
|
85 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
86 | - $file = new DummyFile($content, $ruleset, $config); |
|
87 | - $file->process(); |
|
88 | - |
|
89 | - $errors = $file->getErrors(); |
|
90 | - $numErrors = $file->getErrorCount(); |
|
91 | - $this->assertEquals(0, $numErrors); |
|
92 | - $this->assertCount(0, $errors); |
|
93 | - |
|
94 | - // Process with block comment suppression. |
|
95 | - $content = '<?php '.PHP_EOL.'/* phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/* phpcs:enable */'; |
|
96 | - $file = new DummyFile($content, $ruleset, $config); |
|
97 | - $file->process(); |
|
98 | - |
|
99 | - $errors = $file->getErrors(); |
|
100 | - $numErrors = $file->getErrorCount(); |
|
101 | - $this->assertEquals(0, $numErrors); |
|
102 | - $this->assertCount(0, $errors); |
|
103 | - |
|
104 | - // Process with multi-line block comment suppression. |
|
105 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' phpcs:disable'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' phpcs:enable'.PHP_EOL.' */'; |
|
106 | - $file = new DummyFile($content, $ruleset, $config); |
|
107 | - $file->process(); |
|
108 | - |
|
109 | - $errors = $file->getErrors(); |
|
110 | - $numErrors = $file->getErrorCount(); |
|
111 | - $this->assertEquals(0, $numErrors); |
|
112 | - $this->assertCount(0, $errors); |
|
113 | - |
|
114 | - // Process with multi-line block comment suppression, each line starred. |
|
115 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' * phpcs:disable'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' * phpcs:enable'.PHP_EOL.' */'; |
|
116 | - $file = new DummyFile($content, $ruleset, $config); |
|
117 | - $file->process(); |
|
118 | - |
|
119 | - $errors = $file->getErrors(); |
|
120 | - $numErrors = $file->getErrorCount(); |
|
121 | - $this->assertEquals(0, $numErrors); |
|
122 | - $this->assertCount(0, $errors); |
|
123 | - |
|
124 | - // Process with multi-line block comment suppression, tab-indented. |
|
125 | - $content = '<?php '.PHP_EOL."\t".'/*'.PHP_EOL."\t".' * phpcs:disable'.PHP_EOL."\t".' */'.PHP_EOL."\t".'$var = FALSE;'.PHP_EOL."\t".'/*'.PHP_EOL.' * phpcs:enable'.PHP_EOL.' */'; |
|
126 | - $file = new DummyFile($content, $ruleset, $config); |
|
127 | - $file->process(); |
|
128 | - |
|
129 | - $errors = $file->getErrors(); |
|
130 | - $numErrors = $file->getErrorCount(); |
|
131 | - $this->assertEquals(0, $numErrors); |
|
132 | - $this->assertCount(0, $errors); |
|
133 | - |
|
134 | - // Process with block comment suppression (deprecated syntax). |
|
135 | - $content = '<?php '.PHP_EOL.'/* @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/* @codingStandardsIgnoreEnd */'; |
|
136 | - $file = new DummyFile($content, $ruleset, $config); |
|
137 | - $file->process(); |
|
138 | - |
|
139 | - $errors = $file->getErrors(); |
|
140 | - $numErrors = $file->getErrorCount(); |
|
141 | - $this->assertEquals(0, $numErrors); |
|
142 | - $this->assertCount(0, $errors); |
|
143 | - |
|
144 | - // Process with multi-line block comment suppression (deprecated syntax). |
|
145 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreStart'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreEnd'.PHP_EOL.' */'; |
|
146 | - $file = new DummyFile($content, $ruleset, $config); |
|
147 | - $file->process(); |
|
148 | - |
|
149 | - $errors = $file->getErrors(); |
|
150 | - $numErrors = $file->getErrorCount(); |
|
151 | - $this->assertEquals(0, $numErrors); |
|
152 | - $this->assertCount(0, $errors); |
|
153 | - |
|
154 | - // Process with a docblock suppression. |
|
155 | - $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** phpcs:enable */'; |
|
156 | - $file = new DummyFile($content, $ruleset, $config); |
|
157 | - $file->process(); |
|
158 | - |
|
159 | - $errors = $file->getErrors(); |
|
160 | - $numErrors = $file->getErrorCount(); |
|
161 | - $this->assertEquals(0, $numErrors); |
|
162 | - $this->assertCount(0, $errors); |
|
163 | - |
|
164 | - // Process with a docblock suppression (deprecated syntax). |
|
165 | - $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'; |
|
166 | - $file = new DummyFile($content, $ruleset, $config); |
|
167 | - $file->process(); |
|
168 | - |
|
169 | - $errors = $file->getErrors(); |
|
170 | - $numErrors = $file->getErrorCount(); |
|
171 | - $this->assertEquals(0, $numErrors); |
|
172 | - $this->assertCount(0, $errors); |
|
173 | - |
|
174 | - }//end testSuppressError() |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Test suppressing 1 out of 2 errors. |
|
179 | - * |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - public function testSuppressSomeErrors() |
|
183 | - { |
|
184 | - $config = new Config(); |
|
185 | - $config->standards = ['Generic']; |
|
186 | - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
187 | - |
|
188 | - $ruleset = new Ruleset($config); |
|
189 | - |
|
190 | - // Process without suppression. |
|
191 | - $content = '<?php '.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'; |
|
192 | - $file = new DummyFile($content, $ruleset, $config); |
|
193 | - $file->process(); |
|
194 | - |
|
195 | - $errors = $file->getErrors(); |
|
196 | - $numErrors = $file->getErrorCount(); |
|
197 | - $this->assertEquals(2, $numErrors); |
|
198 | - $this->assertCount(2, $errors); |
|
199 | - |
|
200 | - // Process with suppression. |
|
201 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable'.PHP_EOL.'$var = TRUE;'; |
|
202 | - $file = new DummyFile($content, $ruleset, $config); |
|
203 | - $file->process(); |
|
204 | - |
|
205 | - $errors = $file->getErrors(); |
|
206 | - $numErrors = $file->getErrorCount(); |
|
207 | - $this->assertEquals(1, $numErrors); |
|
208 | - $this->assertCount(1, $errors); |
|
209 | - |
|
210 | - // Process with @ suppression. |
|
211 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @phpcs:enable'.PHP_EOL.'$var = TRUE;'; |
|
212 | - $file = new DummyFile($content, $ruleset, $config); |
|
213 | - $file->process(); |
|
214 | - |
|
215 | - $errors = $file->getErrors(); |
|
216 | - $numErrors = $file->getErrorCount(); |
|
217 | - $this->assertEquals(1, $numErrors); |
|
218 | - $this->assertCount(1, $errors); |
|
219 | - |
|
220 | - // Process with suppression (deprecated syntax). |
|
221 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'.PHP_EOL.'$var = TRUE;'; |
|
222 | - $file = new DummyFile($content, $ruleset, $config); |
|
223 | - $file->process(); |
|
224 | - |
|
225 | - $errors = $file->getErrors(); |
|
226 | - $numErrors = $file->getErrorCount(); |
|
227 | - $this->assertEquals(1, $numErrors); |
|
228 | - $this->assertCount(1, $errors); |
|
229 | - |
|
230 | - // Process with a PHPDoc block suppression. |
|
231 | - $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** phpcs:enable */'.PHP_EOL.'$var = TRUE;'; |
|
232 | - $file = new DummyFile($content, $ruleset, $config); |
|
233 | - $file->process(); |
|
234 | - |
|
235 | - $errors = $file->getErrors(); |
|
236 | - $numErrors = $file->getErrorCount(); |
|
237 | - $this->assertEquals(1, $numErrors); |
|
238 | - $this->assertCount(1, $errors); |
|
239 | - |
|
240 | - // Process with a PHPDoc block suppression (deprecated syntax). |
|
241 | - $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'.PHP_EOL.'$var = TRUE;'; |
|
242 | - $file = new DummyFile($content, $ruleset, $config); |
|
243 | - $file->process(); |
|
244 | - |
|
245 | - $errors = $file->getErrors(); |
|
246 | - $numErrors = $file->getErrorCount(); |
|
247 | - $this->assertEquals(1, $numErrors); |
|
248 | - $this->assertCount(1, $errors); |
|
249 | - |
|
250 | - }//end testSuppressSomeErrors() |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * Test suppressing a single warning. |
|
255 | - * |
|
256 | - * @return void |
|
257 | - */ |
|
258 | - public function testSuppressWarning() |
|
259 | - { |
|
260 | - $config = new Config(); |
|
261 | - $config->standards = ['Generic']; |
|
262 | - $config->sniffs = ['Generic.Commenting.Todo']; |
|
263 | - |
|
264 | - $ruleset = new Ruleset($config); |
|
265 | - |
|
266 | - // Process without suppression. |
|
267 | - $content = '<?php '.PHP_EOL.'//TODO: write some code'; |
|
268 | - $file = new DummyFile($content, $ruleset, $config); |
|
269 | - $file->process(); |
|
270 | - |
|
271 | - $warnings = $file->getWarnings(); |
|
272 | - $numWarnings = $file->getWarningCount(); |
|
273 | - $this->assertEquals(1, $numWarnings); |
|
274 | - $this->assertCount(1, $warnings); |
|
275 | - |
|
276 | - // Process with suppression. |
|
277 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable'; |
|
278 | - $file = new DummyFile($content, $ruleset, $config); |
|
279 | - $file->process(); |
|
280 | - |
|
281 | - $warnings = $file->getWarnings(); |
|
282 | - $numWarnings = $file->getWarningCount(); |
|
283 | - $this->assertEquals(0, $numWarnings); |
|
284 | - $this->assertCount(0, $warnings); |
|
285 | - |
|
286 | - // Process with @ suppression. |
|
287 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// @phpcs:enable'; |
|
288 | - $file = new DummyFile($content, $ruleset, $config); |
|
289 | - $file->process(); |
|
290 | - |
|
291 | - $warnings = $file->getWarnings(); |
|
292 | - $numWarnings = $file->getWarningCount(); |
|
293 | - $this->assertEquals(0, $numWarnings); |
|
294 | - $this->assertCount(0, $warnings); |
|
295 | - |
|
296 | - // Process with suppression (deprecated syntax). |
|
297 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
298 | - $file = new DummyFile($content, $ruleset, $config); |
|
299 | - $file->process(); |
|
300 | - |
|
301 | - $warnings = $file->getWarnings(); |
|
302 | - $numWarnings = $file->getWarningCount(); |
|
303 | - $this->assertEquals(0, $numWarnings); |
|
304 | - $this->assertCount(0, $warnings); |
|
305 | - |
|
306 | - // Process with a docblock suppression. |
|
307 | - $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'/** phpcs:enable */'; |
|
308 | - $file = new DummyFile($content, $ruleset, $config); |
|
309 | - $file->process(); |
|
310 | - |
|
311 | - $warnings = $file->getWarnings(); |
|
312 | - $numWarnings = $file->getWarningCount(); |
|
313 | - $this->assertEquals(0, $numWarnings); |
|
314 | - $this->assertCount(0, $warnings); |
|
315 | - |
|
316 | - // Process with a docblock suppression (deprecated syntax). |
|
317 | - $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'; |
|
318 | - $file = new DummyFile($content, $ruleset, $config); |
|
319 | - $file->process(); |
|
320 | - |
|
321 | - $warnings = $file->getWarnings(); |
|
322 | - $numWarnings = $file->getWarningCount(); |
|
323 | - $this->assertEquals(0, $numWarnings); |
|
324 | - $this->assertCount(0, $warnings); |
|
325 | - |
|
326 | - }//end testSuppressWarning() |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Test suppressing a single error using a single line ignore. |
|
331 | - * |
|
332 | - * @return void |
|
333 | - */ |
|
334 | - public function testSuppressLine() |
|
335 | - { |
|
336 | - $config = new Config(); |
|
337 | - $config->standards = ['Generic']; |
|
338 | - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
339 | - |
|
340 | - $ruleset = new Ruleset($config); |
|
341 | - |
|
342 | - // Process without suppression. |
|
343 | - $content = '<?php '.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
344 | - $file = new DummyFile($content, $ruleset, $config); |
|
345 | - $file->process(); |
|
346 | - |
|
347 | - $errors = $file->getErrors(); |
|
348 | - $numErrors = $file->getErrorCount(); |
|
349 | - $this->assertEquals(2, $numErrors); |
|
350 | - $this->assertCount(2, $errors); |
|
351 | - |
|
352 | - // Process with suppression on line before. |
|
353 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
354 | - $file = new DummyFile($content, $ruleset, $config); |
|
355 | - $file->process(); |
|
356 | - |
|
357 | - $errors = $file->getErrors(); |
|
358 | - $numErrors = $file->getErrorCount(); |
|
359 | - $this->assertEquals(1, $numErrors); |
|
360 | - $this->assertCount(1, $errors); |
|
361 | - |
|
362 | - // Process with @ suppression on line before. |
|
363 | - $content = '<?php '.PHP_EOL.'// @phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
364 | - $file = new DummyFile($content, $ruleset, $config); |
|
365 | - $file->process(); |
|
366 | - |
|
367 | - $errors = $file->getErrors(); |
|
368 | - $numErrors = $file->getErrorCount(); |
|
369 | - $this->assertEquals(1, $numErrors); |
|
370 | - $this->assertCount(1, $errors); |
|
371 | - |
|
372 | - // Process with suppression on line before. |
|
373 | - $content = '<?php '.PHP_EOL.'/* phpcs:ignore */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
374 | - $file = new DummyFile($content, $ruleset, $config); |
|
375 | - $file->process(); |
|
376 | - |
|
377 | - $errors = $file->getErrors(); |
|
378 | - $numErrors = $file->getErrorCount(); |
|
379 | - $this->assertEquals(1, $numErrors); |
|
380 | - $this->assertCount(1, $errors); |
|
381 | - |
|
382 | - // Process with @ suppression on line before. |
|
383 | - $content = '<?php '.PHP_EOL.'/* @phpcs:ignore */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
384 | - $file = new DummyFile($content, $ruleset, $config); |
|
385 | - $file->process(); |
|
386 | - |
|
387 | - $errors = $file->getErrors(); |
|
388 | - $numErrors = $file->getErrorCount(); |
|
389 | - $this->assertEquals(1, $numErrors); |
|
390 | - $this->assertCount(1, $errors); |
|
391 | - |
|
392 | - // Process with suppression on line before (deprecated syntax). |
|
393 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
394 | - $file = new DummyFile($content, $ruleset, $config); |
|
395 | - $file->process(); |
|
396 | - |
|
397 | - $errors = $file->getErrors(); |
|
398 | - $numErrors = $file->getErrorCount(); |
|
399 | - $this->assertEquals(1, $numErrors); |
|
400 | - $this->assertCount(1, $errors); |
|
401 | - |
|
402 | - // Process with suppression on same line. |
|
403 | - $content = '<?php '.PHP_EOL.'$var = FALSE; // phpcs:ignore'.PHP_EOL.'$var = FALSE;'; |
|
404 | - $file = new DummyFile($content, $ruleset, $config); |
|
405 | - $file->process(); |
|
406 | - |
|
407 | - $errors = $file->getErrors(); |
|
408 | - $numErrors = $file->getErrorCount(); |
|
409 | - $this->assertEquals(1, $numErrors); |
|
410 | - $this->assertCount(1, $errors); |
|
411 | - |
|
412 | - // Process with @ suppression on same line. |
|
413 | - $content = '<?php '.PHP_EOL.'$var = FALSE; // @phpcs:ignore'.PHP_EOL.'$var = FALSE;'; |
|
414 | - $file = new DummyFile($content, $ruleset, $config); |
|
415 | - $file->process(); |
|
416 | - |
|
417 | - $errors = $file->getErrors(); |
|
418 | - $numErrors = $file->getErrorCount(); |
|
419 | - $this->assertEquals(1, $numErrors); |
|
420 | - $this->assertCount(1, $errors); |
|
421 | - |
|
422 | - // Process with suppression on same line (deprecated syntax). |
|
423 | - $content = '<?php '.PHP_EOL.'$var = FALSE; // @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'; |
|
424 | - $file = new DummyFile($content, $ruleset, $config); |
|
425 | - $file->process(); |
|
426 | - |
|
427 | - $errors = $file->getErrors(); |
|
428 | - $numErrors = $file->getErrorCount(); |
|
429 | - $this->assertEquals(1, $numErrors); |
|
430 | - $this->assertCount(1, $errors); |
|
431 | - |
|
432 | - }//end testSuppressLine() |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Test that using a single line ignore does not interfere with other suppressions. |
|
437 | - * |
|
438 | - * @return void |
|
439 | - */ |
|
440 | - public function testNestedSuppressLine() |
|
441 | - { |
|
442 | - $config = new Config(); |
|
443 | - $config->standards = ['Generic']; |
|
444 | - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
445 | - |
|
446 | - $ruleset = new Ruleset($config); |
|
447 | - |
|
448 | - // Process with disable/enable suppression and no single line suppression. |
|
449 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// phpcs:enable'; |
|
450 | - $file = new DummyFile($content, $ruleset, $config); |
|
451 | - $file->process(); |
|
452 | - |
|
453 | - $errors = $file->getErrors(); |
|
454 | - $numErrors = $file->getErrorCount(); |
|
455 | - $this->assertEquals(0, $numErrors); |
|
456 | - $this->assertCount(0, $errors); |
|
457 | - |
|
458 | - // Process with disable/enable @ suppression and no single line suppression. |
|
459 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @phpcs:enable'; |
|
460 | - $file = new DummyFile($content, $ruleset, $config); |
|
461 | - $file->process(); |
|
462 | - |
|
463 | - $errors = $file->getErrors(); |
|
464 | - $numErrors = $file->getErrorCount(); |
|
465 | - $this->assertEquals(0, $numErrors); |
|
466 | - $this->assertCount(0, $errors); |
|
467 | - |
|
468 | - // Process with disable/enable suppression and no single line suppression (deprecated syntax). |
|
469 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
470 | - $file = new DummyFile($content, $ruleset, $config); |
|
471 | - $file->process(); |
|
472 | - |
|
473 | - $errors = $file->getErrors(); |
|
474 | - $numErrors = $file->getErrorCount(); |
|
475 | - $this->assertEquals(0, $numErrors); |
|
476 | - $this->assertCount(0, $errors); |
|
477 | - |
|
478 | - // Process with line suppression nested within disable/enable suppression. |
|
479 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'// phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// phpcs:enable'; |
|
480 | - $file = new DummyFile($content, $ruleset, $config); |
|
481 | - $file->process(); |
|
482 | - |
|
483 | - $errors = $file->getErrors(); |
|
484 | - $numErrors = $file->getErrorCount(); |
|
485 | - $this->assertEquals(0, $numErrors); |
|
486 | - $this->assertCount(0, $errors); |
|
487 | - |
|
488 | - // Process with line @ suppression nested within disable/enable @ suppression. |
|
489 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'// @phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @phpcs:enable'; |
|
490 | - $file = new DummyFile($content, $ruleset, $config); |
|
491 | - $file->process(); |
|
492 | - |
|
493 | - $errors = $file->getErrors(); |
|
494 | - $numErrors = $file->getErrorCount(); |
|
495 | - $this->assertEquals(0, $numErrors); |
|
496 | - $this->assertCount(0, $errors); |
|
497 | - |
|
498 | - // Process with line suppression nested within disable/enable suppression (deprecated syntax). |
|
499 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'// @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
500 | - $file = new DummyFile($content, $ruleset, $config); |
|
501 | - $file->process(); |
|
502 | - |
|
503 | - $errors = $file->getErrors(); |
|
504 | - $numErrors = $file->getErrorCount(); |
|
505 | - $this->assertEquals(0, $numErrors); |
|
506 | - $this->assertCount(0, $errors); |
|
507 | - |
|
508 | - }//end testNestedSuppressLine() |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * Test suppressing a scope opener. |
|
513 | - * |
|
514 | - * @return void |
|
515 | - */ |
|
516 | - public function testSuppressScope() |
|
517 | - { |
|
518 | - $config = new Config(); |
|
519 | - $config->standards = ['PEAR']; |
|
520 | - $config->sniffs = ['PEAR.NamingConventions.ValidVariableName']; |
|
521 | - |
|
522 | - $ruleset = new Ruleset($config); |
|
523 | - |
|
524 | - // Process without suppression. |
|
525 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'function myFunction() {'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
526 | - $file = new DummyFile($content, $ruleset, $config); |
|
527 | - $file->process(); |
|
528 | - |
|
529 | - $errors = $file->getErrors(); |
|
530 | - $numErrors = $file->getErrorCount(); |
|
531 | - $this->assertEquals(0, $numErrors); |
|
532 | - $this->assertCount(0, $errors); |
|
533 | - |
|
534 | - // Process with suppression. |
|
535 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//phpcs:disable'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//phpcs:enable'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
536 | - $file = new DummyFile($content, $ruleset, $config); |
|
537 | - $file->process(); |
|
538 | - |
|
539 | - $errors = $file->getErrors(); |
|
540 | - $numErrors = $file->getErrorCount(); |
|
541 | - $this->assertEquals(0, $numErrors); |
|
542 | - $this->assertCount(0, $errors); |
|
543 | - |
|
544 | - // Process with suppression. |
|
545 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//@phpcs:disable'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//@phpcs:enable'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
546 | - $file = new DummyFile($content, $ruleset, $config); |
|
547 | - $file->process(); |
|
548 | - |
|
549 | - $errors = $file->getErrors(); |
|
550 | - $numErrors = $file->getErrorCount(); |
|
551 | - $this->assertEquals(0, $numErrors); |
|
552 | - $this->assertCount(0, $errors); |
|
553 | - |
|
554 | - // Process with suppression (deprecated syntax). |
|
555 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//@codingStandardsIgnoreStart'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//@codingStandardsIgnoreEnd'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
556 | - $file = new DummyFile($content, $ruleset, $config); |
|
557 | - $file->process(); |
|
558 | - |
|
559 | - $errors = $file->getErrors(); |
|
560 | - $numErrors = $file->getErrorCount(); |
|
561 | - $this->assertEquals(0, $numErrors); |
|
562 | - $this->assertCount(0, $errors); |
|
563 | - |
|
564 | - // Process with a docblock suppression. |
|
565 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** phpcs:enable */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
566 | - $file = new DummyFile($content, $ruleset, $config); |
|
567 | - |
|
568 | - $errors = $file->getErrors(); |
|
569 | - $numErrors = $file->getErrorCount(); |
|
570 | - $this->assertEquals(0, $numErrors); |
|
571 | - $this->assertCount(0, $errors); |
|
572 | - |
|
573 | - // Process with a docblock @ suppression. |
|
574 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** @phpcs:disable */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** @phpcs:enable */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
575 | - $file = new DummyFile($content, $ruleset, $config); |
|
576 | - |
|
577 | - $errors = $file->getErrors(); |
|
578 | - $numErrors = $file->getErrorCount(); |
|
579 | - $this->assertEquals(0, $numErrors); |
|
580 | - $this->assertCount(0, $errors); |
|
581 | - |
|
582 | - // Process with a docblock suppression (deprecated syntax). |
|
583 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
584 | - $file = new DummyFile($content, $ruleset, $config); |
|
585 | - |
|
586 | - $errors = $file->getErrors(); |
|
587 | - $numErrors = $file->getErrorCount(); |
|
588 | - $this->assertEquals(0, $numErrors); |
|
589 | - $this->assertCount(0, $errors); |
|
590 | - |
|
591 | - }//end testSuppressScope() |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Test suppressing a whole file. |
|
596 | - * |
|
597 | - * @return void |
|
598 | - */ |
|
599 | - public function testSuppressFile() |
|
600 | - { |
|
601 | - $config = new Config(); |
|
602 | - $config->standards = ['Generic']; |
|
603 | - $config->sniffs = ['Generic.Commenting.Todo']; |
|
604 | - |
|
605 | - $ruleset = new Ruleset($config); |
|
606 | - |
|
607 | - // Process without suppression. |
|
608 | - $content = '<?php '.PHP_EOL.'//TODO: write some code'; |
|
609 | - $file = new DummyFile($content, $ruleset, $config); |
|
610 | - $file->process(); |
|
611 | - |
|
612 | - $warnings = $file->getWarnings(); |
|
613 | - $numWarnings = $file->getWarningCount(); |
|
614 | - $this->assertEquals(1, $numWarnings); |
|
615 | - $this->assertCount(1, $warnings); |
|
616 | - |
|
617 | - // Process with suppression. |
|
618 | - $content = '<?php '.PHP_EOL.'// phpcs:ignoreFile'.PHP_EOL.'//TODO: write some code'; |
|
619 | - $file = new DummyFile($content, $ruleset, $config); |
|
620 | - $file->process(); |
|
621 | - |
|
622 | - $warnings = $file->getWarnings(); |
|
623 | - $numWarnings = $file->getWarningCount(); |
|
624 | - $this->assertEquals(0, $numWarnings); |
|
625 | - $this->assertCount(0, $warnings); |
|
626 | - |
|
627 | - // Process with @ suppression. |
|
628 | - $content = '<?php '.PHP_EOL.'// @phpcs:ignoreFile'.PHP_EOL.'//TODO: write some code'; |
|
629 | - $file = new DummyFile($content, $ruleset, $config); |
|
630 | - $file->process(); |
|
631 | - |
|
632 | - $warnings = $file->getWarnings(); |
|
633 | - $numWarnings = $file->getWarningCount(); |
|
634 | - $this->assertEquals(0, $numWarnings); |
|
635 | - $this->assertCount(0, $warnings); |
|
636 | - |
|
637 | - // Process with suppression (deprecated syntax). |
|
638 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreFile'.PHP_EOL.'//TODO: write some code'; |
|
639 | - $file = new DummyFile($content, $ruleset, $config); |
|
640 | - $file->process(); |
|
641 | - |
|
642 | - $warnings = $file->getWarnings(); |
|
643 | - $numWarnings = $file->getWarningCount(); |
|
644 | - $this->assertEquals(0, $numWarnings); |
|
645 | - $this->assertCount(0, $warnings); |
|
646 | - |
|
647 | - // Process mixed case. |
|
648 | - $content = '<?php '.PHP_EOL.'// PHPCS:Ignorefile'.PHP_EOL.'//TODO: write some code'; |
|
649 | - $file = new DummyFile($content, $ruleset, $config); |
|
650 | - $file->process(); |
|
651 | - |
|
652 | - $warnings = $file->getWarnings(); |
|
653 | - $numWarnings = $file->getWarningCount(); |
|
654 | - $this->assertEquals(0, $numWarnings); |
|
655 | - $this->assertCount(0, $warnings); |
|
656 | - |
|
657 | - // Process late comment. |
|
658 | - $content = '<?php '.PHP_EOL.'class MyClass {}'.PHP_EOL.'$foo = new MyClass()'.PHP_EOL.'// phpcs:ignoreFile'; |
|
659 | - $file = new DummyFile($content, $ruleset, $config); |
|
660 | - $file->process(); |
|
661 | - |
|
662 | - $warnings = $file->getWarnings(); |
|
663 | - $numWarnings = $file->getWarningCount(); |
|
664 | - $this->assertEquals(0, $numWarnings); |
|
665 | - $this->assertCount(0, $warnings); |
|
666 | - |
|
667 | - // Process late comment (deprecated syntax). |
|
668 | - $content = '<?php '.PHP_EOL.'class MyClass {}'.PHP_EOL.'$foo = new MyClass()'.PHP_EOL.'// @codingStandardsIgnoreFile'; |
|
669 | - $file = new DummyFile($content, $ruleset, $config); |
|
670 | - $file->process(); |
|
671 | - |
|
672 | - $warnings = $file->getWarnings(); |
|
673 | - $numWarnings = $file->getWarningCount(); |
|
674 | - $this->assertEquals(0, $numWarnings); |
|
675 | - $this->assertCount(0, $warnings); |
|
676 | - |
|
677 | - // Process with a block comment suppression. |
|
678 | - $content = '<?php '.PHP_EOL.'/* phpcs:ignoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
679 | - $file = new DummyFile($content, $ruleset, $config); |
|
680 | - $file->process(); |
|
681 | - |
|
682 | - $warnings = $file->getWarnings(); |
|
683 | - $numWarnings = $file->getWarningCount(); |
|
684 | - $this->assertEquals(0, $numWarnings); |
|
685 | - $this->assertCount(0, $warnings); |
|
686 | - |
|
687 | - // Process with a multi-line block comment suppression. |
|
688 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' phpcs:ignoreFile'.PHP_EOL.' */'.PHP_EOL.'//TODO: write some code'; |
|
689 | - $file = new DummyFile($content, $ruleset, $config); |
|
690 | - $file->process(); |
|
691 | - |
|
692 | - $warnings = $file->getWarnings(); |
|
693 | - $numWarnings = $file->getWarningCount(); |
|
694 | - $this->assertEquals(0, $numWarnings); |
|
695 | - $this->assertCount(0, $warnings); |
|
696 | - |
|
697 | - // Process with a block comment suppression (deprecated syntax). |
|
698 | - $content = '<?php '.PHP_EOL.'/* @codingStandardsIgnoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
699 | - $file = new DummyFile($content, $ruleset, $config); |
|
700 | - $file->process(); |
|
701 | - |
|
702 | - $warnings = $file->getWarnings(); |
|
703 | - $numWarnings = $file->getWarningCount(); |
|
704 | - $this->assertEquals(0, $numWarnings); |
|
705 | - $this->assertCount(0, $warnings); |
|
706 | - |
|
707 | - // Process with a multi-line block comment suppression (deprecated syntax). |
|
708 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreFile'.PHP_EOL.' */'.PHP_EOL.'//TODO: write some code'; |
|
709 | - $file = new DummyFile($content, $ruleset, $config); |
|
710 | - $file->process(); |
|
711 | - |
|
712 | - $warnings = $file->getWarnings(); |
|
713 | - $numWarnings = $file->getWarningCount(); |
|
714 | - $this->assertEquals(0, $numWarnings); |
|
715 | - $this->assertCount(0, $warnings); |
|
716 | - |
|
717 | - // Process with docblock suppression. |
|
718 | - $content = '<?php '.PHP_EOL.'/** phpcs:ignoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
719 | - $file = new DummyFile($content, $ruleset, $config); |
|
720 | - $file->process(); |
|
721 | - |
|
722 | - $warnings = $file->getWarnings(); |
|
723 | - $numWarnings = $file->getWarningCount(); |
|
724 | - $this->assertEquals(0, $numWarnings); |
|
725 | - $this->assertCount(0, $warnings); |
|
726 | - |
|
727 | - // Process with docblock suppression (deprecated syntax). |
|
728 | - $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
729 | - $file = new DummyFile($content, $ruleset, $config); |
|
730 | - $file->process(); |
|
731 | - |
|
732 | - $warnings = $file->getWarnings(); |
|
733 | - $numWarnings = $file->getWarningCount(); |
|
734 | - $this->assertEquals(0, $numWarnings); |
|
735 | - $this->assertCount(0, $warnings); |
|
736 | - |
|
737 | - }//end testSuppressFile() |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * Test disabling specific sniffs. |
|
742 | - * |
|
743 | - * @return void |
|
744 | - */ |
|
745 | - public function testDisableSelected() |
|
746 | - { |
|
747 | - $config = new Config(); |
|
748 | - $config->standards = ['Generic']; |
|
749 | - $config->sniffs = [ |
|
750 | - 'Generic.PHP.LowerCaseConstant', |
|
751 | - 'Generic.Commenting.Todo', |
|
752 | - ]; |
|
753 | - |
|
754 | - $ruleset = new Ruleset($config); |
|
755 | - |
|
756 | - // Suppress a single sniff. |
|
757 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
758 | - $file = new DummyFile($content, $ruleset, $config); |
|
759 | - $file->process(); |
|
760 | - |
|
761 | - $errors = $file->getErrors(); |
|
762 | - $numErrors = $file->getErrorCount(); |
|
763 | - $warnings = $file->getWarnings(); |
|
764 | - $numWarnings = $file->getWarningCount(); |
|
765 | - $this->assertEquals(1, $numErrors); |
|
766 | - $this->assertCount(1, $errors); |
|
767 | - $this->assertEquals(0, $numWarnings); |
|
768 | - $this->assertCount(0, $warnings); |
|
769 | - |
|
770 | - // Suppress multiple sniffs. |
|
771 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
772 | - $file = new DummyFile($content, $ruleset, $config); |
|
773 | - $file->process(); |
|
774 | - |
|
775 | - $errors = $file->getErrors(); |
|
776 | - $numErrors = $file->getErrorCount(); |
|
777 | - $warnings = $file->getWarnings(); |
|
778 | - $numWarnings = $file->getWarningCount(); |
|
779 | - $this->assertEquals(0, $numErrors); |
|
780 | - $this->assertCount(0, $errors); |
|
781 | - $this->assertEquals(0, $numWarnings); |
|
782 | - $this->assertCount(0, $warnings); |
|
783 | - |
|
784 | - // Suppress adding sniffs. |
|
785 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:disable Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
786 | - $file = new DummyFile($content, $ruleset, $config); |
|
787 | - $file->process(); |
|
788 | - |
|
789 | - $errors = $file->getErrors(); |
|
790 | - $numErrors = $file->getErrorCount(); |
|
791 | - $warnings = $file->getWarnings(); |
|
792 | - $numWarnings = $file->getWarningCount(); |
|
793 | - $this->assertEquals(0, $numErrors); |
|
794 | - $this->assertCount(0, $errors); |
|
795 | - $this->assertEquals(0, $numWarnings); |
|
796 | - $this->assertCount(0, $warnings); |
|
797 | - |
|
798 | - // Suppress a category of sniffs. |
|
799 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
800 | - $file = new DummyFile($content, $ruleset, $config); |
|
801 | - $file->process(); |
|
802 | - |
|
803 | - $errors = $file->getErrors(); |
|
804 | - $numErrors = $file->getErrorCount(); |
|
805 | - $warnings = $file->getWarnings(); |
|
806 | - $numWarnings = $file->getWarningCount(); |
|
807 | - $this->assertEquals(1, $numErrors); |
|
808 | - $this->assertCount(1, $errors); |
|
809 | - $this->assertEquals(0, $numWarnings); |
|
810 | - $this->assertCount(0, $warnings); |
|
811 | - |
|
812 | - // Suppress a whole standard. |
|
813 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
814 | - $file = new DummyFile($content, $ruleset, $config); |
|
815 | - $file->process(); |
|
816 | - |
|
817 | - $errors = $file->getErrors(); |
|
818 | - $numErrors = $file->getErrorCount(); |
|
819 | - $warnings = $file->getWarnings(); |
|
820 | - $numWarnings = $file->getWarningCount(); |
|
821 | - $this->assertEquals(0, $numErrors); |
|
822 | - $this->assertCount(0, $errors); |
|
823 | - $this->assertEquals(0, $numWarnings); |
|
824 | - $this->assertCount(0, $warnings); |
|
825 | - |
|
826 | - // Suppress using docblocks. |
|
827 | - $content = '<?php '.PHP_EOL.'/** |
|
21 | + /** |
|
22 | + * Test suppressing a single error. |
|
23 | + * |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function testSuppressError() |
|
27 | + { |
|
28 | + $config = new Config(); |
|
29 | + $config->standards = ['Generic']; |
|
30 | + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
31 | + |
|
32 | + $ruleset = new Ruleset($config); |
|
33 | + |
|
34 | + // Process without suppression. |
|
35 | + $content = '<?php '.PHP_EOL.'$var = FALSE;'; |
|
36 | + $file = new DummyFile($content, $ruleset, $config); |
|
37 | + $file->process(); |
|
38 | + |
|
39 | + $errors = $file->getErrors(); |
|
40 | + $numErrors = $file->getErrorCount(); |
|
41 | + $this->assertEquals(1, $numErrors); |
|
42 | + $this->assertCount(1, $errors); |
|
43 | + |
|
44 | + // Process with inline comment suppression. |
|
45 | + $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable'; |
|
46 | + $file = new DummyFile($content, $ruleset, $config); |
|
47 | + $file->process(); |
|
48 | + |
|
49 | + $errors = $file->getErrors(); |
|
50 | + $numErrors = $file->getErrorCount(); |
|
51 | + $this->assertEquals(0, $numErrors); |
|
52 | + $this->assertCount(0, $errors); |
|
53 | + |
|
54 | + // Process with multi-line inline comment suppression, tab-indented. |
|
55 | + $content = '<?php '.PHP_EOL."\t".'// For reasons'.PHP_EOL."\t".'// phpcs:disable'.PHP_EOL."\t".'$var = FALSE;'.PHP_EOL."\t".'// phpcs:enable'; |
|
56 | + $file = new DummyFile($content, $ruleset, $config); |
|
57 | + $file->process(); |
|
58 | + |
|
59 | + $errors = $file->getErrors(); |
|
60 | + $numErrors = $file->getErrorCount(); |
|
61 | + $this->assertEquals(0, $numErrors); |
|
62 | + $this->assertCount(0, $errors); |
|
63 | + |
|
64 | + // Process with inline @ comment suppression. |
|
65 | + $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @phpcs:enable'; |
|
66 | + $file = new DummyFile($content, $ruleset, $config); |
|
67 | + $file->process(); |
|
68 | + |
|
69 | + $errors = $file->getErrors(); |
|
70 | + $numErrors = $file->getErrorCount(); |
|
71 | + $this->assertEquals(0, $numErrors); |
|
72 | + $this->assertCount(0, $errors); |
|
73 | + |
|
74 | + // Process with inline comment suppression mixed case. |
|
75 | + $content = '<?php '.PHP_EOL.'// PHPCS:Disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// pHPcs:enabLE'; |
|
76 | + $file = new DummyFile($content, $ruleset, $config); |
|
77 | + $file->process(); |
|
78 | + |
|
79 | + $errors = $file->getErrors(); |
|
80 | + $numErrors = $file->getErrorCount(); |
|
81 | + $this->assertEquals(0, $numErrors); |
|
82 | + $this->assertCount(0, $errors); |
|
83 | + |
|
84 | + // Process with inline comment suppression (deprecated syntax). |
|
85 | + $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
86 | + $file = new DummyFile($content, $ruleset, $config); |
|
87 | + $file->process(); |
|
88 | + |
|
89 | + $errors = $file->getErrors(); |
|
90 | + $numErrors = $file->getErrorCount(); |
|
91 | + $this->assertEquals(0, $numErrors); |
|
92 | + $this->assertCount(0, $errors); |
|
93 | + |
|
94 | + // Process with block comment suppression. |
|
95 | + $content = '<?php '.PHP_EOL.'/* phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/* phpcs:enable */'; |
|
96 | + $file = new DummyFile($content, $ruleset, $config); |
|
97 | + $file->process(); |
|
98 | + |
|
99 | + $errors = $file->getErrors(); |
|
100 | + $numErrors = $file->getErrorCount(); |
|
101 | + $this->assertEquals(0, $numErrors); |
|
102 | + $this->assertCount(0, $errors); |
|
103 | + |
|
104 | + // Process with multi-line block comment suppression. |
|
105 | + $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' phpcs:disable'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' phpcs:enable'.PHP_EOL.' */'; |
|
106 | + $file = new DummyFile($content, $ruleset, $config); |
|
107 | + $file->process(); |
|
108 | + |
|
109 | + $errors = $file->getErrors(); |
|
110 | + $numErrors = $file->getErrorCount(); |
|
111 | + $this->assertEquals(0, $numErrors); |
|
112 | + $this->assertCount(0, $errors); |
|
113 | + |
|
114 | + // Process with multi-line block comment suppression, each line starred. |
|
115 | + $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' * phpcs:disable'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' * phpcs:enable'.PHP_EOL.' */'; |
|
116 | + $file = new DummyFile($content, $ruleset, $config); |
|
117 | + $file->process(); |
|
118 | + |
|
119 | + $errors = $file->getErrors(); |
|
120 | + $numErrors = $file->getErrorCount(); |
|
121 | + $this->assertEquals(0, $numErrors); |
|
122 | + $this->assertCount(0, $errors); |
|
123 | + |
|
124 | + // Process with multi-line block comment suppression, tab-indented. |
|
125 | + $content = '<?php '.PHP_EOL."\t".'/*'.PHP_EOL."\t".' * phpcs:disable'.PHP_EOL."\t".' */'.PHP_EOL."\t".'$var = FALSE;'.PHP_EOL."\t".'/*'.PHP_EOL.' * phpcs:enable'.PHP_EOL.' */'; |
|
126 | + $file = new DummyFile($content, $ruleset, $config); |
|
127 | + $file->process(); |
|
128 | + |
|
129 | + $errors = $file->getErrors(); |
|
130 | + $numErrors = $file->getErrorCount(); |
|
131 | + $this->assertEquals(0, $numErrors); |
|
132 | + $this->assertCount(0, $errors); |
|
133 | + |
|
134 | + // Process with block comment suppression (deprecated syntax). |
|
135 | + $content = '<?php '.PHP_EOL.'/* @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/* @codingStandardsIgnoreEnd */'; |
|
136 | + $file = new DummyFile($content, $ruleset, $config); |
|
137 | + $file->process(); |
|
138 | + |
|
139 | + $errors = $file->getErrors(); |
|
140 | + $numErrors = $file->getErrorCount(); |
|
141 | + $this->assertEquals(0, $numErrors); |
|
142 | + $this->assertCount(0, $errors); |
|
143 | + |
|
144 | + // Process with multi-line block comment suppression (deprecated syntax). |
|
145 | + $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreStart'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreEnd'.PHP_EOL.' */'; |
|
146 | + $file = new DummyFile($content, $ruleset, $config); |
|
147 | + $file->process(); |
|
148 | + |
|
149 | + $errors = $file->getErrors(); |
|
150 | + $numErrors = $file->getErrorCount(); |
|
151 | + $this->assertEquals(0, $numErrors); |
|
152 | + $this->assertCount(0, $errors); |
|
153 | + |
|
154 | + // Process with a docblock suppression. |
|
155 | + $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** phpcs:enable */'; |
|
156 | + $file = new DummyFile($content, $ruleset, $config); |
|
157 | + $file->process(); |
|
158 | + |
|
159 | + $errors = $file->getErrors(); |
|
160 | + $numErrors = $file->getErrorCount(); |
|
161 | + $this->assertEquals(0, $numErrors); |
|
162 | + $this->assertCount(0, $errors); |
|
163 | + |
|
164 | + // Process with a docblock suppression (deprecated syntax). |
|
165 | + $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'; |
|
166 | + $file = new DummyFile($content, $ruleset, $config); |
|
167 | + $file->process(); |
|
168 | + |
|
169 | + $errors = $file->getErrors(); |
|
170 | + $numErrors = $file->getErrorCount(); |
|
171 | + $this->assertEquals(0, $numErrors); |
|
172 | + $this->assertCount(0, $errors); |
|
173 | + |
|
174 | + }//end testSuppressError() |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Test suppressing 1 out of 2 errors. |
|
179 | + * |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + public function testSuppressSomeErrors() |
|
183 | + { |
|
184 | + $config = new Config(); |
|
185 | + $config->standards = ['Generic']; |
|
186 | + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
187 | + |
|
188 | + $ruleset = new Ruleset($config); |
|
189 | + |
|
190 | + // Process without suppression. |
|
191 | + $content = '<?php '.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'; |
|
192 | + $file = new DummyFile($content, $ruleset, $config); |
|
193 | + $file->process(); |
|
194 | + |
|
195 | + $errors = $file->getErrors(); |
|
196 | + $numErrors = $file->getErrorCount(); |
|
197 | + $this->assertEquals(2, $numErrors); |
|
198 | + $this->assertCount(2, $errors); |
|
199 | + |
|
200 | + // Process with suppression. |
|
201 | + $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable'.PHP_EOL.'$var = TRUE;'; |
|
202 | + $file = new DummyFile($content, $ruleset, $config); |
|
203 | + $file->process(); |
|
204 | + |
|
205 | + $errors = $file->getErrors(); |
|
206 | + $numErrors = $file->getErrorCount(); |
|
207 | + $this->assertEquals(1, $numErrors); |
|
208 | + $this->assertCount(1, $errors); |
|
209 | + |
|
210 | + // Process with @ suppression. |
|
211 | + $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @phpcs:enable'.PHP_EOL.'$var = TRUE;'; |
|
212 | + $file = new DummyFile($content, $ruleset, $config); |
|
213 | + $file->process(); |
|
214 | + |
|
215 | + $errors = $file->getErrors(); |
|
216 | + $numErrors = $file->getErrorCount(); |
|
217 | + $this->assertEquals(1, $numErrors); |
|
218 | + $this->assertCount(1, $errors); |
|
219 | + |
|
220 | + // Process with suppression (deprecated syntax). |
|
221 | + $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'.PHP_EOL.'$var = TRUE;'; |
|
222 | + $file = new DummyFile($content, $ruleset, $config); |
|
223 | + $file->process(); |
|
224 | + |
|
225 | + $errors = $file->getErrors(); |
|
226 | + $numErrors = $file->getErrorCount(); |
|
227 | + $this->assertEquals(1, $numErrors); |
|
228 | + $this->assertCount(1, $errors); |
|
229 | + |
|
230 | + // Process with a PHPDoc block suppression. |
|
231 | + $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** phpcs:enable */'.PHP_EOL.'$var = TRUE;'; |
|
232 | + $file = new DummyFile($content, $ruleset, $config); |
|
233 | + $file->process(); |
|
234 | + |
|
235 | + $errors = $file->getErrors(); |
|
236 | + $numErrors = $file->getErrorCount(); |
|
237 | + $this->assertEquals(1, $numErrors); |
|
238 | + $this->assertCount(1, $errors); |
|
239 | + |
|
240 | + // Process with a PHPDoc block suppression (deprecated syntax). |
|
241 | + $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'.PHP_EOL.'$var = TRUE;'; |
|
242 | + $file = new DummyFile($content, $ruleset, $config); |
|
243 | + $file->process(); |
|
244 | + |
|
245 | + $errors = $file->getErrors(); |
|
246 | + $numErrors = $file->getErrorCount(); |
|
247 | + $this->assertEquals(1, $numErrors); |
|
248 | + $this->assertCount(1, $errors); |
|
249 | + |
|
250 | + }//end testSuppressSomeErrors() |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * Test suppressing a single warning. |
|
255 | + * |
|
256 | + * @return void |
|
257 | + */ |
|
258 | + public function testSuppressWarning() |
|
259 | + { |
|
260 | + $config = new Config(); |
|
261 | + $config->standards = ['Generic']; |
|
262 | + $config->sniffs = ['Generic.Commenting.Todo']; |
|
263 | + |
|
264 | + $ruleset = new Ruleset($config); |
|
265 | + |
|
266 | + // Process without suppression. |
|
267 | + $content = '<?php '.PHP_EOL.'//TODO: write some code'; |
|
268 | + $file = new DummyFile($content, $ruleset, $config); |
|
269 | + $file->process(); |
|
270 | + |
|
271 | + $warnings = $file->getWarnings(); |
|
272 | + $numWarnings = $file->getWarningCount(); |
|
273 | + $this->assertEquals(1, $numWarnings); |
|
274 | + $this->assertCount(1, $warnings); |
|
275 | + |
|
276 | + // Process with suppression. |
|
277 | + $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable'; |
|
278 | + $file = new DummyFile($content, $ruleset, $config); |
|
279 | + $file->process(); |
|
280 | + |
|
281 | + $warnings = $file->getWarnings(); |
|
282 | + $numWarnings = $file->getWarningCount(); |
|
283 | + $this->assertEquals(0, $numWarnings); |
|
284 | + $this->assertCount(0, $warnings); |
|
285 | + |
|
286 | + // Process with @ suppression. |
|
287 | + $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// @phpcs:enable'; |
|
288 | + $file = new DummyFile($content, $ruleset, $config); |
|
289 | + $file->process(); |
|
290 | + |
|
291 | + $warnings = $file->getWarnings(); |
|
292 | + $numWarnings = $file->getWarningCount(); |
|
293 | + $this->assertEquals(0, $numWarnings); |
|
294 | + $this->assertCount(0, $warnings); |
|
295 | + |
|
296 | + // Process with suppression (deprecated syntax). |
|
297 | + $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
298 | + $file = new DummyFile($content, $ruleset, $config); |
|
299 | + $file->process(); |
|
300 | + |
|
301 | + $warnings = $file->getWarnings(); |
|
302 | + $numWarnings = $file->getWarningCount(); |
|
303 | + $this->assertEquals(0, $numWarnings); |
|
304 | + $this->assertCount(0, $warnings); |
|
305 | + |
|
306 | + // Process with a docblock suppression. |
|
307 | + $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'/** phpcs:enable */'; |
|
308 | + $file = new DummyFile($content, $ruleset, $config); |
|
309 | + $file->process(); |
|
310 | + |
|
311 | + $warnings = $file->getWarnings(); |
|
312 | + $numWarnings = $file->getWarningCount(); |
|
313 | + $this->assertEquals(0, $numWarnings); |
|
314 | + $this->assertCount(0, $warnings); |
|
315 | + |
|
316 | + // Process with a docblock suppression (deprecated syntax). |
|
317 | + $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'; |
|
318 | + $file = new DummyFile($content, $ruleset, $config); |
|
319 | + $file->process(); |
|
320 | + |
|
321 | + $warnings = $file->getWarnings(); |
|
322 | + $numWarnings = $file->getWarningCount(); |
|
323 | + $this->assertEquals(0, $numWarnings); |
|
324 | + $this->assertCount(0, $warnings); |
|
325 | + |
|
326 | + }//end testSuppressWarning() |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Test suppressing a single error using a single line ignore. |
|
331 | + * |
|
332 | + * @return void |
|
333 | + */ |
|
334 | + public function testSuppressLine() |
|
335 | + { |
|
336 | + $config = new Config(); |
|
337 | + $config->standards = ['Generic']; |
|
338 | + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
339 | + |
|
340 | + $ruleset = new Ruleset($config); |
|
341 | + |
|
342 | + // Process without suppression. |
|
343 | + $content = '<?php '.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
344 | + $file = new DummyFile($content, $ruleset, $config); |
|
345 | + $file->process(); |
|
346 | + |
|
347 | + $errors = $file->getErrors(); |
|
348 | + $numErrors = $file->getErrorCount(); |
|
349 | + $this->assertEquals(2, $numErrors); |
|
350 | + $this->assertCount(2, $errors); |
|
351 | + |
|
352 | + // Process with suppression on line before. |
|
353 | + $content = '<?php '.PHP_EOL.'// phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
354 | + $file = new DummyFile($content, $ruleset, $config); |
|
355 | + $file->process(); |
|
356 | + |
|
357 | + $errors = $file->getErrors(); |
|
358 | + $numErrors = $file->getErrorCount(); |
|
359 | + $this->assertEquals(1, $numErrors); |
|
360 | + $this->assertCount(1, $errors); |
|
361 | + |
|
362 | + // Process with @ suppression on line before. |
|
363 | + $content = '<?php '.PHP_EOL.'// @phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
364 | + $file = new DummyFile($content, $ruleset, $config); |
|
365 | + $file->process(); |
|
366 | + |
|
367 | + $errors = $file->getErrors(); |
|
368 | + $numErrors = $file->getErrorCount(); |
|
369 | + $this->assertEquals(1, $numErrors); |
|
370 | + $this->assertCount(1, $errors); |
|
371 | + |
|
372 | + // Process with suppression on line before. |
|
373 | + $content = '<?php '.PHP_EOL.'/* phpcs:ignore */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
374 | + $file = new DummyFile($content, $ruleset, $config); |
|
375 | + $file->process(); |
|
376 | + |
|
377 | + $errors = $file->getErrors(); |
|
378 | + $numErrors = $file->getErrorCount(); |
|
379 | + $this->assertEquals(1, $numErrors); |
|
380 | + $this->assertCount(1, $errors); |
|
381 | + |
|
382 | + // Process with @ suppression on line before. |
|
383 | + $content = '<?php '.PHP_EOL.'/* @phpcs:ignore */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
384 | + $file = new DummyFile($content, $ruleset, $config); |
|
385 | + $file->process(); |
|
386 | + |
|
387 | + $errors = $file->getErrors(); |
|
388 | + $numErrors = $file->getErrorCount(); |
|
389 | + $this->assertEquals(1, $numErrors); |
|
390 | + $this->assertCount(1, $errors); |
|
391 | + |
|
392 | + // Process with suppression on line before (deprecated syntax). |
|
393 | + $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
394 | + $file = new DummyFile($content, $ruleset, $config); |
|
395 | + $file->process(); |
|
396 | + |
|
397 | + $errors = $file->getErrors(); |
|
398 | + $numErrors = $file->getErrorCount(); |
|
399 | + $this->assertEquals(1, $numErrors); |
|
400 | + $this->assertCount(1, $errors); |
|
401 | + |
|
402 | + // Process with suppression on same line. |
|
403 | + $content = '<?php '.PHP_EOL.'$var = FALSE; // phpcs:ignore'.PHP_EOL.'$var = FALSE;'; |
|
404 | + $file = new DummyFile($content, $ruleset, $config); |
|
405 | + $file->process(); |
|
406 | + |
|
407 | + $errors = $file->getErrors(); |
|
408 | + $numErrors = $file->getErrorCount(); |
|
409 | + $this->assertEquals(1, $numErrors); |
|
410 | + $this->assertCount(1, $errors); |
|
411 | + |
|
412 | + // Process with @ suppression on same line. |
|
413 | + $content = '<?php '.PHP_EOL.'$var = FALSE; // @phpcs:ignore'.PHP_EOL.'$var = FALSE;'; |
|
414 | + $file = new DummyFile($content, $ruleset, $config); |
|
415 | + $file->process(); |
|
416 | + |
|
417 | + $errors = $file->getErrors(); |
|
418 | + $numErrors = $file->getErrorCount(); |
|
419 | + $this->assertEquals(1, $numErrors); |
|
420 | + $this->assertCount(1, $errors); |
|
421 | + |
|
422 | + // Process with suppression on same line (deprecated syntax). |
|
423 | + $content = '<?php '.PHP_EOL.'$var = FALSE; // @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'; |
|
424 | + $file = new DummyFile($content, $ruleset, $config); |
|
425 | + $file->process(); |
|
426 | + |
|
427 | + $errors = $file->getErrors(); |
|
428 | + $numErrors = $file->getErrorCount(); |
|
429 | + $this->assertEquals(1, $numErrors); |
|
430 | + $this->assertCount(1, $errors); |
|
431 | + |
|
432 | + }//end testSuppressLine() |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Test that using a single line ignore does not interfere with other suppressions. |
|
437 | + * |
|
438 | + * @return void |
|
439 | + */ |
|
440 | + public function testNestedSuppressLine() |
|
441 | + { |
|
442 | + $config = new Config(); |
|
443 | + $config->standards = ['Generic']; |
|
444 | + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
445 | + |
|
446 | + $ruleset = new Ruleset($config); |
|
447 | + |
|
448 | + // Process with disable/enable suppression and no single line suppression. |
|
449 | + $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// phpcs:enable'; |
|
450 | + $file = new DummyFile($content, $ruleset, $config); |
|
451 | + $file->process(); |
|
452 | + |
|
453 | + $errors = $file->getErrors(); |
|
454 | + $numErrors = $file->getErrorCount(); |
|
455 | + $this->assertEquals(0, $numErrors); |
|
456 | + $this->assertCount(0, $errors); |
|
457 | + |
|
458 | + // Process with disable/enable @ suppression and no single line suppression. |
|
459 | + $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @phpcs:enable'; |
|
460 | + $file = new DummyFile($content, $ruleset, $config); |
|
461 | + $file->process(); |
|
462 | + |
|
463 | + $errors = $file->getErrors(); |
|
464 | + $numErrors = $file->getErrorCount(); |
|
465 | + $this->assertEquals(0, $numErrors); |
|
466 | + $this->assertCount(0, $errors); |
|
467 | + |
|
468 | + // Process with disable/enable suppression and no single line suppression (deprecated syntax). |
|
469 | + $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
470 | + $file = new DummyFile($content, $ruleset, $config); |
|
471 | + $file->process(); |
|
472 | + |
|
473 | + $errors = $file->getErrors(); |
|
474 | + $numErrors = $file->getErrorCount(); |
|
475 | + $this->assertEquals(0, $numErrors); |
|
476 | + $this->assertCount(0, $errors); |
|
477 | + |
|
478 | + // Process with line suppression nested within disable/enable suppression. |
|
479 | + $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'// phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// phpcs:enable'; |
|
480 | + $file = new DummyFile($content, $ruleset, $config); |
|
481 | + $file->process(); |
|
482 | + |
|
483 | + $errors = $file->getErrors(); |
|
484 | + $numErrors = $file->getErrorCount(); |
|
485 | + $this->assertEquals(0, $numErrors); |
|
486 | + $this->assertCount(0, $errors); |
|
487 | + |
|
488 | + // Process with line @ suppression nested within disable/enable @ suppression. |
|
489 | + $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'// @phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @phpcs:enable'; |
|
490 | + $file = new DummyFile($content, $ruleset, $config); |
|
491 | + $file->process(); |
|
492 | + |
|
493 | + $errors = $file->getErrors(); |
|
494 | + $numErrors = $file->getErrorCount(); |
|
495 | + $this->assertEquals(0, $numErrors); |
|
496 | + $this->assertCount(0, $errors); |
|
497 | + |
|
498 | + // Process with line suppression nested within disable/enable suppression (deprecated syntax). |
|
499 | + $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'// @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
500 | + $file = new DummyFile($content, $ruleset, $config); |
|
501 | + $file->process(); |
|
502 | + |
|
503 | + $errors = $file->getErrors(); |
|
504 | + $numErrors = $file->getErrorCount(); |
|
505 | + $this->assertEquals(0, $numErrors); |
|
506 | + $this->assertCount(0, $errors); |
|
507 | + |
|
508 | + }//end testNestedSuppressLine() |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * Test suppressing a scope opener. |
|
513 | + * |
|
514 | + * @return void |
|
515 | + */ |
|
516 | + public function testSuppressScope() |
|
517 | + { |
|
518 | + $config = new Config(); |
|
519 | + $config->standards = ['PEAR']; |
|
520 | + $config->sniffs = ['PEAR.NamingConventions.ValidVariableName']; |
|
521 | + |
|
522 | + $ruleset = new Ruleset($config); |
|
523 | + |
|
524 | + // Process without suppression. |
|
525 | + $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'function myFunction() {'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
526 | + $file = new DummyFile($content, $ruleset, $config); |
|
527 | + $file->process(); |
|
528 | + |
|
529 | + $errors = $file->getErrors(); |
|
530 | + $numErrors = $file->getErrorCount(); |
|
531 | + $this->assertEquals(0, $numErrors); |
|
532 | + $this->assertCount(0, $errors); |
|
533 | + |
|
534 | + // Process with suppression. |
|
535 | + $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//phpcs:disable'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//phpcs:enable'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
536 | + $file = new DummyFile($content, $ruleset, $config); |
|
537 | + $file->process(); |
|
538 | + |
|
539 | + $errors = $file->getErrors(); |
|
540 | + $numErrors = $file->getErrorCount(); |
|
541 | + $this->assertEquals(0, $numErrors); |
|
542 | + $this->assertCount(0, $errors); |
|
543 | + |
|
544 | + // Process with suppression. |
|
545 | + $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//@phpcs:disable'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//@phpcs:enable'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
546 | + $file = new DummyFile($content, $ruleset, $config); |
|
547 | + $file->process(); |
|
548 | + |
|
549 | + $errors = $file->getErrors(); |
|
550 | + $numErrors = $file->getErrorCount(); |
|
551 | + $this->assertEquals(0, $numErrors); |
|
552 | + $this->assertCount(0, $errors); |
|
553 | + |
|
554 | + // Process with suppression (deprecated syntax). |
|
555 | + $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//@codingStandardsIgnoreStart'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//@codingStandardsIgnoreEnd'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
556 | + $file = new DummyFile($content, $ruleset, $config); |
|
557 | + $file->process(); |
|
558 | + |
|
559 | + $errors = $file->getErrors(); |
|
560 | + $numErrors = $file->getErrorCount(); |
|
561 | + $this->assertEquals(0, $numErrors); |
|
562 | + $this->assertCount(0, $errors); |
|
563 | + |
|
564 | + // Process with a docblock suppression. |
|
565 | + $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** phpcs:enable */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
566 | + $file = new DummyFile($content, $ruleset, $config); |
|
567 | + |
|
568 | + $errors = $file->getErrors(); |
|
569 | + $numErrors = $file->getErrorCount(); |
|
570 | + $this->assertEquals(0, $numErrors); |
|
571 | + $this->assertCount(0, $errors); |
|
572 | + |
|
573 | + // Process with a docblock @ suppression. |
|
574 | + $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** @phpcs:disable */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** @phpcs:enable */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
575 | + $file = new DummyFile($content, $ruleset, $config); |
|
576 | + |
|
577 | + $errors = $file->getErrors(); |
|
578 | + $numErrors = $file->getErrorCount(); |
|
579 | + $this->assertEquals(0, $numErrors); |
|
580 | + $this->assertCount(0, $errors); |
|
581 | + |
|
582 | + // Process with a docblock suppression (deprecated syntax). |
|
583 | + $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
584 | + $file = new DummyFile($content, $ruleset, $config); |
|
585 | + |
|
586 | + $errors = $file->getErrors(); |
|
587 | + $numErrors = $file->getErrorCount(); |
|
588 | + $this->assertEquals(0, $numErrors); |
|
589 | + $this->assertCount(0, $errors); |
|
590 | + |
|
591 | + }//end testSuppressScope() |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Test suppressing a whole file. |
|
596 | + * |
|
597 | + * @return void |
|
598 | + */ |
|
599 | + public function testSuppressFile() |
|
600 | + { |
|
601 | + $config = new Config(); |
|
602 | + $config->standards = ['Generic']; |
|
603 | + $config->sniffs = ['Generic.Commenting.Todo']; |
|
604 | + |
|
605 | + $ruleset = new Ruleset($config); |
|
606 | + |
|
607 | + // Process without suppression. |
|
608 | + $content = '<?php '.PHP_EOL.'//TODO: write some code'; |
|
609 | + $file = new DummyFile($content, $ruleset, $config); |
|
610 | + $file->process(); |
|
611 | + |
|
612 | + $warnings = $file->getWarnings(); |
|
613 | + $numWarnings = $file->getWarningCount(); |
|
614 | + $this->assertEquals(1, $numWarnings); |
|
615 | + $this->assertCount(1, $warnings); |
|
616 | + |
|
617 | + // Process with suppression. |
|
618 | + $content = '<?php '.PHP_EOL.'// phpcs:ignoreFile'.PHP_EOL.'//TODO: write some code'; |
|
619 | + $file = new DummyFile($content, $ruleset, $config); |
|
620 | + $file->process(); |
|
621 | + |
|
622 | + $warnings = $file->getWarnings(); |
|
623 | + $numWarnings = $file->getWarningCount(); |
|
624 | + $this->assertEquals(0, $numWarnings); |
|
625 | + $this->assertCount(0, $warnings); |
|
626 | + |
|
627 | + // Process with @ suppression. |
|
628 | + $content = '<?php '.PHP_EOL.'// @phpcs:ignoreFile'.PHP_EOL.'//TODO: write some code'; |
|
629 | + $file = new DummyFile($content, $ruleset, $config); |
|
630 | + $file->process(); |
|
631 | + |
|
632 | + $warnings = $file->getWarnings(); |
|
633 | + $numWarnings = $file->getWarningCount(); |
|
634 | + $this->assertEquals(0, $numWarnings); |
|
635 | + $this->assertCount(0, $warnings); |
|
636 | + |
|
637 | + // Process with suppression (deprecated syntax). |
|
638 | + $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreFile'.PHP_EOL.'//TODO: write some code'; |
|
639 | + $file = new DummyFile($content, $ruleset, $config); |
|
640 | + $file->process(); |
|
641 | + |
|
642 | + $warnings = $file->getWarnings(); |
|
643 | + $numWarnings = $file->getWarningCount(); |
|
644 | + $this->assertEquals(0, $numWarnings); |
|
645 | + $this->assertCount(0, $warnings); |
|
646 | + |
|
647 | + // Process mixed case. |
|
648 | + $content = '<?php '.PHP_EOL.'// PHPCS:Ignorefile'.PHP_EOL.'//TODO: write some code'; |
|
649 | + $file = new DummyFile($content, $ruleset, $config); |
|
650 | + $file->process(); |
|
651 | + |
|
652 | + $warnings = $file->getWarnings(); |
|
653 | + $numWarnings = $file->getWarningCount(); |
|
654 | + $this->assertEquals(0, $numWarnings); |
|
655 | + $this->assertCount(0, $warnings); |
|
656 | + |
|
657 | + // Process late comment. |
|
658 | + $content = '<?php '.PHP_EOL.'class MyClass {}'.PHP_EOL.'$foo = new MyClass()'.PHP_EOL.'// phpcs:ignoreFile'; |
|
659 | + $file = new DummyFile($content, $ruleset, $config); |
|
660 | + $file->process(); |
|
661 | + |
|
662 | + $warnings = $file->getWarnings(); |
|
663 | + $numWarnings = $file->getWarningCount(); |
|
664 | + $this->assertEquals(0, $numWarnings); |
|
665 | + $this->assertCount(0, $warnings); |
|
666 | + |
|
667 | + // Process late comment (deprecated syntax). |
|
668 | + $content = '<?php '.PHP_EOL.'class MyClass {}'.PHP_EOL.'$foo = new MyClass()'.PHP_EOL.'// @codingStandardsIgnoreFile'; |
|
669 | + $file = new DummyFile($content, $ruleset, $config); |
|
670 | + $file->process(); |
|
671 | + |
|
672 | + $warnings = $file->getWarnings(); |
|
673 | + $numWarnings = $file->getWarningCount(); |
|
674 | + $this->assertEquals(0, $numWarnings); |
|
675 | + $this->assertCount(0, $warnings); |
|
676 | + |
|
677 | + // Process with a block comment suppression. |
|
678 | + $content = '<?php '.PHP_EOL.'/* phpcs:ignoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
679 | + $file = new DummyFile($content, $ruleset, $config); |
|
680 | + $file->process(); |
|
681 | + |
|
682 | + $warnings = $file->getWarnings(); |
|
683 | + $numWarnings = $file->getWarningCount(); |
|
684 | + $this->assertEquals(0, $numWarnings); |
|
685 | + $this->assertCount(0, $warnings); |
|
686 | + |
|
687 | + // Process with a multi-line block comment suppression. |
|
688 | + $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' phpcs:ignoreFile'.PHP_EOL.' */'.PHP_EOL.'//TODO: write some code'; |
|
689 | + $file = new DummyFile($content, $ruleset, $config); |
|
690 | + $file->process(); |
|
691 | + |
|
692 | + $warnings = $file->getWarnings(); |
|
693 | + $numWarnings = $file->getWarningCount(); |
|
694 | + $this->assertEquals(0, $numWarnings); |
|
695 | + $this->assertCount(0, $warnings); |
|
696 | + |
|
697 | + // Process with a block comment suppression (deprecated syntax). |
|
698 | + $content = '<?php '.PHP_EOL.'/* @codingStandardsIgnoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
699 | + $file = new DummyFile($content, $ruleset, $config); |
|
700 | + $file->process(); |
|
701 | + |
|
702 | + $warnings = $file->getWarnings(); |
|
703 | + $numWarnings = $file->getWarningCount(); |
|
704 | + $this->assertEquals(0, $numWarnings); |
|
705 | + $this->assertCount(0, $warnings); |
|
706 | + |
|
707 | + // Process with a multi-line block comment suppression (deprecated syntax). |
|
708 | + $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreFile'.PHP_EOL.' */'.PHP_EOL.'//TODO: write some code'; |
|
709 | + $file = new DummyFile($content, $ruleset, $config); |
|
710 | + $file->process(); |
|
711 | + |
|
712 | + $warnings = $file->getWarnings(); |
|
713 | + $numWarnings = $file->getWarningCount(); |
|
714 | + $this->assertEquals(0, $numWarnings); |
|
715 | + $this->assertCount(0, $warnings); |
|
716 | + |
|
717 | + // Process with docblock suppression. |
|
718 | + $content = '<?php '.PHP_EOL.'/** phpcs:ignoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
719 | + $file = new DummyFile($content, $ruleset, $config); |
|
720 | + $file->process(); |
|
721 | + |
|
722 | + $warnings = $file->getWarnings(); |
|
723 | + $numWarnings = $file->getWarningCount(); |
|
724 | + $this->assertEquals(0, $numWarnings); |
|
725 | + $this->assertCount(0, $warnings); |
|
726 | + |
|
727 | + // Process with docblock suppression (deprecated syntax). |
|
728 | + $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
729 | + $file = new DummyFile($content, $ruleset, $config); |
|
730 | + $file->process(); |
|
731 | + |
|
732 | + $warnings = $file->getWarnings(); |
|
733 | + $numWarnings = $file->getWarningCount(); |
|
734 | + $this->assertEquals(0, $numWarnings); |
|
735 | + $this->assertCount(0, $warnings); |
|
736 | + |
|
737 | + }//end testSuppressFile() |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * Test disabling specific sniffs. |
|
742 | + * |
|
743 | + * @return void |
|
744 | + */ |
|
745 | + public function testDisableSelected() |
|
746 | + { |
|
747 | + $config = new Config(); |
|
748 | + $config->standards = ['Generic']; |
|
749 | + $config->sniffs = [ |
|
750 | + 'Generic.PHP.LowerCaseConstant', |
|
751 | + 'Generic.Commenting.Todo', |
|
752 | + ]; |
|
753 | + |
|
754 | + $ruleset = new Ruleset($config); |
|
755 | + |
|
756 | + // Suppress a single sniff. |
|
757 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
758 | + $file = new DummyFile($content, $ruleset, $config); |
|
759 | + $file->process(); |
|
760 | + |
|
761 | + $errors = $file->getErrors(); |
|
762 | + $numErrors = $file->getErrorCount(); |
|
763 | + $warnings = $file->getWarnings(); |
|
764 | + $numWarnings = $file->getWarningCount(); |
|
765 | + $this->assertEquals(1, $numErrors); |
|
766 | + $this->assertCount(1, $errors); |
|
767 | + $this->assertEquals(0, $numWarnings); |
|
768 | + $this->assertCount(0, $warnings); |
|
769 | + |
|
770 | + // Suppress multiple sniffs. |
|
771 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
772 | + $file = new DummyFile($content, $ruleset, $config); |
|
773 | + $file->process(); |
|
774 | + |
|
775 | + $errors = $file->getErrors(); |
|
776 | + $numErrors = $file->getErrorCount(); |
|
777 | + $warnings = $file->getWarnings(); |
|
778 | + $numWarnings = $file->getWarningCount(); |
|
779 | + $this->assertEquals(0, $numErrors); |
|
780 | + $this->assertCount(0, $errors); |
|
781 | + $this->assertEquals(0, $numWarnings); |
|
782 | + $this->assertCount(0, $warnings); |
|
783 | + |
|
784 | + // Suppress adding sniffs. |
|
785 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:disable Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
786 | + $file = new DummyFile($content, $ruleset, $config); |
|
787 | + $file->process(); |
|
788 | + |
|
789 | + $errors = $file->getErrors(); |
|
790 | + $numErrors = $file->getErrorCount(); |
|
791 | + $warnings = $file->getWarnings(); |
|
792 | + $numWarnings = $file->getWarningCount(); |
|
793 | + $this->assertEquals(0, $numErrors); |
|
794 | + $this->assertCount(0, $errors); |
|
795 | + $this->assertEquals(0, $numWarnings); |
|
796 | + $this->assertCount(0, $warnings); |
|
797 | + |
|
798 | + // Suppress a category of sniffs. |
|
799 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
800 | + $file = new DummyFile($content, $ruleset, $config); |
|
801 | + $file->process(); |
|
802 | + |
|
803 | + $errors = $file->getErrors(); |
|
804 | + $numErrors = $file->getErrorCount(); |
|
805 | + $warnings = $file->getWarnings(); |
|
806 | + $numWarnings = $file->getWarningCount(); |
|
807 | + $this->assertEquals(1, $numErrors); |
|
808 | + $this->assertCount(1, $errors); |
|
809 | + $this->assertEquals(0, $numWarnings); |
|
810 | + $this->assertCount(0, $warnings); |
|
811 | + |
|
812 | + // Suppress a whole standard. |
|
813 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
814 | + $file = new DummyFile($content, $ruleset, $config); |
|
815 | + $file->process(); |
|
816 | + |
|
817 | + $errors = $file->getErrors(); |
|
818 | + $numErrors = $file->getErrorCount(); |
|
819 | + $warnings = $file->getWarnings(); |
|
820 | + $numWarnings = $file->getWarningCount(); |
|
821 | + $this->assertEquals(0, $numErrors); |
|
822 | + $this->assertCount(0, $errors); |
|
823 | + $this->assertEquals(0, $numWarnings); |
|
824 | + $this->assertCount(0, $warnings); |
|
825 | + |
|
826 | + // Suppress using docblocks. |
|
827 | + $content = '<?php '.PHP_EOL.'/** |
|
828 | 828 | '.PHP_EOL.' * phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ '.PHP_EOL.'//TODO: write some code'; |
829 | - $file = new DummyFile($content, $ruleset, $config); |
|
830 | - $file->process(); |
|
831 | - |
|
832 | - $errors = $file->getErrors(); |
|
833 | - $numErrors = $file->getErrorCount(); |
|
834 | - $warnings = $file->getWarnings(); |
|
835 | - $numWarnings = $file->getWarningCount(); |
|
836 | - $this->assertEquals(0, $numErrors); |
|
837 | - $this->assertCount(0, $errors); |
|
838 | - $this->assertEquals(0, $numWarnings); |
|
839 | - $this->assertCount(0, $warnings); |
|
840 | - |
|
841 | - $content = '<?php '.PHP_EOL.'/** |
|
829 | + $file = new DummyFile($content, $ruleset, $config); |
|
830 | + $file->process(); |
|
831 | + |
|
832 | + $errors = $file->getErrors(); |
|
833 | + $numErrors = $file->getErrorCount(); |
|
834 | + $warnings = $file->getWarnings(); |
|
835 | + $numWarnings = $file->getWarningCount(); |
|
836 | + $this->assertEquals(0, $numErrors); |
|
837 | + $this->assertCount(0, $errors); |
|
838 | + $this->assertEquals(0, $numWarnings); |
|
839 | + $this->assertCount(0, $warnings); |
|
840 | + |
|
841 | + $content = '<?php '.PHP_EOL.'/** |
|
842 | 842 | '.PHP_EOL.' * @phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ '.PHP_EOL.'//TODO: write some code'; |
843 | - $file = new DummyFile($content, $ruleset, $config); |
|
844 | - $file->process(); |
|
845 | - |
|
846 | - $errors = $file->getErrors(); |
|
847 | - $numErrors = $file->getErrorCount(); |
|
848 | - $warnings = $file->getWarnings(); |
|
849 | - $numWarnings = $file->getWarningCount(); |
|
850 | - $this->assertEquals(0, $numErrors); |
|
851 | - $this->assertCount(0, $errors); |
|
852 | - $this->assertEquals(0, $numWarnings); |
|
853 | - $this->assertCount(0, $warnings); |
|
854 | - |
|
855 | - // Suppress wrong category using docblocks. |
|
856 | - $content = '<?php '.PHP_EOL.'/** |
|
843 | + $file = new DummyFile($content, $ruleset, $config); |
|
844 | + $file->process(); |
|
845 | + |
|
846 | + $errors = $file->getErrors(); |
|
847 | + $numErrors = $file->getErrorCount(); |
|
848 | + $warnings = $file->getWarnings(); |
|
849 | + $numWarnings = $file->getWarningCount(); |
|
850 | + $this->assertEquals(0, $numErrors); |
|
851 | + $this->assertCount(0, $errors); |
|
852 | + $this->assertEquals(0, $numWarnings); |
|
853 | + $this->assertCount(0, $warnings); |
|
854 | + |
|
855 | + // Suppress wrong category using docblocks. |
|
856 | + $content = '<?php '.PHP_EOL.'/** |
|
857 | 857 | '.PHP_EOL.' * phpcs:disable Generic.Files'.PHP_EOL.' */ '.PHP_EOL.'//TODO: write some code'; |
858 | - $file = new DummyFile($content, $ruleset, $config); |
|
859 | - $file->process(); |
|
860 | - |
|
861 | - $errors = $file->getErrors(); |
|
862 | - $numErrors = $file->getErrorCount(); |
|
863 | - $warnings = $file->getWarnings(); |
|
864 | - $numWarnings = $file->getWarningCount(); |
|
865 | - $this->assertEquals(0, $numErrors); |
|
866 | - $this->assertCount(0, $errors); |
|
867 | - $this->assertEquals(1, $numWarnings); |
|
868 | - $this->assertCount(1, $warnings); |
|
869 | - |
|
870 | - $content = '<?php '.PHP_EOL.'/** |
|
858 | + $file = new DummyFile($content, $ruleset, $config); |
|
859 | + $file->process(); |
|
860 | + |
|
861 | + $errors = $file->getErrors(); |
|
862 | + $numErrors = $file->getErrorCount(); |
|
863 | + $warnings = $file->getWarnings(); |
|
864 | + $numWarnings = $file->getWarningCount(); |
|
865 | + $this->assertEquals(0, $numErrors); |
|
866 | + $this->assertCount(0, $errors); |
|
867 | + $this->assertEquals(1, $numWarnings); |
|
868 | + $this->assertCount(1, $warnings); |
|
869 | + |
|
870 | + $content = '<?php '.PHP_EOL.'/** |
|
871 | 871 | '.PHP_EOL.' * @phpcs:disable Generic.Files'.PHP_EOL.' */ '.PHP_EOL.'//TODO: write some code'; |
872 | - $file = new DummyFile($content, $ruleset, $config); |
|
873 | - $file->process(); |
|
874 | - |
|
875 | - $errors = $file->getErrors(); |
|
876 | - $numErrors = $file->getErrorCount(); |
|
877 | - $warnings = $file->getWarnings(); |
|
878 | - $numWarnings = $file->getWarningCount(); |
|
879 | - $this->assertEquals(0, $numErrors); |
|
880 | - $this->assertCount(0, $errors); |
|
881 | - $this->assertEquals(1, $numWarnings); |
|
882 | - $this->assertCount(1, $warnings); |
|
883 | - |
|
884 | - }//end testDisableSelected() |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * Test re-enabling specific sniffs that have been disabled. |
|
889 | - * |
|
890 | - * @return void |
|
891 | - */ |
|
892 | - public function testEnableSelected() |
|
893 | - { |
|
894 | - $config = new Config(); |
|
895 | - $config->standards = ['Generic']; |
|
896 | - $config->sniffs = [ |
|
897 | - 'Generic.PHP.LowerCaseConstant', |
|
898 | - 'Generic.Commenting.Todo', |
|
899 | - ]; |
|
900 | - |
|
901 | - $ruleset = new Ruleset($config); |
|
902 | - |
|
903 | - // Suppress a single sniff and re-enable. |
|
904 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'; |
|
905 | - $file = new DummyFile($content, $ruleset, $config); |
|
906 | - $file->process(); |
|
907 | - |
|
908 | - $errors = $file->getErrors(); |
|
909 | - $numErrors = $file->getErrorCount(); |
|
910 | - $warnings = $file->getWarnings(); |
|
911 | - $numWarnings = $file->getWarningCount(); |
|
912 | - $this->assertEquals(1, $numErrors); |
|
913 | - $this->assertCount(1, $errors); |
|
914 | - $this->assertEquals(1, $numWarnings); |
|
915 | - $this->assertCount(1, $warnings); |
|
916 | - |
|
917 | - // Suppress multiple sniffs and re-enable. |
|
918 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'; |
|
919 | - $file = new DummyFile($content, $ruleset, $config); |
|
920 | - $file->process(); |
|
921 | - |
|
922 | - $errors = $file->getErrors(); |
|
923 | - $numErrors = $file->getErrorCount(); |
|
924 | - $warnings = $file->getWarnings(); |
|
925 | - $numWarnings = $file->getWarningCount(); |
|
926 | - $this->assertEquals(1, $numErrors); |
|
927 | - $this->assertCount(1, $errors); |
|
928 | - $this->assertEquals(1, $numWarnings); |
|
929 | - $this->assertCount(1, $warnings); |
|
930 | - |
|
931 | - // Suppress multiple sniffs and re-enable one. |
|
932 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'; |
|
933 | - $file = new DummyFile($content, $ruleset, $config); |
|
934 | - $file->process(); |
|
935 | - |
|
936 | - $errors = $file->getErrors(); |
|
937 | - $numErrors = $file->getErrorCount(); |
|
938 | - $warnings = $file->getWarnings(); |
|
939 | - $numWarnings = $file->getWarningCount(); |
|
940 | - $this->assertEquals(0, $numErrors); |
|
941 | - $this->assertCount(0, $errors); |
|
942 | - $this->assertEquals(1, $numWarnings); |
|
943 | - $this->assertCount(1, $warnings); |
|
944 | - |
|
945 | - // Suppress a category of sniffs and re-enable. |
|
946 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
947 | - $file = new DummyFile($content, $ruleset, $config); |
|
948 | - $file->process(); |
|
949 | - |
|
950 | - $errors = $file->getErrors(); |
|
951 | - $numErrors = $file->getErrorCount(); |
|
952 | - $warnings = $file->getWarnings(); |
|
953 | - $numWarnings = $file->getWarningCount(); |
|
954 | - $this->assertEquals(1, $numErrors); |
|
955 | - $this->assertCount(1, $errors); |
|
956 | - $this->assertEquals(1, $numWarnings); |
|
957 | - $this->assertCount(1, $warnings); |
|
958 | - |
|
959 | - // Suppress a whole standard and re-enable. |
|
960 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic'.PHP_EOL.'//TODO: write some code'; |
|
961 | - $file = new DummyFile($content, $ruleset, $config); |
|
962 | - $file->process(); |
|
963 | - |
|
964 | - $errors = $file->getErrors(); |
|
965 | - $numErrors = $file->getErrorCount(); |
|
966 | - $warnings = $file->getWarnings(); |
|
967 | - $numWarnings = $file->getWarningCount(); |
|
968 | - $this->assertEquals(0, $numErrors); |
|
969 | - $this->assertCount(0, $errors); |
|
970 | - $this->assertEquals(1, $numWarnings); |
|
971 | - $this->assertCount(1, $warnings); |
|
972 | - |
|
973 | - // Suppress a whole standard and re-enable a category. |
|
974 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
975 | - $file = new DummyFile($content, $ruleset, $config); |
|
976 | - $file->process(); |
|
977 | - |
|
978 | - $errors = $file->getErrors(); |
|
979 | - $numErrors = $file->getErrorCount(); |
|
980 | - $warnings = $file->getWarnings(); |
|
981 | - $numWarnings = $file->getWarningCount(); |
|
982 | - $this->assertEquals(0, $numErrors); |
|
983 | - $this->assertCount(0, $errors); |
|
984 | - $this->assertEquals(1, $numWarnings); |
|
985 | - $this->assertCount(1, $warnings); |
|
986 | - |
|
987 | - // Suppress a category and re-enable a whole standard. |
|
988 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic'.PHP_EOL.'//TODO: write some code'; |
|
989 | - $file = new DummyFile($content, $ruleset, $config); |
|
990 | - $file->process(); |
|
991 | - |
|
992 | - $errors = $file->getErrors(); |
|
993 | - $numErrors = $file->getErrorCount(); |
|
994 | - $warnings = $file->getWarnings(); |
|
995 | - $numWarnings = $file->getWarningCount(); |
|
996 | - $this->assertEquals(1, $numErrors); |
|
997 | - $this->assertCount(1, $errors); |
|
998 | - $this->assertEquals(1, $numWarnings); |
|
999 | - $this->assertCount(1, $warnings); |
|
1000 | - |
|
1001 | - // Suppress a sniff and re-enable a category. |
|
1002 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
1003 | - $file = new DummyFile($content, $ruleset, $config); |
|
1004 | - $file->process(); |
|
1005 | - |
|
1006 | - $errors = $file->getErrors(); |
|
1007 | - $numErrors = $file->getErrorCount(); |
|
1008 | - $warnings = $file->getWarnings(); |
|
1009 | - $numWarnings = $file->getWarningCount(); |
|
1010 | - $this->assertEquals(1, $numErrors); |
|
1011 | - $this->assertCount(1, $errors); |
|
1012 | - $this->assertEquals(1, $numWarnings); |
|
1013 | - $this->assertCount(1, $warnings); |
|
1014 | - |
|
1015 | - // Suppress a whole standard and re-enable a sniff. |
|
1016 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'; |
|
1017 | - $file = new DummyFile($content, $ruleset, $config); |
|
1018 | - $file->process(); |
|
1019 | - |
|
1020 | - $errors = $file->getErrors(); |
|
1021 | - $numErrors = $file->getErrorCount(); |
|
1022 | - $warnings = $file->getWarnings(); |
|
1023 | - $numWarnings = $file->getWarningCount(); |
|
1024 | - $this->assertEquals(0, $numErrors); |
|
1025 | - $this->assertCount(0, $errors); |
|
1026 | - $this->assertEquals(1, $numWarnings); |
|
1027 | - $this->assertCount(1, $warnings); |
|
1028 | - |
|
1029 | - // Suppress a whole standard and re-enable and re-disable a sniff. |
|
1030 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable'.PHP_EOL.'//TODO: write some code'; |
|
1031 | - $file = new DummyFile($content, $ruleset, $config); |
|
1032 | - $file->process(); |
|
1033 | - |
|
1034 | - $errors = $file->getErrors(); |
|
1035 | - $numErrors = $file->getErrorCount(); |
|
1036 | - $warnings = $file->getWarnings(); |
|
1037 | - $numWarnings = $file->getWarningCount(); |
|
1038 | - $this->assertEquals(0, $numErrors); |
|
1039 | - $this->assertCount(0, $errors); |
|
1040 | - $this->assertEquals(2, $numWarnings); |
|
1041 | - $this->assertCount(2, $warnings); |
|
1042 | - |
|
1043 | - // Suppress a whole standard and re-enable 2 specific sniffs independently. |
|
1044 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable Generic.PHP.LowerCaseConstant'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'.PHP_EOL; |
|
1045 | - $file = new DummyFile($content, $ruleset, $config); |
|
1046 | - $file->process(); |
|
1047 | - |
|
1048 | - $errors = $file->getErrors(); |
|
1049 | - $numErrors = $file->getErrorCount(); |
|
1050 | - $warnings = $file->getWarnings(); |
|
1051 | - $numWarnings = $file->getWarningCount(); |
|
1052 | - $this->assertEquals(1, $numErrors); |
|
1053 | - $this->assertCount(1, $errors); |
|
1054 | - $this->assertEquals(2, $numWarnings); |
|
1055 | - $this->assertCount(2, $warnings); |
|
1056 | - |
|
1057 | - }//end testEnableSelected() |
|
1058 | - |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Test ignoring specific sniffs. |
|
1062 | - * |
|
1063 | - * @return void |
|
1064 | - */ |
|
1065 | - public function testIgnoreSelected() |
|
1066 | - { |
|
1067 | - $config = new Config(); |
|
1068 | - $config->standards = ['Generic']; |
|
1069 | - $config->sniffs = [ |
|
1070 | - 'Generic.PHP.LowerCaseConstant', |
|
1071 | - 'Generic.Commenting.Todo', |
|
1072 | - ]; |
|
1073 | - |
|
1074 | - $ruleset = new Ruleset($config); |
|
1075 | - |
|
1076 | - // No suppression. |
|
1077 | - $content = '<?php '.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1078 | - $file = new DummyFile($content, $ruleset, $config); |
|
1079 | - $file->process(); |
|
1080 | - |
|
1081 | - $errors = $file->getErrors(); |
|
1082 | - $numErrors = $file->getErrorCount(); |
|
1083 | - $warnings = $file->getWarnings(); |
|
1084 | - $numWarnings = $file->getWarningCount(); |
|
1085 | - $this->assertEquals(2, $numErrors); |
|
1086 | - $this->assertCount(2, $errors); |
|
1087 | - $this->assertEquals(2, $numWarnings); |
|
1088 | - $this->assertCount(2, $warnings); |
|
1089 | - |
|
1090 | - // Suppress a single sniff. |
|
1091 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1092 | - $file = new DummyFile($content, $ruleset, $config); |
|
1093 | - $file->process(); |
|
1094 | - |
|
1095 | - $errors = $file->getErrors(); |
|
1096 | - $numErrors = $file->getErrorCount(); |
|
1097 | - $warnings = $file->getWarnings(); |
|
1098 | - $numWarnings = $file->getWarningCount(); |
|
1099 | - $this->assertEquals(2, $numErrors); |
|
1100 | - $this->assertCount(2, $errors); |
|
1101 | - $this->assertEquals(1, $numWarnings); |
|
1102 | - $this->assertCount(1, $warnings); |
|
1103 | - |
|
1104 | - // Suppress multiple sniffs. |
|
1105 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1106 | - $file = new DummyFile($content, $ruleset, $config); |
|
1107 | - $file->process(); |
|
1108 | - |
|
1109 | - $errors = $file->getErrors(); |
|
1110 | - $numErrors = $file->getErrorCount(); |
|
1111 | - $warnings = $file->getWarnings(); |
|
1112 | - $numWarnings = $file->getWarningCount(); |
|
1113 | - $this->assertEquals(1, $numErrors); |
|
1114 | - $this->assertCount(1, $errors); |
|
1115 | - $this->assertEquals(1, $numWarnings); |
|
1116 | - $this->assertCount(1, $warnings); |
|
1117 | - |
|
1118 | - // Add to suppression. |
|
1119 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:ignore Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1120 | - $file = new DummyFile($content, $ruleset, $config); |
|
1121 | - $file->process(); |
|
1122 | - |
|
1123 | - $errors = $file->getErrors(); |
|
1124 | - $numErrors = $file->getErrorCount(); |
|
1125 | - $warnings = $file->getWarnings(); |
|
1126 | - $numWarnings = $file->getWarningCount(); |
|
1127 | - $this->assertEquals(1, $numErrors); |
|
1128 | - $this->assertCount(1, $errors); |
|
1129 | - $this->assertEquals(0, $numWarnings); |
|
1130 | - $this->assertCount(0, $warnings); |
|
1131 | - |
|
1132 | - // Suppress a category of sniffs. |
|
1133 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1134 | - $file = new DummyFile($content, $ruleset, $config); |
|
1135 | - $file->process(); |
|
1136 | - |
|
1137 | - $errors = $file->getErrors(); |
|
1138 | - $numErrors = $file->getErrorCount(); |
|
1139 | - $warnings = $file->getWarnings(); |
|
1140 | - $numWarnings = $file->getWarningCount(); |
|
1141 | - $this->assertEquals(2, $numErrors); |
|
1142 | - $this->assertCount(2, $errors); |
|
1143 | - $this->assertEquals(1, $numWarnings); |
|
1144 | - $this->assertCount(1, $warnings); |
|
1145 | - |
|
1146 | - // Suppress a whole standard. |
|
1147 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1148 | - $file = new DummyFile($content, $ruleset, $config); |
|
1149 | - $file->process(); |
|
1150 | - |
|
1151 | - $errors = $file->getErrors(); |
|
1152 | - $numErrors = $file->getErrorCount(); |
|
1153 | - $warnings = $file->getWarnings(); |
|
1154 | - $numWarnings = $file->getWarningCount(); |
|
1155 | - $this->assertEquals(1, $numErrors); |
|
1156 | - $this->assertCount(1, $errors); |
|
1157 | - $this->assertEquals(1, $numWarnings); |
|
1158 | - $this->assertCount(1, $warnings); |
|
1159 | - |
|
1160 | - }//end testIgnoreSelected() |
|
1161 | - |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * Test ignoring specific sniffs. |
|
1165 | - * |
|
1166 | - * @return void |
|
1167 | - */ |
|
1168 | - public function testCommenting() |
|
1169 | - { |
|
1170 | - $config = new Config(); |
|
1171 | - $config->standards = ['Generic']; |
|
1172 | - $config->sniffs = [ |
|
1173 | - 'Generic.PHP.LowerCaseConstant', |
|
1174 | - 'Generic.Commenting.Todo', |
|
1175 | - ]; |
|
1176 | - |
|
1177 | - $ruleset = new Ruleset($config); |
|
1178 | - |
|
1179 | - // Suppress a single sniff. |
|
1180 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo -- Because reasons'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1181 | - $file = new DummyFile($content, $ruleset, $config); |
|
1182 | - $file->process(); |
|
1183 | - |
|
1184 | - $errors = $file->getErrors(); |
|
1185 | - $numErrors = $file->getErrorCount(); |
|
1186 | - $warnings = $file->getWarnings(); |
|
1187 | - $numWarnings = $file->getWarningCount(); |
|
1188 | - $this->assertEquals(2, $numErrors); |
|
1189 | - $this->assertCount(2, $errors); |
|
1190 | - $this->assertEquals(1, $numWarnings); |
|
1191 | - $this->assertCount(1, $warnings); |
|
1192 | - |
|
1193 | - // Suppress a single sniff and re-enable. |
|
1194 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo --Because reasons'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo -- Because reasons'.PHP_EOL.'//TODO: write some code'; |
|
1195 | - $file = new DummyFile($content, $ruleset, $config); |
|
1196 | - $file->process(); |
|
1197 | - |
|
1198 | - $errors = $file->getErrors(); |
|
1199 | - $numErrors = $file->getErrorCount(); |
|
1200 | - $warnings = $file->getWarnings(); |
|
1201 | - $numWarnings = $file->getWarningCount(); |
|
1202 | - $this->assertEquals(1, $numErrors); |
|
1203 | - $this->assertCount(1, $errors); |
|
1204 | - $this->assertEquals(1, $numWarnings); |
|
1205 | - $this->assertCount(1, $warnings); |
|
1206 | - |
|
1207 | - // Suppress a single sniff using block comments. |
|
1208 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' Disable some checks'.PHP_EOL.' phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'*/'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
1209 | - $file = new DummyFile($content, $ruleset, $config); |
|
1210 | - $file->process(); |
|
1211 | - |
|
1212 | - $errors = $file->getErrors(); |
|
1213 | - $numErrors = $file->getErrorCount(); |
|
1214 | - $warnings = $file->getWarnings(); |
|
1215 | - $numWarnings = $file->getWarningCount(); |
|
1216 | - $this->assertEquals(1, $numErrors); |
|
1217 | - $this->assertCount(1, $errors); |
|
1218 | - $this->assertEquals(0, $numWarnings); |
|
1219 | - $this->assertCount(0, $warnings); |
|
1220 | - |
|
1221 | - // Suppress a single sniff with a multi-line comment. |
|
1222 | - $content = '<?php '.PHP_EOL.'// Turn off a check for the next line of code.'.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1223 | - $file = new DummyFile($content, $ruleset, $config); |
|
1224 | - $file->process(); |
|
1225 | - |
|
1226 | - $errors = $file->getErrors(); |
|
1227 | - $numErrors = $file->getErrorCount(); |
|
1228 | - $warnings = $file->getWarnings(); |
|
1229 | - $numWarnings = $file->getWarningCount(); |
|
1230 | - $this->assertEquals(2, $numErrors); |
|
1231 | - $this->assertCount(2, $errors); |
|
1232 | - $this->assertEquals(1, $numWarnings); |
|
1233 | - $this->assertCount(1, $warnings); |
|
1234 | - |
|
1235 | - // Ignore an enable before a disable. |
|
1236 | - $content = '<?php '.PHP_EOL.'// phpcs:enable Generic.PHP.NoSilencedErrors -- Because reasons'.PHP_EOL.'$var = @delete( $filename );'.PHP_EOL; |
|
1237 | - $file = new DummyFile($content, $ruleset, $config); |
|
1238 | - $file->process(); |
|
1239 | - |
|
1240 | - $errors = $file->getErrors(); |
|
1241 | - $numErrors = $file->getErrorCount(); |
|
1242 | - $warnings = $file->getWarnings(); |
|
1243 | - $numWarnings = $file->getWarningCount(); |
|
1244 | - $this->assertEquals(0, $numErrors); |
|
1245 | - $this->assertCount(0, $errors); |
|
1246 | - $this->assertEquals(0, $numWarnings); |
|
1247 | - $this->assertCount(0, $warnings); |
|
1248 | - |
|
1249 | - }//end testCommenting() |
|
872 | + $file = new DummyFile($content, $ruleset, $config); |
|
873 | + $file->process(); |
|
874 | + |
|
875 | + $errors = $file->getErrors(); |
|
876 | + $numErrors = $file->getErrorCount(); |
|
877 | + $warnings = $file->getWarnings(); |
|
878 | + $numWarnings = $file->getWarningCount(); |
|
879 | + $this->assertEquals(0, $numErrors); |
|
880 | + $this->assertCount(0, $errors); |
|
881 | + $this->assertEquals(1, $numWarnings); |
|
882 | + $this->assertCount(1, $warnings); |
|
883 | + |
|
884 | + }//end testDisableSelected() |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * Test re-enabling specific sniffs that have been disabled. |
|
889 | + * |
|
890 | + * @return void |
|
891 | + */ |
|
892 | + public function testEnableSelected() |
|
893 | + { |
|
894 | + $config = new Config(); |
|
895 | + $config->standards = ['Generic']; |
|
896 | + $config->sniffs = [ |
|
897 | + 'Generic.PHP.LowerCaseConstant', |
|
898 | + 'Generic.Commenting.Todo', |
|
899 | + ]; |
|
900 | + |
|
901 | + $ruleset = new Ruleset($config); |
|
902 | + |
|
903 | + // Suppress a single sniff and re-enable. |
|
904 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'; |
|
905 | + $file = new DummyFile($content, $ruleset, $config); |
|
906 | + $file->process(); |
|
907 | + |
|
908 | + $errors = $file->getErrors(); |
|
909 | + $numErrors = $file->getErrorCount(); |
|
910 | + $warnings = $file->getWarnings(); |
|
911 | + $numWarnings = $file->getWarningCount(); |
|
912 | + $this->assertEquals(1, $numErrors); |
|
913 | + $this->assertCount(1, $errors); |
|
914 | + $this->assertEquals(1, $numWarnings); |
|
915 | + $this->assertCount(1, $warnings); |
|
916 | + |
|
917 | + // Suppress multiple sniffs and re-enable. |
|
918 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'; |
|
919 | + $file = new DummyFile($content, $ruleset, $config); |
|
920 | + $file->process(); |
|
921 | + |
|
922 | + $errors = $file->getErrors(); |
|
923 | + $numErrors = $file->getErrorCount(); |
|
924 | + $warnings = $file->getWarnings(); |
|
925 | + $numWarnings = $file->getWarningCount(); |
|
926 | + $this->assertEquals(1, $numErrors); |
|
927 | + $this->assertCount(1, $errors); |
|
928 | + $this->assertEquals(1, $numWarnings); |
|
929 | + $this->assertCount(1, $warnings); |
|
930 | + |
|
931 | + // Suppress multiple sniffs and re-enable one. |
|
932 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'; |
|
933 | + $file = new DummyFile($content, $ruleset, $config); |
|
934 | + $file->process(); |
|
935 | + |
|
936 | + $errors = $file->getErrors(); |
|
937 | + $numErrors = $file->getErrorCount(); |
|
938 | + $warnings = $file->getWarnings(); |
|
939 | + $numWarnings = $file->getWarningCount(); |
|
940 | + $this->assertEquals(0, $numErrors); |
|
941 | + $this->assertCount(0, $errors); |
|
942 | + $this->assertEquals(1, $numWarnings); |
|
943 | + $this->assertCount(1, $warnings); |
|
944 | + |
|
945 | + // Suppress a category of sniffs and re-enable. |
|
946 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
947 | + $file = new DummyFile($content, $ruleset, $config); |
|
948 | + $file->process(); |
|
949 | + |
|
950 | + $errors = $file->getErrors(); |
|
951 | + $numErrors = $file->getErrorCount(); |
|
952 | + $warnings = $file->getWarnings(); |
|
953 | + $numWarnings = $file->getWarningCount(); |
|
954 | + $this->assertEquals(1, $numErrors); |
|
955 | + $this->assertCount(1, $errors); |
|
956 | + $this->assertEquals(1, $numWarnings); |
|
957 | + $this->assertCount(1, $warnings); |
|
958 | + |
|
959 | + // Suppress a whole standard and re-enable. |
|
960 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic'.PHP_EOL.'//TODO: write some code'; |
|
961 | + $file = new DummyFile($content, $ruleset, $config); |
|
962 | + $file->process(); |
|
963 | + |
|
964 | + $errors = $file->getErrors(); |
|
965 | + $numErrors = $file->getErrorCount(); |
|
966 | + $warnings = $file->getWarnings(); |
|
967 | + $numWarnings = $file->getWarningCount(); |
|
968 | + $this->assertEquals(0, $numErrors); |
|
969 | + $this->assertCount(0, $errors); |
|
970 | + $this->assertEquals(1, $numWarnings); |
|
971 | + $this->assertCount(1, $warnings); |
|
972 | + |
|
973 | + // Suppress a whole standard and re-enable a category. |
|
974 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
975 | + $file = new DummyFile($content, $ruleset, $config); |
|
976 | + $file->process(); |
|
977 | + |
|
978 | + $errors = $file->getErrors(); |
|
979 | + $numErrors = $file->getErrorCount(); |
|
980 | + $warnings = $file->getWarnings(); |
|
981 | + $numWarnings = $file->getWarningCount(); |
|
982 | + $this->assertEquals(0, $numErrors); |
|
983 | + $this->assertCount(0, $errors); |
|
984 | + $this->assertEquals(1, $numWarnings); |
|
985 | + $this->assertCount(1, $warnings); |
|
986 | + |
|
987 | + // Suppress a category and re-enable a whole standard. |
|
988 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic'.PHP_EOL.'//TODO: write some code'; |
|
989 | + $file = new DummyFile($content, $ruleset, $config); |
|
990 | + $file->process(); |
|
991 | + |
|
992 | + $errors = $file->getErrors(); |
|
993 | + $numErrors = $file->getErrorCount(); |
|
994 | + $warnings = $file->getWarnings(); |
|
995 | + $numWarnings = $file->getWarningCount(); |
|
996 | + $this->assertEquals(1, $numErrors); |
|
997 | + $this->assertCount(1, $errors); |
|
998 | + $this->assertEquals(1, $numWarnings); |
|
999 | + $this->assertCount(1, $warnings); |
|
1000 | + |
|
1001 | + // Suppress a sniff and re-enable a category. |
|
1002 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
1003 | + $file = new DummyFile($content, $ruleset, $config); |
|
1004 | + $file->process(); |
|
1005 | + |
|
1006 | + $errors = $file->getErrors(); |
|
1007 | + $numErrors = $file->getErrorCount(); |
|
1008 | + $warnings = $file->getWarnings(); |
|
1009 | + $numWarnings = $file->getWarningCount(); |
|
1010 | + $this->assertEquals(1, $numErrors); |
|
1011 | + $this->assertCount(1, $errors); |
|
1012 | + $this->assertEquals(1, $numWarnings); |
|
1013 | + $this->assertCount(1, $warnings); |
|
1014 | + |
|
1015 | + // Suppress a whole standard and re-enable a sniff. |
|
1016 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'; |
|
1017 | + $file = new DummyFile($content, $ruleset, $config); |
|
1018 | + $file->process(); |
|
1019 | + |
|
1020 | + $errors = $file->getErrors(); |
|
1021 | + $numErrors = $file->getErrorCount(); |
|
1022 | + $warnings = $file->getWarnings(); |
|
1023 | + $numWarnings = $file->getWarningCount(); |
|
1024 | + $this->assertEquals(0, $numErrors); |
|
1025 | + $this->assertCount(0, $errors); |
|
1026 | + $this->assertEquals(1, $numWarnings); |
|
1027 | + $this->assertCount(1, $warnings); |
|
1028 | + |
|
1029 | + // Suppress a whole standard and re-enable and re-disable a sniff. |
|
1030 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable'.PHP_EOL.'//TODO: write some code'; |
|
1031 | + $file = new DummyFile($content, $ruleset, $config); |
|
1032 | + $file->process(); |
|
1033 | + |
|
1034 | + $errors = $file->getErrors(); |
|
1035 | + $numErrors = $file->getErrorCount(); |
|
1036 | + $warnings = $file->getWarnings(); |
|
1037 | + $numWarnings = $file->getWarningCount(); |
|
1038 | + $this->assertEquals(0, $numErrors); |
|
1039 | + $this->assertCount(0, $errors); |
|
1040 | + $this->assertEquals(2, $numWarnings); |
|
1041 | + $this->assertCount(2, $warnings); |
|
1042 | + |
|
1043 | + // Suppress a whole standard and re-enable 2 specific sniffs independently. |
|
1044 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable Generic.PHP.LowerCaseConstant'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'.PHP_EOL; |
|
1045 | + $file = new DummyFile($content, $ruleset, $config); |
|
1046 | + $file->process(); |
|
1047 | + |
|
1048 | + $errors = $file->getErrors(); |
|
1049 | + $numErrors = $file->getErrorCount(); |
|
1050 | + $warnings = $file->getWarnings(); |
|
1051 | + $numWarnings = $file->getWarningCount(); |
|
1052 | + $this->assertEquals(1, $numErrors); |
|
1053 | + $this->assertCount(1, $errors); |
|
1054 | + $this->assertEquals(2, $numWarnings); |
|
1055 | + $this->assertCount(2, $warnings); |
|
1056 | + |
|
1057 | + }//end testEnableSelected() |
|
1058 | + |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Test ignoring specific sniffs. |
|
1062 | + * |
|
1063 | + * @return void |
|
1064 | + */ |
|
1065 | + public function testIgnoreSelected() |
|
1066 | + { |
|
1067 | + $config = new Config(); |
|
1068 | + $config->standards = ['Generic']; |
|
1069 | + $config->sniffs = [ |
|
1070 | + 'Generic.PHP.LowerCaseConstant', |
|
1071 | + 'Generic.Commenting.Todo', |
|
1072 | + ]; |
|
1073 | + |
|
1074 | + $ruleset = new Ruleset($config); |
|
1075 | + |
|
1076 | + // No suppression. |
|
1077 | + $content = '<?php '.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1078 | + $file = new DummyFile($content, $ruleset, $config); |
|
1079 | + $file->process(); |
|
1080 | + |
|
1081 | + $errors = $file->getErrors(); |
|
1082 | + $numErrors = $file->getErrorCount(); |
|
1083 | + $warnings = $file->getWarnings(); |
|
1084 | + $numWarnings = $file->getWarningCount(); |
|
1085 | + $this->assertEquals(2, $numErrors); |
|
1086 | + $this->assertCount(2, $errors); |
|
1087 | + $this->assertEquals(2, $numWarnings); |
|
1088 | + $this->assertCount(2, $warnings); |
|
1089 | + |
|
1090 | + // Suppress a single sniff. |
|
1091 | + $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1092 | + $file = new DummyFile($content, $ruleset, $config); |
|
1093 | + $file->process(); |
|
1094 | + |
|
1095 | + $errors = $file->getErrors(); |
|
1096 | + $numErrors = $file->getErrorCount(); |
|
1097 | + $warnings = $file->getWarnings(); |
|
1098 | + $numWarnings = $file->getWarningCount(); |
|
1099 | + $this->assertEquals(2, $numErrors); |
|
1100 | + $this->assertCount(2, $errors); |
|
1101 | + $this->assertEquals(1, $numWarnings); |
|
1102 | + $this->assertCount(1, $warnings); |
|
1103 | + |
|
1104 | + // Suppress multiple sniffs. |
|
1105 | + $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1106 | + $file = new DummyFile($content, $ruleset, $config); |
|
1107 | + $file->process(); |
|
1108 | + |
|
1109 | + $errors = $file->getErrors(); |
|
1110 | + $numErrors = $file->getErrorCount(); |
|
1111 | + $warnings = $file->getWarnings(); |
|
1112 | + $numWarnings = $file->getWarningCount(); |
|
1113 | + $this->assertEquals(1, $numErrors); |
|
1114 | + $this->assertCount(1, $errors); |
|
1115 | + $this->assertEquals(1, $numWarnings); |
|
1116 | + $this->assertCount(1, $warnings); |
|
1117 | + |
|
1118 | + // Add to suppression. |
|
1119 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:ignore Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1120 | + $file = new DummyFile($content, $ruleset, $config); |
|
1121 | + $file->process(); |
|
1122 | + |
|
1123 | + $errors = $file->getErrors(); |
|
1124 | + $numErrors = $file->getErrorCount(); |
|
1125 | + $warnings = $file->getWarnings(); |
|
1126 | + $numWarnings = $file->getWarningCount(); |
|
1127 | + $this->assertEquals(1, $numErrors); |
|
1128 | + $this->assertCount(1, $errors); |
|
1129 | + $this->assertEquals(0, $numWarnings); |
|
1130 | + $this->assertCount(0, $warnings); |
|
1131 | + |
|
1132 | + // Suppress a category of sniffs. |
|
1133 | + $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1134 | + $file = new DummyFile($content, $ruleset, $config); |
|
1135 | + $file->process(); |
|
1136 | + |
|
1137 | + $errors = $file->getErrors(); |
|
1138 | + $numErrors = $file->getErrorCount(); |
|
1139 | + $warnings = $file->getWarnings(); |
|
1140 | + $numWarnings = $file->getWarningCount(); |
|
1141 | + $this->assertEquals(2, $numErrors); |
|
1142 | + $this->assertCount(2, $errors); |
|
1143 | + $this->assertEquals(1, $numWarnings); |
|
1144 | + $this->assertCount(1, $warnings); |
|
1145 | + |
|
1146 | + // Suppress a whole standard. |
|
1147 | + $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1148 | + $file = new DummyFile($content, $ruleset, $config); |
|
1149 | + $file->process(); |
|
1150 | + |
|
1151 | + $errors = $file->getErrors(); |
|
1152 | + $numErrors = $file->getErrorCount(); |
|
1153 | + $warnings = $file->getWarnings(); |
|
1154 | + $numWarnings = $file->getWarningCount(); |
|
1155 | + $this->assertEquals(1, $numErrors); |
|
1156 | + $this->assertCount(1, $errors); |
|
1157 | + $this->assertEquals(1, $numWarnings); |
|
1158 | + $this->assertCount(1, $warnings); |
|
1159 | + |
|
1160 | + }//end testIgnoreSelected() |
|
1161 | + |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * Test ignoring specific sniffs. |
|
1165 | + * |
|
1166 | + * @return void |
|
1167 | + */ |
|
1168 | + public function testCommenting() |
|
1169 | + { |
|
1170 | + $config = new Config(); |
|
1171 | + $config->standards = ['Generic']; |
|
1172 | + $config->sniffs = [ |
|
1173 | + 'Generic.PHP.LowerCaseConstant', |
|
1174 | + 'Generic.Commenting.Todo', |
|
1175 | + ]; |
|
1176 | + |
|
1177 | + $ruleset = new Ruleset($config); |
|
1178 | + |
|
1179 | + // Suppress a single sniff. |
|
1180 | + $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo -- Because reasons'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1181 | + $file = new DummyFile($content, $ruleset, $config); |
|
1182 | + $file->process(); |
|
1183 | + |
|
1184 | + $errors = $file->getErrors(); |
|
1185 | + $numErrors = $file->getErrorCount(); |
|
1186 | + $warnings = $file->getWarnings(); |
|
1187 | + $numWarnings = $file->getWarningCount(); |
|
1188 | + $this->assertEquals(2, $numErrors); |
|
1189 | + $this->assertCount(2, $errors); |
|
1190 | + $this->assertEquals(1, $numWarnings); |
|
1191 | + $this->assertCount(1, $warnings); |
|
1192 | + |
|
1193 | + // Suppress a single sniff and re-enable. |
|
1194 | + $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo --Because reasons'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo -- Because reasons'.PHP_EOL.'//TODO: write some code'; |
|
1195 | + $file = new DummyFile($content, $ruleset, $config); |
|
1196 | + $file->process(); |
|
1197 | + |
|
1198 | + $errors = $file->getErrors(); |
|
1199 | + $numErrors = $file->getErrorCount(); |
|
1200 | + $warnings = $file->getWarnings(); |
|
1201 | + $numWarnings = $file->getWarningCount(); |
|
1202 | + $this->assertEquals(1, $numErrors); |
|
1203 | + $this->assertCount(1, $errors); |
|
1204 | + $this->assertEquals(1, $numWarnings); |
|
1205 | + $this->assertCount(1, $warnings); |
|
1206 | + |
|
1207 | + // Suppress a single sniff using block comments. |
|
1208 | + $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' Disable some checks'.PHP_EOL.' phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'*/'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
1209 | + $file = new DummyFile($content, $ruleset, $config); |
|
1210 | + $file->process(); |
|
1211 | + |
|
1212 | + $errors = $file->getErrors(); |
|
1213 | + $numErrors = $file->getErrorCount(); |
|
1214 | + $warnings = $file->getWarnings(); |
|
1215 | + $numWarnings = $file->getWarningCount(); |
|
1216 | + $this->assertEquals(1, $numErrors); |
|
1217 | + $this->assertCount(1, $errors); |
|
1218 | + $this->assertEquals(0, $numWarnings); |
|
1219 | + $this->assertCount(0, $warnings); |
|
1220 | + |
|
1221 | + // Suppress a single sniff with a multi-line comment. |
|
1222 | + $content = '<?php '.PHP_EOL.'// Turn off a check for the next line of code.'.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1223 | + $file = new DummyFile($content, $ruleset, $config); |
|
1224 | + $file->process(); |
|
1225 | + |
|
1226 | + $errors = $file->getErrors(); |
|
1227 | + $numErrors = $file->getErrorCount(); |
|
1228 | + $warnings = $file->getWarnings(); |
|
1229 | + $numWarnings = $file->getWarningCount(); |
|
1230 | + $this->assertEquals(2, $numErrors); |
|
1231 | + $this->assertCount(2, $errors); |
|
1232 | + $this->assertEquals(1, $numWarnings); |
|
1233 | + $this->assertCount(1, $warnings); |
|
1234 | + |
|
1235 | + // Ignore an enable before a disable. |
|
1236 | + $content = '<?php '.PHP_EOL.'// phpcs:enable Generic.PHP.NoSilencedErrors -- Because reasons'.PHP_EOL.'$var = @delete( $filename );'.PHP_EOL; |
|
1237 | + $file = new DummyFile($content, $ruleset, $config); |
|
1238 | + $file->process(); |
|
1239 | + |
|
1240 | + $errors = $file->getErrors(); |
|
1241 | + $numErrors = $file->getErrorCount(); |
|
1242 | + $warnings = $file->getWarnings(); |
|
1243 | + $numWarnings = $file->getWarningCount(); |
|
1244 | + $this->assertEquals(0, $numErrors); |
|
1245 | + $this->assertCount(0, $errors); |
|
1246 | + $this->assertEquals(0, $numWarnings); |
|
1247 | + $this->assertCount(0, $warnings); |
|
1248 | + |
|
1249 | + }//end testCommenting() |
|
1250 | 1250 | |
1251 | 1251 | |
1252 | 1252 | }//end class |
@@ -26,150 +26,150 @@ discard block |
||
26 | 26 | public function testSuppressError() |
27 | 27 | { |
28 | 28 | $config = new Config(); |
29 | - $config->standards = ['Generic']; |
|
30 | - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
29 | + $config->standards = [ 'Generic' ]; |
|
30 | + $config->sniffs = [ 'Generic.PHP.LowerCaseConstant' ]; |
|
31 | 31 | |
32 | - $ruleset = new Ruleset($config); |
|
32 | + $ruleset = new Ruleset( $config ); |
|
33 | 33 | |
34 | 34 | // Process without suppression. |
35 | - $content = '<?php '.PHP_EOL.'$var = FALSE;'; |
|
36 | - $file = new DummyFile($content, $ruleset, $config); |
|
35 | + $content = '<?php ' . PHP_EOL . '$var = FALSE;'; |
|
36 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
37 | 37 | $file->process(); |
38 | 38 | |
39 | 39 | $errors = $file->getErrors(); |
40 | 40 | $numErrors = $file->getErrorCount(); |
41 | - $this->assertEquals(1, $numErrors); |
|
42 | - $this->assertCount(1, $errors); |
|
41 | + $this->assertEquals( 1, $numErrors ); |
|
42 | + $this->assertCount( 1, $errors ); |
|
43 | 43 | |
44 | 44 | // Process with inline comment suppression. |
45 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable'; |
|
46 | - $file = new DummyFile($content, $ruleset, $config); |
|
45 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '// phpcs:enable'; |
|
46 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
47 | 47 | $file->process(); |
48 | 48 | |
49 | 49 | $errors = $file->getErrors(); |
50 | 50 | $numErrors = $file->getErrorCount(); |
51 | - $this->assertEquals(0, $numErrors); |
|
52 | - $this->assertCount(0, $errors); |
|
51 | + $this->assertEquals( 0, $numErrors ); |
|
52 | + $this->assertCount( 0, $errors ); |
|
53 | 53 | |
54 | 54 | // Process with multi-line inline comment suppression, tab-indented. |
55 | - $content = '<?php '.PHP_EOL."\t".'// For reasons'.PHP_EOL."\t".'// phpcs:disable'.PHP_EOL."\t".'$var = FALSE;'.PHP_EOL."\t".'// phpcs:enable'; |
|
56 | - $file = new DummyFile($content, $ruleset, $config); |
|
55 | + $content = '<?php ' . PHP_EOL . "\t" . '// For reasons' . PHP_EOL . "\t" . '// phpcs:disable' . PHP_EOL . "\t" . '$var = FALSE;' . PHP_EOL . "\t" . '// phpcs:enable'; |
|
56 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
57 | 57 | $file->process(); |
58 | 58 | |
59 | 59 | $errors = $file->getErrors(); |
60 | 60 | $numErrors = $file->getErrorCount(); |
61 | - $this->assertEquals(0, $numErrors); |
|
62 | - $this->assertCount(0, $errors); |
|
61 | + $this->assertEquals( 0, $numErrors ); |
|
62 | + $this->assertCount( 0, $errors ); |
|
63 | 63 | |
64 | 64 | // Process with inline @ comment suppression. |
65 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @phpcs:enable'; |
|
66 | - $file = new DummyFile($content, $ruleset, $config); |
|
65 | + $content = '<?php ' . PHP_EOL . '// @phpcs:disable' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '// @phpcs:enable'; |
|
66 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
67 | 67 | $file->process(); |
68 | 68 | |
69 | 69 | $errors = $file->getErrors(); |
70 | 70 | $numErrors = $file->getErrorCount(); |
71 | - $this->assertEquals(0, $numErrors); |
|
72 | - $this->assertCount(0, $errors); |
|
71 | + $this->assertEquals( 0, $numErrors ); |
|
72 | + $this->assertCount( 0, $errors ); |
|
73 | 73 | |
74 | 74 | // Process with inline comment suppression mixed case. |
75 | - $content = '<?php '.PHP_EOL.'// PHPCS:Disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// pHPcs:enabLE'; |
|
76 | - $file = new DummyFile($content, $ruleset, $config); |
|
75 | + $content = '<?php ' . PHP_EOL . '// PHPCS:Disable' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '// pHPcs:enabLE'; |
|
76 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
77 | 77 | $file->process(); |
78 | 78 | |
79 | 79 | $errors = $file->getErrors(); |
80 | 80 | $numErrors = $file->getErrorCount(); |
81 | - $this->assertEquals(0, $numErrors); |
|
82 | - $this->assertCount(0, $errors); |
|
81 | + $this->assertEquals( 0, $numErrors ); |
|
82 | + $this->assertCount( 0, $errors ); |
|
83 | 83 | |
84 | 84 | // Process with inline comment suppression (deprecated syntax). |
85 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
86 | - $file = new DummyFile($content, $ruleset, $config); |
|
85 | + $content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreStart' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '// @codingStandardsIgnoreEnd'; |
|
86 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
87 | 87 | $file->process(); |
88 | 88 | |
89 | 89 | $errors = $file->getErrors(); |
90 | 90 | $numErrors = $file->getErrorCount(); |
91 | - $this->assertEquals(0, $numErrors); |
|
92 | - $this->assertCount(0, $errors); |
|
91 | + $this->assertEquals( 0, $numErrors ); |
|
92 | + $this->assertCount( 0, $errors ); |
|
93 | 93 | |
94 | 94 | // Process with block comment suppression. |
95 | - $content = '<?php '.PHP_EOL.'/* phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/* phpcs:enable */'; |
|
96 | - $file = new DummyFile($content, $ruleset, $config); |
|
95 | + $content = '<?php ' . PHP_EOL . '/* phpcs:disable */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/* phpcs:enable */'; |
|
96 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
97 | 97 | $file->process(); |
98 | 98 | |
99 | 99 | $errors = $file->getErrors(); |
100 | 100 | $numErrors = $file->getErrorCount(); |
101 | - $this->assertEquals(0, $numErrors); |
|
102 | - $this->assertCount(0, $errors); |
|
101 | + $this->assertEquals( 0, $numErrors ); |
|
102 | + $this->assertCount( 0, $errors ); |
|
103 | 103 | |
104 | 104 | // Process with multi-line block comment suppression. |
105 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' phpcs:disable'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' phpcs:enable'.PHP_EOL.' */'; |
|
106 | - $file = new DummyFile($content, $ruleset, $config); |
|
105 | + $content = '<?php ' . PHP_EOL . '/*' . PHP_EOL . ' phpcs:disable' . PHP_EOL . ' */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/*' . PHP_EOL . ' phpcs:enable' . PHP_EOL . ' */'; |
|
106 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
107 | 107 | $file->process(); |
108 | 108 | |
109 | 109 | $errors = $file->getErrors(); |
110 | 110 | $numErrors = $file->getErrorCount(); |
111 | - $this->assertEquals(0, $numErrors); |
|
112 | - $this->assertCount(0, $errors); |
|
111 | + $this->assertEquals( 0, $numErrors ); |
|
112 | + $this->assertCount( 0, $errors ); |
|
113 | 113 | |
114 | 114 | // Process with multi-line block comment suppression, each line starred. |
115 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' * phpcs:disable'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' * phpcs:enable'.PHP_EOL.' */'; |
|
116 | - $file = new DummyFile($content, $ruleset, $config); |
|
115 | + $content = '<?php ' . PHP_EOL . '/*' . PHP_EOL . ' * phpcs:disable' . PHP_EOL . ' */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/*' . PHP_EOL . ' * phpcs:enable' . PHP_EOL . ' */'; |
|
116 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
117 | 117 | $file->process(); |
118 | 118 | |
119 | 119 | $errors = $file->getErrors(); |
120 | 120 | $numErrors = $file->getErrorCount(); |
121 | - $this->assertEquals(0, $numErrors); |
|
122 | - $this->assertCount(0, $errors); |
|
121 | + $this->assertEquals( 0, $numErrors ); |
|
122 | + $this->assertCount( 0, $errors ); |
|
123 | 123 | |
124 | 124 | // Process with multi-line block comment suppression, tab-indented. |
125 | - $content = '<?php '.PHP_EOL."\t".'/*'.PHP_EOL."\t".' * phpcs:disable'.PHP_EOL."\t".' */'.PHP_EOL."\t".'$var = FALSE;'.PHP_EOL."\t".'/*'.PHP_EOL.' * phpcs:enable'.PHP_EOL.' */'; |
|
126 | - $file = new DummyFile($content, $ruleset, $config); |
|
125 | + $content = '<?php ' . PHP_EOL . "\t" . '/*' . PHP_EOL . "\t" . ' * phpcs:disable' . PHP_EOL . "\t" . ' */' . PHP_EOL . "\t" . '$var = FALSE;' . PHP_EOL . "\t" . '/*' . PHP_EOL . ' * phpcs:enable' . PHP_EOL . ' */'; |
|
126 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
127 | 127 | $file->process(); |
128 | 128 | |
129 | 129 | $errors = $file->getErrors(); |
130 | 130 | $numErrors = $file->getErrorCount(); |
131 | - $this->assertEquals(0, $numErrors); |
|
132 | - $this->assertCount(0, $errors); |
|
131 | + $this->assertEquals( 0, $numErrors ); |
|
132 | + $this->assertCount( 0, $errors ); |
|
133 | 133 | |
134 | 134 | // Process with block comment suppression (deprecated syntax). |
135 | - $content = '<?php '.PHP_EOL.'/* @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/* @codingStandardsIgnoreEnd */'; |
|
136 | - $file = new DummyFile($content, $ruleset, $config); |
|
135 | + $content = '<?php ' . PHP_EOL . '/* @codingStandardsIgnoreStart */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/* @codingStandardsIgnoreEnd */'; |
|
136 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
137 | 137 | $file->process(); |
138 | 138 | |
139 | 139 | $errors = $file->getErrors(); |
140 | 140 | $numErrors = $file->getErrorCount(); |
141 | - $this->assertEquals(0, $numErrors); |
|
142 | - $this->assertCount(0, $errors); |
|
141 | + $this->assertEquals( 0, $numErrors ); |
|
142 | + $this->assertCount( 0, $errors ); |
|
143 | 143 | |
144 | 144 | // Process with multi-line block comment suppression (deprecated syntax). |
145 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreStart'.PHP_EOL.' */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreEnd'.PHP_EOL.' */'; |
|
146 | - $file = new DummyFile($content, $ruleset, $config); |
|
145 | + $content = '<?php ' . PHP_EOL . '/*' . PHP_EOL . ' @codingStandardsIgnoreStart' . PHP_EOL . ' */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/*' . PHP_EOL . ' @codingStandardsIgnoreEnd' . PHP_EOL . ' */'; |
|
146 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
147 | 147 | $file->process(); |
148 | 148 | |
149 | 149 | $errors = $file->getErrors(); |
150 | 150 | $numErrors = $file->getErrorCount(); |
151 | - $this->assertEquals(0, $numErrors); |
|
152 | - $this->assertCount(0, $errors); |
|
151 | + $this->assertEquals( 0, $numErrors ); |
|
152 | + $this->assertCount( 0, $errors ); |
|
153 | 153 | |
154 | 154 | // Process with a docblock suppression. |
155 | - $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** phpcs:enable */'; |
|
156 | - $file = new DummyFile($content, $ruleset, $config); |
|
155 | + $content = '<?php ' . PHP_EOL . '/** phpcs:disable */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/** phpcs:enable */'; |
|
156 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
157 | 157 | $file->process(); |
158 | 158 | |
159 | 159 | $errors = $file->getErrors(); |
160 | 160 | $numErrors = $file->getErrorCount(); |
161 | - $this->assertEquals(0, $numErrors); |
|
162 | - $this->assertCount(0, $errors); |
|
161 | + $this->assertEquals( 0, $numErrors ); |
|
162 | + $this->assertCount( 0, $errors ); |
|
163 | 163 | |
164 | 164 | // Process with a docblock suppression (deprecated syntax). |
165 | - $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'; |
|
166 | - $file = new DummyFile($content, $ruleset, $config); |
|
165 | + $content = '<?php ' . PHP_EOL . '/** @codingStandardsIgnoreStart */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/** @codingStandardsIgnoreEnd */'; |
|
166 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
167 | 167 | $file->process(); |
168 | 168 | |
169 | 169 | $errors = $file->getErrors(); |
170 | 170 | $numErrors = $file->getErrorCount(); |
171 | - $this->assertEquals(0, $numErrors); |
|
172 | - $this->assertCount(0, $errors); |
|
171 | + $this->assertEquals( 0, $numErrors ); |
|
172 | + $this->assertCount( 0, $errors ); |
|
173 | 173 | |
174 | 174 | }//end testSuppressError() |
175 | 175 | |
@@ -182,70 +182,70 @@ discard block |
||
182 | 182 | public function testSuppressSomeErrors() |
183 | 183 | { |
184 | 184 | $config = new Config(); |
185 | - $config->standards = ['Generic']; |
|
186 | - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
185 | + $config->standards = [ 'Generic' ]; |
|
186 | + $config->sniffs = [ 'Generic.PHP.LowerCaseConstant' ]; |
|
187 | 187 | |
188 | - $ruleset = new Ruleset($config); |
|
188 | + $ruleset = new Ruleset( $config ); |
|
189 | 189 | |
190 | 190 | // Process without suppression. |
191 | - $content = '<?php '.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'; |
|
192 | - $file = new DummyFile($content, $ruleset, $config); |
|
191 | + $content = '<?php ' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = TRUE;'; |
|
192 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
193 | 193 | $file->process(); |
194 | 194 | |
195 | 195 | $errors = $file->getErrors(); |
196 | 196 | $numErrors = $file->getErrorCount(); |
197 | - $this->assertEquals(2, $numErrors); |
|
198 | - $this->assertCount(2, $errors); |
|
197 | + $this->assertEquals( 2, $numErrors ); |
|
198 | + $this->assertCount( 2, $errors ); |
|
199 | 199 | |
200 | 200 | // Process with suppression. |
201 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable'.PHP_EOL.'$var = TRUE;'; |
|
202 | - $file = new DummyFile($content, $ruleset, $config); |
|
201 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '// phpcs:enable' . PHP_EOL . '$var = TRUE;'; |
|
202 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
203 | 203 | $file->process(); |
204 | 204 | |
205 | 205 | $errors = $file->getErrors(); |
206 | 206 | $numErrors = $file->getErrorCount(); |
207 | - $this->assertEquals(1, $numErrors); |
|
208 | - $this->assertCount(1, $errors); |
|
207 | + $this->assertEquals( 1, $numErrors ); |
|
208 | + $this->assertCount( 1, $errors ); |
|
209 | 209 | |
210 | 210 | // Process with @ suppression. |
211 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @phpcs:enable'.PHP_EOL.'$var = TRUE;'; |
|
212 | - $file = new DummyFile($content, $ruleset, $config); |
|
211 | + $content = '<?php ' . PHP_EOL . '// @phpcs:disable' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '// @phpcs:enable' . PHP_EOL . '$var = TRUE;'; |
|
212 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
213 | 213 | $file->process(); |
214 | 214 | |
215 | 215 | $errors = $file->getErrors(); |
216 | 216 | $numErrors = $file->getErrorCount(); |
217 | - $this->assertEquals(1, $numErrors); |
|
218 | - $this->assertCount(1, $errors); |
|
217 | + $this->assertEquals( 1, $numErrors ); |
|
218 | + $this->assertCount( 1, $errors ); |
|
219 | 219 | |
220 | 220 | // Process with suppression (deprecated syntax). |
221 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'.PHP_EOL.'$var = TRUE;'; |
|
222 | - $file = new DummyFile($content, $ruleset, $config); |
|
221 | + $content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreStart' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '// @codingStandardsIgnoreEnd' . PHP_EOL . '$var = TRUE;'; |
|
222 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
223 | 223 | $file->process(); |
224 | 224 | |
225 | 225 | $errors = $file->getErrors(); |
226 | 226 | $numErrors = $file->getErrorCount(); |
227 | - $this->assertEquals(1, $numErrors); |
|
228 | - $this->assertCount(1, $errors); |
|
227 | + $this->assertEquals( 1, $numErrors ); |
|
228 | + $this->assertCount( 1, $errors ); |
|
229 | 229 | |
230 | 230 | // Process with a PHPDoc block suppression. |
231 | - $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** phpcs:enable */'.PHP_EOL.'$var = TRUE;'; |
|
232 | - $file = new DummyFile($content, $ruleset, $config); |
|
231 | + $content = '<?php ' . PHP_EOL . '/** phpcs:disable */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/** phpcs:enable */' . PHP_EOL . '$var = TRUE;'; |
|
232 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
233 | 233 | $file->process(); |
234 | 234 | |
235 | 235 | $errors = $file->getErrors(); |
236 | 236 | $numErrors = $file->getErrorCount(); |
237 | - $this->assertEquals(1, $numErrors); |
|
238 | - $this->assertCount(1, $errors); |
|
237 | + $this->assertEquals( 1, $numErrors ); |
|
238 | + $this->assertCount( 1, $errors ); |
|
239 | 239 | |
240 | 240 | // Process with a PHPDoc block suppression (deprecated syntax). |
241 | - $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'.PHP_EOL.'$var = TRUE;'; |
|
242 | - $file = new DummyFile($content, $ruleset, $config); |
|
241 | + $content = '<?php ' . PHP_EOL . '/** @codingStandardsIgnoreStart */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '/** @codingStandardsIgnoreEnd */' . PHP_EOL . '$var = TRUE;'; |
|
242 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
243 | 243 | $file->process(); |
244 | 244 | |
245 | 245 | $errors = $file->getErrors(); |
246 | 246 | $numErrors = $file->getErrorCount(); |
247 | - $this->assertEquals(1, $numErrors); |
|
248 | - $this->assertCount(1, $errors); |
|
247 | + $this->assertEquals( 1, $numErrors ); |
|
248 | + $this->assertCount( 1, $errors ); |
|
249 | 249 | |
250 | 250 | }//end testSuppressSomeErrors() |
251 | 251 | |
@@ -258,70 +258,70 @@ discard block |
||
258 | 258 | public function testSuppressWarning() |
259 | 259 | { |
260 | 260 | $config = new Config(); |
261 | - $config->standards = ['Generic']; |
|
262 | - $config->sniffs = ['Generic.Commenting.Todo']; |
|
261 | + $config->standards = [ 'Generic' ]; |
|
262 | + $config->sniffs = [ 'Generic.Commenting.Todo' ]; |
|
263 | 263 | |
264 | - $ruleset = new Ruleset($config); |
|
264 | + $ruleset = new Ruleset( $config ); |
|
265 | 265 | |
266 | 266 | // Process without suppression. |
267 | - $content = '<?php '.PHP_EOL.'//TODO: write some code'; |
|
268 | - $file = new DummyFile($content, $ruleset, $config); |
|
267 | + $content = '<?php ' . PHP_EOL . '//TODO: write some code'; |
|
268 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
269 | 269 | $file->process(); |
270 | 270 | |
271 | 271 | $warnings = $file->getWarnings(); |
272 | 272 | $numWarnings = $file->getWarningCount(); |
273 | - $this->assertEquals(1, $numWarnings); |
|
274 | - $this->assertCount(1, $warnings); |
|
273 | + $this->assertEquals( 1, $numWarnings ); |
|
274 | + $this->assertCount( 1, $warnings ); |
|
275 | 275 | |
276 | 276 | // Process with suppression. |
277 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable'; |
|
278 | - $file = new DummyFile($content, $ruleset, $config); |
|
277 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable'; |
|
278 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
279 | 279 | $file->process(); |
280 | 280 | |
281 | 281 | $warnings = $file->getWarnings(); |
282 | 282 | $numWarnings = $file->getWarningCount(); |
283 | - $this->assertEquals(0, $numWarnings); |
|
284 | - $this->assertCount(0, $warnings); |
|
283 | + $this->assertEquals( 0, $numWarnings ); |
|
284 | + $this->assertCount( 0, $warnings ); |
|
285 | 285 | |
286 | 286 | // Process with @ suppression. |
287 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// @phpcs:enable'; |
|
288 | - $file = new DummyFile($content, $ruleset, $config); |
|
287 | + $content = '<?php ' . PHP_EOL . '// @phpcs:disable' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// @phpcs:enable'; |
|
288 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
289 | 289 | $file->process(); |
290 | 290 | |
291 | 291 | $warnings = $file->getWarnings(); |
292 | 292 | $numWarnings = $file->getWarningCount(); |
293 | - $this->assertEquals(0, $numWarnings); |
|
294 | - $this->assertCount(0, $warnings); |
|
293 | + $this->assertEquals( 0, $numWarnings ); |
|
294 | + $this->assertCount( 0, $warnings ); |
|
295 | 295 | |
296 | 296 | // Process with suppression (deprecated syntax). |
297 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
298 | - $file = new DummyFile($content, $ruleset, $config); |
|
297 | + $content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreStart' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// @codingStandardsIgnoreEnd'; |
|
298 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
299 | 299 | $file->process(); |
300 | 300 | |
301 | 301 | $warnings = $file->getWarnings(); |
302 | 302 | $numWarnings = $file->getWarningCount(); |
303 | - $this->assertEquals(0, $numWarnings); |
|
304 | - $this->assertCount(0, $warnings); |
|
303 | + $this->assertEquals( 0, $numWarnings ); |
|
304 | + $this->assertCount( 0, $warnings ); |
|
305 | 305 | |
306 | 306 | // Process with a docblock suppression. |
307 | - $content = '<?php '.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'/** phpcs:enable */'; |
|
308 | - $file = new DummyFile($content, $ruleset, $config); |
|
307 | + $content = '<?php ' . PHP_EOL . '/** phpcs:disable */' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '/** phpcs:enable */'; |
|
308 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
309 | 309 | $file->process(); |
310 | 310 | |
311 | 311 | $warnings = $file->getWarnings(); |
312 | 312 | $numWarnings = $file->getWarningCount(); |
313 | - $this->assertEquals(0, $numWarnings); |
|
314 | - $this->assertCount(0, $warnings); |
|
313 | + $this->assertEquals( 0, $numWarnings ); |
|
314 | + $this->assertCount( 0, $warnings ); |
|
315 | 315 | |
316 | 316 | // Process with a docblock suppression (deprecated syntax). |
317 | - $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'; |
|
318 | - $file = new DummyFile($content, $ruleset, $config); |
|
317 | + $content = '<?php ' . PHP_EOL . '/** @codingStandardsIgnoreStart */' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '/** @codingStandardsIgnoreEnd */'; |
|
318 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
319 | 319 | $file->process(); |
320 | 320 | |
321 | 321 | $warnings = $file->getWarnings(); |
322 | 322 | $numWarnings = $file->getWarningCount(); |
323 | - $this->assertEquals(0, $numWarnings); |
|
324 | - $this->assertCount(0, $warnings); |
|
323 | + $this->assertEquals( 0, $numWarnings ); |
|
324 | + $this->assertCount( 0, $warnings ); |
|
325 | 325 | |
326 | 326 | }//end testSuppressWarning() |
327 | 327 | |
@@ -334,100 +334,100 @@ discard block |
||
334 | 334 | public function testSuppressLine() |
335 | 335 | { |
336 | 336 | $config = new Config(); |
337 | - $config->standards = ['Generic']; |
|
338 | - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
337 | + $config->standards = [ 'Generic' ]; |
|
338 | + $config->sniffs = [ 'Generic.PHP.LowerCaseConstant' ]; |
|
339 | 339 | |
340 | - $ruleset = new Ruleset($config); |
|
340 | + $ruleset = new Ruleset( $config ); |
|
341 | 341 | |
342 | 342 | // Process without suppression. |
343 | - $content = '<?php '.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
344 | - $file = new DummyFile($content, $ruleset, $config); |
|
343 | + $content = '<?php ' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = FALSE;'; |
|
344 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
345 | 345 | $file->process(); |
346 | 346 | |
347 | 347 | $errors = $file->getErrors(); |
348 | 348 | $numErrors = $file->getErrorCount(); |
349 | - $this->assertEquals(2, $numErrors); |
|
350 | - $this->assertCount(2, $errors); |
|
349 | + $this->assertEquals( 2, $numErrors ); |
|
350 | + $this->assertCount( 2, $errors ); |
|
351 | 351 | |
352 | 352 | // Process with suppression on line before. |
353 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
354 | - $file = new DummyFile($content, $ruleset, $config); |
|
353 | + $content = '<?php ' . PHP_EOL . '// phpcs:ignore' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = FALSE;'; |
|
354 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
355 | 355 | $file->process(); |
356 | 356 | |
357 | 357 | $errors = $file->getErrors(); |
358 | 358 | $numErrors = $file->getErrorCount(); |
359 | - $this->assertEquals(1, $numErrors); |
|
360 | - $this->assertCount(1, $errors); |
|
359 | + $this->assertEquals( 1, $numErrors ); |
|
360 | + $this->assertCount( 1, $errors ); |
|
361 | 361 | |
362 | 362 | // Process with @ suppression on line before. |
363 | - $content = '<?php '.PHP_EOL.'// @phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
364 | - $file = new DummyFile($content, $ruleset, $config); |
|
363 | + $content = '<?php ' . PHP_EOL . '// @phpcs:ignore' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = FALSE;'; |
|
364 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
365 | 365 | $file->process(); |
366 | 366 | |
367 | 367 | $errors = $file->getErrors(); |
368 | 368 | $numErrors = $file->getErrorCount(); |
369 | - $this->assertEquals(1, $numErrors); |
|
370 | - $this->assertCount(1, $errors); |
|
369 | + $this->assertEquals( 1, $numErrors ); |
|
370 | + $this->assertCount( 1, $errors ); |
|
371 | 371 | |
372 | 372 | // Process with suppression on line before. |
373 | - $content = '<?php '.PHP_EOL.'/* phpcs:ignore */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
374 | - $file = new DummyFile($content, $ruleset, $config); |
|
373 | + $content = '<?php ' . PHP_EOL . '/* phpcs:ignore */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = FALSE;'; |
|
374 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
375 | 375 | $file->process(); |
376 | 376 | |
377 | 377 | $errors = $file->getErrors(); |
378 | 378 | $numErrors = $file->getErrorCount(); |
379 | - $this->assertEquals(1, $numErrors); |
|
380 | - $this->assertCount(1, $errors); |
|
379 | + $this->assertEquals( 1, $numErrors ); |
|
380 | + $this->assertCount( 1, $errors ); |
|
381 | 381 | |
382 | 382 | // Process with @ suppression on line before. |
383 | - $content = '<?php '.PHP_EOL.'/* @phpcs:ignore */'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
384 | - $file = new DummyFile($content, $ruleset, $config); |
|
383 | + $content = '<?php ' . PHP_EOL . '/* @phpcs:ignore */' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = FALSE;'; |
|
384 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
385 | 385 | $file->process(); |
386 | 386 | |
387 | 387 | $errors = $file->getErrors(); |
388 | 388 | $numErrors = $file->getErrorCount(); |
389 | - $this->assertEquals(1, $numErrors); |
|
390 | - $this->assertCount(1, $errors); |
|
389 | + $this->assertEquals( 1, $numErrors ); |
|
390 | + $this->assertCount( 1, $errors ); |
|
391 | 391 | |
392 | 392 | // Process with suppression on line before (deprecated syntax). |
393 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = FALSE;'; |
|
394 | - $file = new DummyFile($content, $ruleset, $config); |
|
393 | + $content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreLine' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = FALSE;'; |
|
394 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
395 | 395 | $file->process(); |
396 | 396 | |
397 | 397 | $errors = $file->getErrors(); |
398 | 398 | $numErrors = $file->getErrorCount(); |
399 | - $this->assertEquals(1, $numErrors); |
|
400 | - $this->assertCount(1, $errors); |
|
399 | + $this->assertEquals( 1, $numErrors ); |
|
400 | + $this->assertCount( 1, $errors ); |
|
401 | 401 | |
402 | 402 | // Process with suppression on same line. |
403 | - $content = '<?php '.PHP_EOL.'$var = FALSE; // phpcs:ignore'.PHP_EOL.'$var = FALSE;'; |
|
404 | - $file = new DummyFile($content, $ruleset, $config); |
|
403 | + $content = '<?php ' . PHP_EOL . '$var = FALSE; // phpcs:ignore' . PHP_EOL . '$var = FALSE;'; |
|
404 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
405 | 405 | $file->process(); |
406 | 406 | |
407 | 407 | $errors = $file->getErrors(); |
408 | 408 | $numErrors = $file->getErrorCount(); |
409 | - $this->assertEquals(1, $numErrors); |
|
410 | - $this->assertCount(1, $errors); |
|
409 | + $this->assertEquals( 1, $numErrors ); |
|
410 | + $this->assertCount( 1, $errors ); |
|
411 | 411 | |
412 | 412 | // Process with @ suppression on same line. |
413 | - $content = '<?php '.PHP_EOL.'$var = FALSE; // @phpcs:ignore'.PHP_EOL.'$var = FALSE;'; |
|
414 | - $file = new DummyFile($content, $ruleset, $config); |
|
413 | + $content = '<?php ' . PHP_EOL . '$var = FALSE; // @phpcs:ignore' . PHP_EOL . '$var = FALSE;'; |
|
414 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
415 | 415 | $file->process(); |
416 | 416 | |
417 | 417 | $errors = $file->getErrors(); |
418 | 418 | $numErrors = $file->getErrorCount(); |
419 | - $this->assertEquals(1, $numErrors); |
|
420 | - $this->assertCount(1, $errors); |
|
419 | + $this->assertEquals( 1, $numErrors ); |
|
420 | + $this->assertCount( 1, $errors ); |
|
421 | 421 | |
422 | 422 | // Process with suppression on same line (deprecated syntax). |
423 | - $content = '<?php '.PHP_EOL.'$var = FALSE; // @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'; |
|
424 | - $file = new DummyFile($content, $ruleset, $config); |
|
423 | + $content = '<?php ' . PHP_EOL . '$var = FALSE; // @codingStandardsIgnoreLine' . PHP_EOL . '$var = FALSE;'; |
|
424 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
425 | 425 | $file->process(); |
426 | 426 | |
427 | 427 | $errors = $file->getErrors(); |
428 | 428 | $numErrors = $file->getErrorCount(); |
429 | - $this->assertEquals(1, $numErrors); |
|
430 | - $this->assertCount(1, $errors); |
|
429 | + $this->assertEquals( 1, $numErrors ); |
|
430 | + $this->assertCount( 1, $errors ); |
|
431 | 431 | |
432 | 432 | }//end testSuppressLine() |
433 | 433 | |
@@ -440,70 +440,70 @@ discard block |
||
440 | 440 | public function testNestedSuppressLine() |
441 | 441 | { |
442 | 442 | $config = new Config(); |
443 | - $config->standards = ['Generic']; |
|
444 | - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
|
443 | + $config->standards = [ 'Generic' ]; |
|
444 | + $config->sniffs = [ 'Generic.PHP.LowerCaseConstant' ]; |
|
445 | 445 | |
446 | - $ruleset = new Ruleset($config); |
|
446 | + $ruleset = new Ruleset( $config ); |
|
447 | 447 | |
448 | 448 | // Process with disable/enable suppression and no single line suppression. |
449 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// phpcs:enable'; |
|
450 | - $file = new DummyFile($content, $ruleset, $config); |
|
449 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = TRUE;' . PHP_EOL . '// phpcs:enable'; |
|
450 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
451 | 451 | $file->process(); |
452 | 452 | |
453 | 453 | $errors = $file->getErrors(); |
454 | 454 | $numErrors = $file->getErrorCount(); |
455 | - $this->assertEquals(0, $numErrors); |
|
456 | - $this->assertCount(0, $errors); |
|
455 | + $this->assertEquals( 0, $numErrors ); |
|
456 | + $this->assertCount( 0, $errors ); |
|
457 | 457 | |
458 | 458 | // Process with disable/enable @ suppression and no single line suppression. |
459 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @phpcs:enable'; |
|
460 | - $file = new DummyFile($content, $ruleset, $config); |
|
459 | + $content = '<?php ' . PHP_EOL . '// @phpcs:disable' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = TRUE;' . PHP_EOL . '// @phpcs:enable'; |
|
460 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
461 | 461 | $file->process(); |
462 | 462 | |
463 | 463 | $errors = $file->getErrors(); |
464 | 464 | $numErrors = $file->getErrorCount(); |
465 | - $this->assertEquals(0, $numErrors); |
|
466 | - $this->assertCount(0, $errors); |
|
465 | + $this->assertEquals( 0, $numErrors ); |
|
466 | + $this->assertCount( 0, $errors ); |
|
467 | 467 | |
468 | 468 | // Process with disable/enable suppression and no single line suppression (deprecated syntax). |
469 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
470 | - $file = new DummyFile($content, $ruleset, $config); |
|
469 | + $content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreStart' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = TRUE;' . PHP_EOL . '// @codingStandardsIgnoreEnd'; |
|
470 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
471 | 471 | $file->process(); |
472 | 472 | |
473 | 473 | $errors = $file->getErrors(); |
474 | 474 | $numErrors = $file->getErrorCount(); |
475 | - $this->assertEquals(0, $numErrors); |
|
476 | - $this->assertCount(0, $errors); |
|
475 | + $this->assertEquals( 0, $numErrors ); |
|
476 | + $this->assertCount( 0, $errors ); |
|
477 | 477 | |
478 | 478 | // Process with line suppression nested within disable/enable suppression. |
479 | - $content = '<?php '.PHP_EOL.'// phpcs:disable'.PHP_EOL.'// phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// phpcs:enable'; |
|
480 | - $file = new DummyFile($content, $ruleset, $config); |
|
479 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable' . PHP_EOL . '// phpcs:ignore' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = TRUE;' . PHP_EOL . '// phpcs:enable'; |
|
480 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
481 | 481 | $file->process(); |
482 | 482 | |
483 | 483 | $errors = $file->getErrors(); |
484 | 484 | $numErrors = $file->getErrorCount(); |
485 | - $this->assertEquals(0, $numErrors); |
|
486 | - $this->assertCount(0, $errors); |
|
485 | + $this->assertEquals( 0, $numErrors ); |
|
486 | + $this->assertCount( 0, $errors ); |
|
487 | 487 | |
488 | 488 | // Process with line @ suppression nested within disable/enable @ suppression. |
489 | - $content = '<?php '.PHP_EOL.'// @phpcs:disable'.PHP_EOL.'// @phpcs:ignore'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @phpcs:enable'; |
|
490 | - $file = new DummyFile($content, $ruleset, $config); |
|
489 | + $content = '<?php ' . PHP_EOL . '// @phpcs:disable' . PHP_EOL . '// @phpcs:ignore' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = TRUE;' . PHP_EOL . '// @phpcs:enable'; |
|
490 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
491 | 491 | $file->process(); |
492 | 492 | |
493 | 493 | $errors = $file->getErrors(); |
494 | 494 | $numErrors = $file->getErrorCount(); |
495 | - $this->assertEquals(0, $numErrors); |
|
496 | - $this->assertCount(0, $errors); |
|
495 | + $this->assertEquals( 0, $numErrors ); |
|
496 | + $this->assertCount( 0, $errors ); |
|
497 | 497 | |
498 | 498 | // Process with line suppression nested within disable/enable suppression (deprecated syntax). |
499 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreStart'.PHP_EOL.'// @codingStandardsIgnoreLine'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'$var = TRUE;'.PHP_EOL.'// @codingStandardsIgnoreEnd'; |
|
500 | - $file = new DummyFile($content, $ruleset, $config); |
|
499 | + $content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreStart' . PHP_EOL . '// @codingStandardsIgnoreLine' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '$var = TRUE;' . PHP_EOL . '// @codingStandardsIgnoreEnd'; |
|
500 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
501 | 501 | $file->process(); |
502 | 502 | |
503 | 503 | $errors = $file->getErrors(); |
504 | 504 | $numErrors = $file->getErrorCount(); |
505 | - $this->assertEquals(0, $numErrors); |
|
506 | - $this->assertCount(0, $errors); |
|
505 | + $this->assertEquals( 0, $numErrors ); |
|
506 | + $this->assertCount( 0, $errors ); |
|
507 | 507 | |
508 | 508 | }//end testNestedSuppressLine() |
509 | 509 | |
@@ -516,77 +516,77 @@ discard block |
||
516 | 516 | public function testSuppressScope() |
517 | 517 | { |
518 | 518 | $config = new Config(); |
519 | - $config->standards = ['PEAR']; |
|
520 | - $config->sniffs = ['PEAR.NamingConventions.ValidVariableName']; |
|
519 | + $config->standards = [ 'PEAR' ]; |
|
520 | + $config->sniffs = [ 'PEAR.NamingConventions.ValidVariableName' ]; |
|
521 | 521 | |
522 | - $ruleset = new Ruleset($config); |
|
522 | + $ruleset = new Ruleset( $config ); |
|
523 | 523 | |
524 | 524 | // Process without suppression. |
525 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'function myFunction() {'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
526 | - $file = new DummyFile($content, $ruleset, $config); |
|
525 | + $content = '<?php ' . PHP_EOL . 'class MyClass() {' . PHP_EOL . 'function myFunction() {' . PHP_EOL . '$this->foo();' . PHP_EOL . '}' . PHP_EOL . '}'; |
|
526 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
527 | 527 | $file->process(); |
528 | 528 | |
529 | 529 | $errors = $file->getErrors(); |
530 | 530 | $numErrors = $file->getErrorCount(); |
531 | - $this->assertEquals(0, $numErrors); |
|
532 | - $this->assertCount(0, $errors); |
|
531 | + $this->assertEquals( 0, $numErrors ); |
|
532 | + $this->assertCount( 0, $errors ); |
|
533 | 533 | |
534 | 534 | // Process with suppression. |
535 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//phpcs:disable'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//phpcs:enable'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
536 | - $file = new DummyFile($content, $ruleset, $config); |
|
535 | + $content = '<?php ' . PHP_EOL . 'class MyClass() {' . PHP_EOL . '//phpcs:disable' . PHP_EOL . 'function myFunction() {' . PHP_EOL . '//phpcs:enable' . PHP_EOL . '$this->foo();' . PHP_EOL . '}' . PHP_EOL . '}'; |
|
536 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
537 | 537 | $file->process(); |
538 | 538 | |
539 | 539 | $errors = $file->getErrors(); |
540 | 540 | $numErrors = $file->getErrorCount(); |
541 | - $this->assertEquals(0, $numErrors); |
|
542 | - $this->assertCount(0, $errors); |
|
541 | + $this->assertEquals( 0, $numErrors ); |
|
542 | + $this->assertCount( 0, $errors ); |
|
543 | 543 | |
544 | 544 | // Process with suppression. |
545 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//@phpcs:disable'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//@phpcs:enable'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
546 | - $file = new DummyFile($content, $ruleset, $config); |
|
545 | + $content = '<?php ' . PHP_EOL . 'class MyClass() {' . PHP_EOL . '//@phpcs:disable' . PHP_EOL . 'function myFunction() {' . PHP_EOL . '//@phpcs:enable' . PHP_EOL . '$this->foo();' . PHP_EOL . '}' . PHP_EOL . '}'; |
|
546 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
547 | 547 | $file->process(); |
548 | 548 | |
549 | 549 | $errors = $file->getErrors(); |
550 | 550 | $numErrors = $file->getErrorCount(); |
551 | - $this->assertEquals(0, $numErrors); |
|
552 | - $this->assertCount(0, $errors); |
|
551 | + $this->assertEquals( 0, $numErrors ); |
|
552 | + $this->assertCount( 0, $errors ); |
|
553 | 553 | |
554 | 554 | // Process with suppression (deprecated syntax). |
555 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'//@codingStandardsIgnoreStart'.PHP_EOL.'function myFunction() {'.PHP_EOL.'//@codingStandardsIgnoreEnd'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
556 | - $file = new DummyFile($content, $ruleset, $config); |
|
555 | + $content = '<?php ' . PHP_EOL . 'class MyClass() {' . PHP_EOL . '//@codingStandardsIgnoreStart' . PHP_EOL . 'function myFunction() {' . PHP_EOL . '//@codingStandardsIgnoreEnd' . PHP_EOL . '$this->foo();' . PHP_EOL . '}' . PHP_EOL . '}'; |
|
556 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
557 | 557 | $file->process(); |
558 | 558 | |
559 | 559 | $errors = $file->getErrors(); |
560 | 560 | $numErrors = $file->getErrorCount(); |
561 | - $this->assertEquals(0, $numErrors); |
|
562 | - $this->assertCount(0, $errors); |
|
561 | + $this->assertEquals( 0, $numErrors ); |
|
562 | + $this->assertCount( 0, $errors ); |
|
563 | 563 | |
564 | 564 | // Process with a docblock suppression. |
565 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** phpcs:disable */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** phpcs:enable */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
566 | - $file = new DummyFile($content, $ruleset, $config); |
|
565 | + $content = '<?php ' . PHP_EOL . 'class MyClass() {' . PHP_EOL . '/** phpcs:disable */' . PHP_EOL . 'function myFunction() {' . PHP_EOL . '/** phpcs:enable */' . PHP_EOL . '$this->foo();' . PHP_EOL . '}' . PHP_EOL . '}'; |
|
566 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
567 | 567 | |
568 | 568 | $errors = $file->getErrors(); |
569 | 569 | $numErrors = $file->getErrorCount(); |
570 | - $this->assertEquals(0, $numErrors); |
|
571 | - $this->assertCount(0, $errors); |
|
570 | + $this->assertEquals( 0, $numErrors ); |
|
571 | + $this->assertCount( 0, $errors ); |
|
572 | 572 | |
573 | 573 | // Process with a docblock @ suppression. |
574 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** @phpcs:disable */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** @phpcs:enable */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
575 | - $file = new DummyFile($content, $ruleset, $config); |
|
574 | + $content = '<?php ' . PHP_EOL . 'class MyClass() {' . PHP_EOL . '/** @phpcs:disable */' . PHP_EOL . 'function myFunction() {' . PHP_EOL . '/** @phpcs:enable */' . PHP_EOL . '$this->foo();' . PHP_EOL . '}' . PHP_EOL . '}'; |
|
575 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
576 | 576 | |
577 | 577 | $errors = $file->getErrors(); |
578 | 578 | $numErrors = $file->getErrorCount(); |
579 | - $this->assertEquals(0, $numErrors); |
|
580 | - $this->assertCount(0, $errors); |
|
579 | + $this->assertEquals( 0, $numErrors ); |
|
580 | + $this->assertCount( 0, $errors ); |
|
581 | 581 | |
582 | 582 | // Process with a docblock suppression (deprecated syntax). |
583 | - $content = '<?php '.PHP_EOL.'class MyClass() {'.PHP_EOL.'/** @codingStandardsIgnoreStart */'.PHP_EOL.'function myFunction() {'.PHP_EOL.'/** @codingStandardsIgnoreEnd */'.PHP_EOL.'$this->foo();'.PHP_EOL.'}'.PHP_EOL.'}'; |
|
584 | - $file = new DummyFile($content, $ruleset, $config); |
|
583 | + $content = '<?php ' . PHP_EOL . 'class MyClass() {' . PHP_EOL . '/** @codingStandardsIgnoreStart */' . PHP_EOL . 'function myFunction() {' . PHP_EOL . '/** @codingStandardsIgnoreEnd */' . PHP_EOL . '$this->foo();' . PHP_EOL . '}' . PHP_EOL . '}'; |
|
584 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
585 | 585 | |
586 | 586 | $errors = $file->getErrors(); |
587 | 587 | $numErrors = $file->getErrorCount(); |
588 | - $this->assertEquals(0, $numErrors); |
|
589 | - $this->assertCount(0, $errors); |
|
588 | + $this->assertEquals( 0, $numErrors ); |
|
589 | + $this->assertCount( 0, $errors ); |
|
590 | 590 | |
591 | 591 | }//end testSuppressScope() |
592 | 592 | |
@@ -599,140 +599,140 @@ discard block |
||
599 | 599 | public function testSuppressFile() |
600 | 600 | { |
601 | 601 | $config = new Config(); |
602 | - $config->standards = ['Generic']; |
|
603 | - $config->sniffs = ['Generic.Commenting.Todo']; |
|
602 | + $config->standards = [ 'Generic' ]; |
|
603 | + $config->sniffs = [ 'Generic.Commenting.Todo' ]; |
|
604 | 604 | |
605 | - $ruleset = new Ruleset($config); |
|
605 | + $ruleset = new Ruleset( $config ); |
|
606 | 606 | |
607 | 607 | // Process without suppression. |
608 | - $content = '<?php '.PHP_EOL.'//TODO: write some code'; |
|
609 | - $file = new DummyFile($content, $ruleset, $config); |
|
608 | + $content = '<?php ' . PHP_EOL . '//TODO: write some code'; |
|
609 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
610 | 610 | $file->process(); |
611 | 611 | |
612 | 612 | $warnings = $file->getWarnings(); |
613 | 613 | $numWarnings = $file->getWarningCount(); |
614 | - $this->assertEquals(1, $numWarnings); |
|
615 | - $this->assertCount(1, $warnings); |
|
614 | + $this->assertEquals( 1, $numWarnings ); |
|
615 | + $this->assertCount( 1, $warnings ); |
|
616 | 616 | |
617 | 617 | // Process with suppression. |
618 | - $content = '<?php '.PHP_EOL.'// phpcs:ignoreFile'.PHP_EOL.'//TODO: write some code'; |
|
619 | - $file = new DummyFile($content, $ruleset, $config); |
|
618 | + $content = '<?php ' . PHP_EOL . '// phpcs:ignoreFile' . PHP_EOL . '//TODO: write some code'; |
|
619 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
620 | 620 | $file->process(); |
621 | 621 | |
622 | 622 | $warnings = $file->getWarnings(); |
623 | 623 | $numWarnings = $file->getWarningCount(); |
624 | - $this->assertEquals(0, $numWarnings); |
|
625 | - $this->assertCount(0, $warnings); |
|
624 | + $this->assertEquals( 0, $numWarnings ); |
|
625 | + $this->assertCount( 0, $warnings ); |
|
626 | 626 | |
627 | 627 | // Process with @ suppression. |
628 | - $content = '<?php '.PHP_EOL.'// @phpcs:ignoreFile'.PHP_EOL.'//TODO: write some code'; |
|
629 | - $file = new DummyFile($content, $ruleset, $config); |
|
628 | + $content = '<?php ' . PHP_EOL . '// @phpcs:ignoreFile' . PHP_EOL . '//TODO: write some code'; |
|
629 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
630 | 630 | $file->process(); |
631 | 631 | |
632 | 632 | $warnings = $file->getWarnings(); |
633 | 633 | $numWarnings = $file->getWarningCount(); |
634 | - $this->assertEquals(0, $numWarnings); |
|
635 | - $this->assertCount(0, $warnings); |
|
634 | + $this->assertEquals( 0, $numWarnings ); |
|
635 | + $this->assertCount( 0, $warnings ); |
|
636 | 636 | |
637 | 637 | // Process with suppression (deprecated syntax). |
638 | - $content = '<?php '.PHP_EOL.'// @codingStandardsIgnoreFile'.PHP_EOL.'//TODO: write some code'; |
|
639 | - $file = new DummyFile($content, $ruleset, $config); |
|
638 | + $content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreFile' . PHP_EOL . '//TODO: write some code'; |
|
639 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
640 | 640 | $file->process(); |
641 | 641 | |
642 | 642 | $warnings = $file->getWarnings(); |
643 | 643 | $numWarnings = $file->getWarningCount(); |
644 | - $this->assertEquals(0, $numWarnings); |
|
645 | - $this->assertCount(0, $warnings); |
|
644 | + $this->assertEquals( 0, $numWarnings ); |
|
645 | + $this->assertCount( 0, $warnings ); |
|
646 | 646 | |
647 | 647 | // Process mixed case. |
648 | - $content = '<?php '.PHP_EOL.'// PHPCS:Ignorefile'.PHP_EOL.'//TODO: write some code'; |
|
649 | - $file = new DummyFile($content, $ruleset, $config); |
|
648 | + $content = '<?php ' . PHP_EOL . '// PHPCS:Ignorefile' . PHP_EOL . '//TODO: write some code'; |
|
649 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
650 | 650 | $file->process(); |
651 | 651 | |
652 | 652 | $warnings = $file->getWarnings(); |
653 | 653 | $numWarnings = $file->getWarningCount(); |
654 | - $this->assertEquals(0, $numWarnings); |
|
655 | - $this->assertCount(0, $warnings); |
|
654 | + $this->assertEquals( 0, $numWarnings ); |
|
655 | + $this->assertCount( 0, $warnings ); |
|
656 | 656 | |
657 | 657 | // Process late comment. |
658 | - $content = '<?php '.PHP_EOL.'class MyClass {}'.PHP_EOL.'$foo = new MyClass()'.PHP_EOL.'// phpcs:ignoreFile'; |
|
659 | - $file = new DummyFile($content, $ruleset, $config); |
|
658 | + $content = '<?php ' . PHP_EOL . 'class MyClass {}' . PHP_EOL . '$foo = new MyClass()' . PHP_EOL . '// phpcs:ignoreFile'; |
|
659 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
660 | 660 | $file->process(); |
661 | 661 | |
662 | 662 | $warnings = $file->getWarnings(); |
663 | 663 | $numWarnings = $file->getWarningCount(); |
664 | - $this->assertEquals(0, $numWarnings); |
|
665 | - $this->assertCount(0, $warnings); |
|
664 | + $this->assertEquals( 0, $numWarnings ); |
|
665 | + $this->assertCount( 0, $warnings ); |
|
666 | 666 | |
667 | 667 | // Process late comment (deprecated syntax). |
668 | - $content = '<?php '.PHP_EOL.'class MyClass {}'.PHP_EOL.'$foo = new MyClass()'.PHP_EOL.'// @codingStandardsIgnoreFile'; |
|
669 | - $file = new DummyFile($content, $ruleset, $config); |
|
668 | + $content = '<?php ' . PHP_EOL . 'class MyClass {}' . PHP_EOL . '$foo = new MyClass()' . PHP_EOL . '// @codingStandardsIgnoreFile'; |
|
669 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
670 | 670 | $file->process(); |
671 | 671 | |
672 | 672 | $warnings = $file->getWarnings(); |
673 | 673 | $numWarnings = $file->getWarningCount(); |
674 | - $this->assertEquals(0, $numWarnings); |
|
675 | - $this->assertCount(0, $warnings); |
|
674 | + $this->assertEquals( 0, $numWarnings ); |
|
675 | + $this->assertCount( 0, $warnings ); |
|
676 | 676 | |
677 | 677 | // Process with a block comment suppression. |
678 | - $content = '<?php '.PHP_EOL.'/* phpcs:ignoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
679 | - $file = new DummyFile($content, $ruleset, $config); |
|
678 | + $content = '<?php ' . PHP_EOL . '/* phpcs:ignoreFile */' . PHP_EOL . '//TODO: write some code'; |
|
679 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
680 | 680 | $file->process(); |
681 | 681 | |
682 | 682 | $warnings = $file->getWarnings(); |
683 | 683 | $numWarnings = $file->getWarningCount(); |
684 | - $this->assertEquals(0, $numWarnings); |
|
685 | - $this->assertCount(0, $warnings); |
|
684 | + $this->assertEquals( 0, $numWarnings ); |
|
685 | + $this->assertCount( 0, $warnings ); |
|
686 | 686 | |
687 | 687 | // Process with a multi-line block comment suppression. |
688 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' phpcs:ignoreFile'.PHP_EOL.' */'.PHP_EOL.'//TODO: write some code'; |
|
689 | - $file = new DummyFile($content, $ruleset, $config); |
|
688 | + $content = '<?php ' . PHP_EOL . '/*' . PHP_EOL . ' phpcs:ignoreFile' . PHP_EOL . ' */' . PHP_EOL . '//TODO: write some code'; |
|
689 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
690 | 690 | $file->process(); |
691 | 691 | |
692 | 692 | $warnings = $file->getWarnings(); |
693 | 693 | $numWarnings = $file->getWarningCount(); |
694 | - $this->assertEquals(0, $numWarnings); |
|
695 | - $this->assertCount(0, $warnings); |
|
694 | + $this->assertEquals( 0, $numWarnings ); |
|
695 | + $this->assertCount( 0, $warnings ); |
|
696 | 696 | |
697 | 697 | // Process with a block comment suppression (deprecated syntax). |
698 | - $content = '<?php '.PHP_EOL.'/* @codingStandardsIgnoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
699 | - $file = new DummyFile($content, $ruleset, $config); |
|
698 | + $content = '<?php ' . PHP_EOL . '/* @codingStandardsIgnoreFile */' . PHP_EOL . '//TODO: write some code'; |
|
699 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
700 | 700 | $file->process(); |
701 | 701 | |
702 | 702 | $warnings = $file->getWarnings(); |
703 | 703 | $numWarnings = $file->getWarningCount(); |
704 | - $this->assertEquals(0, $numWarnings); |
|
705 | - $this->assertCount(0, $warnings); |
|
704 | + $this->assertEquals( 0, $numWarnings ); |
|
705 | + $this->assertCount( 0, $warnings ); |
|
706 | 706 | |
707 | 707 | // Process with a multi-line block comment suppression (deprecated syntax). |
708 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' @codingStandardsIgnoreFile'.PHP_EOL.' */'.PHP_EOL.'//TODO: write some code'; |
|
709 | - $file = new DummyFile($content, $ruleset, $config); |
|
708 | + $content = '<?php ' . PHP_EOL . '/*' . PHP_EOL . ' @codingStandardsIgnoreFile' . PHP_EOL . ' */' . PHP_EOL . '//TODO: write some code'; |
|
709 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
710 | 710 | $file->process(); |
711 | 711 | |
712 | 712 | $warnings = $file->getWarnings(); |
713 | 713 | $numWarnings = $file->getWarningCount(); |
714 | - $this->assertEquals(0, $numWarnings); |
|
715 | - $this->assertCount(0, $warnings); |
|
714 | + $this->assertEquals( 0, $numWarnings ); |
|
715 | + $this->assertCount( 0, $warnings ); |
|
716 | 716 | |
717 | 717 | // Process with docblock suppression. |
718 | - $content = '<?php '.PHP_EOL.'/** phpcs:ignoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
719 | - $file = new DummyFile($content, $ruleset, $config); |
|
718 | + $content = '<?php ' . PHP_EOL . '/** phpcs:ignoreFile */' . PHP_EOL . '//TODO: write some code'; |
|
719 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
720 | 720 | $file->process(); |
721 | 721 | |
722 | 722 | $warnings = $file->getWarnings(); |
723 | 723 | $numWarnings = $file->getWarningCount(); |
724 | - $this->assertEquals(0, $numWarnings); |
|
725 | - $this->assertCount(0, $warnings); |
|
724 | + $this->assertEquals( 0, $numWarnings ); |
|
725 | + $this->assertCount( 0, $warnings ); |
|
726 | 726 | |
727 | 727 | // Process with docblock suppression (deprecated syntax). |
728 | - $content = '<?php '.PHP_EOL.'/** @codingStandardsIgnoreFile */'.PHP_EOL.'//TODO: write some code'; |
|
729 | - $file = new DummyFile($content, $ruleset, $config); |
|
728 | + $content = '<?php ' . PHP_EOL . '/** @codingStandardsIgnoreFile */' . PHP_EOL . '//TODO: write some code'; |
|
729 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
730 | 730 | $file->process(); |
731 | 731 | |
732 | 732 | $warnings = $file->getWarnings(); |
733 | 733 | $numWarnings = $file->getWarningCount(); |
734 | - $this->assertEquals(0, $numWarnings); |
|
735 | - $this->assertCount(0, $warnings); |
|
734 | + $this->assertEquals( 0, $numWarnings ); |
|
735 | + $this->assertCount( 0, $warnings ); |
|
736 | 736 | |
737 | 737 | }//end testSuppressFile() |
738 | 738 | |
@@ -745,141 +745,141 @@ discard block |
||
745 | 745 | public function testDisableSelected() |
746 | 746 | { |
747 | 747 | $config = new Config(); |
748 | - $config->standards = ['Generic']; |
|
748 | + $config->standards = [ 'Generic' ]; |
|
749 | 749 | $config->sniffs = [ |
750 | 750 | 'Generic.PHP.LowerCaseConstant', |
751 | 751 | 'Generic.Commenting.Todo', |
752 | 752 | ]; |
753 | 753 | |
754 | - $ruleset = new Ruleset($config); |
|
754 | + $ruleset = new Ruleset( $config ); |
|
755 | 755 | |
756 | 756 | // Suppress a single sniff. |
757 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
758 | - $file = new DummyFile($content, $ruleset, $config); |
|
757 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code'; |
|
758 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
759 | 759 | $file->process(); |
760 | 760 | |
761 | 761 | $errors = $file->getErrors(); |
762 | 762 | $numErrors = $file->getErrorCount(); |
763 | 763 | $warnings = $file->getWarnings(); |
764 | 764 | $numWarnings = $file->getWarningCount(); |
765 | - $this->assertEquals(1, $numErrors); |
|
766 | - $this->assertCount(1, $errors); |
|
767 | - $this->assertEquals(0, $numWarnings); |
|
768 | - $this->assertCount(0, $warnings); |
|
765 | + $this->assertEquals( 1, $numErrors ); |
|
766 | + $this->assertCount( 1, $errors ); |
|
767 | + $this->assertEquals( 0, $numWarnings ); |
|
768 | + $this->assertCount( 0, $warnings ); |
|
769 | 769 | |
770 | 770 | // Suppress multiple sniffs. |
771 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
772 | - $file = new DummyFile($content, $ruleset, $config); |
|
771 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code'; |
|
772 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
773 | 773 | $file->process(); |
774 | 774 | |
775 | 775 | $errors = $file->getErrors(); |
776 | 776 | $numErrors = $file->getErrorCount(); |
777 | 777 | $warnings = $file->getWarnings(); |
778 | 778 | $numWarnings = $file->getWarningCount(); |
779 | - $this->assertEquals(0, $numErrors); |
|
780 | - $this->assertCount(0, $errors); |
|
781 | - $this->assertEquals(0, $numWarnings); |
|
782 | - $this->assertCount(0, $warnings); |
|
779 | + $this->assertEquals( 0, $numErrors ); |
|
780 | + $this->assertCount( 0, $errors ); |
|
781 | + $this->assertEquals( 0, $numWarnings ); |
|
782 | + $this->assertCount( 0, $warnings ); |
|
783 | 783 | |
784 | 784 | // Suppress adding sniffs. |
785 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:disable Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
786 | - $file = new DummyFile($content, $ruleset, $config); |
|
785 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo' . PHP_EOL . '// phpcs:disable Generic.PHP.LowerCaseConstant' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code'; |
|
786 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
787 | 787 | $file->process(); |
788 | 788 | |
789 | 789 | $errors = $file->getErrors(); |
790 | 790 | $numErrors = $file->getErrorCount(); |
791 | 791 | $warnings = $file->getWarnings(); |
792 | 792 | $numWarnings = $file->getWarningCount(); |
793 | - $this->assertEquals(0, $numErrors); |
|
794 | - $this->assertCount(0, $errors); |
|
795 | - $this->assertEquals(0, $numWarnings); |
|
796 | - $this->assertCount(0, $warnings); |
|
793 | + $this->assertEquals( 0, $numErrors ); |
|
794 | + $this->assertCount( 0, $errors ); |
|
795 | + $this->assertEquals( 0, $numWarnings ); |
|
796 | + $this->assertCount( 0, $warnings ); |
|
797 | 797 | |
798 | 798 | // Suppress a category of sniffs. |
799 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
800 | - $file = new DummyFile($content, $ruleset, $config); |
|
799 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code'; |
|
800 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
801 | 801 | $file->process(); |
802 | 802 | |
803 | 803 | $errors = $file->getErrors(); |
804 | 804 | $numErrors = $file->getErrorCount(); |
805 | 805 | $warnings = $file->getWarnings(); |
806 | 806 | $numWarnings = $file->getWarningCount(); |
807 | - $this->assertEquals(1, $numErrors); |
|
808 | - $this->assertCount(1, $errors); |
|
809 | - $this->assertEquals(0, $numWarnings); |
|
810 | - $this->assertCount(0, $warnings); |
|
807 | + $this->assertEquals( 1, $numErrors ); |
|
808 | + $this->assertCount( 1, $errors ); |
|
809 | + $this->assertEquals( 0, $numWarnings ); |
|
810 | + $this->assertCount( 0, $warnings ); |
|
811 | 811 | |
812 | 812 | // Suppress a whole standard. |
813 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
814 | - $file = new DummyFile($content, $ruleset, $config); |
|
813 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code'; |
|
814 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
815 | 815 | $file->process(); |
816 | 816 | |
817 | 817 | $errors = $file->getErrors(); |
818 | 818 | $numErrors = $file->getErrorCount(); |
819 | 819 | $warnings = $file->getWarnings(); |
820 | 820 | $numWarnings = $file->getWarningCount(); |
821 | - $this->assertEquals(0, $numErrors); |
|
822 | - $this->assertCount(0, $errors); |
|
823 | - $this->assertEquals(0, $numWarnings); |
|
824 | - $this->assertCount(0, $warnings); |
|
821 | + $this->assertEquals( 0, $numErrors ); |
|
822 | + $this->assertCount( 0, $errors ); |
|
823 | + $this->assertEquals( 0, $numWarnings ); |
|
824 | + $this->assertCount( 0, $warnings ); |
|
825 | 825 | |
826 | 826 | // Suppress using docblocks. |
827 | - $content = '<?php '.PHP_EOL.'/** |
|
828 | - '.PHP_EOL.' * phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ '.PHP_EOL.'//TODO: write some code'; |
|
829 | - $file = new DummyFile($content, $ruleset, $config); |
|
827 | + $content = '<?php ' . PHP_EOL . '/** |
|
828 | + '.PHP_EOL . ' * phpcs:disable Generic.Commenting.Todo' . PHP_EOL . ' */ ' . PHP_EOL . '//TODO: write some code'; |
|
829 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
830 | 830 | $file->process(); |
831 | 831 | |
832 | 832 | $errors = $file->getErrors(); |
833 | 833 | $numErrors = $file->getErrorCount(); |
834 | 834 | $warnings = $file->getWarnings(); |
835 | 835 | $numWarnings = $file->getWarningCount(); |
836 | - $this->assertEquals(0, $numErrors); |
|
837 | - $this->assertCount(0, $errors); |
|
838 | - $this->assertEquals(0, $numWarnings); |
|
839 | - $this->assertCount(0, $warnings); |
|
836 | + $this->assertEquals( 0, $numErrors ); |
|
837 | + $this->assertCount( 0, $errors ); |
|
838 | + $this->assertEquals( 0, $numWarnings ); |
|
839 | + $this->assertCount( 0, $warnings ); |
|
840 | 840 | |
841 | - $content = '<?php '.PHP_EOL.'/** |
|
842 | - '.PHP_EOL.' * @phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ '.PHP_EOL.'//TODO: write some code'; |
|
843 | - $file = new DummyFile($content, $ruleset, $config); |
|
841 | + $content = '<?php ' . PHP_EOL . '/** |
|
842 | + '.PHP_EOL . ' * @phpcs:disable Generic.Commenting.Todo' . PHP_EOL . ' */ ' . PHP_EOL . '//TODO: write some code'; |
|
843 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
844 | 844 | $file->process(); |
845 | 845 | |
846 | 846 | $errors = $file->getErrors(); |
847 | 847 | $numErrors = $file->getErrorCount(); |
848 | 848 | $warnings = $file->getWarnings(); |
849 | 849 | $numWarnings = $file->getWarningCount(); |
850 | - $this->assertEquals(0, $numErrors); |
|
851 | - $this->assertCount(0, $errors); |
|
852 | - $this->assertEquals(0, $numWarnings); |
|
853 | - $this->assertCount(0, $warnings); |
|
850 | + $this->assertEquals( 0, $numErrors ); |
|
851 | + $this->assertCount( 0, $errors ); |
|
852 | + $this->assertEquals( 0, $numWarnings ); |
|
853 | + $this->assertCount( 0, $warnings ); |
|
854 | 854 | |
855 | 855 | // Suppress wrong category using docblocks. |
856 | - $content = '<?php '.PHP_EOL.'/** |
|
857 | - '.PHP_EOL.' * phpcs:disable Generic.Files'.PHP_EOL.' */ '.PHP_EOL.'//TODO: write some code'; |
|
858 | - $file = new DummyFile($content, $ruleset, $config); |
|
856 | + $content = '<?php ' . PHP_EOL . '/** |
|
857 | + '.PHP_EOL . ' * phpcs:disable Generic.Files' . PHP_EOL . ' */ ' . PHP_EOL . '//TODO: write some code'; |
|
858 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
859 | 859 | $file->process(); |
860 | 860 | |
861 | 861 | $errors = $file->getErrors(); |
862 | 862 | $numErrors = $file->getErrorCount(); |
863 | 863 | $warnings = $file->getWarnings(); |
864 | 864 | $numWarnings = $file->getWarningCount(); |
865 | - $this->assertEquals(0, $numErrors); |
|
866 | - $this->assertCount(0, $errors); |
|
867 | - $this->assertEquals(1, $numWarnings); |
|
868 | - $this->assertCount(1, $warnings); |
|
865 | + $this->assertEquals( 0, $numErrors ); |
|
866 | + $this->assertCount( 0, $errors ); |
|
867 | + $this->assertEquals( 1, $numWarnings ); |
|
868 | + $this->assertCount( 1, $warnings ); |
|
869 | 869 | |
870 | - $content = '<?php '.PHP_EOL.'/** |
|
871 | - '.PHP_EOL.' * @phpcs:disable Generic.Files'.PHP_EOL.' */ '.PHP_EOL.'//TODO: write some code'; |
|
872 | - $file = new DummyFile($content, $ruleset, $config); |
|
870 | + $content = '<?php ' . PHP_EOL . '/** |
|
871 | + '.PHP_EOL . ' * @phpcs:disable Generic.Files' . PHP_EOL . ' */ ' . PHP_EOL . '//TODO: write some code'; |
|
872 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
873 | 873 | $file->process(); |
874 | 874 | |
875 | 875 | $errors = $file->getErrors(); |
876 | 876 | $numErrors = $file->getErrorCount(); |
877 | 877 | $warnings = $file->getWarnings(); |
878 | 878 | $numWarnings = $file->getWarningCount(); |
879 | - $this->assertEquals(0, $numErrors); |
|
880 | - $this->assertCount(0, $errors); |
|
881 | - $this->assertEquals(1, $numWarnings); |
|
882 | - $this->assertCount(1, $warnings); |
|
879 | + $this->assertEquals( 0, $numErrors ); |
|
880 | + $this->assertCount( 0, $errors ); |
|
881 | + $this->assertEquals( 1, $numWarnings ); |
|
882 | + $this->assertCount( 1, $warnings ); |
|
883 | 883 | |
884 | 884 | }//end testDisableSelected() |
885 | 885 | |
@@ -892,167 +892,167 @@ discard block |
||
892 | 892 | public function testEnableSelected() |
893 | 893 | { |
894 | 894 | $config = new Config(); |
895 | - $config->standards = ['Generic']; |
|
895 | + $config->standards = [ 'Generic' ]; |
|
896 | 896 | $config->sniffs = [ |
897 | 897 | 'Generic.PHP.LowerCaseConstant', |
898 | 898 | 'Generic.Commenting.Todo', |
899 | 899 | ]; |
900 | 900 | |
901 | - $ruleset = new Ruleset($config); |
|
901 | + $ruleset = new Ruleset( $config ); |
|
902 | 902 | |
903 | 903 | // Suppress a single sniff and re-enable. |
904 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'; |
|
905 | - $file = new DummyFile($content, $ruleset, $config); |
|
904 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting.Todo' . PHP_EOL . '//TODO: write some code'; |
|
905 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
906 | 906 | $file->process(); |
907 | 907 | |
908 | 908 | $errors = $file->getErrors(); |
909 | 909 | $numErrors = $file->getErrorCount(); |
910 | 910 | $warnings = $file->getWarnings(); |
911 | 911 | $numWarnings = $file->getWarningCount(); |
912 | - $this->assertEquals(1, $numErrors); |
|
913 | - $this->assertCount(1, $errors); |
|
914 | - $this->assertEquals(1, $numWarnings); |
|
915 | - $this->assertCount(1, $warnings); |
|
912 | + $this->assertEquals( 1, $numErrors ); |
|
913 | + $this->assertCount( 1, $errors ); |
|
914 | + $this->assertEquals( 1, $numWarnings ); |
|
915 | + $this->assertCount( 1, $warnings ); |
|
916 | 916 | |
917 | 917 | // Suppress multiple sniffs and re-enable. |
918 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'; |
|
919 | - $file = new DummyFile($content, $ruleset, $config); |
|
918 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '$var = FALSE;'; |
|
919 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
920 | 920 | $file->process(); |
921 | 921 | |
922 | 922 | $errors = $file->getErrors(); |
923 | 923 | $numErrors = $file->getErrorCount(); |
924 | 924 | $warnings = $file->getWarnings(); |
925 | 925 | $numWarnings = $file->getWarningCount(); |
926 | - $this->assertEquals(1, $numErrors); |
|
927 | - $this->assertCount(1, $errors); |
|
928 | - $this->assertEquals(1, $numWarnings); |
|
929 | - $this->assertCount(1, $warnings); |
|
926 | + $this->assertEquals( 1, $numErrors ); |
|
927 | + $this->assertCount( 1, $errors ); |
|
928 | + $this->assertEquals( 1, $numWarnings ); |
|
929 | + $this->assertCount( 1, $warnings ); |
|
930 | 930 | |
931 | 931 | // Suppress multiple sniffs and re-enable one. |
932 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'; |
|
933 | - $file = new DummyFile($content, $ruleset, $config); |
|
932 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting.Todo' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '$var = FALSE;'; |
|
933 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
934 | 934 | $file->process(); |
935 | 935 | |
936 | 936 | $errors = $file->getErrors(); |
937 | 937 | $numErrors = $file->getErrorCount(); |
938 | 938 | $warnings = $file->getWarnings(); |
939 | 939 | $numWarnings = $file->getWarningCount(); |
940 | - $this->assertEquals(0, $numErrors); |
|
941 | - $this->assertCount(0, $errors); |
|
942 | - $this->assertEquals(1, $numWarnings); |
|
943 | - $this->assertCount(1, $warnings); |
|
940 | + $this->assertEquals( 0, $numErrors ); |
|
941 | + $this->assertCount( 0, $errors ); |
|
942 | + $this->assertEquals( 1, $numWarnings ); |
|
943 | + $this->assertCount( 1, $warnings ); |
|
944 | 944 | |
945 | 945 | // Suppress a category of sniffs and re-enable. |
946 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
947 | - $file = new DummyFile($content, $ruleset, $config); |
|
946 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting' . PHP_EOL . '//TODO: write some code'; |
|
947 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
948 | 948 | $file->process(); |
949 | 949 | |
950 | 950 | $errors = $file->getErrors(); |
951 | 951 | $numErrors = $file->getErrorCount(); |
952 | 952 | $warnings = $file->getWarnings(); |
953 | 953 | $numWarnings = $file->getWarningCount(); |
954 | - $this->assertEquals(1, $numErrors); |
|
955 | - $this->assertCount(1, $errors); |
|
956 | - $this->assertEquals(1, $numWarnings); |
|
957 | - $this->assertCount(1, $warnings); |
|
954 | + $this->assertEquals( 1, $numErrors ); |
|
955 | + $this->assertCount( 1, $errors ); |
|
956 | + $this->assertEquals( 1, $numWarnings ); |
|
957 | + $this->assertCount( 1, $warnings ); |
|
958 | 958 | |
959 | 959 | // Suppress a whole standard and re-enable. |
960 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic'.PHP_EOL.'//TODO: write some code'; |
|
961 | - $file = new DummyFile($content, $ruleset, $config); |
|
960 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic' . PHP_EOL . '//TODO: write some code'; |
|
961 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
962 | 962 | $file->process(); |
963 | 963 | |
964 | 964 | $errors = $file->getErrors(); |
965 | 965 | $numErrors = $file->getErrorCount(); |
966 | 966 | $warnings = $file->getWarnings(); |
967 | 967 | $numWarnings = $file->getWarningCount(); |
968 | - $this->assertEquals(0, $numErrors); |
|
969 | - $this->assertCount(0, $errors); |
|
970 | - $this->assertEquals(1, $numWarnings); |
|
971 | - $this->assertCount(1, $warnings); |
|
968 | + $this->assertEquals( 0, $numErrors ); |
|
969 | + $this->assertCount( 0, $errors ); |
|
970 | + $this->assertEquals( 1, $numWarnings ); |
|
971 | + $this->assertCount( 1, $warnings ); |
|
972 | 972 | |
973 | 973 | // Suppress a whole standard and re-enable a category. |
974 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
975 | - $file = new DummyFile($content, $ruleset, $config); |
|
974 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting' . PHP_EOL . '//TODO: write some code'; |
|
975 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
976 | 976 | $file->process(); |
977 | 977 | |
978 | 978 | $errors = $file->getErrors(); |
979 | 979 | $numErrors = $file->getErrorCount(); |
980 | 980 | $warnings = $file->getWarnings(); |
981 | 981 | $numWarnings = $file->getWarningCount(); |
982 | - $this->assertEquals(0, $numErrors); |
|
983 | - $this->assertCount(0, $errors); |
|
984 | - $this->assertEquals(1, $numWarnings); |
|
985 | - $this->assertCount(1, $warnings); |
|
982 | + $this->assertEquals( 0, $numErrors ); |
|
983 | + $this->assertCount( 0, $errors ); |
|
984 | + $this->assertEquals( 1, $numWarnings ); |
|
985 | + $this->assertCount( 1, $warnings ); |
|
986 | 986 | |
987 | 987 | // Suppress a category and re-enable a whole standard. |
988 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic'.PHP_EOL.'//TODO: write some code'; |
|
989 | - $file = new DummyFile($content, $ruleset, $config); |
|
988 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic' . PHP_EOL . '//TODO: write some code'; |
|
989 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
990 | 990 | $file->process(); |
991 | 991 | |
992 | 992 | $errors = $file->getErrors(); |
993 | 993 | $numErrors = $file->getErrorCount(); |
994 | 994 | $warnings = $file->getWarnings(); |
995 | 995 | $numWarnings = $file->getWarningCount(); |
996 | - $this->assertEquals(1, $numErrors); |
|
997 | - $this->assertCount(1, $errors); |
|
998 | - $this->assertEquals(1, $numWarnings); |
|
999 | - $this->assertCount(1, $warnings); |
|
996 | + $this->assertEquals( 1, $numErrors ); |
|
997 | + $this->assertCount( 1, $errors ); |
|
998 | + $this->assertEquals( 1, $numWarnings ); |
|
999 | + $this->assertCount( 1, $warnings ); |
|
1000 | 1000 | |
1001 | 1001 | // Suppress a sniff and re-enable a category. |
1002 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting'.PHP_EOL.'//TODO: write some code'; |
|
1003 | - $file = new DummyFile($content, $ruleset, $config); |
|
1002 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting' . PHP_EOL . '//TODO: write some code'; |
|
1003 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1004 | 1004 | $file->process(); |
1005 | 1005 | |
1006 | 1006 | $errors = $file->getErrors(); |
1007 | 1007 | $numErrors = $file->getErrorCount(); |
1008 | 1008 | $warnings = $file->getWarnings(); |
1009 | 1009 | $numWarnings = $file->getWarningCount(); |
1010 | - $this->assertEquals(1, $numErrors); |
|
1011 | - $this->assertCount(1, $errors); |
|
1012 | - $this->assertEquals(1, $numWarnings); |
|
1013 | - $this->assertCount(1, $warnings); |
|
1010 | + $this->assertEquals( 1, $numErrors ); |
|
1011 | + $this->assertCount( 1, $errors ); |
|
1012 | + $this->assertEquals( 1, $numWarnings ); |
|
1013 | + $this->assertCount( 1, $warnings ); |
|
1014 | 1014 | |
1015 | 1015 | // Suppress a whole standard and re-enable a sniff. |
1016 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'; |
|
1017 | - $file = new DummyFile($content, $ruleset, $config); |
|
1016 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting.Todo' . PHP_EOL . '//TODO: write some code'; |
|
1017 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1018 | 1018 | $file->process(); |
1019 | 1019 | |
1020 | 1020 | $errors = $file->getErrors(); |
1021 | 1021 | $numErrors = $file->getErrorCount(); |
1022 | 1022 | $warnings = $file->getWarnings(); |
1023 | 1023 | $numWarnings = $file->getWarningCount(); |
1024 | - $this->assertEquals(0, $numErrors); |
|
1025 | - $this->assertCount(0, $errors); |
|
1026 | - $this->assertEquals(1, $numWarnings); |
|
1027 | - $this->assertCount(1, $warnings); |
|
1024 | + $this->assertEquals( 0, $numErrors ); |
|
1025 | + $this->assertCount( 0, $errors ); |
|
1026 | + $this->assertEquals( 1, $numWarnings ); |
|
1027 | + $this->assertCount( 1, $warnings ); |
|
1028 | 1028 | |
1029 | 1029 | // Suppress a whole standard and re-enable and re-disable a sniff. |
1030 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable'.PHP_EOL.'//TODO: write some code'; |
|
1031 | - $file = new DummyFile($content, $ruleset, $config); |
|
1030 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting.Todo' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable' . PHP_EOL . '//TODO: write some code'; |
|
1031 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1032 | 1032 | $file->process(); |
1033 | 1033 | |
1034 | 1034 | $errors = $file->getErrors(); |
1035 | 1035 | $numErrors = $file->getErrorCount(); |
1036 | 1036 | $warnings = $file->getWarnings(); |
1037 | 1037 | $numWarnings = $file->getWarningCount(); |
1038 | - $this->assertEquals(0, $numErrors); |
|
1039 | - $this->assertCount(0, $errors); |
|
1040 | - $this->assertEquals(2, $numWarnings); |
|
1041 | - $this->assertCount(2, $warnings); |
|
1038 | + $this->assertEquals( 0, $numErrors ); |
|
1039 | + $this->assertCount( 0, $errors ); |
|
1040 | + $this->assertEquals( 2, $numWarnings ); |
|
1041 | + $this->assertCount( 2, $warnings ); |
|
1042 | 1042 | |
1043 | 1043 | // Suppress a whole standard and re-enable 2 specific sniffs independently. |
1044 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'// phpcs:enable Generic.PHP.LowerCaseConstant'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'$var = FALSE;'.PHP_EOL; |
|
1045 | - $file = new DummyFile($content, $ruleset, $config); |
|
1044 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting.Todo' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '// phpcs:enable Generic.PHP.LowerCaseConstant' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '$var = FALSE;' . PHP_EOL; |
|
1045 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1046 | 1046 | $file->process(); |
1047 | 1047 | |
1048 | 1048 | $errors = $file->getErrors(); |
1049 | 1049 | $numErrors = $file->getErrorCount(); |
1050 | 1050 | $warnings = $file->getWarnings(); |
1051 | 1051 | $numWarnings = $file->getWarningCount(); |
1052 | - $this->assertEquals(1, $numErrors); |
|
1053 | - $this->assertCount(1, $errors); |
|
1054 | - $this->assertEquals(2, $numWarnings); |
|
1055 | - $this->assertCount(2, $warnings); |
|
1052 | + $this->assertEquals( 1, $numErrors ); |
|
1053 | + $this->assertCount( 1, $errors ); |
|
1054 | + $this->assertEquals( 2, $numWarnings ); |
|
1055 | + $this->assertCount( 2, $warnings ); |
|
1056 | 1056 | |
1057 | 1057 | }//end testEnableSelected() |
1058 | 1058 | |
@@ -1065,97 +1065,97 @@ discard block |
||
1065 | 1065 | public function testIgnoreSelected() |
1066 | 1066 | { |
1067 | 1067 | $config = new Config(); |
1068 | - $config->standards = ['Generic']; |
|
1068 | + $config->standards = [ 'Generic' ]; |
|
1069 | 1069 | $config->sniffs = [ |
1070 | 1070 | 'Generic.PHP.LowerCaseConstant', |
1071 | 1071 | 'Generic.Commenting.Todo', |
1072 | 1072 | ]; |
1073 | 1073 | |
1074 | - $ruleset = new Ruleset($config); |
|
1074 | + $ruleset = new Ruleset( $config ); |
|
1075 | 1075 | |
1076 | 1076 | // No suppression. |
1077 | - $content = '<?php '.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1078 | - $file = new DummyFile($content, $ruleset, $config); |
|
1077 | + $content = '<?php ' . PHP_EOL . '$var = FALSE; //TODO: write some code' . PHP_EOL . '$var = FALSE; //TODO: write some code'; |
|
1078 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1079 | 1079 | $file->process(); |
1080 | 1080 | |
1081 | 1081 | $errors = $file->getErrors(); |
1082 | 1082 | $numErrors = $file->getErrorCount(); |
1083 | 1083 | $warnings = $file->getWarnings(); |
1084 | 1084 | $numWarnings = $file->getWarningCount(); |
1085 | - $this->assertEquals(2, $numErrors); |
|
1086 | - $this->assertCount(2, $errors); |
|
1087 | - $this->assertEquals(2, $numWarnings); |
|
1088 | - $this->assertCount(2, $warnings); |
|
1085 | + $this->assertEquals( 2, $numErrors ); |
|
1086 | + $this->assertCount( 2, $errors ); |
|
1087 | + $this->assertEquals( 2, $numWarnings ); |
|
1088 | + $this->assertCount( 2, $warnings ); |
|
1089 | 1089 | |
1090 | 1090 | // Suppress a single sniff. |
1091 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1092 | - $file = new DummyFile($content, $ruleset, $config); |
|
1091 | + $content = '<?php ' . PHP_EOL . '// phpcs:ignore Generic.Commenting.Todo' . PHP_EOL . '$var = FALSE; //TODO: write some code' . PHP_EOL . '$var = FALSE; //TODO: write some code'; |
|
1092 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1093 | 1093 | $file->process(); |
1094 | 1094 | |
1095 | 1095 | $errors = $file->getErrors(); |
1096 | 1096 | $numErrors = $file->getErrorCount(); |
1097 | 1097 | $warnings = $file->getWarnings(); |
1098 | 1098 | $numWarnings = $file->getWarningCount(); |
1099 | - $this->assertEquals(2, $numErrors); |
|
1100 | - $this->assertCount(2, $errors); |
|
1101 | - $this->assertEquals(1, $numWarnings); |
|
1102 | - $this->assertCount(1, $warnings); |
|
1099 | + $this->assertEquals( 2, $numErrors ); |
|
1100 | + $this->assertCount( 2, $errors ); |
|
1101 | + $this->assertEquals( 1, $numWarnings ); |
|
1102 | + $this->assertCount( 1, $warnings ); |
|
1103 | 1103 | |
1104 | 1104 | // Suppress multiple sniffs. |
1105 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1106 | - $file = new DummyFile($content, $ruleset, $config); |
|
1105 | + $content = '<?php ' . PHP_EOL . '// phpcs:ignore Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant' . PHP_EOL . '$var = FALSE; //TODO: write some code' . PHP_EOL . '$var = FALSE; //TODO: write some code'; |
|
1106 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1107 | 1107 | $file->process(); |
1108 | 1108 | |
1109 | 1109 | $errors = $file->getErrors(); |
1110 | 1110 | $numErrors = $file->getErrorCount(); |
1111 | 1111 | $warnings = $file->getWarnings(); |
1112 | 1112 | $numWarnings = $file->getWarningCount(); |
1113 | - $this->assertEquals(1, $numErrors); |
|
1114 | - $this->assertCount(1, $errors); |
|
1115 | - $this->assertEquals(1, $numWarnings); |
|
1116 | - $this->assertCount(1, $warnings); |
|
1113 | + $this->assertEquals( 1, $numErrors ); |
|
1114 | + $this->assertCount( 1, $errors ); |
|
1115 | + $this->assertEquals( 1, $numWarnings ); |
|
1116 | + $this->assertCount( 1, $warnings ); |
|
1117 | 1117 | |
1118 | 1118 | // Add to suppression. |
1119 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:ignore Generic.PHP.LowerCaseConstant'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1120 | - $file = new DummyFile($content, $ruleset, $config); |
|
1119 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo' . PHP_EOL . '// phpcs:ignore Generic.PHP.LowerCaseConstant' . PHP_EOL . '$var = FALSE; //TODO: write some code' . PHP_EOL . '$var = FALSE; //TODO: write some code'; |
|
1120 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1121 | 1121 | $file->process(); |
1122 | 1122 | |
1123 | 1123 | $errors = $file->getErrors(); |
1124 | 1124 | $numErrors = $file->getErrorCount(); |
1125 | 1125 | $warnings = $file->getWarnings(); |
1126 | 1126 | $numWarnings = $file->getWarningCount(); |
1127 | - $this->assertEquals(1, $numErrors); |
|
1128 | - $this->assertCount(1, $errors); |
|
1129 | - $this->assertEquals(0, $numWarnings); |
|
1130 | - $this->assertCount(0, $warnings); |
|
1127 | + $this->assertEquals( 1, $numErrors ); |
|
1128 | + $this->assertCount( 1, $errors ); |
|
1129 | + $this->assertEquals( 0, $numWarnings ); |
|
1130 | + $this->assertCount( 0, $warnings ); |
|
1131 | 1131 | |
1132 | 1132 | // Suppress a category of sniffs. |
1133 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1134 | - $file = new DummyFile($content, $ruleset, $config); |
|
1133 | + $content = '<?php ' . PHP_EOL . '// phpcs:ignore Generic.Commenting' . PHP_EOL . '$var = FALSE; //TODO: write some code' . PHP_EOL . '$var = FALSE; //TODO: write some code'; |
|
1134 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1135 | 1135 | $file->process(); |
1136 | 1136 | |
1137 | 1137 | $errors = $file->getErrors(); |
1138 | 1138 | $numErrors = $file->getErrorCount(); |
1139 | 1139 | $warnings = $file->getWarnings(); |
1140 | 1140 | $numWarnings = $file->getWarningCount(); |
1141 | - $this->assertEquals(2, $numErrors); |
|
1142 | - $this->assertCount(2, $errors); |
|
1143 | - $this->assertEquals(1, $numWarnings); |
|
1144 | - $this->assertCount(1, $warnings); |
|
1141 | + $this->assertEquals( 2, $numErrors ); |
|
1142 | + $this->assertCount( 2, $errors ); |
|
1143 | + $this->assertEquals( 1, $numWarnings ); |
|
1144 | + $this->assertCount( 1, $warnings ); |
|
1145 | 1145 | |
1146 | 1146 | // Suppress a whole standard. |
1147 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1148 | - $file = new DummyFile($content, $ruleset, $config); |
|
1147 | + $content = '<?php ' . PHP_EOL . '// phpcs:ignore Generic' . PHP_EOL . '$var = FALSE; //TODO: write some code' . PHP_EOL . '$var = FALSE; //TODO: write some code'; |
|
1148 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1149 | 1149 | $file->process(); |
1150 | 1150 | |
1151 | 1151 | $errors = $file->getErrors(); |
1152 | 1152 | $numErrors = $file->getErrorCount(); |
1153 | 1153 | $warnings = $file->getWarnings(); |
1154 | 1154 | $numWarnings = $file->getWarningCount(); |
1155 | - $this->assertEquals(1, $numErrors); |
|
1156 | - $this->assertCount(1, $errors); |
|
1157 | - $this->assertEquals(1, $numWarnings); |
|
1158 | - $this->assertCount(1, $warnings); |
|
1155 | + $this->assertEquals( 1, $numErrors ); |
|
1156 | + $this->assertCount( 1, $errors ); |
|
1157 | + $this->assertEquals( 1, $numWarnings ); |
|
1158 | + $this->assertCount( 1, $warnings ); |
|
1159 | 1159 | |
1160 | 1160 | }//end testIgnoreSelected() |
1161 | 1161 | |
@@ -1168,83 +1168,83 @@ discard block |
||
1168 | 1168 | public function testCommenting() |
1169 | 1169 | { |
1170 | 1170 | $config = new Config(); |
1171 | - $config->standards = ['Generic']; |
|
1171 | + $config->standards = [ 'Generic' ]; |
|
1172 | 1172 | $config->sniffs = [ |
1173 | 1173 | 'Generic.PHP.LowerCaseConstant', |
1174 | 1174 | 'Generic.Commenting.Todo', |
1175 | 1175 | ]; |
1176 | 1176 | |
1177 | - $ruleset = new Ruleset($config); |
|
1177 | + $ruleset = new Ruleset( $config ); |
|
1178 | 1178 | |
1179 | 1179 | // Suppress a single sniff. |
1180 | - $content = '<?php '.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo -- Because reasons'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1181 | - $file = new DummyFile($content, $ruleset, $config); |
|
1180 | + $content = '<?php ' . PHP_EOL . '// phpcs:ignore Generic.Commenting.Todo -- Because reasons' . PHP_EOL . '$var = FALSE; //TODO: write some code' . PHP_EOL . '$var = FALSE; //TODO: write some code'; |
|
1181 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1182 | 1182 | $file->process(); |
1183 | 1183 | |
1184 | 1184 | $errors = $file->getErrors(); |
1185 | 1185 | $numErrors = $file->getErrorCount(); |
1186 | 1186 | $warnings = $file->getWarnings(); |
1187 | 1187 | $numWarnings = $file->getWarningCount(); |
1188 | - $this->assertEquals(2, $numErrors); |
|
1189 | - $this->assertCount(2, $errors); |
|
1190 | - $this->assertEquals(1, $numWarnings); |
|
1191 | - $this->assertCount(1, $warnings); |
|
1188 | + $this->assertEquals( 2, $numErrors ); |
|
1189 | + $this->assertCount( 2, $errors ); |
|
1190 | + $this->assertEquals( 1, $numWarnings ); |
|
1191 | + $this->assertCount( 1, $warnings ); |
|
1192 | 1192 | |
1193 | 1193 | // Suppress a single sniff and re-enable. |
1194 | - $content = '<?php '.PHP_EOL.'// phpcs:disable Generic.Commenting.Todo --Because reasons'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'.PHP_EOL.'// phpcs:enable Generic.Commenting.Todo -- Because reasons'.PHP_EOL.'//TODO: write some code'; |
|
1195 | - $file = new DummyFile($content, $ruleset, $config); |
|
1194 | + $content = '<?php ' . PHP_EOL . '// phpcs:disable Generic.Commenting.Todo --Because reasons' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code' . PHP_EOL . '// phpcs:enable Generic.Commenting.Todo -- Because reasons' . PHP_EOL . '//TODO: write some code'; |
|
1195 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1196 | 1196 | $file->process(); |
1197 | 1197 | |
1198 | 1198 | $errors = $file->getErrors(); |
1199 | 1199 | $numErrors = $file->getErrorCount(); |
1200 | 1200 | $warnings = $file->getWarnings(); |
1201 | 1201 | $numWarnings = $file->getWarningCount(); |
1202 | - $this->assertEquals(1, $numErrors); |
|
1203 | - $this->assertCount(1, $errors); |
|
1204 | - $this->assertEquals(1, $numWarnings); |
|
1205 | - $this->assertCount(1, $warnings); |
|
1202 | + $this->assertEquals( 1, $numErrors ); |
|
1203 | + $this->assertCount( 1, $errors ); |
|
1204 | + $this->assertEquals( 1, $numWarnings ); |
|
1205 | + $this->assertCount( 1, $warnings ); |
|
1206 | 1206 | |
1207 | 1207 | // Suppress a single sniff using block comments. |
1208 | - $content = '<?php '.PHP_EOL.'/*'.PHP_EOL.' Disable some checks'.PHP_EOL.' phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'*/'.PHP_EOL.'$var = FALSE;'.PHP_EOL.'//TODO: write some code'; |
|
1209 | - $file = new DummyFile($content, $ruleset, $config); |
|
1208 | + $content = '<?php ' . PHP_EOL . '/*' . PHP_EOL . ' Disable some checks' . PHP_EOL . ' phpcs:disable Generic.Commenting.Todo' . PHP_EOL . '*/' . PHP_EOL . '$var = FALSE;' . PHP_EOL . '//TODO: write some code'; |
|
1209 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1210 | 1210 | $file->process(); |
1211 | 1211 | |
1212 | 1212 | $errors = $file->getErrors(); |
1213 | 1213 | $numErrors = $file->getErrorCount(); |
1214 | 1214 | $warnings = $file->getWarnings(); |
1215 | 1215 | $numWarnings = $file->getWarningCount(); |
1216 | - $this->assertEquals(1, $numErrors); |
|
1217 | - $this->assertCount(1, $errors); |
|
1218 | - $this->assertEquals(0, $numWarnings); |
|
1219 | - $this->assertCount(0, $warnings); |
|
1216 | + $this->assertEquals( 1, $numErrors ); |
|
1217 | + $this->assertCount( 1, $errors ); |
|
1218 | + $this->assertEquals( 0, $numWarnings ); |
|
1219 | + $this->assertCount( 0, $warnings ); |
|
1220 | 1220 | |
1221 | 1221 | // Suppress a single sniff with a multi-line comment. |
1222 | - $content = '<?php '.PHP_EOL.'// Turn off a check for the next line of code.'.PHP_EOL.'// phpcs:ignore Generic.Commenting.Todo'.PHP_EOL.'$var = FALSE; //TODO: write some code'.PHP_EOL.'$var = FALSE; //TODO: write some code'; |
|
1223 | - $file = new DummyFile($content, $ruleset, $config); |
|
1222 | + $content = '<?php ' . PHP_EOL . '// Turn off a check for the next line of code.' . PHP_EOL . '// phpcs:ignore Generic.Commenting.Todo' . PHP_EOL . '$var = FALSE; //TODO: write some code' . PHP_EOL . '$var = FALSE; //TODO: write some code'; |
|
1223 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1224 | 1224 | $file->process(); |
1225 | 1225 | |
1226 | 1226 | $errors = $file->getErrors(); |
1227 | 1227 | $numErrors = $file->getErrorCount(); |
1228 | 1228 | $warnings = $file->getWarnings(); |
1229 | 1229 | $numWarnings = $file->getWarningCount(); |
1230 | - $this->assertEquals(2, $numErrors); |
|
1231 | - $this->assertCount(2, $errors); |
|
1232 | - $this->assertEquals(1, $numWarnings); |
|
1233 | - $this->assertCount(1, $warnings); |
|
1230 | + $this->assertEquals( 2, $numErrors ); |
|
1231 | + $this->assertCount( 2, $errors ); |
|
1232 | + $this->assertEquals( 1, $numWarnings ); |
|
1233 | + $this->assertCount( 1, $warnings ); |
|
1234 | 1234 | |
1235 | 1235 | // Ignore an enable before a disable. |
1236 | - $content = '<?php '.PHP_EOL.'// phpcs:enable Generic.PHP.NoSilencedErrors -- Because reasons'.PHP_EOL.'$var = @delete( $filename );'.PHP_EOL; |
|
1237 | - $file = new DummyFile($content, $ruleset, $config); |
|
1236 | + $content = '<?php ' . PHP_EOL . '// phpcs:enable Generic.PHP.NoSilencedErrors -- Because reasons' . PHP_EOL . '$var = @delete( $filename );' . PHP_EOL; |
|
1237 | + $file = new DummyFile( $content, $ruleset, $config ); |
|
1238 | 1238 | $file->process(); |
1239 | 1239 | |
1240 | 1240 | $errors = $file->getErrors(); |
1241 | 1241 | $numErrors = $file->getErrorCount(); |
1242 | 1242 | $warnings = $file->getWarnings(); |
1243 | 1243 | $numWarnings = $file->getWarningCount(); |
1244 | - $this->assertEquals(0, $numErrors); |
|
1245 | - $this->assertCount(0, $errors); |
|
1246 | - $this->assertEquals(0, $numWarnings); |
|
1247 | - $this->assertCount(0, $warnings); |
|
1244 | + $this->assertEquals( 0, $numErrors ); |
|
1245 | + $this->assertCount( 0, $errors ); |
|
1246 | + $this->assertEquals( 0, $numWarnings ); |
|
1247 | + $this->assertCount( 0, $warnings ); |
|
1248 | 1248 | |
1249 | 1249 | }//end testCommenting() |
1250 | 1250 |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | use PHP_CodeSniffer\Files\DummyFile; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | 16 | |
17 | -class ErrorSuppressionTest extends TestCase |
|
18 | -{ |
|
17 | +class ErrorSuppressionTest extends TestCase { |
|
19 | 18 | |
20 | 19 | |
21 | 20 | /** |
@@ -23,8 +22,7 @@ discard block |
||
23 | 22 | * |
24 | 23 | * @return void |
25 | 24 | */ |
26 | - public function testSuppressError() |
|
27 | - { |
|
25 | + public function testSuppressError() { |
|
28 | 26 | $config = new Config(); |
29 | 27 | $config->standards = ['Generic']; |
30 | 28 | $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
@@ -179,8 +177,7 @@ discard block |
||
179 | 177 | * |
180 | 178 | * @return void |
181 | 179 | */ |
182 | - public function testSuppressSomeErrors() |
|
183 | - { |
|
180 | + public function testSuppressSomeErrors() { |
|
184 | 181 | $config = new Config(); |
185 | 182 | $config->standards = ['Generic']; |
186 | 183 | $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
@@ -255,8 +252,7 @@ discard block |
||
255 | 252 | * |
256 | 253 | * @return void |
257 | 254 | */ |
258 | - public function testSuppressWarning() |
|
259 | - { |
|
255 | + public function testSuppressWarning() { |
|
260 | 256 | $config = new Config(); |
261 | 257 | $config->standards = ['Generic']; |
262 | 258 | $config->sniffs = ['Generic.Commenting.Todo']; |
@@ -331,8 +327,7 @@ discard block |
||
331 | 327 | * |
332 | 328 | * @return void |
333 | 329 | */ |
334 | - public function testSuppressLine() |
|
335 | - { |
|
330 | + public function testSuppressLine() { |
|
336 | 331 | $config = new Config(); |
337 | 332 | $config->standards = ['Generic']; |
338 | 333 | $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
@@ -437,8 +432,7 @@ discard block |
||
437 | 432 | * |
438 | 433 | * @return void |
439 | 434 | */ |
440 | - public function testNestedSuppressLine() |
|
441 | - { |
|
435 | + public function testNestedSuppressLine() { |
|
442 | 436 | $config = new Config(); |
443 | 437 | $config->standards = ['Generic']; |
444 | 438 | $config->sniffs = ['Generic.PHP.LowerCaseConstant']; |
@@ -513,8 +507,7 @@ discard block |
||
513 | 507 | * |
514 | 508 | * @return void |
515 | 509 | */ |
516 | - public function testSuppressScope() |
|
517 | - { |
|
510 | + public function testSuppressScope() { |
|
518 | 511 | $config = new Config(); |
519 | 512 | $config->standards = ['PEAR']; |
520 | 513 | $config->sniffs = ['PEAR.NamingConventions.ValidVariableName']; |
@@ -596,8 +589,7 @@ discard block |
||
596 | 589 | * |
597 | 590 | * @return void |
598 | 591 | */ |
599 | - public function testSuppressFile() |
|
600 | - { |
|
592 | + public function testSuppressFile() { |
|
601 | 593 | $config = new Config(); |
602 | 594 | $config->standards = ['Generic']; |
603 | 595 | $config->sniffs = ['Generic.Commenting.Todo']; |
@@ -742,8 +734,7 @@ discard block |
||
742 | 734 | * |
743 | 735 | * @return void |
744 | 736 | */ |
745 | - public function testDisableSelected() |
|
746 | - { |
|
737 | + public function testDisableSelected() { |
|
747 | 738 | $config = new Config(); |
748 | 739 | $config->standards = ['Generic']; |
749 | 740 | $config->sniffs = [ |
@@ -889,8 +880,7 @@ discard block |
||
889 | 880 | * |
890 | 881 | * @return void |
891 | 882 | */ |
892 | - public function testEnableSelected() |
|
893 | - { |
|
883 | + public function testEnableSelected() { |
|
894 | 884 | $config = new Config(); |
895 | 885 | $config->standards = ['Generic']; |
896 | 886 | $config->sniffs = [ |
@@ -1062,8 +1052,7 @@ discard block |
||
1062 | 1052 | * |
1063 | 1053 | * @return void |
1064 | 1054 | */ |
1065 | - public function testIgnoreSelected() |
|
1066 | - { |
|
1055 | + public function testIgnoreSelected() { |
|
1067 | 1056 | $config = new Config(); |
1068 | 1057 | $config->standards = ['Generic']; |
1069 | 1058 | $config->sniffs = [ |
@@ -1165,8 +1154,7 @@ discard block |
||
1165 | 1154 | * |
1166 | 1155 | * @return void |
1167 | 1156 | */ |
1168 | - public function testCommenting() |
|
1169 | - { |
|
1157 | + public function testCommenting() { |
|
1170 | 1158 | $config = new Config(); |
1171 | 1159 | $config->standards = ['Generic']; |
1172 | 1160 | $config->sniffs = [ |