Skip to content

Commit

Permalink
Merge pull request #503 from magento-performance/MAGETWO-59078
Browse files Browse the repository at this point in the history
[PERFORMANCE] MAGETWO-59078: ModuleDBChangeTest failed in 2.1 branch
  • Loading branch information
slavvka authored Oct 17, 2016
2 parents 391e33e + 99b2f80 commit 77ac059
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 17 deletions.
40 changes: 37 additions & 3 deletions dev/tests/static/get_github_changes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// @codingStandardsIgnoreFile

define(
'USAGE',
<<<USAGE
php -f get_github_changes.php --
'USAGE',
<<<USAGE
php -f get_github_changes.php --
--output-file="<output_file>"
--base-path="<base_path>"
--repo="<main_repo>"
Expand All @@ -36,6 +36,8 @@

$mainline = 'mainline_' . (string)rand(0, 9999);
$repo = getRepo($options, $mainline);
$branches = $repo->getBranches('--remotes');
generateBranchesList($options['output-file'], $branches, $options['branch']);
$changes = retrieveChangesAcrossForks($mainline, $repo, $options['branch']);
$changedFiles = getChangedFiles($changes, $fileExtensions);
generateChangedFilesList($options['output-file'], $changedFiles);
Expand All @@ -57,6 +59,25 @@ function generateChangedFilesList($outputFile, $changedFiles)
fclose($changedFilesList);
}

/**
* Generates a file containing origin branches
*
* @param string $outputFile
* @param array $branches
* @param string $branchName
* @return void
*/
function generateBranchesList($outputFile, $branches, $branchName)
{
$branchOutputFile = str_replace('changed_files', 'branches', $outputFile);
$branchesList = fopen($branchOutputFile, 'w');
fwrite($branchesList, $branchName . PHP_EOL);
foreach ($branches as $branch) {
fwrite($branchesList, substr(strrchr($branch, '/'), 1) . PHP_EOL);
}
fclose($branchesList);
}

/**
* Gets list of changed files
*
Expand Down Expand Up @@ -203,6 +224,19 @@ public function fetch($remoteAlias)
$this->call(sprintf('fetch %s', $remoteAlias));
}

/**
* Returns repo branches
*
* @param string $source
* @return array|mixed
*/
public function getBranches($source = '--all')
{
$result = $this->call(sprintf('branch ' . $source));

return is_array($result) ? $result : [];
}

/**
* Returns files changes between branch and HEAD
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,46 @@ class ModuleDBChangeTest extends \PHPUnit_Framework_TestCase
/**
* @var string
*/
protected static $changedFilesPattern = __DIR__ . '/../_files/changed_files*';
private static $branchesFilesPattern = __DIR__ . '/../_files/branches*';

/**
* @var string
*/
protected static $changedFileList = '';
private static $changedFilesPattern = __DIR__ . '/../_files/changed_files*';

/**
* @var string
*/
private static $changedFileList = '';

/**
* @var bool
*/
private static $actualBranch = false;

/**
* Set changed files paths and list for all projects
*/
public static function setUpBeforeClass()
{
foreach (glob(self::$branchesFilesPattern) as $branchesFile) {
//get the current branchname from the first line
$branchName = trim(file($branchesFile)[0]);
if ($branchName === 'develop') {
self::$actualBranch = true;
} else {
//get current minor branch name
preg_match('|^(\d+\.\d+)|', $branchName, $minorBranch);
$branchName = $minorBranch[0];

//get all version branches
preg_match_all('|^(\d+\.\d+)|m', file_get_contents($branchesFile), $matches);

//check is this the latest release branch
self::$actualBranch = ($branchName == max($matches[0]));
}
}

foreach (glob(self::$changedFilesPattern) as $changedFile) {
self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL;
}
Expand All @@ -37,24 +65,28 @@ public static function setUpBeforeClass()
*/
public function testModuleXmlFiles()
{
preg_match_all('|etc/module\.xml$|mi', self::$changedFileList, $matches);
$this->assertEmpty(
reset($matches),
'module.xml changes for patch releases in non-actual branches are not allowed:' . PHP_EOL .
implode(PHP_EOL, array_values(reset($matches)))
);
if (!self::$actualBranch) {
preg_match_all('|etc/module\.xml$|mi', self::$changedFileList, $matches);
$this->assertEmpty(
reset($matches),
'module.xml changes for patch releases in non-actual branches are not allowed:' . PHP_EOL .
implode(PHP_EOL, array_values(reset($matches)))
);
}
}

/**
* Test changes for files in Module Setup dir
*/
public function testModuleSetupFiles()
{
preg_match_all('|app/code/Magento/[^/]+/Setup/[^/]+$|mi', self::$changedFileList, $matches);
$this->assertEmpty(
reset($matches),
'Code with changes for DB schema or data in non-actual branches are not allowed:' . PHP_EOL .
implode(PHP_EOL, array_values(reset($matches)))
);
if (!self::$actualBranch) {
preg_match_all('|app/code/Magento/[^/]+/Setup/[^/]+$|mi', self::$changedFileList, $matches);
$this->assertEmpty(
reset($matches),
'Code with changes for DB schema or data in non-actual branches are not allowed:' . PHP_EOL .
implode(PHP_EOL, array_values(reset($matches)))
);
}
}
}

0 comments on commit 77ac059

Please sign in to comment.