Skip to content

Commit 7443644

Browse files
rodrigoprimojrfnl
authored andcommitted
Squiz/ClosingDeclarationComment: improve test coverage
This commit improve the test coverage for the Squiz.Commenting.ClosingDeclarationComment sniff by adding the following tests: - Function without a closing comment - Misplaced closing comment with indentation - Misplaced closing comment with multiple newlines - Class missing a opening or closing bracket It also documents via tests that anonymous classes and arrow functions do not require a closing comment.
1 parent 6b7bea2 commit 7443644

5 files changed

+91
-9
lines changed

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.1.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,35 @@ enum MissingClosingComment {
8484

8585
enum HasClosingComment {
8686
}//end enum
87+
88+
function misplacedClosingCommentWhitespace() {
89+
} //end misplacedClosingCommentWhitespace()
90+
91+
function misplacedClosingCommentMultipleNewlines() {
92+
}
93+
94+
95+
//end misplacedClosingCommentMultipleNewlines()
96+
97+
function missingClosingComment() {
98+
}
99+
100+
function commentHasMoreIndentationThanFunction() {
101+
}
102+
//end commentHasMoreIndentationThanFunction()
103+
104+
class Foo {
105+
function commentHasLessIndentationThanFunction() {
106+
}
107+
//end commentHasLessIndentationThanFunction()
108+
109+
function misplacedClosingCommentWithIndentation() {
110+
}
111+
//end misplacedClosingCommentWithIndentation()
112+
}//end class
113+
114+
// Anonymous classes don't need end comments.
115+
$anon = new class {};
116+
117+
// Arrow functions don't need end comments.
118+
$arrow = fn($a) => $a;

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.1.inc.fixed

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,29 @@ enum MissingClosingComment {
8383

8484
enum HasClosingComment {
8585
}//end enum
86+
87+
function misplacedClosingCommentWhitespace() {
88+
}//end misplacedClosingCommentWhitespace()
89+
90+
function misplacedClosingCommentMultipleNewlines() {
91+
}//end misplacedClosingCommentMultipleNewlines()
92+
93+
function missingClosingComment() {
94+
}//end missingClosingComment()
95+
96+
function commentHasMoreIndentationThanFunction() {
97+
}//end commentHasMoreIndentationThanFunction()
98+
99+
class Foo {
100+
function commentHasLessIndentationThanFunction() {
101+
}//end commentHasLessIndentationThanFunction()
102+
103+
function misplacedClosingCommentWithIndentation() {
104+
}//end misplacedClosingCommentWithIndentation()
105+
}//end class
106+
107+
// Anonymous classes don't need end comments.
108+
$anon = new class {};
109+
110+
// Arrow functions don't need end comments.
111+
$arrow = fn($a) => $a;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (missing opening bracket).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is triggered.
6+
7+
class MissingOpeningBracket
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (missing closing bracket).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is triggered.
6+
7+
class MissingClosingBracket {

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,21 @@ public function getErrorList($testFile='')
3535
switch ($testFile) {
3636
case 'ClosingDeclarationCommentUnitTest.1.inc':
3737
return [
38-
13 => 1,
39-
17 => 1,
40-
31 => 1,
41-
41 => 1,
42-
59 => 1,
43-
63 => 1,
44-
67 => 1,
45-
79 => 1,
46-
83 => 1,
38+
13 => 1,
39+
17 => 1,
40+
31 => 1,
41+
41 => 1,
42+
59 => 1,
43+
63 => 1,
44+
67 => 1,
45+
79 => 1,
46+
83 => 1,
47+
89 => 1,
48+
92 => 1,
49+
98 => 1,
50+
101 => 1,
51+
106 => 1,
52+
110 => 1,
4753
];
4854

4955
default:
@@ -69,6 +75,10 @@ public function getWarningList($testFile='')
6975
case 'ClosingDeclarationCommentUnitTest.1.inc':
7076
return [71 => 1];
7177

78+
case 'ClosingDeclarationCommentUnitTest.2.inc':
79+
case 'ClosingDeclarationCommentUnitTest.3.inc':
80+
return [7 => 1];
81+
7282
default:
7383
return [];
7484
}

0 commit comments

Comments
 (0)