@@ -189,101 +189,27 @@ function ($file) use ($fileHasAllowedType, $fileIsInAllowedDirectory) {
189
189
}
190
190
191
191
/**
192
- * Run the PSR2 code sniffs on the code
192
+ * Retrieves full list of codebase paths without any files/folders filtered out
193
193
*
194
- * @TODO: combine with testCodeStyle
195
- * @return void
194
+ * @return array
196
195
*/
197
- public function testCodeStylePsr2 ()
196
+ private function getFullWhitelist ()
198
197
{
199
- $ reportFile = self ::$ reportDir . '/phpcs_psr2_report.txt ' ;
200
- $ wrapper = new Wrapper ();
201
- $ codeSniffer = new CodeSniffer ('PSR2 ' , $ reportFile , $ wrapper );
202
- if (!$ codeSniffer ->canRun ()) {
203
- $ this ->markTestSkipped ('PHP Code Sniffer is not installed. ' );
204
- }
205
- if (version_compare ($ wrapper ->version (), '1.4.7 ' ) === -1 ) {
206
- $ this ->markTestSkipped ('PHP Code Sniffer Build Too Old. ' );
207
- }
208
-
209
- $ result = $ codeSniffer ->run (self ::getWhitelist ());
210
-
211
- $ output = "" ;
212
- if (file_exists ($ reportFile )) {
213
- $ output = file_get_contents ($ reportFile );
214
- }
215
- $ this ->assertEquals (
216
- 0 ,
217
- $ result ,
218
- "PHP Code Sniffer has found {$ result } error(s): " . PHP_EOL . $ output
219
- );
198
+ return Files::init ()->readLists (__DIR__ . '/_files/whitelist/common.txt ' );
220
199
}
221
200
222
- /**
223
- * Run the magento specific coding standards on the code
224
- *
225
- * @return void
226
- */
227
- public function testCodeStyle ()
201
+ public function testNoViolationsDetectedByPhpCodeSniffer ()
228
202
{
229
203
$ reportFile = self ::$ reportDir . '/phpcs_report.txt ' ;
230
- $ wrapper = new Wrapper ();
231
- $ codeSniffer = new CodeSniffer (realpath (__DIR__ . '/_files/phpcs ' ), $ reportFile , $ wrapper );
232
- if (!$ codeSniffer ->canRun ()) {
233
- $ this ->markTestSkipped ('PHP Code Sniffer is not installed. ' );
234
- }
235
- $ codeSniffer ->setExtensions (['php ' , 'phtml ' ]);
236
- $ result = $ codeSniffer ->run (self ::getWhitelist (['php ' , 'phtml ' ]));
237
-
238
- $ output = "" ;
239
- if (file_exists ($ reportFile )) {
240
- $ output = file_get_contents ($ reportFile );
241
- }
242
-
243
- $ this ->assertEquals (
244
- 0 ,
245
- $ result ,
246
- "PHP Code Sniffer has found {$ result } error(s): " . PHP_EOL . $ output
247
- );
248
- }
249
-
250
- /**
251
- * Run the annotations sniffs on the code
252
- *
253
- * @return void
254
- * @todo Combine with normal code style at some point.
255
- */
256
- public function testAnnotationStandard ()
257
- {
258
- $ reportFile = self ::$ reportDir . '/phpcs_annotations_report.txt ' ;
259
- $ wrapper = new Wrapper ();
260
- $ codeSniffer = new CodeSniffer (
261
- realpath (__DIR__ . '/../../../../framework/Magento/ruleset.xml ' ),
262
- $ reportFile ,
263
- $ wrapper
264
- );
265
- if (!$ codeSniffer ->canRun ()) {
266
- $ this ->markTestSkipped ('PHP Code Sniffer is not installed. ' );
267
- }
268
-
269
- $ result = $ codeSniffer ->run (self ::getWhitelist (['php ' ]));
270
- $ output = "" ;
271
- if (file_exists ($ reportFile )) {
272
- $ output = file_get_contents ($ reportFile );
273
- }
204
+ $ codeSniffer = new CodeSniffer ('Magento ' , $ reportFile , new Wrapper ());
274
205
$ this ->assertEquals (
275
206
0 ,
276
- $ result ,
277
- "PHP Code Sniffer has found {$ result } error (s): " . PHP_EOL . $ output
207
+ $ result = $ codeSniffer -> run ( $ this -> getFullWhitelist ()) ,
208
+ "PHP Code Sniffer detected {$ result } violation (s): " . PHP_EOL . file_get_contents ( $ reportFile )
278
209
);
279
210
}
280
211
281
- /**
282
- * Run mess detector on code
283
- *
284
- * @return void
285
- */
286
- public function testCodeMess ()
212
+ public function testNoViolationsDetectedByPhpMessDetector ()
287
213
{
288
214
$ reportFile = self ::$ reportDir . '/phpmd_report.txt ' ;
289
215
$ codeMessDetector = new CodeMessDetector (realpath (__DIR__ . '/_files/phpmd/ruleset.xml ' ), $ reportFile );
@@ -312,12 +238,7 @@ public function testCodeMess()
312
238
}
313
239
}
314
240
315
- /**
316
- * Run copy paste detector on code
317
- *
318
- * @return void
319
- */
320
- public function testCopyPaste ()
241
+ public function testNoViolationsDetectedByPhpCopyPasteDetector ()
321
242
{
322
243
$ reportFile = self ::$ reportDir . '/phpcpd_report.xml ' ;
323
244
$ copyPasteDetector = new CopyPasteDetector ($ reportFile );
0 commit comments