Skip to content

Commit 2ed35e6

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #7 from magento-folks/bugfix
[Folks]Obsolete code test fix
2 parents d9fb06a + 26a1107 commit 2ed35e6

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Magento\Framework\App\Utility\AggregateInvoker;
1515
use Magento\TestFramework\Utility\ChangedFiles;
1616

17+
/**
18+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
19+
*/
1720
class ObsoleteCodeTest extends \PHPUnit_Framework_TestCase
1821
{
1922
/**@#+
@@ -871,7 +874,7 @@ protected function _assertNotRegexp($regex, $content, $message)
871874

872875
public function testMageMethodsObsolete()
873876
{
874-
$ignored = $this->getBlacklistFiles();
877+
$ignored = $this->getBlacklistFiles(true);
875878
$files = Files::init()->getPhpFiles(
876879
Files::INCLUDE_APP_CODE
877880
| Files::INCLUDE_TESTS
@@ -900,18 +903,43 @@ function ($file) {
900903
);
901904
}
902905

906+
/**
907+
* @param string $appPath
908+
* @param string $pattern
909+
* @return array
910+
* @throws \Exception
911+
*/
912+
private function processPattern($appPath, $pattern)
913+
{
914+
$files = [];
915+
$relativePathStart = strlen($appPath);
916+
917+
$fileSet = glob($appPath . DIRECTORY_SEPARATOR . $pattern, GLOB_NOSORT);
918+
foreach ($fileSet as $file) {
919+
$files[] = substr($file, $relativePathStart);
920+
}
921+
922+
return $files;
923+
}
924+
903925
/**
904926
* Reads list of blacklisted files
905927
*
928+
* @param bool $absolutePath
906929
* @return array
930+
* @throws \Exception
907931
*/
908-
private function getBlacklistFiles()
932+
private function getBlacklistFiles($absolutePath = false)
909933
{
910934
$blackList = include __DIR__ . '/_files/blacklist/obsolete_mage.php';
911935
$ignored = [];
912936
$appPath = Files::init()->getPathToSource();
913937
foreach ($blackList as $file) {
914-
$ignored = array_merge($ignored, glob($appPath . '/' . $file, GLOB_NOSORT));
938+
if ($absolutePath) {
939+
$ignored = array_merge($ignored, glob($appPath . DIRECTORY_SEPARATOR . $file, GLOB_NOSORT));
940+
} else {
941+
$ignored = array_merge($ignored, $this->processPattern($appPath, $file));
942+
}
915943
}
916944
return $ignored;
917945
}

0 commit comments

Comments
 (0)