17
17
/**
18
18
* Tests for PHP_CodeSniffer error suppression tags.
19
19
*
20
- * @coversNothing
20
+ * @covers PHP_CodeSniffer\Files\File::addMessage
21
+ * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
21
22
*/
22
23
final class ErrorSuppressionTest extends TestCase
23
24
{
@@ -32,7 +33,6 @@ final class ErrorSuppressionTest extends TestCase
32
33
* Defaults to 0.
33
34
*
34
35
* @dataProvider dataSuppressError
35
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
36
36
*
37
37
* @return void
38
38
*/
@@ -63,7 +63,7 @@ public function testSuppressError($before, $after, $expectedErrors=0)
63
63
*
64
64
* @see testSuppressError()
65
65
*
66
- * @return array
66
+ * @return array<string, array<string, string|int>>
67
67
*/
68
68
public static function dataSuppressError ()
69
69
{
@@ -165,7 +165,6 @@ public static function dataSuppressError()
165
165
* Defaults to 1.
166
166
*
167
167
* @dataProvider dataSuppressSomeErrors
168
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
169
168
*
170
169
* @return void
171
170
*/
@@ -202,7 +201,7 @@ public function testSuppressSomeErrors($before, $between, $expectedErrors=1)
202
201
*
203
202
* @see testSuppressSomeErrors()
204
203
*
205
- * @return array
204
+ * @return array<string, array<string, string|int>>
206
205
*/
207
206
public static function dataSuppressSomeErrors ()
208
207
{
@@ -258,7 +257,6 @@ public static function dataSuppressSomeErrors()
258
257
* Defaults to 0.
259
258
*
260
259
* @dataProvider dataSuppressWarning
261
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
262
260
*
263
261
* @return void
264
262
*/
@@ -294,7 +292,7 @@ public function testSuppressWarning($before, $after, $expectedWarnings=0)
294
292
*
295
293
* @see testSuppressWarning()
296
294
*
297
- * @return array
295
+ * @return array<string, array<string, string|int>>
298
296
*/
299
297
public static function dataSuppressWarning ()
300
298
{
@@ -343,7 +341,6 @@ public static function dataSuppressWarning()
343
341
* Defaults to 1.
344
342
*
345
343
* @dataProvider dataSuppressLine
346
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
347
344
*
348
345
* @return void
349
346
*/
@@ -379,7 +376,7 @@ public function testSuppressLine($before, $after='', $expectedErrors=1)
379
376
*
380
377
* @see testSuppressLine()
381
378
*
382
- * @return array
379
+ * @return array<string, array<string, string|int>>
383
380
*/
384
381
public static function dataSuppressLine ()
385
382
{
@@ -391,12 +388,24 @@ public static function dataSuppressLine()
391
388
],
392
389
393
390
// With suppression on line before.
394
- 'ignore: line before, slash comment ' => ['before ' => '// phpcs:ignore ' ],
395
- 'ignore: line before, slash comment, with @ ' => ['before ' => '// @phpcs:ignore ' ],
396
- 'ignore: line before, hash comment ' => ['before ' => '# phpcs:ignore ' ],
397
- 'ignore: line before, hash comment, with @ ' => ['before ' => '# @phpcs:ignore ' ],
398
- 'ignore: line before, star comment ' => ['before ' => '/* phpcs:ignore */ ' ],
399
- 'ignore: line before, star comment, with @ ' => ['before ' => '/* @phpcs:ignore */ ' ],
391
+ 'ignore: line before, slash comment ' => [
392
+ 'before ' => '// phpcs:ignore ' ,
393
+ ],
394
+ 'ignore: line before, slash comment, with @ ' => [
395
+ 'before ' => '// @phpcs:ignore ' ,
396
+ ],
397
+ 'ignore: line before, hash comment ' => [
398
+ 'before ' => '# phpcs:ignore ' ,
399
+ ],
400
+ 'ignore: line before, hash comment, with @ ' => [
401
+ 'before ' => '# @phpcs:ignore ' ,
402
+ ],
403
+ 'ignore: line before, star comment ' => [
404
+ 'before ' => '/* phpcs:ignore */ ' ,
405
+ ],
406
+ 'ignore: line before, star comment, with @ ' => [
407
+ 'before ' => '/* @phpcs:ignore */ ' ,
408
+ ],
400
409
401
410
// With suppression as trailing comment on code line.
402
411
'ignore: end of line, slash comment ' => [
@@ -417,7 +426,9 @@ public static function dataSuppressLine()
417
426
],
418
427
419
428
// Deprecated syntax.
420
- 'old style: line before, slash comment ' => ['before ' => '// @codingStandardsIgnoreLine ' ],
429
+ 'old style: line before, slash comment ' => [
430
+ 'before ' => '// @codingStandardsIgnoreLine ' ,
431
+ ],
421
432
'old style: end of line, slash comment ' => [
422
433
'before ' => '' ,
423
434
'after ' => ' // @codingStandardsIgnoreLine ' ,
@@ -430,8 +441,6 @@ public static function dataSuppressLine()
430
441
/**
431
442
* Test suppressing a single error using a single line ignore in the middle of a line.
432
443
*
433
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
434
- *
435
444
* @return void
436
445
*/
437
446
public function testSuppressLineMidLine ()
@@ -455,8 +464,6 @@ public function testSuppressLineMidLine()
455
464
/**
456
465
* Test suppressing a single error using a single line ignore within a docblock.
457
466
*
458
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
459
- *
460
467
* @return void
461
468
*/
462
469
public function testSuppressLineWithinDocblock ()
@@ -493,7 +500,6 @@ public function testSuppressLineWithinDocblock()
493
500
* @param string $after Annotation to place after the code.
494
501
*
495
502
* @dataProvider dataNestedSuppressLine
496
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
497
503
*
498
504
* @return void
499
505
*/
@@ -530,7 +536,7 @@ public function testNestedSuppressLine($before, $after)
530
536
*
531
537
* @see testNestedSuppressLine()
532
538
*
533
- * @return array
539
+ * @return array<string, array<string, string>>
534
540
*/
535
541
public static function dataNestedSuppressLine ()
536
542
{
@@ -584,7 +590,6 @@ public static function dataNestedSuppressLine()
584
590
* Defaults to 0.
585
591
*
586
592
* @dataProvider dataSuppressScope
587
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
588
593
*
589
594
* @return void
590
595
*/
@@ -625,7 +630,7 @@ function myFunction() {
625
630
*
626
631
* @see testSuppressScope()
627
632
*
628
- * @return array
633
+ * @return array<string, array<string, string|int>>
629
634
*/
630
635
public static function dataSuppressScope ()
631
636
{
@@ -682,7 +687,6 @@ public static function dataSuppressScope()
682
687
* Defaults to 0.
683
688
*
684
689
* @dataProvider dataSuppressFile
685
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
686
690
*
687
691
* @return void
688
692
*/
@@ -720,7 +724,7 @@ class MyClass {}
720
724
*
721
725
* @see testSuppressFile()
722
726
*
723
- * @return array
727
+ * @return array<string, array<string, string|int>>
724
728
*/
725
729
public static function dataSuppressFile ()
726
730
{
@@ -732,16 +736,30 @@ public static function dataSuppressFile()
732
736
],
733
737
734
738
// Process with suppression.
735
- 'ignoreFile: start of file, slash comment ' => ['before ' => '// phpcs:ignoreFile ' ],
736
- 'ignoreFile: start of file, slash comment, with @ ' => ['before ' => '// @phpcs:ignoreFile ' ],
737
- 'ignoreFile: start of file, slash comment, mixed case ' => ['before ' => '// PHPCS:Ignorefile ' ],
738
- 'ignoreFile: start of file, hash comment ' => ['before ' => '# phpcs:ignoreFile ' ],
739
- 'ignoreFile: start of file, hash comment, with @ ' => ['before ' => '# @phpcs:ignoreFile ' ],
740
- 'ignoreFile: start of file, single-line star comment ' => ['before ' => '/* phpcs:ignoreFile */ ' ],
739
+ 'ignoreFile: start of file, slash comment ' => [
740
+ 'before ' => '// phpcs:ignoreFile ' ,
741
+ ],
742
+ 'ignoreFile: start of file, slash comment, with @ ' => [
743
+ 'before ' => '// @phpcs:ignoreFile ' ,
744
+ ],
745
+ 'ignoreFile: start of file, slash comment, mixed case ' => [
746
+ 'before ' => '// PHPCS:Ignorefile ' ,
747
+ ],
748
+ 'ignoreFile: start of file, hash comment ' => [
749
+ 'before ' => '# phpcs:ignoreFile ' ,
750
+ ],
751
+ 'ignoreFile: start of file, hash comment, with @ ' => [
752
+ 'before ' => '# @phpcs:ignoreFile ' ,
753
+ ],
754
+ 'ignoreFile: start of file, single-line star comment ' => [
755
+ 'before ' => '/* phpcs:ignoreFile */ ' ,
756
+ ],
741
757
'ignoreFile: start of file, multi-line star comment ' => [
742
758
'before ' => '/* ' .PHP_EOL .' phpcs:ignoreFile ' .PHP_EOL .' */ ' ,
743
759
],
744
- 'ignoreFile: start of file, single-line docblock comment ' => ['before ' => '/** phpcs:ignoreFile */ ' ],
760
+ 'ignoreFile: start of file, single-line docblock comment ' => [
761
+ 'before ' => '/** phpcs:ignoreFile */ ' ,
762
+ ],
745
763
746
764
// Process late comment.
747
765
'ignoreFile: late comment, slash comment ' => [
@@ -750,12 +768,18 @@ public static function dataSuppressFile()
750
768
],
751
769
752
770
// Deprecated syntax.
753
- 'old style: start of file, slash comment ' => ['before ' => '// @codingStandardsIgnoreFile ' ],
754
- 'old style: start of file, single-line star comment ' => ['before ' => '/* @codingStandardsIgnoreFile */ ' ],
771
+ 'old style: start of file, slash comment ' => [
772
+ 'before ' => '// @codingStandardsIgnoreFile ' ,
773
+ ],
774
+ 'old style: start of file, single-line star comment ' => [
775
+ 'before ' => '/* @codingStandardsIgnoreFile */ ' ,
776
+ ],
755
777
'old style: start of file, multi-line star comment ' => [
756
778
'before ' => '/* ' .PHP_EOL .' @codingStandardsIgnoreFile ' .PHP_EOL .' */ ' ,
757
779
],
758
- 'old style: start of file, single-line docblock comment ' => ['before ' => '/** @codingStandardsIgnoreFile */ ' ],
780
+ 'old style: start of file, single-line docblock comment ' => [
781
+ 'before ' => '/** @codingStandardsIgnoreFile */ ' ,
782
+ ],
759
783
760
784
// Deprecated syntax, late comment.
761
785
'old style: late comment, slash comment ' => [
@@ -777,7 +801,6 @@ public static function dataSuppressFile()
777
801
* Defaults to 0.
778
802
*
779
803
* @dataProvider dataDisableSelected
780
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
781
804
*
782
805
* @return void
783
806
*/
@@ -819,7 +842,7 @@ public function testDisableSelected($before, $expectedErrors=0, $expectedWarning
819
842
*
820
843
* @see testDisableSelected()
821
844
*
822
- * @return array
845
+ * @return array<string, array<string, string|int>>
823
846
*/
824
847
public static function dataDisableSelected ()
825
848
{
@@ -843,7 +866,9 @@ public static function dataDisableSelected()
843
866
],
844
867
845
868
// Multiple sniffs.
846
- 'disable: multiple sniffs in one comment ' => ['before ' => '// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant ' ],
869
+ 'disable: multiple sniffs in one comment ' => [
870
+ 'before ' => '// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant ' ,
871
+ ],
847
872
'disable: multiple sniff in multiple comments ' => [
848
873
'before ' => '// phpcs:disable Generic.Commenting.Todo ' .PHP_EOL .'// phpcs:disable Generic.PHP.LowerCaseConstant ' ,
849
874
],
@@ -853,12 +878,16 @@ public static function dataDisableSelected()
853
878
'before ' => '// phpcs:disable Generic.Commenting ' ,
854
879
'expectedErrors ' => 1 ,
855
880
],
856
- 'disable: whole standard ' => ['before ' => '// phpcs:disable Generic ' ],
881
+ 'disable: whole standard ' => [
882
+ 'before ' => '// phpcs:disable Generic ' ,
883
+ ],
857
884
'disable: single errorcode ' => [
858
885
'before ' => '# @phpcs:disable Generic.Commenting.Todo.TaskFound ' ,
859
886
'expectedErrors ' => 1 ,
860
887
],
861
- 'disable: single errorcode and a category ' => ['before ' => '// phpcs:disable Generic.PHP.LowerCaseConstant.Found,Generic.Commenting ' ],
888
+ 'disable: single errorcode and a category ' => [
889
+ 'before ' => '// phpcs:disable Generic.PHP.LowerCaseConstant.Found,Generic.Commenting ' ,
890
+ ],
862
891
863
892
// Wrong category/sniff/code.
864
893
'disable: wrong error code and category ' => [
@@ -889,7 +918,6 @@ public static function dataDisableSelected()
889
918
* @param int $expectedWarnings Number of warnings expected.
890
919
*
891
920
* @dataProvider dataEnableSelected
892
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
893
921
*
894
922
* @return void
895
923
*/
@@ -926,7 +954,7 @@ public function testEnableSelected($code, $expectedErrors, $expectedWarnings)
926
954
*
927
955
* @see testEnableSelected()
928
956
*
929
- * @return array
957
+ * @return array<string, array<string, string|int>>
930
958
*/
931
959
public static function dataEnableSelected ()
932
960
{
@@ -1064,7 +1092,6 @@ public static function dataEnableSelected()
1064
1092
* @param int $expectedWarnings Number of warnings expected.
1065
1093
*
1066
1094
* @dataProvider dataIgnoreSelected
1067
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
1068
1095
*
1069
1096
* @return void
1070
1097
*/
@@ -1106,7 +1133,7 @@ public function testIgnoreSelected($before, $expectedErrors, $expectedWarnings)
1106
1133
*
1107
1134
* @see testIgnoreSelected()
1108
1135
*
1109
- * @return array
1136
+ * @return array<string, array<string, string|int>>
1110
1137
*/
1111
1138
public static function dataIgnoreSelected ()
1112
1139
{
@@ -1156,7 +1183,6 @@ public static function dataIgnoreSelected()
1156
1183
* @param int $expectedWarnings Number of warnings expected.
1157
1184
*
1158
1185
* @dataProvider dataCommenting
1159
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
1160
1186
*
1161
1187
* @return void
1162
1188
*/
@@ -1193,7 +1219,7 @@ public function testCommenting($code, $expectedErrors, $expectedWarnings)
1193
1219
*
1194
1220
* @see testCommenting()
1195
1221
*
1196
- * @return array
1222
+ * @return array<string, array<string, string|int>>
1197
1223
*/
1198
1224
public static function dataCommenting ()
1199
1225
{
0 commit comments