Completed
Pull Request — develop (#1492)
by Zack
15:57
created
php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -17,126 +17,126 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.inc 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -6,56 +6,56 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.php 1 patch
Indentation   +382 added lines, -382 removed lines patch added patch discarded remove patch
@@ -17,388 +17,388 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.php 1 patch
Indentation   +550 added lines, -550 removed lines patch added patch discarded remove patch
@@ -17,556 +17,556 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/tests/Core/File/IsReferenceTest.php 1 patch
Indentation   +248 added lines, -248 removed lines patch added patch discarded remove patch
@@ -17,269 +17,269 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/tests/Core/AllTests.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -26,38 +26,38 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/tests/Core/ErrorSuppressionTest.php 1 patch
Indentation   +1225 added lines, -1225 removed lines patch added patch discarded remove patch
@@ -18,1235 +18,1235 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/autoload.php 1 patch
Indentation   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -17,284 +17,284 @@
 block discarded – undo
17 17
 namespace PHP_CodeSniffer;
18 18
 
19 19
 if (class_exists('PHP_CodeSniffer\Autoload', false) === false) {
20
-    class Autoload
21
-    {
22
-
23
-        /**
24
-         * The composer autoloader.
25
-         *
26
-         * @var \Composer\Autoload\ClassLoader
27
-         */
28
-        private static $composerAutoloader = null;
29
-
30
-        /**
31
-         * A mapping of file names to class names.
32
-         *
33
-         * @var array<string, string>
34
-         */
35
-        private static $loadedClasses = [];
36
-
37
-        /**
38
-         * A mapping of class names to file names.
39
-         *
40
-         * @var array<string, string>
41
-         */
42
-        private static $loadedFiles = [];
43
-
44
-        /**
45
-         * A list of additional directories to search during autoloading.
46
-         *
47
-         * This is typically a list of coding standard directories.
48
-         *
49
-         * @var string[]
50
-         */
51
-        private static $searchPaths = [];
52
-
53
-
54
-        /**
55
-         * Loads a class.
56
-         *
57
-         * This method only loads classes that exist in the PHP_CodeSniffer namespace.
58
-         * All other classes are ignored and loaded by subsequent autoloaders.
59
-         *
60
-         * @param string $class The name of the class to load.
61
-         *
62
-         * @return bool
63
-         */
64
-        public static function load($class)
65
-        {
66
-            // Include the composer autoloader if there is one, but re-register it
67
-            // so this autoloader runs before the composer one as we need to include
68
-            // all files so we can figure out what the class/interface/trait name is.
69
-            if (self::$composerAutoloader === null) {
70
-                // Make sure we don't try to load any of Composer's classes
71
-                // while the autoloader is being setup.
72
-                if (strpos($class, 'Composer\\') === 0) {
73
-                    return;
74
-                }
75
-
76
-                if (strpos(__DIR__, 'phar://') !== 0
77
-                    && file_exists(__DIR__.'/../../autoload.php') === true
78
-                ) {
79
-                    self::$composerAutoloader = include __DIR__.'/../../autoload.php';
80
-                    if (self::$composerAutoloader instanceof \Composer\Autoload\ClassLoader) {
81
-                        self::$composerAutoloader->unregister();
82
-                        self::$composerAutoloader->register();
83
-                    } else {
84
-                        // Something went wrong, so keep going without the autoloader
85
-                        // although namespaced sniffs might error.
86
-                        self::$composerAutoloader = false;
87
-                    }
88
-                } else {
89
-                    self::$composerAutoloader = false;
90
-                }
91
-            }//end if
92
-
93
-            $ds   = DIRECTORY_SEPARATOR;
94
-            $path = false;
95
-
96
-            if (substr($class, 0, 16) === 'PHP_CodeSniffer\\') {
97
-                if (substr($class, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
98
-                    $isInstalled = !is_dir(__DIR__.$ds.'tests');
99
-                    if ($isInstalled === false) {
100
-                        $path = __DIR__.$ds.'tests';
101
-                    } else {
102
-                        $path = '@test_dir@'.$ds.'PHP_CodeSniffer'.$ds.'CodeSniffer';
103
-                    }
104
-
105
-                    $path .= $ds.substr(str_replace('\\', $ds, $class), 22).'.php';
106
-                } else {
107
-                    $path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $class), 16).'.php';
108
-                }
109
-            }
110
-
111
-            // See if the composer autoloader knows where the class is.
112
-            if ($path === false && self::$composerAutoloader !== false) {
113
-                $path = self::$composerAutoloader->findFile($class);
114
-            }
115
-
116
-            // See if the class is inside one of our alternate search paths.
117
-            if ($path === false) {
118
-                foreach (self::$searchPaths as $searchPath => $nsPrefix) {
119
-                    $className = $class;
120
-                    if ($nsPrefix !== '' && substr($class, 0, strlen($nsPrefix)) === $nsPrefix) {
121
-                        $className = substr($class, (strlen($nsPrefix) + 1));
122
-                    }
123
-
124
-                    $path = $searchPath.$ds.str_replace('\\', $ds, $className).'.php';
125
-                    if (is_file($path) === true) {
126
-                        break;
127
-                    }
128
-
129
-                    $path = false;
130
-                }
131
-            }
132
-
133
-            if ($path !== false && is_file($path) === true) {
134
-                self::loadFile($path);
135
-                return true;
136
-            }
137
-
138
-            return false;
139
-
140
-        }//end load()
141
-
142
-
143
-        /**
144
-         * Includes a file and tracks what class or interface was loaded as a result.
145
-         *
146
-         * @param string $path The path of the file to load.
147
-         *
148
-         * @return string The fully qualified name of the class in the loaded file.
149
-         */
150
-        public static function loadFile($path)
151
-        {
152
-            if (strpos(__DIR__, 'phar://') !== 0) {
153
-                $path = realpath($path);
154
-                if ($path === false) {
155
-                    return false;
156
-                }
157
-            }
158
-
159
-            if (isset(self::$loadedClasses[$path]) === true) {
160
-                return self::$loadedClasses[$path];
161
-            }
162
-
163
-            $classes    = get_declared_classes();
164
-            $interfaces = get_declared_interfaces();
165
-            $traits     = get_declared_traits();
166
-
167
-            include $path;
168
-
169
-            $className  = null;
170
-            $newClasses = array_reverse(array_diff(get_declared_classes(), $classes));
171
-            foreach ($newClasses as $name) {
172
-                if (isset(self::$loadedFiles[$name]) === false) {
173
-                    $className = $name;
174
-                    break;
175
-                }
176
-            }
177
-
178
-            if ($className === null) {
179
-                $newClasses = array_reverse(array_diff(get_declared_interfaces(), $interfaces));
180
-                foreach ($newClasses as $name) {
181
-                    if (isset(self::$loadedFiles[$name]) === false) {
182
-                        $className = $name;
183
-                        break;
184
-                    }
185
-                }
186
-            }
187
-
188
-            if ($className === null) {
189
-                $newClasses = array_reverse(array_diff(get_declared_traits(), $traits));
190
-                foreach ($newClasses as $name) {
191
-                    if (isset(self::$loadedFiles[$name]) === false) {
192
-                        $className = $name;
193
-                        break;
194
-                    }
195
-                }
196
-            }
197
-
198
-            self::$loadedClasses[$path]    = $className;
199
-            self::$loadedFiles[$className] = $path;
200
-            return self::$loadedClasses[$path];
201
-
202
-        }//end loadFile()
203
-
204
-
205
-        /**
206
-         * Adds a directory to search during autoloading.
207
-         *
208
-         * @param string $path     The path to the directory to search.
209
-         * @param string $nsPrefix The namespace prefix used by files under this path.
210
-         *
211
-         * @return void
212
-         */
213
-        public static function addSearchPath($path, $nsPrefix='')
214
-        {
215
-            self::$searchPaths[$path] = rtrim(trim((string) $nsPrefix), '\\');
216
-
217
-        }//end addSearchPath()
218
-
219
-
220
-        /**
221
-         * Retrieve the namespaces and paths registered by external standards.
222
-         *
223
-         * @return array
224
-         */
225
-        public static function getSearchPaths()
226
-        {
227
-            return self::$searchPaths;
228
-
229
-        }//end getSearchPaths()
230
-
231
-
232
-        /**
233
-         * Gets the class name for the given file path.
234
-         *
235
-         * @param string $path The name of the file.
236
-         *
237
-         * @throws \Exception If the file path has not been loaded.
238
-         * @return string
239
-         */
240
-        public static function getLoadedClassName($path)
241
-        {
242
-            if (isset(self::$loadedClasses[$path]) === false) {
243
-                throw new \Exception("Cannot get class name for $path; file has not been included");
244
-            }
245
-
246
-            return self::$loadedClasses[$path];
247
-
248
-        }//end getLoadedClassName()
249
-
250
-
251
-        /**
252
-         * Gets the file path for the given class name.
253
-         *
254
-         * @param string $class The name of the class.
255
-         *
256
-         * @throws \Exception If the class name has not been loaded
257
-         * @return string
258
-         */
259
-        public static function getLoadedFileName($class)
260
-        {
261
-            if (isset(self::$loadedFiles[$class]) === false) {
262
-                throw new \Exception("Cannot get file name for $class; class has not been included");
263
-            }
264
-
265
-            return self::$loadedFiles[$class];
266
-
267
-        }//end getLoadedFileName()
268
-
269
-
270
-        /**
271
-         * Gets the mapping of file names to class names.
272
-         *
273
-         * @return array<string, string>
274
-         */
275
-        public static function getLoadedClasses()
276
-        {
277
-            return self::$loadedClasses;
278
-
279
-        }//end getLoadedClasses()
280
-
281
-
282
-        /**
283
-         * Gets the mapping of class names to file names.
284
-         *
285
-         * @return array<string, string>
286
-         */
287
-        public static function getLoadedFiles()
288
-        {
289
-            return self::$loadedFiles;
290
-
291
-        }//end getLoadedFiles()
292
-
293
-
294
-    }//end class
295
-
296
-    // Register the autoloader before any existing autoloaders to ensure
297
-    // it gets a chance to hear about every autoload request, and record
298
-    // the file and class name for it.
299
-    spl_autoload_register(__NAMESPACE__.'\Autoload::load', true, true);
20
+	class Autoload
21
+	{
22
+
23
+		/**
24
+		 * The composer autoloader.
25
+		 *
26
+		 * @var \Composer\Autoload\ClassLoader
27
+		 */
28
+		private static $composerAutoloader = null;
29
+
30
+		/**
31
+		 * A mapping of file names to class names.
32
+		 *
33
+		 * @var array<string, string>
34
+		 */
35
+		private static $loadedClasses = [];
36
+
37
+		/**
38
+		 * A mapping of class names to file names.
39
+		 *
40
+		 * @var array<string, string>
41
+		 */
42
+		private static $loadedFiles = [];
43
+
44
+		/**
45
+		 * A list of additional directories to search during autoloading.
46
+		 *
47
+		 * This is typically a list of coding standard directories.
48
+		 *
49
+		 * @var string[]
50
+		 */
51
+		private static $searchPaths = [];
52
+
53
+
54
+		/**
55
+		 * Loads a class.
56
+		 *
57
+		 * This method only loads classes that exist in the PHP_CodeSniffer namespace.
58
+		 * All other classes are ignored and loaded by subsequent autoloaders.
59
+		 *
60
+		 * @param string $class The name of the class to load.
61
+		 *
62
+		 * @return bool
63
+		 */
64
+		public static function load($class)
65
+		{
66
+			// Include the composer autoloader if there is one, but re-register it
67
+			// so this autoloader runs before the composer one as we need to include
68
+			// all files so we can figure out what the class/interface/trait name is.
69
+			if (self::$composerAutoloader === null) {
70
+				// Make sure we don't try to load any of Composer's classes
71
+				// while the autoloader is being setup.
72
+				if (strpos($class, 'Composer\\') === 0) {
73
+					return;
74
+				}
75
+
76
+				if (strpos(__DIR__, 'phar://') !== 0
77
+					&& file_exists(__DIR__.'/../../autoload.php') === true
78
+				) {
79
+					self::$composerAutoloader = include __DIR__.'/../../autoload.php';
80
+					if (self::$composerAutoloader instanceof \Composer\Autoload\ClassLoader) {
81
+						self::$composerAutoloader->unregister();
82
+						self::$composerAutoloader->register();
83
+					} else {
84
+						// Something went wrong, so keep going without the autoloader
85
+						// although namespaced sniffs might error.
86
+						self::$composerAutoloader = false;
87
+					}
88
+				} else {
89
+					self::$composerAutoloader = false;
90
+				}
91
+			}//end if
92
+
93
+			$ds   = DIRECTORY_SEPARATOR;
94
+			$path = false;
95
+
96
+			if (substr($class, 0, 16) === 'PHP_CodeSniffer\\') {
97
+				if (substr($class, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
98
+					$isInstalled = !is_dir(__DIR__.$ds.'tests');
99
+					if ($isInstalled === false) {
100
+						$path = __DIR__.$ds.'tests';
101
+					} else {
102
+						$path = '@test_dir@'.$ds.'PHP_CodeSniffer'.$ds.'CodeSniffer';
103
+					}
104
+
105
+					$path .= $ds.substr(str_replace('\\', $ds, $class), 22).'.php';
106
+				} else {
107
+					$path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $class), 16).'.php';
108
+				}
109
+			}
110
+
111
+			// See if the composer autoloader knows where the class is.
112
+			if ($path === false && self::$composerAutoloader !== false) {
113
+				$path = self::$composerAutoloader->findFile($class);
114
+			}
115
+
116
+			// See if the class is inside one of our alternate search paths.
117
+			if ($path === false) {
118
+				foreach (self::$searchPaths as $searchPath => $nsPrefix) {
119
+					$className = $class;
120
+					if ($nsPrefix !== '' && substr($class, 0, strlen($nsPrefix)) === $nsPrefix) {
121
+						$className = substr($class, (strlen($nsPrefix) + 1));
122
+					}
123
+
124
+					$path = $searchPath.$ds.str_replace('\\', $ds, $className).'.php';
125
+					if (is_file($path) === true) {
126
+						break;
127
+					}
128
+
129
+					$path = false;
130
+				}
131
+			}
132
+
133
+			if ($path !== false && is_file($path) === true) {
134
+				self::loadFile($path);
135
+				return true;
136
+			}
137
+
138
+			return false;
139
+
140
+		}//end load()
141
+
142
+
143
+		/**
144
+		 * Includes a file and tracks what class or interface was loaded as a result.
145
+		 *
146
+		 * @param string $path The path of the file to load.
147
+		 *
148
+		 * @return string The fully qualified name of the class in the loaded file.
149
+		 */
150
+		public static function loadFile($path)
151
+		{
152
+			if (strpos(__DIR__, 'phar://') !== 0) {
153
+				$path = realpath($path);
154
+				if ($path === false) {
155
+					return false;
156
+				}
157
+			}
158
+
159
+			if (isset(self::$loadedClasses[$path]) === true) {
160
+				return self::$loadedClasses[$path];
161
+			}
162
+
163
+			$classes    = get_declared_classes();
164
+			$interfaces = get_declared_interfaces();
165
+			$traits     = get_declared_traits();
166
+
167
+			include $path;
168
+
169
+			$className  = null;
170
+			$newClasses = array_reverse(array_diff(get_declared_classes(), $classes));
171
+			foreach ($newClasses as $name) {
172
+				if (isset(self::$loadedFiles[$name]) === false) {
173
+					$className = $name;
174
+					break;
175
+				}
176
+			}
177
+
178
+			if ($className === null) {
179
+				$newClasses = array_reverse(array_diff(get_declared_interfaces(), $interfaces));
180
+				foreach ($newClasses as $name) {
181
+					if (isset(self::$loadedFiles[$name]) === false) {
182
+						$className = $name;
183
+						break;
184
+					}
185
+				}
186
+			}
187
+
188
+			if ($className === null) {
189
+				$newClasses = array_reverse(array_diff(get_declared_traits(), $traits));
190
+				foreach ($newClasses as $name) {
191
+					if (isset(self::$loadedFiles[$name]) === false) {
192
+						$className = $name;
193
+						break;
194
+					}
195
+				}
196
+			}
197
+
198
+			self::$loadedClasses[$path]    = $className;
199
+			self::$loadedFiles[$className] = $path;
200
+			return self::$loadedClasses[$path];
201
+
202
+		}//end loadFile()
203
+
204
+
205
+		/**
206
+		 * Adds a directory to search during autoloading.
207
+		 *
208
+		 * @param string $path     The path to the directory to search.
209
+		 * @param string $nsPrefix The namespace prefix used by files under this path.
210
+		 *
211
+		 * @return void
212
+		 */
213
+		public static function addSearchPath($path, $nsPrefix='')
214
+		{
215
+			self::$searchPaths[$path] = rtrim(trim((string) $nsPrefix), '\\');
216
+
217
+		}//end addSearchPath()
218
+
219
+
220
+		/**
221
+		 * Retrieve the namespaces and paths registered by external standards.
222
+		 *
223
+		 * @return array
224
+		 */
225
+		public static function getSearchPaths()
226
+		{
227
+			return self::$searchPaths;
228
+
229
+		}//end getSearchPaths()
230
+
231
+
232
+		/**
233
+		 * Gets the class name for the given file path.
234
+		 *
235
+		 * @param string $path The name of the file.
236
+		 *
237
+		 * @throws \Exception If the file path has not been loaded.
238
+		 * @return string
239
+		 */
240
+		public static function getLoadedClassName($path)
241
+		{
242
+			if (isset(self::$loadedClasses[$path]) === false) {
243
+				throw new \Exception("Cannot get class name for $path; file has not been included");
244
+			}
245
+
246
+			return self::$loadedClasses[$path];
247
+
248
+		}//end getLoadedClassName()
249
+
250
+
251
+		/**
252
+		 * Gets the file path for the given class name.
253
+		 *
254
+		 * @param string $class The name of the class.
255
+		 *
256
+		 * @throws \Exception If the class name has not been loaded
257
+		 * @return string
258
+		 */
259
+		public static function getLoadedFileName($class)
260
+		{
261
+			if (isset(self::$loadedFiles[$class]) === false) {
262
+				throw new \Exception("Cannot get file name for $class; class has not been included");
263
+			}
264
+
265
+			return self::$loadedFiles[$class];
266
+
267
+		}//end getLoadedFileName()
268
+
269
+
270
+		/**
271
+		 * Gets the mapping of file names to class names.
272
+		 *
273
+		 * @return array<string, string>
274
+		 */
275
+		public static function getLoadedClasses()
276
+		{
277
+			return self::$loadedClasses;
278
+
279
+		}//end getLoadedClasses()
280
+
281
+
282
+		/**
283
+		 * Gets the mapping of class names to file names.
284
+		 *
285
+		 * @return array<string, string>
286
+		 */
287
+		public static function getLoadedFiles()
288
+		{
289
+			return self::$loadedFiles;
290
+
291
+		}//end getLoadedFiles()
292
+
293
+
294
+	}//end class
295
+
296
+	// Register the autoloader before any existing autoloaders to ensure
297
+	// it gets a chance to hear about every autoload request, and record
298
+	// the file and class name for it.
299
+	spl_autoload_register(__NAMESPACE__.'\Autoload::load', true, true);
300 300
 }//end if
Please login to merge, or discard this patch.
squizlabs/php_codesniffer/scripts/ValidatePEAR/ValidatePEARPackageXML.php 1 patch
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -17,344 +17,344 @@
 block discarded – undo
17 17
 class ValidatePEARPackageXML
18 18
 {
19 19
 
20
-    /**
21
-     * The root directory of the project.
22
-     *
23
-     * @var string
24
-     */
25
-    protected $projectRoot = '';
26
-
27
-    /**
28
-     * The contents of the package.xml file.
29
-     *
30
-     * @var \SimpleXMLElement
31
-     */
32
-    protected $packageXML;
33
-
34
-    /**
35
-     * List of all files in the repo.
36
-     *
37
-     * @var array
38
-     */
39
-    protected $allFiles = [];
40
-
41
-    /**
42
-     * Valid file roles.
43
-     *
44
-     * @var array
45
-     *
46
-     * @link https://pear.php.net/manual/en/developers.packagedef.intro.php#developers.packagedef.roles
47
-     */
48
-    private $validRoles = [
49
-        'data'   => true,
50
-        'doc'    => true,
51
-        'ext'    => true,
52
-        'extsrc' => true,
53
-        'php'    => true,
54
-        'script' => true,
55
-        'src'    => true,
56
-        'test'   => true,
57
-    ];
58
-
59
-    /**
60
-     * Files encountered in the package.xml <contents> tag.
61
-     *
62
-     * @var array
63
-     */
64
-    private $listedContents = [];
65
-
66
-
67
-    /**
68
-     * Constructor.
69
-     */
70
-    public function __construct()
71
-    {
72
-        $this->projectRoot = dirname(dirname(__DIR__)).'/';
73
-        $this->packageXML  = simplexml_load_file($this->projectRoot.'package.xml');
74
-
75
-        $allFiles       = (new FileList($this->projectRoot, $this->projectRoot))->getList();
76
-        $this->allFiles = array_flip($allFiles);
77
-
78
-    }//end __construct()
79
-
80
-
81
-    /**
82
-     * Validate the file listings in the package.xml file.
83
-     *
84
-     * @return void
85
-     */
86
-    public function validate()
87
-    {
88
-        $exitCode = 0;
89
-        if ($this->checkContents() !== true) {
90
-            $exitCode = 1;
91
-        }
92
-
93
-        if ($this->checkPHPRelease() !== true) {
94
-            $exitCode = 1;
95
-        }
96
-
97
-        exit($exitCode);
98
-
99
-    }//end validate()
100
-
101
-
102
-    /**
103
-     * Validate the file listings in the <contents> tag.
104
-     *
105
-     * @return bool
106
-     */
107
-    protected function checkContents()
108
-    {
109
-        echo PHP_EOL.'Checking Contents tag'.PHP_EOL;
110
-        echo '====================='.PHP_EOL;
111
-
112
-        $valid = true;
113
-
114
-        /*
20
+	/**
21
+	 * The root directory of the project.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	protected $projectRoot = '';
26
+
27
+	/**
28
+	 * The contents of the package.xml file.
29
+	 *
30
+	 * @var \SimpleXMLElement
31
+	 */
32
+	protected $packageXML;
33
+
34
+	/**
35
+	 * List of all files in the repo.
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $allFiles = [];
40
+
41
+	/**
42
+	 * Valid file roles.
43
+	 *
44
+	 * @var array
45
+	 *
46
+	 * @link https://pear.php.net/manual/en/developers.packagedef.intro.php#developers.packagedef.roles
47
+	 */
48
+	private $validRoles = [
49
+		'data'   => true,
50
+		'doc'    => true,
51
+		'ext'    => true,
52
+		'extsrc' => true,
53
+		'php'    => true,
54
+		'script' => true,
55
+		'src'    => true,
56
+		'test'   => true,
57
+	];
58
+
59
+	/**
60
+	 * Files encountered in the package.xml <contents> tag.
61
+	 *
62
+	 * @var array
63
+	 */
64
+	private $listedContents = [];
65
+
66
+
67
+	/**
68
+	 * Constructor.
69
+	 */
70
+	public function __construct()
71
+	{
72
+		$this->projectRoot = dirname(dirname(__DIR__)).'/';
73
+		$this->packageXML  = simplexml_load_file($this->projectRoot.'package.xml');
74
+
75
+		$allFiles       = (new FileList($this->projectRoot, $this->projectRoot))->getList();
76
+		$this->allFiles = array_flip($allFiles);
77
+
78
+	}//end __construct()
79
+
80
+
81
+	/**
82
+	 * Validate the file listings in the package.xml file.
83
+	 *
84
+	 * @return void
85
+	 */
86
+	public function validate()
87
+	{
88
+		$exitCode = 0;
89
+		if ($this->checkContents() !== true) {
90
+			$exitCode = 1;
91
+		}
92
+
93
+		if ($this->checkPHPRelease() !== true) {
94
+			$exitCode = 1;
95
+		}
96
+
97
+		exit($exitCode);
98
+
99
+	}//end validate()
100
+
101
+
102
+	/**
103
+	 * Validate the file listings in the <contents> tag.
104
+	 *
105
+	 * @return bool
106
+	 */
107
+	protected function checkContents()
108
+	{
109
+		echo PHP_EOL.'Checking Contents tag'.PHP_EOL;
110
+		echo '====================='.PHP_EOL;
111
+
112
+		$valid = true;
113
+
114
+		/*
115 115
          * - Check that every file that is mentioned in the `<content>` tag exists in the repo.
116 116
          * - Check that the "role" value is valid.
117 117
          * - Check that the "baseinstalldir" value is valid.
118 118
          */
119 119
 
120
-        $valid = $this->walkDirTag($this->packageXML->contents);
121
-        if ($valid === true) {
122
-            echo "Existing listings in the Contents tag are valid.".PHP_EOL;
123
-        }
120
+		$valid = $this->walkDirTag($this->packageXML->contents);
121
+		if ($valid === true) {
122
+			echo "Existing listings in the Contents tag are valid.".PHP_EOL;
123
+		}
124 124
 
125
-        /*
125
+		/*
126 126
          * Verify that all files in the `src` and the `tests` directories are listed in the `<contents>` tag.
127 127
          */
128 128
 
129
-        $srcFiles   = (new FileList(
130
-            $this->projectRoot.'src/',
131
-            $this->projectRoot,
132
-            '`\.(css|fixed|inc|js|php|xml)$`Di'
133
-        ))->getList();
134
-        $testsFiles = (new FileList(
135
-            $this->projectRoot.'tests/',
136
-            $this->projectRoot,
137
-            '`\.(css|inc|js|php|xml)$`Di'
138
-        ))->getList();
139
-        $files      = array_merge($srcFiles, $testsFiles);
140
-
141
-        foreach ($files as $file) {
142
-            if (isset($this->listedContents[$file]) === true) {
143
-                continue;
144
-            }
145
-
146
-            echo "- File '{$file}' is missing from Contents tag.".PHP_EOL;
147
-            $valid = false;
148
-        }
149
-
150
-        if ($valid === true) {
151
-            echo "No missing files in the Contents tag.".PHP_EOL;
152
-        }
153
-
154
-        return $valid;
155
-
156
-    }//end checkContents()
157
-
158
-
159
-    /**
160
-     * Validate all child tags within a <dir> tag.
161
-     *
162
-     * @param \SimpleXMLElement $tag              The current XML tag to examine.
163
-     * @param string            $currentDirectory The complete relative path to the
164
-     *                                            directory being examined.
165
-     *
166
-     * @return bool
167
-     */
168
-    protected function walkDirTag($tag, $currentDirectory='')
169
-    {
170
-        $valid = true;
171
-        $name  = (string) $tag['name'];
172
-        if ($name !== '/' && empty($name) === false) {
173
-            $currentDirectory .= $name.'/';
174
-        }
175
-
176
-        $children = $tag->children();
177
-        foreach ($children as $key => $value) {
178
-            if ($key === 'dir') {
179
-                if ($this->walkDirTag($value, $currentDirectory) === false) {
180
-                    $valid = false;
181
-                }
182
-            }
183
-
184
-            if ($key === 'file') {
185
-                if ($this->checkFileTag($value, $currentDirectory) === false) {
186
-                    $valid = false;
187
-                }
188
-            }
189
-        }
190
-
191
-        return $valid;
192
-
193
-    }//end walkDirTag()
194
-
195
-
196
-    /**
197
-     * Validate the information within a <file> tag.
198
-     *
199
-     * @param \SimpleXMLElement $tag              The current XML tag to examine.
200
-     * @param string            $currentDirectory The complete relative path to the
201
-     *                                            directory being examined.
202
-     *
203
-     * @return bool
204
-     */
205
-    protected function checkFileTag($tag, $currentDirectory='')
206
-    {
207
-        $valid          = true;
208
-        $attributes     = $tag->attributes();
209
-        $baseinstalldir = (string) $attributes['baseinstalldir'];
210
-        $name           = $currentDirectory.(string) $attributes['name'];
211
-        $role           = (string) $attributes['role'];
212
-
213
-        $this->listedContents[$name] = true;
214
-
215
-        if (empty($name) === true) {
216
-            echo "- Name attribute missing.".PHP_EOL;
217
-            $valid = false;
218
-        } else {
219
-            if (isset($this->allFiles[$name]) === false) {
220
-                echo "- File '{$name}' does not exist.".PHP_EOL;
221
-                $valid = false;
222
-            }
223
-
224
-            if (empty($role) === true) {
225
-                echo "- Role attribute missing for file '{$name}'.".PHP_EOL;
226
-                $valid = false;
227
-            } else {
228
-                if (isset($this->validRoles[$role]) === false) {
229
-                    echo "- Role for file '{$name}' is invalid.".PHP_EOL;
230
-                    $valid = false;
231
-                } else {
232
-                    // Limited validation of the "role" tags.
233
-                    if (strpos($name, 'Test.') !== false && $role !== 'test') {
234
-                        echo "- Test files should have the role 'test'. Found: '$role' for file '{$name}'.".PHP_EOL;
235
-                        $valid = false;
236
-                    } else if ((strpos($name, 'Standard.xml') !== false || strpos($name, 'Sniff.php') !== false)
237
-                        && $role !== 'php'
238
-                    ) {
239
-                        echo "- Sniff files, including sniff documentation files should have the role 'php'. Found: '$role' for file '{$name}'.".PHP_EOL;
240
-                        $valid = false;
241
-                    }
242
-                }
243
-
244
-                if (empty($baseinstalldir) === true) {
245
-                    if ($role !== 'script' && strpos($name, 'tests/') !== 0) {
246
-                        echo "- Baseinstalldir attribute missing for file '{$name}'.".PHP_EOL;
247
-                        $valid = false;
248
-                    }
249
-                } else {
250
-                    if ($role === 'script' ||  strpos($name, 'tests/') === 0) {
251
-                        echo "- Baseinstalldir for file '{$name}' should be empty.".PHP_EOL;
252
-                        $valid = false;
253
-                    }
254
-
255
-                    if ($role !== 'script' && $baseinstalldir !== 'PHP/CodeSniffer') {
256
-                        echo "- Baseinstalldir for file '{$name}' is invalid.".PHP_EOL;
257
-                        $valid = false;
258
-                    }
259
-                }
260
-            }//end if
261
-        }//end if
262
-
263
-        return $valid;
264
-
265
-    }//end checkFileTag()
266
-
267
-
268
-    /**
269
-     * Validate the file listings in the <phprelease> tags.
270
-     *
271
-     * @return bool True if the info in the "phprelease" tags is valid. False otherwise.
272
-     */
273
-    protected function checkPHPRelease()
274
-    {
275
-        echo PHP_EOL.'Checking PHPRelease tags'.PHP_EOL;
276
-        echo '========================'.PHP_EOL;
277
-
278
-        $valid       = true;
279
-        $listedFiles = [];
280
-        $releaseTags = 1;
281
-
282
-        /*
129
+		$srcFiles   = (new FileList(
130
+			$this->projectRoot.'src/',
131
+			$this->projectRoot,
132
+			'`\.(css|fixed|inc|js|php|xml)$`Di'
133
+		))->getList();
134
+		$testsFiles = (new FileList(
135
+			$this->projectRoot.'tests/',
136
+			$this->projectRoot,
137
+			'`\.(css|inc|js|php|xml)$`Di'
138
+		))->getList();
139
+		$files      = array_merge($srcFiles, $testsFiles);
140
+
141
+		foreach ($files as $file) {
142
+			if (isset($this->listedContents[$file]) === true) {
143
+				continue;
144
+			}
145
+
146
+			echo "- File '{$file}' is missing from Contents tag.".PHP_EOL;
147
+			$valid = false;
148
+		}
149
+
150
+		if ($valid === true) {
151
+			echo "No missing files in the Contents tag.".PHP_EOL;
152
+		}
153
+
154
+		return $valid;
155
+
156
+	}//end checkContents()
157
+
158
+
159
+	/**
160
+	 * Validate all child tags within a <dir> tag.
161
+	 *
162
+	 * @param \SimpleXMLElement $tag              The current XML tag to examine.
163
+	 * @param string            $currentDirectory The complete relative path to the
164
+	 *                                            directory being examined.
165
+	 *
166
+	 * @return bool
167
+	 */
168
+	protected function walkDirTag($tag, $currentDirectory='')
169
+	{
170
+		$valid = true;
171
+		$name  = (string) $tag['name'];
172
+		if ($name !== '/' && empty($name) === false) {
173
+			$currentDirectory .= $name.'/';
174
+		}
175
+
176
+		$children = $tag->children();
177
+		foreach ($children as $key => $value) {
178
+			if ($key === 'dir') {
179
+				if ($this->walkDirTag($value, $currentDirectory) === false) {
180
+					$valid = false;
181
+				}
182
+			}
183
+
184
+			if ($key === 'file') {
185
+				if ($this->checkFileTag($value, $currentDirectory) === false) {
186
+					$valid = false;
187
+				}
188
+			}
189
+		}
190
+
191
+		return $valid;
192
+
193
+	}//end walkDirTag()
194
+
195
+
196
+	/**
197
+	 * Validate the information within a <file> tag.
198
+	 *
199
+	 * @param \SimpleXMLElement $tag              The current XML tag to examine.
200
+	 * @param string            $currentDirectory The complete relative path to the
201
+	 *                                            directory being examined.
202
+	 *
203
+	 * @return bool
204
+	 */
205
+	protected function checkFileTag($tag, $currentDirectory='')
206
+	{
207
+		$valid          = true;
208
+		$attributes     = $tag->attributes();
209
+		$baseinstalldir = (string) $attributes['baseinstalldir'];
210
+		$name           = $currentDirectory.(string) $attributes['name'];
211
+		$role           = (string) $attributes['role'];
212
+
213
+		$this->listedContents[$name] = true;
214
+
215
+		if (empty($name) === true) {
216
+			echo "- Name attribute missing.".PHP_EOL;
217
+			$valid = false;
218
+		} else {
219
+			if (isset($this->allFiles[$name]) === false) {
220
+				echo "- File '{$name}' does not exist.".PHP_EOL;
221
+				$valid = false;
222
+			}
223
+
224
+			if (empty($role) === true) {
225
+				echo "- Role attribute missing for file '{$name}'.".PHP_EOL;
226
+				$valid = false;
227
+			} else {
228
+				if (isset($this->validRoles[$role]) === false) {
229
+					echo "- Role for file '{$name}' is invalid.".PHP_EOL;
230
+					$valid = false;
231
+				} else {
232
+					// Limited validation of the "role" tags.
233
+					if (strpos($name, 'Test.') !== false && $role !== 'test') {
234
+						echo "- Test files should have the role 'test'. Found: '$role' for file '{$name}'.".PHP_EOL;
235
+						$valid = false;
236
+					} else if ((strpos($name, 'Standard.xml') !== false || strpos($name, 'Sniff.php') !== false)
237
+						&& $role !== 'php'
238
+					) {
239
+						echo "- Sniff files, including sniff documentation files should have the role 'php'. Found: '$role' for file '{$name}'.".PHP_EOL;
240
+						$valid = false;
241
+					}
242
+				}
243
+
244
+				if (empty($baseinstalldir) === true) {
245
+					if ($role !== 'script' && strpos($name, 'tests/') !== 0) {
246
+						echo "- Baseinstalldir attribute missing for file '{$name}'.".PHP_EOL;
247
+						$valid = false;
248
+					}
249
+				} else {
250
+					if ($role === 'script' ||  strpos($name, 'tests/') === 0) {
251
+						echo "- Baseinstalldir for file '{$name}' should be empty.".PHP_EOL;
252
+						$valid = false;
253
+					}
254
+
255
+					if ($role !== 'script' && $baseinstalldir !== 'PHP/CodeSniffer') {
256
+						echo "- Baseinstalldir for file '{$name}' is invalid.".PHP_EOL;
257
+						$valid = false;
258
+					}
259
+				}
260
+			}//end if
261
+		}//end if
262
+
263
+		return $valid;
264
+
265
+	}//end checkFileTag()
266
+
267
+
268
+	/**
269
+	 * Validate the file listings in the <phprelease> tags.
270
+	 *
271
+	 * @return bool True if the info in the "phprelease" tags is valid. False otherwise.
272
+	 */
273
+	protected function checkPHPRelease()
274
+	{
275
+		echo PHP_EOL.'Checking PHPRelease tags'.PHP_EOL;
276
+		echo '========================'.PHP_EOL;
277
+
278
+		$valid       = true;
279
+		$listedFiles = [];
280
+		$releaseTags = 1;
281
+
282
+		/*
283 283
          * - Check that every file that is mentioned in the `<phprelease>` tags exists in the repo.
284 284
          * - Check that the "as" value is valid.
285 285
          */
286 286
 
287
-        foreach ($this->packageXML->phprelease as $release) {
288
-            foreach ($release->filelist->install as $install) {
289
-                $attributes = $install->attributes();
290
-                $name       = (string) $attributes['name'];
291
-                $as         = (string) $attributes['as'];
292
-
293
-                $listedFiles[$releaseTags][$name] = $as;
294
-
295
-                if (empty($as) === true || empty($name) === true) {
296
-                    continue;
297
-                }
298
-
299
-                if (isset($this->allFiles[$name]) === false) {
300
-                    echo "- File '{$name}' does not exist.".PHP_EOL;
301
-                    $valid = false;
302
-                }
303
-
304
-                // Rest of the checks only apply to the test files.
305
-                if (strpos($name, 'tests/') !== 0) {
306
-                    continue;
307
-                }
308
-
309
-                // Check validity of the tags for files in the tests root directory.
310
-                if (preg_match('`^tests/([^/]+\.php)$`', $name, $matches) === 1
311
-                    && ($as === $name || $as === $matches[1])
312
-                ) {
313
-                    continue;
314
-                }
315
-
316
-                // Check validity of the tags for files in the tests root subdirectories.
317
-                if (preg_match('`^tests/.+\.(php|inc|js|css|xml)$`', $name) === 1
318
-                    && $as === str_replace('tests/', 'CodeSniffer/', $name)
319
-                ) {
320
-                    continue;
321
-                }
322
-
323
-                echo "- Invalid 'as' attribute '{$as}' for test file '{$name}'.".PHP_EOL;
324
-                $valid = false;
325
-            }//end foreach
326
-
327
-            ++$releaseTags;
328
-        }//end foreach
329
-
330
-        if ($valid === true) {
331
-            echo "Existing PHPRelease tags are valid.".PHP_EOL;
332
-        }
333
-
334
-        /*
287
+		foreach ($this->packageXML->phprelease as $release) {
288
+			foreach ($release->filelist->install as $install) {
289
+				$attributes = $install->attributes();
290
+				$name       = (string) $attributes['name'];
291
+				$as         = (string) $attributes['as'];
292
+
293
+				$listedFiles[$releaseTags][$name] = $as;
294
+
295
+				if (empty($as) === true || empty($name) === true) {
296
+					continue;
297
+				}
298
+
299
+				if (isset($this->allFiles[$name]) === false) {
300
+					echo "- File '{$name}' does not exist.".PHP_EOL;
301
+					$valid = false;
302
+				}
303
+
304
+				// Rest of the checks only apply to the test files.
305
+				if (strpos($name, 'tests/') !== 0) {
306
+					continue;
307
+				}
308
+
309
+				// Check validity of the tags for files in the tests root directory.
310
+				if (preg_match('`^tests/([^/]+\.php)$`', $name, $matches) === 1
311
+					&& ($as === $name || $as === $matches[1])
312
+				) {
313
+					continue;
314
+				}
315
+
316
+				// Check validity of the tags for files in the tests root subdirectories.
317
+				if (preg_match('`^tests/.+\.(php|inc|js|css|xml)$`', $name) === 1
318
+					&& $as === str_replace('tests/', 'CodeSniffer/', $name)
319
+				) {
320
+					continue;
321
+				}
322
+
323
+				echo "- Invalid 'as' attribute '{$as}' for test file '{$name}'.".PHP_EOL;
324
+				$valid = false;
325
+			}//end foreach
326
+
327
+			++$releaseTags;
328
+		}//end foreach
329
+
330
+		if ($valid === true) {
331
+			echo "Existing PHPRelease tags are valid.".PHP_EOL;
332
+		}
333
+
334
+		/*
335 335
          * Verify that all files in the `tests` directory are listed in both `<phprelease>` tags.
336 336
          */
337 337
 
338
-        $testFiles = (new FileList($this->projectRoot.'tests/', $this->projectRoot, '`\.(inc|php|js|css|xml)$`Di'))->getList();
338
+		$testFiles = (new FileList($this->projectRoot.'tests/', $this->projectRoot, '`\.(inc|php|js|css|xml)$`Di'))->getList();
339 339
 
340
-        foreach ($testFiles as $file) {
341
-            foreach ($listedFiles as $key => $listed) {
342
-                if (isset($listed[$file]) === true) {
343
-                    continue;
344
-                }
340
+		foreach ($testFiles as $file) {
341
+			foreach ($listedFiles as $key => $listed) {
342
+				if (isset($listed[$file]) === true) {
343
+					continue;
344
+				}
345 345
 
346
-                echo "- File '{$file}' is missing from PHPRelease tag [{$key}] .".PHP_EOL;
347
-                $valid = false;
348
-            }
349
-        }
346
+				echo "- File '{$file}' is missing from PHPRelease tag [{$key}] .".PHP_EOL;
347
+				$valid = false;
348
+			}
349
+		}
350 350
 
351
-        if ($valid === true) {
352
-            echo "No missing PHPRelease tags.".PHP_EOL;
353
-        }
351
+		if ($valid === true) {
352
+			echo "No missing PHPRelease tags.".PHP_EOL;
353
+		}
354 354
 
355
-        return $valid;
355
+		return $valid;
356 356
 
357
-    }//end checkPHPRelease()
357
+	}//end checkPHPRelease()
358 358
 
359 359
 
360 360
 }//end class
Please login to merge, or discard this patch.