1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of PHP CS Fixer. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
7
|
|
|
* Dariusz Rumiński <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This source file is subject to the MIT license that is bundled |
10
|
|
|
* with this source code in the file LICENSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Addiks\MorePhpCsFixers\Tests\Unit\Whitespace; |
14
|
|
|
|
15
|
|
|
use PhpCsFixer\Tests\Test\AbstractFixerTestCase; |
16
|
|
|
use Addiks\MorePhpCsFixers\Whitespace\BlankLineBeforeElseBlockFixer; |
17
|
|
|
use PhpCsFixer\FixerDefinition\FixerDefinition; |
18
|
|
|
use PhpCsFixer\FixerDefinition\CodeSample; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @internal |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
final class BlankLineBeforeElseBlockFixerTest extends AbstractFixerTestCase |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param string $expected |
27
|
|
|
* @param null|string $input |
28
|
|
|
* |
29
|
|
|
* @dataProvider provideFixCases |
30
|
|
|
*/ |
31
|
|
|
public function testFix($expected, $input = null) |
32
|
|
|
{ |
33
|
|
|
$this->doTest($expected, $input); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function provideFixCases() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
[ |
40
|
|
|
'<?php |
41
|
|
|
if ($a) { |
42
|
|
|
foo(); |
43
|
|
|
|
44
|
|
|
} elseif ($b) { |
45
|
|
|
bar(); |
46
|
|
|
|
47
|
|
|
} else { |
48
|
|
|
baz(); |
49
|
|
|
}', |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
'<?php |
53
|
|
|
if ($a) { |
54
|
|
|
foo(); |
55
|
|
|
|
56
|
|
|
} elseif ($b) { |
57
|
|
|
bar(); |
58
|
|
|
|
59
|
|
|
} else { |
60
|
|
|
baz(); |
61
|
|
|
}', |
62
|
|
|
'<?php |
63
|
|
|
if ($a) { |
64
|
|
|
foo(); |
65
|
|
|
} elseif ($b) { |
66
|
|
|
bar(); |
67
|
|
|
} else { |
68
|
|
|
baz(); |
69
|
|
|
}', |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
'<?php |
73
|
|
|
if ($a) { |
74
|
|
|
foo(); |
75
|
|
|
|
76
|
|
|
} elseif ($b) { |
77
|
|
|
bar(); |
78
|
|
|
|
79
|
|
|
} else { |
80
|
|
|
baz(); |
81
|
|
|
}', |
82
|
|
|
'<?php |
83
|
|
|
if ($a) { |
84
|
|
|
foo(); |
85
|
|
|
} elseif ($b) { |
86
|
|
|
bar(); |
87
|
|
|
} else { |
88
|
|
|
baz(); |
89
|
|
|
}', |
90
|
|
|
], |
91
|
|
|
[ |
92
|
|
|
'<?php |
93
|
|
|
if ($a) { |
94
|
|
|
foo(); |
95
|
|
|
|
96
|
|
|
/* Lorem ipsum */} elseif ($b) { |
97
|
|
|
bar(); |
98
|
|
|
|
99
|
|
|
} else { |
100
|
|
|
baz(); |
101
|
|
|
}', |
102
|
|
|
'<?php |
103
|
|
|
if ($a) { |
104
|
|
|
foo(); |
105
|
|
|
/* Lorem ipsum */} elseif ($b) { |
106
|
|
|
bar(); |
107
|
|
|
} else { |
108
|
|
|
baz(); |
109
|
|
|
}', |
110
|
|
|
], |
111
|
|
|
[ |
112
|
|
|
'<?php if ($a) {foo();} elseif ($b) {bar();} else {baz();}', |
113
|
|
|
], |
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
*/ |
120
|
|
|
public function shouldHaveAFixerDefinition() |
121
|
|
|
{ |
122
|
|
|
$this->assertEquals( |
123
|
|
|
new FixerDefinition( |
124
|
|
|
'An empty line feed must precede any else or elseif codeblock.', |
125
|
|
|
[ |
126
|
|
|
new CodeSample( |
127
|
|
|
'<?php |
128
|
|
|
if ($a) { |
129
|
|
|
foo(); |
130
|
|
|
|
131
|
|
|
} elseif ($b) { |
132
|
|
|
bar(); |
133
|
|
|
|
134
|
|
|
} else { |
135
|
|
|
baz(); |
136
|
|
|
} |
137
|
|
|
' |
138
|
|
|
), |
139
|
|
|
] |
140
|
|
|
), |
141
|
|
|
$this->createFixer()->getDefinition() |
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @test |
147
|
|
|
*/ |
148
|
|
|
public function shouldHaveTheRightPriority() |
149
|
|
|
{ |
150
|
|
|
$this->assertEquals(-26, $this->createFixer()->getPriority()); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
protected function createFixer() |
154
|
|
|
{ |
155
|
|
|
return new BlankLineBeforeElseBlockFixer(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.