Skip to content

Commit 89f4fc6

Browse files
committed
Generic/InlineControlStructure: improve code coverage
1 parent b1ae5ae commit 89f4fc6

7 files changed

+77
-2
lines changed

src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,13 @@ if (false) {
289289
} else ($shouldTriggerSniff);
290290

291291
foreach ($array as $shouldNotTriggerSniff);
292+
293+
do echo $i++; while ($i < 5);
294+
295+
// phpcs:set Generic.ControlStructures.InlineControlStructure error false
296+
if ($something) echo 'hello';
297+
// phpcs:set Generic.ControlStructures.InlineControlStructure error true
298+
299+
if ($noSpaceAfterClosingParenthesis)echo 'hello';
300+
301+
do ; while ($i > 5);

src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,17 @@ if (false) {
326326
}
327327

328328
foreach ($array as $shouldNotTriggerSniff);
329+
330+
do { echo $i++;
331+
} while ($i < 5);
332+
333+
// phpcs:set Generic.ControlStructures.InlineControlStructure error false
334+
if ($something) { echo 'hello';
335+
}
336+
// phpcs:set Generic.ControlStructures.InlineControlStructure error true
337+
338+
if ($noSpaceAfterClosingParenthesis) { echo 'hello';
339+
}
340+
341+
do { ;
342+
} while ($i > 5);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// This should be the only test in this file.
4+
// There should be only empty tokens after the scope closer of the "if" token.
5+
6+
for ($i = 0; $i < 5; $i++)
7+
if ($i === 3) {
8+
echo $i;
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// This should be the only test in this file.
4+
// There should be only empty tokens after the scope closer of the "if" token.
5+
6+
for ($i = 0; $i < 5; $i++) {
7+
if ($i === 3) {
8+
echo $i;
9+
}
10+
}
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 (nothing after for closing parenthesis).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
for ($i = 0; $i < 5; $i++)
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 (nothing after while closing parenthesis).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
while ($i < 5)

src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public function getErrorList($testFile='')
8080
269 => 1,
8181
278 => 1,
8282
289 => 1,
83+
293 => 1,
84+
299 => 1,
85+
301 => 1,
86+
];
87+
88+
case 'InlineControlStructureUnitTest.10.inc':
89+
return [
90+
6 => 1,
8391
];
8492

8593
case 'InlineControlStructureUnitTest.1.js':
@@ -108,11 +116,21 @@ public function getErrorList($testFile='')
108116
* The key of the array should represent the line number and the value
109117
* should represent the number of warnings that should occur on that line.
110118
*
119+
* @param string $testFile The name of the file being tested.
120+
*
111121
* @return array<int, int>
112122
*/
113-
public function getWarningList()
123+
public function getWarningList($testFile='')
114124
{
115-
return [];
125+
switch ($testFile) {
126+
case 'InlineControlStructureUnitTest.1.inc':
127+
return [
128+
296 => 1,
129+
];
130+
131+
default:
132+
return [];
133+
}
116134

117135
}//end getWarningList()
118136

0 commit comments

Comments
 (0)