Skip to content

Commit 5434f45

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-31575' into static_tests
2 parents f1d581f + fc00959 commit 5434f45

File tree

14 files changed

+168
-475
lines changed

14 files changed

+168
-475
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
*
4+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
5+
*/
6+
7+
namespace Magento\TestFramework\CodingStandard\Tool;
8+
9+
interface BlacklistInterface
10+
{
11+
/**
12+
* Set list of paths to be excluded from tool run
13+
*
14+
* @param array $blackList
15+
* @return void
16+
*/
17+
public function setBlackList(array $blackList);
18+
}

dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CodeMessDetector.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88
*/
99
namespace Magento\TestFramework\CodingStandard\Tool;
1010

11-
class CodeMessDetector implements \Magento\TestFramework\CodingStandard\ToolInterface
11+
use \Magento\TestFramework\CodingStandard\ToolInterface;
12+
13+
class CodeMessDetector implements ToolInterface
1214
{
1315
/**
1416
* Ruleset directory
1517
*
1618
* @var string
1719
*/
18-
protected $_rulesetFile;
20+
private $rulesetFile;
1921

2022
/**
2123
* Report file
2224
*
2325
* @var string
2426
*/
25-
protected $_reportFile;
27+
private $reportFile;
2628

2729
/**
2830
* Constructor
@@ -32,8 +34,8 @@ class CodeMessDetector implements \Magento\TestFramework\CodingStandard\ToolInte
3234
*/
3335
public function __construct($rulesetFile, $reportFile)
3436
{
35-
$this->_reportFile = $reportFile;
36-
$this->_rulesetFile = $rulesetFile;
37+
$this->reportFile = $reportFile;
38+
$this->rulesetFile = $rulesetFile;
3739
}
3840

3941
/**
@@ -47,25 +49,21 @@ public function canRun()
4749
}
4850

4951
/**
50-
* Run tool for files specified
51-
*
52-
* @param array $whiteList Files/directories to be inspected
53-
* @param array $blackList Files/directories to be excluded from the inspection
54-
* @param array $extensions Array of alphanumeric strings, for example: 'php', 'xml', 'phtml', 'css'...
55-
*
56-
* @return int
52+
* {@inheritdoc}
5753
*/
58-
public function run(array $whiteList, array $blackList = [], array $extensions = [])
54+
public function run(array $whiteList)
5955
{
56+
if (empty($whiteList)) {
57+
return \PHP_PMD_TextUI_Command::EXIT_SUCCESS;
58+
}
59+
6060
$commandLineArguments = [
6161
'run_file_mock', //emulate script name in console arguments
6262
implode(',', $whiteList),
6363
'xml', //report format
64-
$this->_rulesetFile,
65-
'--exclude',
66-
implode(',', $blackList),
64+
$this->rulesetFile,
6765
'--reportfile',
68-
$this->_reportFile,
66+
$this->reportFile,
6967
];
7068

7169
$options = new \PHP_PMD_TextUI_CommandLineOptions($commandLineArguments);

dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CodeSniffer.php

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,35 @@
1111
use Magento\TestFramework\CodingStandard\Tool\CodeSniffer\Wrapper;
1212
use Magento\TestFramework\CodingStandard\ToolInterface;
1313

14-
class CodeSniffer implements ToolInterface
14+
class CodeSniffer implements ToolInterface, ExtensionInterface
1515
{
1616
/**
1717
* Ruleset directory
1818
*
1919
* @var string
2020
*/
21-
protected $rulesetDir;
21+
private $rulesetDir;
2222

2323
/**
2424
* Report file
2525
*
2626
* @var string
2727
*/
28-
protected $reportFile;
28+
private $reportFile;
2929

3030
/**
3131
* PHPCS cli tool wrapper
3232
*
3333
* @var Wrapper
3434
*/
35-
protected $wrapper;
35+
private $wrapper;
36+
37+
/**
38+
* List of extensions for tool run
39+
*
40+
* @var array
41+
*/
42+
private $extensions = ['php'];
3643

3744
/**
3845
* Constructor
@@ -49,64 +56,41 @@ public function __construct($rulesetDir, $reportFile, Wrapper $wrapper)
4956
}
5057

5158
/**
52-
* Whether the tool can be ran on the current environment
53-
*
54-
* @return bool
59+
* {@inheritdoc}
5560
*/
56-
public function canRun()
61+
public function setExtensions(array $extensions)
5762
{
58-
return class_exists('PHP_CodeSniffer_CLI');
63+
$this->extensions = $extensions;
5964
}
6065

6166
/**
62-
* Return the version of code sniffer found
67+
* Whether the tool can be ran on the current environment
6368
*
64-
* @return string
69+
* @return bool
6570
*/
66-
public function version()
71+
public function canRun()
6772
{
68-
return $this->wrapper->version();
73+
return class_exists('PHP_CodeSniffer_CLI');
6974
}
7075

7176
/**
72-
* Run tool for files specified
73-
*
74-
* @param array $whiteList Files/directories to be inspected
75-
* @param array $blackList Files/directories to be excluded from the inspection
76-
* @param array $extensions Array of alphanumeric strings, for example: 'php', 'xml', 'phtml', 'css'...
77-
* @param int $warningSeverity Severity level of warnings, default is 0
78-
*
79-
* @return int
77+
* {@inheritdoc}
8078
*/
81-
public function run(
82-
array $whiteList,
83-
array $blackList = [],
84-
array $extensions = [],
85-
$warningSeverity = 0
86-
) {
87-
$whiteList = array_map(
88-
function ($item) {
89-
return $item;
90-
},
91-
$whiteList
92-
);
93-
94-
$blackList = array_map(
95-
function ($item) {
96-
return preg_quote($item);
97-
},
98-
$blackList
99-
);
79+
public function run(array $whiteList)
80+
{
81+
if (empty($whiteList)) {
82+
return 0;
83+
}
10084

10185
$this->wrapper->checkRequirements();
10286
$settings = $this->wrapper->getDefaults();
10387
$settings['files'] = $whiteList;
10488
$settings['standard'] = [$this->rulesetDir];
105-
$settings['ignored'] = $blackList;
106-
$settings['extensions'] = $extensions;
89+
$settings['extensions'] = $this->extensions;
10790
$settings['reportFile'] = $this->reportFile;
108-
$settings['warningSeverity'] = $warningSeverity;
91+
$settings['warningSeverity'] = 0;
10992
$settings['reports']['checkstyle'] = null;
93+
11094
$this->wrapper->setValues($settings);
11195

11296
ob_start();
@@ -115,14 +99,4 @@ function ($item) {
11599

116100
return $result;
117101
}
118-
119-
/**
120-
* Get report file
121-
*
122-
* @return string
123-
*/
124-
public function getReportFile()
125-
{
126-
return $this->reportFile;
127-
}
128102
}

dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CopyPasteDetector.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@
88
*/
99
namespace Magento\TestFramework\CodingStandard\Tool;
1010

11-
class CopyPasteDetector implements \Magento\TestFramework\CodingStandard\ToolInterface
11+
use Magento\TestFramework\CodingStandard\ToolInterface;
12+
13+
class CopyPasteDetector implements ToolInterface, BlacklistInterface
1214
{
1315
/**
1416
* Report file
1517
*
1618
* @var string
1719
*/
18-
protected $_reportFile;
20+
private $reportFile;
21+
22+
/**
23+
* List of paths to be excluded from tool run
24+
*
25+
* @var array
26+
*/
27+
private $blacklist;
1928

2029
/**
2130
* Constructor
@@ -24,7 +33,15 @@ class CopyPasteDetector implements \Magento\TestFramework\CodingStandard\ToolInt
2433
*/
2534
public function __construct($reportFile)
2635
{
27-
$this->_reportFile = $reportFile;
36+
$this->reportFile = $reportFile;
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function setBlackList(array $blackList)
43+
{
44+
$this->blacklist = $blackList;
2845
}
2946

3047
/**
@@ -44,17 +61,14 @@ public function canRun()
4461
* Run tool for files specified
4562
*
4663
* @param array $whiteList Files/directories to be inspected
47-
* @param array $blackList Files/directories to be excluded from the inspection
48-
* @param array $extensions Array of alphanumeric strings, for example: 'php', 'xml', 'phtml', 'css'...
64+
* @return int
4965
*
5066
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
51-
*
52-
* @return int
5367
*/
54-
public function run(array $whiteList, array $blackList = [], array $extensions = [])
68+
public function run(array $whiteList)
5569
{
5670
$blackListStr = ' ';
57-
foreach ($blackList as $file) {
71+
foreach ($this->blacklist as $file) {
5872
$file = escapeshellarg(trim($file));
5973
if (!$file) {
6074
continue;
@@ -63,8 +77,8 @@ public function run(array $whiteList, array $blackList = [], array $extensions =
6377
}
6478

6579
$command = 'phpcpd' . ' --log-pmd ' . escapeshellarg(
66-
$this->_reportFile
67-
) . ' --min-lines 13' . $blackListStr . ' ' . BP;
80+
$this->reportFile
81+
) . ' --min-lines 13' . $blackListStr . ' ' . implode(' ', $whiteList);
6882

6983
exec($command, $output, $exitCode);
7084

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
*
4+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
5+
*/
6+
7+
namespace Magento\TestFramework\CodingStandard\Tool;
8+
9+
interface ExtensionInterface
10+
{
11+
/**
12+
* Set extensions for tool to run
13+
* Example: 'php', 'xml', 'phtml', 'css'
14+
*
15+
* @param array $extensions
16+
* @return void
17+
*/
18+
public function setExtensions(array $extensions);
19+
}

dev/tests/static/framework/Magento/TestFramework/CodingStandard/ToolInterface.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ interface ToolInterface
1818
public function canRun();
1919

2020
/**
21-
* Run tool for files cpecified
21+
* Run tool for files specified
2222
*
2323
* @param array $whiteList Files/directories to be inspected
24-
* @param array $blackList Files/directories to be excluded from the inspection
25-
* @param array $extensions Array of alphanumeric strings, for example: 'php', 'xml', 'phtml', 'css'...
26-
*
2724
* @return int
2825
*/
29-
public function run(array $whiteList, array $blackList = [], array $extensions = []);
26+
public function run(array $whiteList);
3027
}

dev/tests/static/framework/Magento/TestFramework/Utility/ChangedFiles.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
namespace Magento\TestFramework\Utility;
77

8+
use Magento\Framework\Test\Utility\Files;
9+
810
/**
911
* A helper to gather various changed files
1012
* if INCREMENTAL_BUILD env variable is set by CI build infrastructure, only files changed in the
@@ -23,7 +25,12 @@ public static function getPhpFiles($changedFilesList)
2325
$fileHelper = \Magento\Framework\Test\Utility\Files::init();
2426
$allPhpFiles = $fileHelper->getPhpFiles();
2527
if (isset($_ENV['INCREMENTAL_BUILD'])) {
26-
$phpFiles = file($changedFilesList, FILE_IGNORE_NEW_LINES);
28+
try {
29+
$phpFiles = Files::readLists($changedFilesList);
30+
} catch (\Exception $e){
31+
$phpFiles = [];
32+
}
33+
2734
foreach ($phpFiles as $key => $phpFile) {
2835
$phpFiles[$key] = $fileHelper->getPathToSource() . '/' . $phpFile;
2936
}

dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/CodingStandard/Tool/CodeSnifferTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,4 @@ public function testRun()
6060

6161
$this->_tool->run($whiteList, $blackList, $extensions);
6262
}
63-
64-
public function testGetReportFile()
65-
{
66-
$this->assertEquals(self::REPORT_FILE, $this->_tool->getReportFile());
67-
}
6863
}

dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function ($file) {
129129
$this->_testObsoleteConstants($content);
130130
$this->_testObsoletePropertySkipCalculate($content);
131131
},
132-
\Magento\TestFramework\Utility\ChangedFiles::getPhpFiles(__DIR__ . '/_files/changed_files.txt')
132+
\Magento\TestFramework\Utility\ChangedFiles::getPhpFiles(__DIR__ . '/_files/changed_files')
133133
);
134134
}
135135

0 commit comments

Comments
 (0)