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\BlankLineBeforeCatchBlockFixer; |
17
|
|
|
use PhpCsFixer\FixerDefinition\FixerDefinition; |
18
|
|
|
use PhpCsFixer\FixerDefinition\CodeSample; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @internal |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
final class BlankLineBeforeCatchBlockFixerTest 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
|
|
|
try { |
42
|
|
|
foo(); |
43
|
|
|
|
44
|
|
|
} catch (\Exception $b) { |
45
|
|
|
bar(); |
46
|
|
|
|
47
|
|
|
} finally { |
48
|
|
|
baz(); |
49
|
|
|
}', |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
'<?php |
53
|
|
|
try { |
54
|
|
|
foo(); |
55
|
|
|
|
56
|
|
|
} catch (\Exception $b) { |
57
|
|
|
bar(); |
58
|
|
|
|
59
|
|
|
} finally { |
60
|
|
|
baz(); |
61
|
|
|
}', |
62
|
|
|
'<?php |
63
|
|
|
try { |
64
|
|
|
foo(); |
65
|
|
|
} catch (\Exception $b) { |
66
|
|
|
bar(); |
67
|
|
|
} finally { |
68
|
|
|
baz(); |
69
|
|
|
}', |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
'<?php |
73
|
|
|
try { |
74
|
|
|
foo(); |
75
|
|
|
|
76
|
|
|
} catch (\Exception $b) { |
77
|
|
|
bar(); |
78
|
|
|
|
79
|
|
|
} finally { |
80
|
|
|
baz(); |
81
|
|
|
}', |
82
|
|
|
'<?php |
83
|
|
|
try { |
84
|
|
|
foo(); |
85
|
|
|
} catch (\Exception $b) { |
86
|
|
|
bar(); |
87
|
|
|
} finally { |
88
|
|
|
baz(); |
89
|
|
|
}', |
90
|
|
|
], |
91
|
|
|
[ |
92
|
|
|
'<?php |
93
|
|
|
try { |
94
|
|
|
foo(); |
95
|
|
|
|
96
|
|
|
/* Lorem ipsum */} catch (\Exception $b) { |
97
|
|
|
bar(); |
98
|
|
|
|
99
|
|
|
} finally { |
100
|
|
|
baz(); |
101
|
|
|
}', |
102
|
|
|
'<?php |
103
|
|
|
try { |
104
|
|
|
foo(); |
105
|
|
|
/* Lorem ipsum */} catch (\Exception $b) { |
106
|
|
|
bar(); |
107
|
|
|
} finally { |
108
|
|
|
baz(); |
109
|
|
|
}', |
110
|
|
|
], |
111
|
|
|
[ |
112
|
|
|
'<?php try {foo();} catch (\Exception $b) {bar();} finally {baz();}', |
113
|
|
|
], |
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
*/ |
120
|
|
|
public function shouldHaveTheRightPriority() |
121
|
|
|
{ |
122
|
|
|
$this->assertEquals(-26, $this->createFixer()->getPriority()); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @test |
127
|
|
|
*/ |
128
|
|
|
public function shouldHaveAFixerDefinition() |
129
|
|
|
{ |
130
|
|
|
$this->assertEquals( |
131
|
|
|
new FixerDefinition( |
132
|
|
|
'An empty line feed must precede any catch or finally codeblock.', |
133
|
|
|
[ |
134
|
|
|
new CodeSample( |
135
|
|
|
'<?php |
136
|
|
|
try { |
137
|
|
|
foo(); |
138
|
|
|
|
139
|
|
|
} catch (\Exception $b) { |
140
|
|
|
bar(); |
141
|
|
|
|
142
|
|
|
} finally { |
143
|
|
|
baz(); |
144
|
|
|
} |
145
|
|
|
' |
146
|
|
|
), |
147
|
|
|
] |
148
|
|
|
), |
149
|
|
|
$this->createFixer()->getDefinition() |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
protected function createFixer() |
154
|
|
|
{ |
155
|
|
|
return new BlankLineBeforeCatchBlockFixer(); |
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.