Skip to content

Commit 73d8ff4

Browse files
committed
Generic/InlineControlStructure: improve code coverage
1 parent 8820099 commit 73d8ff4

11 files changed

+140
-2
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,22 @@ foreach ($array as $sniffShouldBailEarly)
297297
/* some comment */;
298298

299299
do ; while ($sniffShouldBailEarly > 5);
300+
301+
do echo $i++; while ($i < 5);
302+
303+
// phpcs:set Generic.ControlStructures.InlineControlStructure error false
304+
if ($something) echo 'hello';
305+
// phpcs:set Generic.ControlStructures.InlineControlStructure error true
306+
307+
for ($i = 0; $i < 5; $i++)
308+
if ($i === 3) {
309+
echo 'three';
310+
} elseif ($i === 4) {
311+
echo 'four';
312+
} elseif ($i === 5) {
313+
echo 'five';
314+
}
315+
316+
if ($noSpaceAfterClosingParenthesis)echo 'hello'; ?>
317+
318+
<?php if ( $model->scenario == 'simple' ) $widget->renderPager() ?>

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,26 @@ foreach ($array as $sniffShouldBailEarly)
336336
/* some comment */;
337337

338338
do ; while ($sniffShouldBailEarly > 5);
339+
340+
do { echo $i++;
341+
} while ($i < 5);
342+
343+
// phpcs:set Generic.ControlStructures.InlineControlStructure error false
344+
if ($something) { echo 'hello';
345+
}
346+
// phpcs:set Generic.ControlStructures.InlineControlStructure error true
347+
348+
for ($i = 0; $i < 5; $i++) {
349+
if ($i === 3) {
350+
echo 'three';
351+
} elseif ($i === 4) {
352+
echo 'four';
353+
} elseif ($i === 5) {
354+
echo 'five';
355+
}
356+
}
357+
358+
if ($noSpaceAfterClosingParenthesis) { echo 'hello';
359+
} ?>
360+
361+
<?php if ( $model->scenario == 'simple' ) { $widget->renderPager(); } ?>
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// Intentional parse error (missing semicolon). Should still trigger the sniff error.
4+
// This should be the only test in this file.
5+
// This test should explicitly NOT contain a new line at the end of the file.
6+
7+
if ($bar)
8+
doSomething()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// Intentional parse error (missing semicolon). Should still trigger the sniff error.
4+
// This should be the only test in this file.
5+
// This test should explicitly NOT contain a new line at the end of the file.
6+
7+
if ($bar) {
8+
doSomething();
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// Intentional parse error (nothing after else).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
if ($bar) {
8+
doSomething();
9+
} else
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
// Intentional parse error (missing closing brace for the first if).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
// Test for https://github.com/squizlabs/PHP_CodeSniffer/pull/2989.
7+
8+
if ( true ) {
9+
10+
// This second if is here to ensure that the sniff completely bows out of this file after
11+
// encountering the first one without a closing brace.
12+
if ( true )
13+
echo 'foo';
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)

0 commit comments

Comments
 (0)