@@ -15,18 +15,46 @@ class ModuleDBChangeTest extends \PHPUnit_Framework_TestCase
15
15
/**
16
16
* @var string
17
17
*/
18
- protected static $ changedFilesPattern = __DIR__ . '/../_files/changed_files * ' ;
18
+ private static $ branchesFilesPattern = __DIR__ . '/../_files/branches * ' ;
19
19
20
20
/**
21
21
* @var string
22
22
*/
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 ;
24
34
25
35
/**
26
36
* Set changed files paths and list for all projects
27
37
*/
28
38
public static function setUpBeforeClass ()
29
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 the latest release branch
54
+ self ::$ actualBranch = ($ branchName == max ($ matches [0 ]));
55
+ }
56
+ }
57
+
30
58
foreach (glob (self ::$ changedFilesPattern ) as $ changedFile ) {
31
59
self ::$ changedFileList .= file_get_contents ($ changedFile ) . PHP_EOL ;
32
60
}
@@ -37,24 +65,28 @@ public static function setUpBeforeClass()
37
65
*/
38
66
public function testModuleXmlFiles ()
39
67
{
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
+ }
46
76
}
47
77
48
78
/**
49
79
* Test changes for files in Module Setup dir
50
80
*/
51
81
public function testModuleSetupFiles ()
52
82
{
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
+ }
59
91
}
60
92
}
0 commit comments