Skip to content

Commit 77ac059

Browse files
authored
Merge pull request #503 from magento-performance/MAGETWO-59078
[PERFORMANCE] MAGETWO-59078: ModuleDBChangeTest failed in 2.1 branch
2 parents 391e33e + 99b2f80 commit 77ac059

File tree

2 files changed

+83
-17
lines changed

2 files changed

+83
-17
lines changed

dev/tests/static/get_github_changes.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// @codingStandardsIgnoreFile
1313

1414
define(
15-
'USAGE',
16-
<<<USAGE
17-
php -f get_github_changes.php --
15+
'USAGE',
16+
<<<USAGE
17+
php -f get_github_changes.php --
1818
--output-file="<output_file>"
1919
--base-path="<base_path>"
2020
--repo="<main_repo>"
@@ -36,6 +36,8 @@
3636

3737
$mainline = 'mainline_' . (string)rand(0, 9999);
3838
$repo = getRepo($options, $mainline);
39+
$branches = $repo->getBranches('--remotes');
40+
generateBranchesList($options['output-file'], $branches, $options['branch']);
3941
$changes = retrieveChangesAcrossForks($mainline, $repo, $options['branch']);
4042
$changedFiles = getChangedFiles($changes, $fileExtensions);
4143
generateChangedFilesList($options['output-file'], $changedFiles);
@@ -57,6 +59,25 @@ function generateChangedFilesList($outputFile, $changedFiles)
5759
fclose($changedFilesList);
5860
}
5961

62+
/**
63+
* Generates a file containing origin branches
64+
*
65+
* @param string $outputFile
66+
* @param array $branches
67+
* @param string $branchName
68+
* @return void
69+
*/
70+
function generateBranchesList($outputFile, $branches, $branchName)
71+
{
72+
$branchOutputFile = str_replace('changed_files', 'branches', $outputFile);
73+
$branchesList = fopen($branchOutputFile, 'w');
74+
fwrite($branchesList, $branchName . PHP_EOL);
75+
foreach ($branches as $branch) {
76+
fwrite($branchesList, substr(strrchr($branch, '/'), 1) . PHP_EOL);
77+
}
78+
fclose($branchesList);
79+
}
80+
6081
/**
6182
* Gets list of changed files
6283
*
@@ -203,6 +224,19 @@ public function fetch($remoteAlias)
203224
$this->call(sprintf('fetch %s', $remoteAlias));
204225
}
205226

227+
/**
228+
* Returns repo branches
229+
*
230+
* @param string $source
231+
* @return array|mixed
232+
*/
233+
public function getBranches($source = '--all')
234+
{
235+
$result = $this->call(sprintf('branch ' . $source));
236+
237+
return is_array($result) ? $result : [];
238+
}
239+
206240
/**
207241
* Returns files changes between branch and HEAD
208242
*

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

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,46 @@ class ModuleDBChangeTest extends \PHPUnit_Framework_TestCase
1515
/**
1616
* @var string
1717
*/
18-
protected static $changedFilesPattern = __DIR__ . '/../_files/changed_files*';
18+
private static $branchesFilesPattern = __DIR__ . '/../_files/branches*';
1919

2020
/**
2121
* @var string
2222
*/
23-
protected static $changedFileList = '';
23+
private static $changedFilesPattern = __DIR__ . '/../_files/changed_files*';
24+
25+
/**
26+
* @var string
27+
*/
28+
private static $changedFileList = '';
29+
30+
/**
31+
* @var bool
32+
*/
33+
private static $actualBranch = false;
2434

2535
/**
2636
* Set changed files paths and list for all projects
2737
*/
2838
public static function setUpBeforeClass()
2939
{
40+
foreach (glob(self::$branchesFilesPattern) as $branchesFile) {
41+
//get the current branchname from the first line
42+
$branchName = trim(file($branchesFile)[0]);
43+
if ($branchName === 'develop') {
44+
self::$actualBranch = true;
45+
} else {
46+
//get current minor branch name
47+
preg_match('|^(\d+\.\d+)|', $branchName, $minorBranch);
48+
$branchName = $minorBranch[0];
49+
50+
//get all version branches
51+
preg_match_all('|^(\d+\.\d+)|m', file_get_contents($branchesFile), $matches);
52+
53+
//check is this the latest release branch
54+
self::$actualBranch = ($branchName == max($matches[0]));
55+
}
56+
}
57+
3058
foreach (glob(self::$changedFilesPattern) as $changedFile) {
3159
self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL;
3260
}
@@ -37,24 +65,28 @@ public static function setUpBeforeClass()
3765
*/
3866
public function testModuleXmlFiles()
3967
{
40-
preg_match_all('|etc/module\.xml$|mi', self::$changedFileList, $matches);
41-
$this->assertEmpty(
42-
reset($matches),
43-
'module.xml changes for patch releases in non-actual branches are not allowed:' . PHP_EOL .
44-
implode(PHP_EOL, array_values(reset($matches)))
45-
);
68+
if (!self::$actualBranch) {
69+
preg_match_all('|etc/module\.xml$|mi', self::$changedFileList, $matches);
70+
$this->assertEmpty(
71+
reset($matches),
72+
'module.xml changes for patch releases in non-actual branches are not allowed:' . PHP_EOL .
73+
implode(PHP_EOL, array_values(reset($matches)))
74+
);
75+
}
4676
}
4777

4878
/**
4979
* Test changes for files in Module Setup dir
5080
*/
5181
public function testModuleSetupFiles()
5282
{
53-
preg_match_all('|app/code/Magento/[^/]+/Setup/[^/]+$|mi', self::$changedFileList, $matches);
54-
$this->assertEmpty(
55-
reset($matches),
56-
'Code with changes for DB schema or data in non-actual branches are not allowed:' . PHP_EOL .
57-
implode(PHP_EOL, array_values(reset($matches)))
58-
);
83+
if (!self::$actualBranch) {
84+
preg_match_all('|app/code/Magento/[^/]+/Setup/[^/]+$|mi', self::$changedFileList, $matches);
85+
$this->assertEmpty(
86+
reset($matches),
87+
'Code with changes for DB schema or data in non-actual branches are not allowed:' . PHP_EOL .
88+
implode(PHP_EOL, array_values(reset($matches)))
89+
);
90+
}
5991
}
6092
}

0 commit comments

Comments
 (0)