ModuleDBChangeTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Scan source code for DB schema or data updates for patch releases in non-actual branches
  8. * Backwards compatibility test
  9. */
  10. namespace Magento\Test\Legacy;
  11. class ModuleDBChangeTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var string
  15. */
  16. private static $branchesFilesPattern = __DIR__ . '/../_files/branches*';
  17. /**
  18. * @var string
  19. */
  20. private static $changedFilesPattern = __DIR__ . '/../_files/changed_files*';
  21. /**
  22. * @var string
  23. */
  24. private static $changedFileList = '';
  25. /**
  26. * @var bool
  27. */
  28. private static $actualBranch = false;
  29. /**
  30. * Set changed files paths and list for all projects
  31. */
  32. public static function setUpBeforeClass()
  33. {
  34. foreach (glob(self::$branchesFilesPattern) as $branchesFile) {
  35. //get the current branchname from the first line
  36. $branchName = trim(file($branchesFile)[0]);
  37. if ($branchName === 'develop') {
  38. self::$actualBranch = true;
  39. } else {
  40. //get current minor branch name
  41. preg_match('|^(\d+\.\d+)|', $branchName, $minorBranch);
  42. $branchName = $minorBranch[0];
  43. //get all version branches
  44. preg_match_all('|^(\d+\.\d+)|m', file_get_contents($branchesFile), $matches);
  45. //check is this a latest release branch
  46. self::$actualBranch = ($branchName == max($matches[0]));
  47. }
  48. }
  49. foreach (glob(self::$changedFilesPattern) as $changedFile) {
  50. self::$changedFileList .= file_get_contents($changedFile) . PHP_EOL;
  51. }
  52. }
  53. /**
  54. * Test changes for module.xml files
  55. */
  56. public function testModuleXmlFiles()
  57. {
  58. if (!self::$actualBranch) {
  59. preg_match_all('|etc/module\.xml$|mi', self::$changedFileList, $matches);
  60. $this->assertEmpty(
  61. reset($matches),
  62. 'module.xml changes for patch releases in non-actual branches are not allowed:' . PHP_EOL .
  63. implode(PHP_EOL, array_values(reset($matches)))
  64. );
  65. }
  66. }
  67. /**
  68. * Test changes for files in Module Setup dir
  69. */
  70. public function testModuleSetupFiles()
  71. {
  72. if (!self::$actualBranch) {
  73. preg_match_all('|app/code/Magento/[^/]+/Setup/[^/]+$|mi', self::$changedFileList, $matches);
  74. $this->assertEmpty(
  75. reset($matches),
  76. 'Code with changes for DB schema or data in non-actual branches are not allowed:' . PHP_EOL .
  77. implode(PHP_EOL, array_values(reset($matches)))
  78. );
  79. }
  80. }
  81. }