Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ModuleDBChangeTest.php
Go to the documentation of this file.
1 <?php
11 namespace Magento\Test\Legacy;
12 
13 class ModuleDBChangeTest extends \PHPUnit\Framework\TestCase
14 {
18  private static $branchesFilesPattern = __DIR__ . '/../_files/branches*';
19 
23  private static $changedFilesPattern = __DIR__ . '/../_files/changed_files*';
24 
28  private static $changedFileList = '';
29 
33  private static $actualBranch = false;
34 
38  public static function setUpBeforeClass()
39  {
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 a latest release branch
54  self::$actualBranch = ($branchName == max($matches[0]));
55  }
56  }
57 
58  foreach (glob(self::$changedFilesPattern) as $changedFile) {
59  self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL;
60  }
61  }
62 
66  public function testModuleXmlFiles()
67  {
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  }
76  }
77 
81  public function testModuleSetupFiles()
82  {
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  }
91  }
92 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60