Skip to content
Snippets Groups Projects
Commit 17ddf578 authored by Roman Ganin's avatar Roman Ganin
Browse files

Merge remote-tracking branch 'origin/MAGETWO-60201' into troll_pr

parents 38360b51 ea16e9ab
No related merge requests found
...@@ -60,10 +60,14 @@ class ChangedFiles ...@@ -60,10 +60,14 @@ class ChangedFiles
*/ */
public static function getChangedContent($fileName) public static function getChangedContent($fileName)
{ {
$data = [];
$extension = self::getFileExtension($fileName); $extension = self::getFileExtension($fileName);
$fileName = ltrim(str_replace(BP, '', $fileName), DIRECTORY_SEPARATOR); $fileName = ltrim(str_replace(BP, '', $fileName), DIRECTORY_SEPARATOR);
$changedContent = file_get_contents(BP . sprintf(self::CHANGED_FILES_CONTENT_FILE, $extension)); $changedFilesContentFile = BP . sprintf(self::CHANGED_FILES_CONTENT_FILE, $extension);
$data = json_decode($changedContent, true); if (file_exists($changedFilesContentFile)) {
$changedContent = file_get_contents($changedFilesContentFile);
$data = json_decode($changedContent, true);
}
return isset($data[$fileName]) ? $data[$fileName] : ''; return isset($data[$fileName]) ? $data[$fileName] : '';
} }
......
...@@ -36,22 +36,64 @@ class FunctionDetector ...@@ -36,22 +36,64 @@ class FunctionDetector
$result = []; $result = [];
$regexp = $this->composeRegexp($functions); $regexp = $this->composeRegexp($functions);
if ($regexp) { if (!$regexp) {
$fileContent = \Magento\TestFramework\Utility\ChangedFiles::getChangedContent($filePath); return $result;
$matches = preg_grep($regexp, explode("\n", $fileContent)); }
$file = file($filePath);
if (!empty($matches)) { $fileContent = \Magento\TestFramework\Utility\ChangedFiles::getChangedContent($filePath);
foreach ($matches as $line) { $file = file($filePath);
$actualFunctions = [];
foreach ($functions as $function) { return $fileContent
if (false !== strpos($line, $function)) { ? $this->grepChangedContent($file, $regexp, $functions, $fileContent)
$actualFunctions[] = $function; : $this->grepFile($file, $regexp);
} }
/**
* Grep only changed content.
*
* @param array $file
* @param string $regexp
* @param string[] $functions
* @param string $fileContent
* @return array
*/
public function grepChangedContent(array $file, $regexp, $functions, $fileContent)
{
$result = [];
$matches = preg_grep($regexp, explode("\n", $fileContent));
if (!empty($matches)) {
foreach ($matches as $line) {
$actualFunctions = [];
foreach ($functions as $function) {
if (false !== strpos($line, $function)) {
$actualFunctions[] = $function;
} }
$result[array_search($line . "\n", $file) + 1] = $actualFunctions;
} }
$result[array_search($line . "\n", $file) + 1] = $actualFunctions;
} }
} }
return $result;
}
/**
* Grep File.
*
* @param array $file
* @param string $regexp
* @return array
*/
public function grepFile(array $file, $regexp)
{
$result = [];
array_unshift($file, '');
$lines = preg_grep($regexp, $file);
foreach ($lines as $lineNumber => $line) {
if (preg_match_all($regexp, $line, $matches)) {
$result[$lineNumber] = $matches[1];
}
}
return $result; return $result;
} }
......
...@@ -56,7 +56,11 @@ function saveChangedFileContent(GitRepo $repo) ...@@ -56,7 +56,11 @@ function saveChangedFileContent(GitRepo $repo)
{ {
$changedFilesContentFileName = BP . Magento\TestFramework\Utility\ChangedFiles::CHANGED_FILES_CONTENT_FILE; $changedFilesContentFileName = BP . Magento\TestFramework\Utility\ChangedFiles::CHANGED_FILES_CONTENT_FILE;
foreach ($repo->getChangedContentFiles() as $key => $changedContentFile) { foreach ($repo->getChangedContentFiles() as $key => $changedContentFile) {
file_put_contents(sprintf($changedFilesContentFileName, $key), json_encode($changedContentFile), FILE_APPEND); $filePath = sprintf($changedFilesContentFileName, $key);
$oldContent = file_exists($filePath) ? file_get_contents($filePath) : '{}';
$oldData = json_decode($oldContent, true);
$data = array_merge($oldData, $changedContentFile);
file_put_contents($filePath, json_encode($data));
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment