Skip to content

Commit 2cb3111

Browse files
committed
Added test coverage for PreferenceClassGenerator
1 parent cb4d358 commit 2cb3111

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Foo\Bar\Model;
4+
5+
interface InterfaceOverride
6+
{
7+
8+
}

tests/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceClassGeneratorTest.java

+30-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public void testGeneratePreferenceClassFile() {
2626
"SimpleModelOneOverride",
2727
"Foo\\Bar\\Model\\Override\\SimpleModelOneOverride",
2828
"Foo\\Bar\\Model\\Override",
29+
false,
2930
false
3031
);
3132
final String filePath = this.getFixturePath("SimpleModelOneOverride.php");
@@ -38,6 +39,29 @@ public void testGeneratePreferenceClassFile() {
3839
);
3940
}
4041

42+
/**
43+
* Test preference class file generation.
44+
*/
45+
public void testGeneratePreferenceInterfaceFile() {
46+
final PsiFile preferenceClassFile = createPreferenceClassFile(
47+
TARGET_MODEL_ONE_CLASS_FQN,
48+
"Model",
49+
"InterfaceOverride",
50+
"Foo\\Bar\\Model\\InterfaceOverride",
51+
"Foo\\Bar\\Model",
52+
false,
53+
true
54+
);
55+
final String filePath = this.getFixturePath("InterfaceOverride.php");
56+
final PsiFile expectedFile = myFixture.configureByFile(filePath);
57+
58+
assertGeneratedFileIsCorrect(
59+
expectedFile,
60+
"src/app/code/Foo/Bar/Model",
61+
preferenceClassFile
62+
);
63+
}
64+
4165
/**
4266
* Test preference class file generation with inheritance.
4367
*/
@@ -48,7 +72,8 @@ public void testGeneratePreferenceClassFileWithInheritance() {
4872
"SimpleModelTwoOverride",
4973
"Foo\\Bar\\Model\\Override\\SimpleModelTwoOverride",
5074
"Foo\\Bar\\Model\\Override",
51-
true
75+
true,
76+
false
5277
);
5378
final String filePath = this.getFixturePath("SimpleModelTwoOverride.php");
5479
final PsiFile expectedFile = myFixture.configureByFile(filePath);
@@ -77,7 +102,8 @@ private PsiFile createPreferenceClassFile(
77102
final String preferenceClassName,
78103
final String preferenceFqn,
79104
final String namespace,
80-
final Boolean inheritClass
105+
final Boolean inheritClass,
106+
final Boolean isInterface
81107
) {
82108
final Project project = myFixture.getProject();
83109
final PhpClass targetClass = GetPhpClassByFQN.getInstance(project).execute(targetClassFnq);
@@ -88,7 +114,8 @@ private PsiFile createPreferenceClassFile(
88114
targetClass,
89115
preferenceFqn,
90116
namespace,
91-
inheritClass
117+
inheritClass,
118+
isInterface
92119
);
93120
final PreferenceClassGenerator preferenceClassGenerator = new PreferenceClassGenerator(
94121
preferenceFileData,

0 commit comments

Comments
 (0)