diff --git a/dev/tests/static/get_github_changes.php b/dev/tests/static/get_github_changes.php index c142aae18d8ecd5a4ab3fa895e32e5510b71683b..f332208cd17d0861dd1b28bd7096a0b3fe0066a5 100644 --- a/dev/tests/static/get_github_changes.php +++ b/dev/tests/static/get_github_changes.php @@ -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>" @@ -36,6 +36,8 @@ $fileExtensions = explode(',', isset($options['file-extensions']) ? $options['fi $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); @@ -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 * @@ -84,7 +105,7 @@ function getChangedFiles(array $changes, array $fileExtensions) * * @param array $options * @param string $mainline - * @return array + * @return GitRepo * @throws Exception */ function getRepo($options, $mainline) @@ -203,6 +224,19 @@ class GitRepo $this->call(sprintf('fetch %s', $remoteAlias)); } + /** + * Returns 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 * diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/ModuleDBChangeTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/ModuleDBChangeTest.php index 87bd329ef3b5611475c6ee9486cdc9f27c4ea5fe..2f3d312fb41ffba1287bafd324a64ac751316d5c 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/ModuleDBChangeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/ModuleDBChangeTest.php @@ -15,38 +15,49 @@ 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 Path for Magento's composer.json + * @var string */ - protected static $composerFilePath = BP . '/composer.json'; + private static $changedFileList = ''; /** - * @var bool Is tests executes on develop branch + * @var bool */ - protected static $isOnDevVersion = false; + private static $actualBranch = false; /** * Set changed files paths and list for all projects */ public static function setUpBeforeClass() { - foreach (glob(self::$changedFilesPattern) as $changedFile) { - self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL; - } + 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); - if (file_exists(self::$composerFilePath)) { - $jsonData = json_decode(file_get_contents(self::$composerFilePath)); - if (substr((string) $jsonData->version, -4) == '-dev') { - self::$isOnDevVersion = true; + //check is this a latest release branch + self::$actualBranch = ($branchName == max($matches[0])); } } + + foreach (glob(self::$changedFilesPattern) as $changedFile) { + self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL; + } } /** @@ -54,15 +65,14 @@ class ModuleDBChangeTest extends \PHPUnit_Framework_TestCase */ public function testModuleXmlFiles() { - if (self::$isOnDevVersion) { - $this->markTestSkipped('This test isn\'t applicable to the developer version of Magento'); + 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))) + ); } - 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))) - ); } /** @@ -70,14 +80,13 @@ class ModuleDBChangeTest extends \PHPUnit_Framework_TestCase */ public function testModuleSetupFiles() { - if (self::$isOnDevVersion) { - $this->markTestSkipped('This test isn\'t applicable to the developer version of Magento'); + 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))) + ); } - 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))) - ); } }