Skip to content

Commit f436108

Browse files
authored
Merge pull request #176 from rodrigoprimo/language-construct-spacing-improve-code-coverage
Generic/LanguageConstructSpacing: improve sniff code coverage
2 parents 9627bea + bd6641e commit f436108

File tree

4 files changed

+81
-34
lines changed

4 files changed

+81
-34
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,42 @@
22
echo $blah;
33
echo $blah;
44
echo($blah);
5+
echo$blah;
56

67
print $blah;
78
print $blah;
89
print($blah);
10+
print$blah;
911

1012
include $blah;
1113
include $blah;
1214
include($blah);
15+
include$blah;
1316

1417
include_once $blah;
1518
include_once $blah;
1619
include_once($blah);
20+
include_once$blah;
1721

1822
require $blah;
1923
require $blah;
2024
require($blah);
25+
require$blah;
2126

2227
require_once $blah;
2328
require_once $blah;
2429
require_once($blah);
30+
require_once$blah;
2531

2632
$obj = new MyClass();
2733
$obj = new MyClass();
2834

35+
$obj = new $className();
36+
$obj = new$className();
37+
2938
yield $blah;
3039
yield $blah;
40+
yield$blah;
3141

3242
yield from $test();
3343
yield FROM $test();
@@ -39,12 +49,16 @@ yield
3949

4050

4151
From $test();
52+
yield FROM$test();
4253

4354
throw new Exception();
4455
throw new Exception();
4556
throw new Exception();
4657
throw new Exception();
4758

59+
throw $exception;
60+
throw$exception;
61+
4862
namespace MyClass;
4963
namespace MyClass;
5064
namespace MyNamespace\MyClass;
@@ -66,6 +80,7 @@ return;
6680
return $blah;
6781
return $blah;
6882
return($blah);
83+
return$blah;
6984

7085
return $tab;
7186
return
@@ -74,6 +89,3 @@ $newLine;
7489
// The following line must have a single space at the end (after return)
7590
return
7691
$spaceAndNewLine;
77-
78-
// The following line must be the last line in the file
79-
return

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,40 @@
22
echo $blah;
33
echo $blah;
44
echo($blah);
5+
echo $blah;
56

67
print $blah;
78
print $blah;
89
print($blah);
10+
print $blah;
911

1012
include $blah;
1113
include $blah;
1214
include($blah);
15+
include $blah;
1316

1417
include_once $blah;
1518
include_once $blah;
1619
include_once($blah);
20+
include_once $blah;
1721

1822
require $blah;
1923
require $blah;
2024
require($blah);
25+
require $blah;
2126

2227
require_once $blah;
2328
require_once $blah;
2429
require_once($blah);
30+
require_once $blah;
2531

2632
$obj = new MyClass();
2733
$obj = new MyClass();
2834

35+
$obj = new $className();
36+
$obj = new $className();
37+
38+
yield $blah;
2939
yield $blah;
3040
yield $blah;
3141

@@ -35,12 +45,16 @@ YIELD from $test();
3545
yield from $test();
3646
yield from $test();
3747
yield From $test();
48+
yield FROM $test();
3849

3950
throw new Exception();
4051
throw new Exception();
4152
throw new Exception();
4253
throw new Exception();
4354

55+
throw $exception;
56+
throw $exception;
57+
4458
namespace MyClass;
4559
namespace MyClass;
4660
namespace MyNamespace\MyClass;
@@ -62,12 +76,10 @@ return;
6276
return $blah;
6377
return $blah;
6478
return($blah);
79+
return $blah;
6580

6681
return $tab;
6782
return $newLine;
6883

6984
// The following line must have a single space at the end (after return)
7085
return $spaceAndNewLine;
71-
72-
// The following line must be the last line in the file
73-
return
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+
return

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

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,56 @@ class LanguageConstructSpacingUnitTest 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-
3 => 1,
35-
7 => 1,
36-
11 => 1,
37-
15 => 1,
38-
19 => 1,
39-
23 => 1,
40-
27 => 1,
41-
30 => 1,
42-
33 => 1,
43-
34 => 1,
44-
35 => 1,
45-
36 => 1,
46-
38 => 1,
47-
44 => 1,
48-
45 => 1,
49-
46 => 2,
50-
49 => 1,
51-
51 => 1,
52-
59 => 1,
53-
61 => 1,
54-
63 => 1,
55-
67 => 1,
56-
70 => 1,
57-
71 => 1,
58-
75 => 1,
59-
];
35+
switch ($testFile) {
36+
case 'LanguageConstructSpacingUnitTest.1.inc':
37+
return [
38+
3 => 1,
39+
5 => 1,
40+
8 => 1,
41+
10 => 1,
42+
13 => 1,
43+
15 => 1,
44+
18 => 1,
45+
20 => 1,
46+
23 => 1,
47+
25 => 1,
48+
28 => 1,
49+
30 => 1,
50+
33 => 1,
51+
36 => 1,
52+
39 => 1,
53+
40 => 1,
54+
43 => 1,
55+
44 => 1,
56+
45 => 1,
57+
46 => 1,
58+
48 => 1,
59+
52 => 1,
60+
55 => 1,
61+
56 => 1,
62+
57 => 2,
63+
60 => 1,
64+
63 => 1,
65+
65 => 1,
66+
73 => 1,
67+
75 => 1,
68+
77 => 1,
69+
81 => 1,
70+
83 => 1,
71+
85 => 1,
72+
86 => 1,
73+
90 => 1,
74+
];
75+
76+
default:
77+
return [];
78+
}//end switch
6079

6180
}//end getErrorList()
6281

0 commit comments

Comments
 (0)