Skip to content

Commit 88d3cec

Browse files
authored
Merge pull request #163 from rodrigoprimo/update-assignement-in-condition-code-coverage
Generic/AssignmentInCondition: improve sniff code coverage
2 parents 186814f + 1fad6ab commit 88d3cec

7 files changed

+70
-37
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
// Intentional parse error. Testing that the sniff is *not* triggered in this case.
4+
if ($a == 123
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
// Intentional parse error. Testing that the sniff is *not* triggered in this case.
4+
for ($i = 0; $i == 100; $i++
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. Testing that the sniff is *not* triggered in this case.
4+
for ($i = 0) {
5+
echo 'foo';
6+
}
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. Testing that the sniff is *not* triggered in this case.
4+
for ($i = 0; $i == 100) {
5+
echo 'foo';
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
// Intentional parse error. Testing that the sniff is *not* triggered in this case.
4+
switch ( true ) {
5+
case $sample == 'something'

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

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,46 +41,54 @@ public function getErrorList()
4141
* The key of the array should represent the line number and the value
4242
* should represent the number of warnings that should occur on that line.
4343
*
44+
* @param string $testFile The name of the file being tested.
45+
*
4446
* @return array<int, int>
4547
*/
46-
public function getWarningList()
48+
public function getWarningList($testFile='')
4749
{
48-
return [
49-
46 => 1,
50-
47 => 1,
51-
48 => 1,
52-
49 => 1,
53-
50 => 1,
54-
51 => 1,
55-
52 => 1,
56-
53 => 1,
57-
54 => 1,
58-
55 => 1,
59-
56 => 1,
60-
57 => 1,
61-
58 => 1,
62-
59 => 1,
63-
60 => 1,
64-
61 => 2,
65-
63 => 1,
66-
64 => 1,
67-
67 => 1,
68-
68 => 1,
69-
69 => 1,
70-
70 => 1,
71-
71 => 1,
72-
72 => 1,
73-
73 => 1,
74-
75 => 1,
75-
77 => 1,
76-
80 => 2,
77-
84 => 1,
78-
85 => 2,
79-
88 => 1,
80-
90 => 1,
81-
92 => 1,
82-
95 => 1,
83-
];
50+
switch ($testFile) {
51+
case 'AssignmentInConditionUnitTest.1.inc':
52+
return [
53+
46 => 1,
54+
47 => 1,
55+
48 => 1,
56+
49 => 1,
57+
50 => 1,
58+
51 => 1,
59+
52 => 1,
60+
53 => 1,
61+
54 => 1,
62+
55 => 1,
63+
56 => 1,
64+
57 => 1,
65+
58 => 1,
66+
59 => 1,
67+
60 => 1,
68+
61 => 2,
69+
63 => 1,
70+
64 => 1,
71+
67 => 1,
72+
68 => 1,
73+
69 => 1,
74+
70 => 1,
75+
71 => 1,
76+
72 => 1,
77+
73 => 1,
78+
75 => 1,
79+
77 => 1,
80+
80 => 2,
81+
84 => 1,
82+
85 => 2,
83+
88 => 1,
84+
90 => 1,
85+
92 => 1,
86+
95 => 1,
87+
];
88+
89+
default:
90+
return [];
91+
}//end switch
8492

8593
}//end getWarningList()
8694

0 commit comments

Comments
 (0)