Skip to content

Commit bfdbad8

Browse files
committed
Generic/ForLoopWithTestFunctionCall: consolidate tests in the main file
This commit moves the tests for the alternative `for` syntax to the main test case file following a request during the PR review: PHPCSStandards#235 (comment) It also renames the subsequent test case files to keep the filenames consistent.
1 parent 45b1e7a commit bfdbad8

5 files changed

+36
-38
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
// This test case file only deals with the normal "for" loop syntax.
4-
53
$a = array(1, 2, 3, 4);
64
for ($i = 0; $i < count($a); $i++) {
75
$a[$i] *= $i;
@@ -23,3 +21,25 @@ for ($i = 0; MyClass::staticMethod($i); $i++) {
2321
for ($i = 0; $countFunction($i); $i++) {
2422
echo $i;
2523
}
24+
25+
$a = array(1, 2, 3, 4);
26+
for ($i = 0; $i < count($a); $i++):
27+
$a[$i] *= $i;
28+
endfor;
29+
30+
for ($i = 0, $c = sizeof($a); $i < $c; ++$i):
31+
$a[$i] *= $i;
32+
endfor;
33+
34+
$it = new ArrayIterator($a);
35+
for ($it->rewind(); $it->valid(); $it->next()):
36+
echo $it->current();
37+
endfor;
38+
39+
for ($i = 0; MyClass::staticMethod($i); $i++) :
40+
echo $i;
41+
endfor;
42+
43+
for ($i = 0; $countFunction($i); $i++):
44+
echo $i;
45+
endfor;
Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
<?php
22

3-
// This test case file only deals with the alternative "for" loop syntax.
4-
5-
$a = array(1, 2, 3, 4);
6-
for ($i = 0; $i < count($a); $i++):
7-
$a[$i] *= $i;
8-
endfor;
9-
10-
for ($i = 0, $c = sizeof($a); $i < $c; ++$i):
11-
$a[$i] *= $i;
12-
endfor;
13-
14-
$it = new ArrayIterator($a);
15-
for ($it->rewind(); $it->valid(); $it->next()):
16-
echo $it->current();
17-
endfor;
18-
19-
for ($i = 0; MyClass::staticMethod($i); $i++) :
20-
echo $i;
21-
endfor;
22-
23-
for ($i = 0; $countFunction($i); $i++):
24-
echo $i;
25-
endfor;
3+
// Intentional parse error (missing open parenthesis). Testing that the sniff is *not* triggered
4+
// in this case and that no PHP 8.3+ deprecation notice is thrown.
5+
for
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3-
// Intentional parse error (missing open parenthesis). Testing that the sniff is *not* triggered
3+
// Similar to issue PHPCSStandards/PHP_CodeSniffer#226
4+
// Intentional parse error (missing close parenthesis). Testing that the sniff is *not* triggered
45
// in this case and that no PHP 8.3+ deprecation notice is thrown.
5-
for
6+
for ($i = 0; $i < count($a); $i++

src/Standards/Generic/Tests/CodeAnalysis/ForLoopWithTestFunctionCallUnitTest.4.inc

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ public function getWarningList($testFile='')
4949
{
5050
switch ($testFile) {
5151
case 'ForLoopWithTestFunctionCallUnitTest.1.inc':
52-
case 'ForLoopWithTestFunctionCallUnitTest.2.inc':
5352
return [
54-
6 => 1,
55-
15 => 1,
56-
19 => 1,
57-
23 => 1,
53+
4 => 1,
54+
13 => 1,
55+
17 => 1,
56+
21 => 1,
57+
26 => 1,
58+
35 => 1,
59+
39 => 1,
60+
43 => 1,
5861
];
5962
default:
6063
return [];

0 commit comments

Comments
 (0)