Skip to content

Commit 9627bea

Browse files
authored
Merge pull request #174 from rodrigoprimo/improve-test-coverage-arbitrary-parentheses-spacing
Generic/ArbitraryParenthesesSpacing: improve sniff code coverage
2 parents be32eca + afffe6c commit 9627bea

File tree

4 files changed

+71
-41
lines changed

4 files changed

+71
-41
lines changed

src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc renamed to src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.1.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,8 @@ class NonArbitraryParenthesesWithKeywords {
175175
$d = new parent( $foo,$bar );
176176
}
177177
}
178+
179+
// Test that the match expression does not trigger the sniff.
180+
$b = match ( $a ) {
181+
1 => true,
182+
};

src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed renamed to src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.1.inc.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,8 @@ class NonArbitraryParenthesesWithKeywords {
163163
$d = new parent( $foo,$bar );
164164
}
165165
}
166+
167+
// Test that the match expression does not trigger the sniff.
168+
$b = match ( $a ) {
169+
1 => true,
170+
};
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+
function something $param ) {}

src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,53 @@ class ArbitraryParenthesesSpacingUnitTest extends AbstractSniffUnitTest
2626
* The key of the array should represent the line number and the value
2727
* should represent the number of errors that should occur on that line.
2828
*
29+
* @param string $testFile The name of the file being tested.
30+
*
2931
* @return array<int, int>
3032
*/
31-
public function getErrorList()
33+
public function getErrorList($testFile='')
3234
{
33-
return [
34-
64 => 4,
35-
66 => 1,
36-
68 => 1,
37-
69 => 1,
38-
72 => 2,
39-
73 => 2,
40-
77 => 2,
41-
81 => 4,
42-
90 => 4,
43-
94 => 1,
44-
95 => 1,
45-
97 => 1,
46-
100 => 2,
47-
101 => 2,
48-
104 => 2,
49-
107 => 2,
50-
109 => 4,
51-
111 => 4,
52-
113 => 2,
53-
115 => 2,
54-
123 => 1,
55-
125 => 2,
56-
127 => 1,
57-
131 => 1,
58-
133 => 1,
59-
137 => 1,
60-
139 => 2,
61-
141 => 1,
62-
144 => 1,
63-
146 => 1,
64-
163 => 1,
65-
164 => 1,
66-
165 => 1,
67-
];
35+
switch ($testFile) {
36+
case 'ArbitraryParenthesesSpacingUnitTest.1.inc':
37+
return [
38+
64 => 4,
39+
66 => 1,
40+
68 => 1,
41+
69 => 1,
42+
72 => 2,
43+
73 => 2,
44+
77 => 2,
45+
81 => 4,
46+
90 => 4,
47+
94 => 1,
48+
95 => 1,
49+
97 => 1,
50+
100 => 2,
51+
101 => 2,
52+
104 => 2,
53+
107 => 2,
54+
109 => 4,
55+
111 => 4,
56+
113 => 2,
57+
115 => 2,
58+
123 => 1,
59+
125 => 2,
60+
127 => 1,
61+
131 => 1,
62+
133 => 1,
63+
137 => 1,
64+
139 => 2,
65+
141 => 1,
66+
144 => 1,
67+
146 => 1,
68+
163 => 1,
69+
164 => 1,
70+
165 => 1,
71+
];
72+
73+
default:
74+
return [];
75+
}//end switch
6876

6977
}//end getErrorList()
7078

@@ -75,14 +83,22 @@ public function getErrorList()
7583
* The key of the array should represent the line number and the value
7684
* should represent the number of warnings that should occur on that line.
7785
*
86+
* @param string $testFile The name of the file being tested.
87+
*
7888
* @return array<int, int>
7989
*/
80-
public function getWarningList()
90+
public function getWarningList($testFile='')
8191
{
82-
return [
83-
55 => 1,
84-
56 => 1,
85-
];
92+
switch ($testFile) {
93+
case 'ArbitraryParenthesesSpacingUnitTest.1.inc':
94+
return [
95+
55 => 1,
96+
56 => 1,
97+
];
98+
99+
default:
100+
return [];
101+
}//end switch
86102

87103
}//end getWarningList()
88104

0 commit comments

Comments
 (0)