Skip to content

Commit 79ff264

Browse files
committed
Squiz/FunctionClosingBraceSpace: add some more tests
A significant part of this sniff (handling of nested functions) is only covered by JS tests, so let's make sure this functionality also has tests for PHP.
1 parent 8894b66 commit 79ff264

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

src/Standards/Squiz/Tests/WhiteSpace/FunctionClosingBraceSpaceUnitTest.inc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,54 @@ function foo()
3737

3838

3939
}
40+
41+
// Nested functions - okay.
42+
function hasNestedOkay() {
43+
function nestedFunction() {
44+
echo 'hello';
45+
}
46+
47+
}
48+
49+
$cl = function() {
50+
function nestedFunction() {
51+
echo 'hello';
52+
}
53+
54+
};
55+
56+
mycallback(
57+
'name',
58+
function() {
59+
echo 'hello';
60+
}
61+
62+
);
63+
64+
// Nested functions - not okay.
65+
function hasNestedNotOkay() {
66+
function nestedFunction() {}
67+
68+
}
69+
70+
$cl = function() {
71+
function nestedFunction() {
72+
echo 'hello'; }
73+
74+
};
75+
76+
mycallback('name', function() {
77+
echo 'hello';
78+
79+
80+
81+
}
82+
83+
);
84+
85+
mycallback('name', function() {
86+
// Comment
87+
88+
}
89+
90+
);

src/Standards/Squiz/Tests/WhiteSpace/FunctionClosingBraceSpaceUnitTest.inc.fixed

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,52 @@ function foo()
4343
}//end for
4444

4545
}
46+
47+
// Nested functions - okay.
48+
function hasNestedOkay() {
49+
function nestedFunction() {
50+
echo 'hello';
51+
}
52+
53+
}
54+
55+
$cl = function() {
56+
function nestedFunction() {
57+
echo 'hello';
58+
}
59+
60+
};
61+
62+
mycallback(
63+
'name',
64+
function() {
65+
echo 'hello';
66+
}
67+
68+
);
69+
70+
// Nested functions - not okay.
71+
function hasNestedNotOkay() {
72+
function nestedFunction() {
73+
}
74+
75+
}
76+
77+
$cl = function() {
78+
function nestedFunction() {
79+
echo 'hello';
80+
}
81+
82+
};
83+
84+
mycallback('name', function() {
85+
echo 'hello';
86+
}
87+
88+
);
89+
90+
mycallback('name', function() {
91+
// Comment
92+
}
93+
94+
);

src/Standards/Squiz/Tests/WhiteSpace/FunctionClosingBraceSpaceUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function getErrorList($testFile='')
4141
29 => 1,
4242
31 => 1,
4343
39 => 1,
44+
66 => 1,
45+
72 => 1,
46+
81 => 1,
47+
88 => 1,
4448
];
4549

4650
case 'FunctionClosingBraceSpaceUnitTest.js':

0 commit comments

Comments
 (0)