22 * Copyright © Magento, Inc. All rights reserved.
33 * See COPYING.txt for license details.
44 */
5+
56package com .magento .idea .magento2plugin .actions .generation .generator ;
67
78import com .intellij .openapi .project .Project ;
1516
1617public class ModuleComposerJsonGeneratorTest extends BaseGeneratorTestCase {
1718
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 ();
2226
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" );
2534
2635 assertGeneratedFileIsCorrect (
27- expectedFile ,
28- expectedDirectory ,
29- composerJson
36+ expectedFile ,
37+ expectedDirectory ,
38+ composerJson
3039 );
3140 }
3241
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 ();
3749
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" );
4056
4157 assertGeneratedFileIsCorrect (expectedFile , composerJsonDirPath , composerJson );
4258 }
4359
60+ /**
61+ * Test case for the composer.json generation without dependencies.
62+ */
4463 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" );
5074
5175 assertGeneratedFileIsCorrect (
5276 expectedFile ,
@@ -55,40 +79,40 @@ public void testGenerateModuleFileWithoutDependencies() {
5579 );
5680 }
5781
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+ */
7191 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" ))
7899 : 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
90113 );
91- ModuleComposerJsonGenerator composerJsonGenerator = new ModuleComposerJsonGenerator (composerJsonData , project );
114+ final ModuleComposerJsonGenerator composerJsonGenerator =
115+ new ModuleComposerJsonGenerator (composerJsonData , project );
92116 return composerJsonGenerator .generate ("test" );
93117 }
94118}
0 commit comments