Skip to content

Commit dcfad08

Browse files
committed
MAGETWO-57697: ModuleDBChangeTest failed in develop branch
1 parent bc9df94 commit dcfad08

File tree

2 files changed

+74
-32
lines changed

2 files changed

+74
-32
lines changed

dev/tests/static/get_github_changes.php

Lines changed: 36 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();
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,18 @@ public function fetch($remoteAlias)
203224
$this->call(sprintf('fetch %s', $remoteAlias));
204225
}
205226

227+
/**
228+
* Returns branches
229+
*
230+
* @return array
231+
*/
232+
public function getBranches()
233+
{
234+
$result = $this->call(sprintf('branch -r'));
235+
236+
return is_array($result) ? $result : [];
237+
}
238+
206239
/**
207240
* Returns files changes between branch and HEAD
208241
*

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

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,69 +15,78 @@ 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*';
2424

2525
/**
26-
* @var string Path for Magento's composer.json
26+
* @var string
2727
*/
28-
protected static $composerFilePath = BP . '/composer.json';
28+
private static $changedFileList = '';
2929

3030
/**
31-
* @var bool Is tests executes on develop branch
31+
* @var bool
3232
*/
33-
protected static $isOnDevVersion = false;
33+
private static $actualBranch = false;
3434

3535
/**
3636
* Set changed files paths and list for all projects
3737
*/
3838
public static function setUpBeforeClass()
3939
{
40-
foreach (glob(self::$changedFilesPattern) as $changedFile) {
41-
self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL;
42-
}
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);
4352

44-
if (file_exists(self::$composerFilePath)) {
45-
$jsonData = json_decode(file_get_contents(self::$composerFilePath));
46-
if (substr((string) $jsonData->version, -4) == '-dev') {
47-
self::$isOnDevVersion = true;
53+
//check is this a latest release branch
54+
self::$actualBranch = ($branchName == max($matches[0]));
4855
}
4956
}
57+
58+
foreach (glob(self::$changedFilesPattern) as $changedFile) {
59+
self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL;
60+
}
5061
}
5162

5263
/**
5364
* Test changes for module.xml files
5465
*/
5566
public function testModuleXmlFiles()
5667
{
57-
if (self::$isOnDevVersion) {
58-
$this->markTestSkipped('This test isn\'t applicable to the developer version of Magento');
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+
);
5975
}
60-
preg_match_all('|etc/module\.xml$|mi', self::$changedFileList, $matches);
61-
$this->assertEmpty(
62-
reset($matches),
63-
'module.xml changes for patch releases in non-actual branches are not allowed:' . PHP_EOL .
64-
implode(PHP_EOL, array_values(reset($matches)))
65-
);
6676
}
6777

6878
/**
6979
* Test changes for files in Module Setup dir
7080
*/
7181
public function testModuleSetupFiles()
7282
{
73-
if (self::$isOnDevVersion) {
74-
$this->markTestSkipped('This test isn\'t applicable to the developer version of Magento');
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+
);
7590
}
76-
preg_match_all('|app/code/Magento/[^/]+/Setup/[^/]+$|mi', self::$changedFileList, $matches);
77-
$this->assertEmpty(
78-
reset($matches),
79-
'Code with changes for DB schema or data in non-actual branches are not allowed:' . PHP_EOL .
80-
implode(PHP_EOL, array_values(reset($matches)))
81-
);
8291
}
8392
}

0 commit comments

Comments
 (0)