Skip to content

Commit fd7b175

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/JumbledIncrementer: improve test coverage
This commit adds tests for: - for alternative syntax - for loops missing one or more condition parts - sniff bails early when it encounters a parse error (missing for body and inner for loop missing opening parenthesis - for loops with more than one incrementer - for loops with decrementers
1 parent 6dc74f2 commit fd7b175

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

src/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.1.inc

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,68 @@ for ($i = 0; $i < 20; $i++) {
2222

2323
}
2424
}
25-
}
25+
}
26+
27+
for (; $i < 10; $i++) {
28+
for ($j = 0;; $j++) {
29+
if ($j > 5) {
30+
break;
31+
}
32+
for (;; $k++) {
33+
if ($k > 5) {
34+
break;
35+
}
36+
}
37+
}
38+
}
39+
40+
for (; $same < 10; $same++) {
41+
for ($j = 0;; $same++) {
42+
if ($j > 5) {
43+
break;
44+
}
45+
for (;; $same++) {
46+
if ($k > 5) {
47+
break;
48+
}
49+
}
50+
}
51+
}
52+
53+
for ($i = 0; $i < 20; $i++) :
54+
for ($j = 0; $j < 5; $j += 2) :
55+
endfor;
56+
endfor;
57+
58+
for ($same = 0; $same < 20; $same++) :
59+
for ($j = 0; $j < 5; $same += 2) :
60+
endfor;
61+
endfor;
62+
63+
// Sniff bails early when there is no incrementor in the third expression of the outer for loop.
64+
for ($same = 0; $same < 10;) {
65+
++$same;
66+
for ($j = 0; $j < 5; $same++) {}
67+
}
68+
69+
for ($i = 1, $same = 0; $i <= 10; $i++, $same++) {
70+
for ($same = 0, $k = 0; $k < 5; $same++, $k++) {}
71+
}
72+
73+
for ($i = 20; $i > 0; $i--) {
74+
for ($j = 5; $j > 0; $j -= 2) {
75+
for ($k = 3; $k > 0; $k--) {}
76+
}
77+
}
78+
79+
for ($same = 20; $same > 0; $same--) {
80+
for ($j = 5; $j > 0; $same -= 2) {
81+
for ($k = 3; $k > 0; $same--) {}
82+
}
83+
}
84+
85+
for ($i = 0; $i < 20; $i++);
86+
87+
for ($same = 0; $same < 20; $same++) {
88+
for ($j = 0; $j < 20; $same++);
89+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
// Intentional parse error (missing for conditions).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
for
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 (inner for loop missing opening parenthesis).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
for ($i = 0; $i < 20; $i++) {
7+
for
8+
}

src/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ public function getWarningList($testFile='')
5353
3 => 2,
5454
4 => 1,
5555
20 => 1,
56+
40 => 2,
57+
41 => 1,
58+
58 => 1,
59+
69 => 1,
60+
79 => 2,
61+
80 => 1,
62+
87 => 1,
5663
];
5764

5865
default:

0 commit comments

Comments
 (0)