1717/**
1818 * Tests for PHP_CodeSniffer error suppression tags.
1919 *
20- * @coversNothing
20+ * @covers PHP_CodeSniffer\Files\File::addMessage
21+ * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
2122 */
2223final class ErrorSuppressionTest extends TestCase
2324{
@@ -32,7 +33,6 @@ final class ErrorSuppressionTest extends TestCase
3233 * Defaults to 0.
3334 *
3435 * @dataProvider dataSuppressError
35- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
3636 *
3737 * @return void
3838 */
@@ -63,7 +63,7 @@ public function testSuppressError($before, $after, $expectedErrors=0)
6363 *
6464 * @see testSuppressError()
6565 *
66- * @return array
66+ * @return array<string, array<string, string|int>>
6767 */
6868 public static function dataSuppressError ()
6969 {
@@ -165,7 +165,6 @@ public static function dataSuppressError()
165165 * Defaults to 1.
166166 *
167167 * @dataProvider dataSuppressSomeErrors
168- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
169168 *
170169 * @return void
171170 */
@@ -202,7 +201,7 @@ public function testSuppressSomeErrors($before, $between, $expectedErrors=1)
202201 *
203202 * @see testSuppressSomeErrors()
204203 *
205- * @return array
204+ * @return array<string, array<string, string|int>>
206205 */
207206 public static function dataSuppressSomeErrors ()
208207 {
@@ -258,7 +257,6 @@ public static function dataSuppressSomeErrors()
258257 * Defaults to 0.
259258 *
260259 * @dataProvider dataSuppressWarning
261- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
262260 *
263261 * @return void
264262 */
@@ -294,7 +292,7 @@ public function testSuppressWarning($before, $after, $expectedWarnings=0)
294292 *
295293 * @see testSuppressWarning()
296294 *
297- * @return array
295+ * @return array<string, array<string, string|int>>
298296 */
299297 public static function dataSuppressWarning ()
300298 {
@@ -343,7 +341,6 @@ public static function dataSuppressWarning()
343341 * Defaults to 1.
344342 *
345343 * @dataProvider dataSuppressLine
346- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
347344 *
348345 * @return void
349346 */
@@ -379,7 +376,7 @@ public function testSuppressLine($before, $after='', $expectedErrors=1)
379376 *
380377 * @see testSuppressLine()
381378 *
382- * @return array
379+ * @return array<string, array<string, string|int>>
383380 */
384381 public static function dataSuppressLine ()
385382 {
@@ -391,12 +388,24 @@ public static function dataSuppressLine()
391388 ],
392389
393390 // 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+ ],
400409
401410 // With suppression as trailing comment on code line.
402411 'ignore: end of line, slash comment ' => [
@@ -417,7 +426,9 @@ public static function dataSuppressLine()
417426 ],
418427
419428 // Deprecated syntax.
420- 'old style: line before, slash comment ' => ['before ' => '// @codingStandardsIgnoreLine ' ],
429+ 'old style: line before, slash comment ' => [
430+ 'before ' => '// @codingStandardsIgnoreLine ' ,
431+ ],
421432 'old style: end of line, slash comment ' => [
422433 'before ' => '' ,
423434 'after ' => ' // @codingStandardsIgnoreLine ' ,
@@ -430,8 +441,6 @@ public static function dataSuppressLine()
430441 /**
431442 * Test suppressing a single error using a single line ignore in the middle of a line.
432443 *
433- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
434- *
435444 * @return void
436445 */
437446 public function testSuppressLineMidLine ()
@@ -455,8 +464,6 @@ public function testSuppressLineMidLine()
455464 /**
456465 * Test suppressing a single error using a single line ignore within a docblock.
457466 *
458- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
459- *
460467 * @return void
461468 */
462469 public function testSuppressLineWithinDocblock ()
@@ -493,7 +500,6 @@ public function testSuppressLineWithinDocblock()
493500 * @param string $after Annotation to place after the code.
494501 *
495502 * @dataProvider dataNestedSuppressLine
496- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
497503 *
498504 * @return void
499505 */
@@ -530,7 +536,7 @@ public function testNestedSuppressLine($before, $after)
530536 *
531537 * @see testNestedSuppressLine()
532538 *
533- * @return array
539+ * @return array<string, array<string, string>>
534540 */
535541 public static function dataNestedSuppressLine ()
536542 {
@@ -584,7 +590,6 @@ public static function dataNestedSuppressLine()
584590 * Defaults to 0.
585591 *
586592 * @dataProvider dataSuppressScope
587- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
588593 *
589594 * @return void
590595 */
@@ -625,7 +630,7 @@ function myFunction() {
625630 *
626631 * @see testSuppressScope()
627632 *
628- * @return array
633+ * @return array<string, array<string, string|int>>
629634 */
630635 public static function dataSuppressScope ()
631636 {
@@ -682,7 +687,6 @@ public static function dataSuppressScope()
682687 * Defaults to 0.
683688 *
684689 * @dataProvider dataSuppressFile
685- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
686690 *
687691 * @return void
688692 */
@@ -720,7 +724,7 @@ class MyClass {}
720724 *
721725 * @see testSuppressFile()
722726 *
723- * @return array
727+ * @return array<string, array<string, string|int>>
724728 */
725729 public static function dataSuppressFile ()
726730 {
@@ -732,16 +736,30 @@ public static function dataSuppressFile()
732736 ],
733737
734738 // 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+ ],
741757 'ignoreFile: start of file, multi-line star comment ' => [
742758 'before ' => '/* ' .PHP_EOL .' phpcs:ignoreFile ' .PHP_EOL .' */ ' ,
743759 ],
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+ ],
745763
746764 // Process late comment.
747765 'ignoreFile: late comment, slash comment ' => [
@@ -750,12 +768,18 @@ public static function dataSuppressFile()
750768 ],
751769
752770 // 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+ ],
755777 'old style: start of file, multi-line star comment ' => [
756778 'before ' => '/* ' .PHP_EOL .' @codingStandardsIgnoreFile ' .PHP_EOL .' */ ' ,
757779 ],
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+ ],
759783
760784 // Deprecated syntax, late comment.
761785 'old style: late comment, slash comment ' => [
@@ -777,7 +801,6 @@ public static function dataSuppressFile()
777801 * Defaults to 0.
778802 *
779803 * @dataProvider dataDisableSelected
780- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
781804 *
782805 * @return void
783806 */
@@ -819,7 +842,7 @@ public function testDisableSelected($before, $expectedErrors=0, $expectedWarning
819842 *
820843 * @see testDisableSelected()
821844 *
822- * @return array
845+ * @return array<string, array<string, string|int>>
823846 */
824847 public static function dataDisableSelected ()
825848 {
@@ -843,7 +866,9 @@ public static function dataDisableSelected()
843866 ],
844867
845868 // 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+ ],
847872 'disable: multiple sniff in multiple comments ' => [
848873 'before ' => '// phpcs:disable Generic.Commenting.Todo ' .PHP_EOL .'// phpcs:disable Generic.PHP.LowerCaseConstant ' ,
849874 ],
@@ -853,12 +878,16 @@ public static function dataDisableSelected()
853878 'before ' => '// phpcs:disable Generic.Commenting ' ,
854879 'expectedErrors ' => 1 ,
855880 ],
856- 'disable: whole standard ' => ['before ' => '// phpcs:disable Generic ' ],
881+ 'disable: whole standard ' => [
882+ 'before ' => '// phpcs:disable Generic ' ,
883+ ],
857884 'disable: single errorcode ' => [
858885 'before ' => '# @phpcs:disable Generic.Commenting.Todo.TaskFound ' ,
859886 'expectedErrors ' => 1 ,
860887 ],
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+ ],
862891
863892 // Wrong category/sniff/code.
864893 'disable: wrong error code and category ' => [
@@ -889,7 +918,6 @@ public static function dataDisableSelected()
889918 * @param int $expectedWarnings Number of warnings expected.
890919 *
891920 * @dataProvider dataEnableSelected
892- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
893921 *
894922 * @return void
895923 */
@@ -926,7 +954,7 @@ public function testEnableSelected($code, $expectedErrors, $expectedWarnings)
926954 *
927955 * @see testEnableSelected()
928956 *
929- * @return array
957+ * @return array<string, array<string, string|int>>
930958 */
931959 public static function dataEnableSelected ()
932960 {
@@ -1064,7 +1092,6 @@ public static function dataEnableSelected()
10641092 * @param int $expectedWarnings Number of warnings expected.
10651093 *
10661094 * @dataProvider dataIgnoreSelected
1067- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
10681095 *
10691096 * @return void
10701097 */
@@ -1106,7 +1133,7 @@ public function testIgnoreSelected($before, $expectedErrors, $expectedWarnings)
11061133 *
11071134 * @see testIgnoreSelected()
11081135 *
1109- * @return array
1136+ * @return array<string, array<string, string|int>>
11101137 */
11111138 public static function dataIgnoreSelected ()
11121139 {
@@ -1156,7 +1183,6 @@ public static function dataIgnoreSelected()
11561183 * @param int $expectedWarnings Number of warnings expected.
11571184 *
11581185 * @dataProvider dataCommenting
1159- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
11601186 *
11611187 * @return void
11621188 */
@@ -1193,7 +1219,7 @@ public function testCommenting($code, $expectedErrors, $expectedWarnings)
11931219 *
11941220 * @see testCommenting()
11951221 *
1196- * @return array
1222+ * @return array<string, array<string, string|int>>
11971223 */
11981224 public static function dataCommenting ()
11991225 {
0 commit comments