Skip to content

Commit bd6641e

Browse files
committed
Improve test coverage of the LanguageConstructSpacing sniff
This sniff has an `else if` condition (https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/c855348766a424d23425eba5cc4420e26e4a3e38/src/Standards/Generic/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php#L131) to handle language constructs that are followed by some content without a space or opening parenthesis first. This code was not exercised by the automated tests. This commit adds a few examples to make sure this part of the code is covered.
1 parent 6355e6e commit bd6641e

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

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

Lines changed: 15 additions & 0 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

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

Lines changed: 15 additions & 0 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,6 +76,7 @@ return;
6276
return $blah;
6377
return $blah;
6478
return($blah);
79+
return $blah;
6580

6681
return $tab;
6782
return $newLine;

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,41 @@ public function getErrorList($testFile='')
3636
case 'LanguageConstructSpacingUnitTest.1.inc':
3737
return [
3838
3 => 1,
39-
7 => 1,
40-
11 => 1,
39+
5 => 1,
40+
8 => 1,
41+
10 => 1,
42+
13 => 1,
4143
15 => 1,
42-
19 => 1,
44+
18 => 1,
45+
20 => 1,
4346
23 => 1,
44-
27 => 1,
47+
25 => 1,
48+
28 => 1,
4549
30 => 1,
4650
33 => 1,
47-
34 => 1,
48-
35 => 1,
4951
36 => 1,
50-
38 => 1,
52+
39 => 1,
53+
40 => 1,
54+
43 => 1,
5155
44 => 1,
5256
45 => 1,
53-
46 => 2,
54-
49 => 1,
55-
51 => 1,
56-
59 => 1,
57-
61 => 1,
57+
46 => 1,
58+
48 => 1,
59+
52 => 1,
60+
55 => 1,
61+
56 => 1,
62+
57 => 2,
63+
60 => 1,
5864
63 => 1,
59-
67 => 1,
60-
70 => 1,
61-
71 => 1,
65+
65 => 1,
66+
73 => 1,
6267
75 => 1,
68+
77 => 1,
69+
81 => 1,
70+
83 => 1,
71+
85 => 1,
72+
86 => 1,
73+
90 => 1,
6374
];
6475

6576
default:

0 commit comments

Comments
 (0)