Skip to content

Commit 3bd0afc

Browse files
author
Vitaliy
authored
Merge pull request #214 from magento/195-cover-composer-json-generation
Cover composer.json generator by tests
2 parents 6fa278d + 6cc8906 commit 3bd0afc

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "test/module",
3+
"version": "1.0.0-dev",
4+
"description": "test-description",
5+
"type": "magento2-module",
6+
"require": {
7+
"magento/framework": "*",
8+
"foo/bar": "*",
9+
"magento/backend": "*"
10+
},
11+
"license": [
12+
"Test License 1",
13+
"Test License 2"
14+
],
15+
"autoload": {
16+
"files": [
17+
"registration.php"
18+
],
19+
"psr-4": {
20+
"Test\\Module\\": ""
21+
}
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "test/module",
3+
"version": "1.0.0-dev",
4+
"description": "test-description",
5+
"type": "magento2-module",
6+
"require": {
7+
"magento/framework": "*",
8+
"foo/bar": "*",
9+
"magento/backend": "*"
10+
},
11+
"license": [
12+
"Test License 1",
13+
"Test License 2"
14+
],
15+
"autoload": {
16+
"files": [
17+
"registration.php"
18+
],
19+
"psr-4": {
20+
"Test\\Module\\": ""
21+
}
22+
}
23+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.actions.generation.generator;
6+
7+
import com.intellij.openapi.project.Project;
8+
import com.intellij.psi.PsiDirectory;
9+
import com.intellij.psi.PsiFile;
10+
import com.magento.idea.magento2plugin.actions.generation.data.ModuleComposerJsonData;
11+
import com.magento.idea.magento2plugin.magento.files.ComposerJson;
12+
import java.util.ArrayList;
13+
import java.util.Arrays;
14+
import java.util.List;
15+
16+
public class ModuleComposerJsonGeneratorTest extends BaseGeneratorTestCase {
17+
18+
public void testGenerateModuleFile() {
19+
String filePath = this.getFixturePath(ComposerJson.FILE_NAME);
20+
PsiFile expectedFile = myFixture.configureByFile(filePath);
21+
PsiDirectory projectDir = getProjectDirectory();
22+
23+
PsiFile composerJson = generateComposerJson(true, projectDir);
24+
25+
assertGeneratedFileIsCorrect(
26+
expectedFile,
27+
projectDir.getVirtualFile().getPath() + "/Test/Module",
28+
composerJson
29+
);
30+
}
31+
32+
public void testGenerateFileInRoot() {
33+
String filePath = this.getFixturePath(ComposerJson.FILE_NAME);
34+
PsiFile expectedFile = myFixture.configureByFile(filePath);
35+
PsiDirectory projectDir = getProjectDirectory();
36+
37+
PsiFile composerJson = generateComposerJson(false, projectDir);
38+
39+
assertGeneratedFileIsCorrect(
40+
expectedFile,
41+
projectDir.getVirtualFile().getPath(),
42+
composerJson
43+
);
44+
}
45+
46+
private PsiFile generateComposerJson(boolean createModuleDirectories, PsiDirectory projectDir) {
47+
Project project = myFixture.getProject();
48+
List<String> dependencies = new ArrayList<>(Arrays.asList("Foo_Bar", "Magento_Backend"));
49+
List<String> licenses = new ArrayList<>(Arrays.asList("Test License 1", "Test License 2"));
50+
ModuleComposerJsonData composerJsonData = new ModuleComposerJsonData(
51+
"Test",
52+
"Module",
53+
projectDir,
54+
"test-description",
55+
"test/module",
56+
"1.0.0-dev",
57+
licenses,
58+
dependencies,
59+
createModuleDirectories
60+
);
61+
ModuleComposerJsonGenerator composerJsonGenerator = new ModuleComposerJsonGenerator(composerJsonData, project);
62+
return composerJsonGenerator.generate("test");
63+
}
64+
}

0 commit comments

Comments
 (0)