2
2
* Copyright © Magento, Inc. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
+
5
6
package com .magento .idea .magento2plugin .actions .generation .generator ;
6
7
7
8
import com .intellij .openapi .project .Project ;
15
16
16
17
public class ModuleComposerJsonGeneratorTest extends BaseGeneratorTestCase {
17
18
18
- public void testGenerateModuleFileWithDependencies () {
19
- String filePath = this .getFixturePath (ComposerJson .FILE_NAME );
20
- PsiFile expectedFile = myFixture .configureByFile (filePath );
21
- PsiDirectory projectDir = getProjectDirectory ();
19
+ /**
20
+ * Test for the module composer.json generation with dependencies.
21
+ */
22
+ public void testGenerateModuleFile () {
23
+ final String filePath = this .getFixturePath (ComposerJson .FILE_NAME );
24
+ final PsiFile expectedFile = myFixture .configureByFile (filePath );
25
+ final PsiDirectory projectDir = getProjectDirectory ();
22
26
23
- String expectedDirectory = projectDir .getVirtualFile ().getPath () + "/Test/Module" ;
24
- PsiFile composerJson = generateComposerJson (true , projectDir , true );
27
+ final String expectedDirectory =
28
+ projectDir .getVirtualFile ().getPath () + "/TestWithDependencies/Module" ;
29
+ final PsiFile composerJson = generateComposerJson (
30
+ true ,
31
+ projectDir ,
32
+ true ,
33
+ "TestWithDependencies" );
25
34
26
35
assertGeneratedFileIsCorrect (
27
- expectedFile ,
28
- expectedDirectory ,
29
- composerJson
36
+ expectedFile ,
37
+ expectedDirectory ,
38
+ composerJson
30
39
);
31
40
}
32
41
33
- public void testGenerateFileInRootWithDependencies () {
34
- String filePath = this .getFixturePath (ComposerJson .FILE_NAME );
35
- PsiFile expectedFile = myFixture .configureByFile (filePath );
36
- PsiDirectory projectDir = getProjectDirectory ();
42
+ /**
43
+ * Test for generation the composer.json with dependencies in the root directory.
44
+ */
45
+ public void testGenerateFileInRoot () {
46
+ final String filePath = this .getFixturePath (ComposerJson .FILE_NAME );
47
+ final PsiFile expectedFile = myFixture .configureByFile (filePath );
48
+ final PsiDirectory projectDir = getProjectDirectory ();
37
49
38
- String composerJsonDirPath = projectDir .getVirtualFile ().getPath ();
39
- PsiFile composerJson = generateComposerJson (false , projectDir , true );
50
+ final String composerJsonDirPath = projectDir .getVirtualFile ().getPath ();
51
+ final PsiFile composerJson = generateComposerJson (
52
+ false ,
53
+ projectDir ,
54
+ true ,
55
+ "TestWithDependencies" );
40
56
41
57
assertGeneratedFileIsCorrect (expectedFile , composerJsonDirPath , composerJson );
42
58
}
43
59
60
+ /**
61
+ * Test case for the composer.json generation without dependencies.
62
+ */
44
63
public void testGenerateModuleFileWithoutDependencies () {
45
- String filePath = this .getFixturePath (ComposerJson .FILE_NAME );
46
- PsiFile expectedFile = myFixture .configureByFile (filePath );
47
- PsiDirectory projectDir = getProjectDirectory ();
48
- String expectedDirectory = projectDir .getVirtualFile ().getPath () + "/Test/Module" ;
49
- PsiFile composerJson = generateComposerJson (true , projectDir , false );
64
+ final String filePath = this .getFixturePath (ComposerJson .FILE_NAME );
65
+ final PsiFile expectedFile = myFixture .configureByFile (filePath );
66
+ final PsiDirectory projectDir = getProjectDirectory ();
67
+ final String expectedDirectory = projectDir .getVirtualFile ().getPath ()
68
+ + "/TestWithoutDependencies/Module" ;
69
+ final PsiFile composerJson = generateComposerJson (
70
+ true ,
71
+ projectDir ,
72
+ false ,
73
+ "TestWithoutDependencies" );
50
74
51
75
assertGeneratedFileIsCorrect (
52
76
expectedFile ,
@@ -55,40 +79,40 @@ public void testGenerateModuleFileWithoutDependencies() {
55
79
);
56
80
}
57
81
58
- public void testGenerateFileInRootWithoutDependencies () {
59
- String filePath = this .getFixturePath (ComposerJson .FILE_NAME );
60
- PsiFile expectedFile = myFixture .configureByFile (filePath );
61
- PsiDirectory projectDir = getProjectDirectory ();
62
- PsiFile composerJson = generateComposerJson (false , projectDir , false );
63
-
64
- assertGeneratedFileIsCorrect (
65
- expectedFile ,
66
- projectDir .getVirtualFile ().getPath (),
67
- composerJson
68
- );
69
- }
70
-
82
+ /**
83
+ * Generate composer.json file for tests.
84
+ *
85
+ * @param createModuleDirectories create module directory flag
86
+ * @param projectDir project directory
87
+ * @param withDependencies generate composer.json with dependencies or not
88
+ * @param packageName the package name of the test module
89
+ * @return PsiFile
90
+ */
71
91
private PsiFile generateComposerJson (
72
- boolean createModuleDirectories ,
73
- PsiDirectory projectDir ,
74
- boolean withDependencies ) {
75
- Project project = myFixture .getProject ();
76
- List <String > dependencies = withDependencies ?
77
- new ArrayList <>(Arrays .asList ("Foo_Bar" , "Magento_Backend" ))
92
+ final boolean createModuleDirectories ,
93
+ final PsiDirectory projectDir ,
94
+ final boolean withDependencies ,
95
+ final String packageName ) {
96
+ final Project project = myFixture .getProject ();
97
+ final List <String > dependencies = withDependencies
98
+ ? new ArrayList <>(Arrays .asList ("Foo_Bar" , "Magento_Backend" ))
78
99
: new ArrayList <>(Arrays .asList ("Foo_BarWithOutComposer" ));
79
- List <String > licenses = new ArrayList <>(Arrays .asList ("Test License 1" , "Test License 2" ));
80
- ModuleComposerJsonData composerJsonData = new ModuleComposerJsonData (
81
- "Test" ,
82
- "Module" ,
83
- projectDir ,
84
- "test-description" ,
85
- "test/module" ,
86
- "1.0.0-dev" ,
87
- licenses ,
88
- dependencies ,
89
- createModuleDirectories
100
+ final List <String > licenses = new ArrayList <>(
101
+ Arrays .asList ("Test License 1" , "Test License 2" )
102
+ );
103
+ final ModuleComposerJsonData composerJsonData = new ModuleComposerJsonData (
104
+ packageName ,
105
+ "Module" ,
106
+ projectDir ,
107
+ "test-description" ,
108
+ "test/module" ,
109
+ "1.0.0-dev" ,
110
+ licenses ,
111
+ dependencies ,
112
+ createModuleDirectories
90
113
);
91
- ModuleComposerJsonGenerator composerJsonGenerator = new ModuleComposerJsonGenerator (composerJsonData , project );
114
+ final ModuleComposerJsonGenerator composerJsonGenerator =
115
+ new ModuleComposerJsonGenerator (composerJsonData , project );
92
116
return composerJsonGenerator .generate ("test" );
93
117
}
94
118
}
0 commit comments