@@ -9,7 +9,9 @@ class DeclareStrictTypesSniffTest extends TestCase
9
9
10
10
public function testMultipleOpenTagsInFile (): void
11
11
{
12
- $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesMultipleOpenTags.php ' );
12
+ $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesMultipleOpenTags.php ' , [
13
+ 'declareOnFirstLine ' => true ,
14
+ ]);
13
15
self ::assertNoSniffErrorInFile ($ report );
14
16
}
15
17
@@ -79,7 +81,9 @@ public function testDeclareStrictTypesIncorrectFormat(string $file): void
79
81
80
82
public function testEmptyFile (): void
81
83
{
82
- $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesEmptyFile.php ' );
84
+ $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesEmptyFile.php ' , [
85
+ 'declareOnFirstLine ' => true ,
86
+ ]);
83
87
self ::assertNoSniffErrorInFile ($ report );
84
88
}
85
89
@@ -94,14 +98,16 @@ public function testDeclareStrictTypesIncorrectFormatNoSpaces(): void
94
98
public function testDeclareStrictTwoNewlinesBefore (): void
95
99
{
96
100
$ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesTwoNewlinesBefore.php ' , [
97
- 'newlinesCountBeforeDeclare ' => ' 2 ' ,
101
+ 'linesCountBeforeDeclare ' => ' 1 ' ,
98
102
]);
99
103
self ::assertNoSniffErrorInFile ($ report );
100
104
}
101
105
102
106
public function testDeclareStrictTwoNewlinesBeforeError (): void
103
107
{
104
- $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesTwoNewlinesBeforeError.php ' );
108
+ $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesTwoNewlinesBeforeError.php ' , [
109
+ 'declareOnFirstLine ' => true ,
110
+ ]);
105
111
self ::assertSniffError (
106
112
$ report ,
107
113
3 ,
@@ -113,7 +119,7 @@ public function testDeclareStrictTwoNewlinesBeforeError(): void
113
119
public function testDeclareStrictTwoNewlinesAfter (): void
114
120
{
115
121
$ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesTwoNewlinesAfter.php ' , [
116
- 'newlinesCountAfterDeclare ' => ' 2 ' ,
122
+ 'linesCountAfterDeclare ' => ' 1 ' ,
117
123
], [DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_AFTER_DECLARE ]);
118
124
self ::assertNoSniffErrorInFile ($ report );
119
125
}
@@ -125,91 +131,103 @@ public function testDeclareStrictTwoNewlinesAfterError(): void
125
131
$ report ,
126
132
3 ,
127
133
DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_AFTER_DECLARE ,
128
- 'Expected 2 newlines after declare statement, found 1 . '
134
+ 'Expected 1 lines after declare statement, found 0 . '
129
135
);
130
136
}
131
137
132
138
public function testDeclareStrictOneSpaceError (): void
133
139
{
134
140
$ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesOneSpaceError.php ' , [
135
- 'newlinesCountBeforeDeclare ' => '2 ' ,
141
+ 'linesCountBeforeDeclare ' => '1 ' ,
136
142
]);
137
143
self ::assertSniffError (
138
144
$ report ,
139
145
1 ,
140
146
DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ,
141
- 'Expected 2 newlines before declare statement, found 0. '
147
+ 'Expected 1 lines before declare statement, found 0. '
142
148
);
143
149
}
144
150
145
151
public function testDeclareStrictOneSpace (): void
146
152
{
147
- $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesOneSpace.php ' );
153
+ $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesOneSpace.php ' , [
154
+ 'declareOnFirstLine ' => true ,
155
+ ]);
148
156
self ::assertNoSniffErrorInFile ($ report );
149
157
}
150
158
151
159
public function testDeclareStrictWithFileCommentAbove (): void
152
160
{
153
161
$ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesWithFileCommentAbove.php ' , [
154
- 'newlinesCountBeforeDeclare ' => 2 ,
162
+ 'linesCountBeforeDeclare ' => 1 ,
155
163
]);
156
164
self ::assertNoSniffErrorInFile ($ report );
157
165
}
158
166
159
167
public function testDeclareStrictWithTicks (): void
160
168
{
161
- $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesWithTicks.php ' );
169
+ $ report = self ::checkFile (__DIR__ . '/data/declareStrictTypesWithTicks.php ' , [
170
+ 'declareOnFirstLine ' => true ,
171
+ ]);
162
172
self ::assertNoSniffErrorInFile ($ report );
163
173
}
164
174
165
175
public function testFixableNoNewLinesBefore (): void
166
176
{
167
177
$ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesNoNewLinesBefore.php ' , [
168
- 'newlinesCountBeforeDeclare ' => 0 ,
178
+ 'declareOnFirstLine ' => true ,
169
179
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING , DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ]);
170
180
self ::assertAllFixedInFile ($ report );
171
181
}
172
182
173
183
public function testFixableMissingNoNewLines (): void
174
184
{
175
185
$ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesMissingNoNewLines.php ' , [
176
- 'newlinesCountBeforeDeclare ' => 0 ,
186
+ 'declareOnFirstLine ' => true ,
177
187
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING , DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ]);
178
188
self ::assertAllFixedInFile ($ report );
179
189
}
180
190
181
191
public function testFixableOneNewLineBefore (): void
182
192
{
183
193
$ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesOneNewLineBefore.php ' , [
184
- 'newlinesCountBeforeDeclare ' => 1 ,
194
+ 'linesCountBeforeDeclare ' => 0 ,
185
195
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING , DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ]);
186
196
self ::assertAllFixedInFile ($ report );
187
197
}
188
198
189
199
public function testFixableMissingOneNewLine (): void
190
200
{
191
201
$ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesMissingOneNewLine.php ' , [
192
- 'newlinesCountBeforeDeclare ' => 1 ,
202
+ 'linesCountBeforeDeclare ' => 0 ,
193
203
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING , DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ]);
194
204
self ::assertAllFixedInFile ($ report );
195
205
}
196
206
197
207
public function testFixableMoreNewLinesBefore (): void
198
208
{
199
209
$ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesMoreNewLinesBefore.php ' , [
200
- 'newlinesCountBeforeDeclare ' => 4 ,
210
+ 'linesCountBeforeDeclare ' => 3 ,
201
211
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING , DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ]);
202
212
self ::assertAllFixedInFile ($ report );
203
213
}
204
214
205
215
public function testFixableMissingMoreNewLines (): void
206
216
{
207
217
$ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesMissingMoreNewLines.php ' , [
208
- 'newlinesCountBeforeDeclare ' => 4 ,
218
+ 'linesCountBeforeDeclare ' => 3 ,
209
219
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING , DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ]);
210
220
self ::assertAllFixedInFile ($ report );
211
221
}
212
222
223
+ public function testFixableCommentBefore (): void
224
+ {
225
+ $ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesCommentBefore.php ' , [
226
+ 'linesCountBeforeDeclare ' => 1 ,
227
+ ], [DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ]);
228
+ self ::assertAllFixedInFile ($ report );
229
+ }
230
+
213
231
public function testFixableMissingIncorrectFormatOneSpace (): void
214
232
{
215
233
$ report = self ::checkFile (
@@ -259,33 +277,17 @@ public function testFixableDisabled(): void
259
277
public function testFixableOneNewLineAfter (): void
260
278
{
261
279
$ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesOneNewLineAfter.php ' , [
262
- 'newlinesCountAfterDeclare ' => 2 ,
263
- ], [DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_AFTER_DECLARE ]);
264
- self ::assertAllFixedInFile ($ report );
265
- }
266
-
267
- public function testFixableNoNewLinesAfter (): void
268
- {
269
- $ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesNoNewLinesAfter.php ' , [
270
- 'newlinesCountAfterDeclare ' => 0 ,
280
+ 'linesCountAfterDeclare ' => 1 ,
271
281
], [DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_AFTER_DECLARE ]);
272
282
self ::assertAllFixedInFile ($ report );
273
283
}
274
284
275
285
public function testFixableMoreNewLinesAfter (): void
276
286
{
277
287
$ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesMoreNewLinesAfter.php ' , [
278
- 'newlinesCountAfterDeclare ' => 4 ,
288
+ 'linesCountAfterDeclare ' => 3 ,
279
289
], [DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_AFTER_DECLARE ]);
280
290
self ::assertAllFixedInFile ($ report );
281
291
}
282
292
283
- public function testFixableCommentBefore (): void
284
- {
285
- $ report = self ::checkFile (__DIR__ . '/data/fixableDeclareStrictTypesCommentBefore.php ' , [
286
- 'newlinesCountBeforeDeclare ' => 2 ,
287
- ], [DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE ]);
288
- self ::assertAllFixedInFile ($ report );
289
- }
290
-
291
293
}
0 commit comments