@@ -15,69 +15,78 @@ 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
24
25
25
/**
26
- * @var string Path for Magento's composer.json
26
+ * @var string
27
27
*/
28
- protected static $ composerFilePath = BP . ' /composer.json ' ;
28
+ private static $ changedFileList = ' ' ;
29
29
30
30
/**
31
- * @var bool Is tests executes on develop branch
31
+ * @var bool
32
32
*/
33
- protected static $ isOnDevVersion = false ;
33
+ private static $ actualBranch = false ;
34
34
35
35
/**
36
36
* Set changed files paths and list for all projects
37
37
*/
38
38
public static function setUpBeforeClass ()
39
39
{
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 );
43
52
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 ]));
48
55
}
49
56
}
57
+
58
+ foreach (glob (self ::$ changedFilesPattern ) as $ changedFile ) {
59
+ self ::$ changedFileList .= file_get_contents ($ changedFile ) . PHP_EOL ;
60
+ }
50
61
}
51
62
52
63
/**
53
64
* Test changes for module.xml files
54
65
*/
55
66
public function testModuleXmlFiles ()
56
67
{
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
+ );
59
75
}
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
- );
66
76
}
67
77
68
78
/**
69
79
* Test changes for files in Module Setup dir
70
80
*/
71
81
public function testModuleSetupFiles ()
72
82
{
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
+ );
75
90
}
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
- );
82
91
}
83
92
}
0 commit comments