1
1
package fr .adrienbrault .idea .symfony2plugin .tests .form .util ;
2
2
3
+ import com .intellij .psi .PsiElement ;
3
4
import com .intellij .util .containers .ContainerUtil ;
5
+ import com .jetbrains .php .lang .PhpFileType ;
4
6
import fr .adrienbrault .idea .symfony2plugin .form .dict .FormClass ;
5
7
import fr .adrienbrault .idea .symfony2plugin .form .dict .FormClassEnum ;
8
+ import fr .adrienbrault .idea .symfony2plugin .form .dict .FormOptionEnum ;
6
9
import fr .adrienbrault .idea .symfony2plugin .form .util .FormOptionsUtil ;
10
+ import fr .adrienbrault .idea .symfony2plugin .form .visitor .FormOptionVisitor ;
7
11
import fr .adrienbrault .idea .symfony2plugin .tests .SymfonyLightCodeInsightFixtureTestCase ;
12
+ import org .jetbrains .annotations .NotNull ;
8
13
9
14
import java .io .File ;
15
+ import java .util .HashSet ;
16
+ import java .util .Set ;
10
17
11
18
/**
12
19
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -17,7 +24,25 @@ public class FormOptionsUtilTest extends SymfonyLightCodeInsightFixtureTestCase
17
24
18
25
public void setUp () throws Exception {
19
26
super .setUp ();
27
+
28
+ myFixture .configureByText (PhpFileType .INSTANCE , "<?php\n " +
29
+ "namespace Symfony\\ Component\\ Form\n " +
30
+ "{\n " +
31
+ " interface FormTypeExtensionInterface\n " +
32
+ " {\n " +
33
+ " public function getExtendedType();\n " +
34
+ " }\n " +
35
+ "\n " +
36
+ " interface FormTypeInterface\n " +
37
+ " {\n " +
38
+ " public function getName();\n " +
39
+ " }\n " +
40
+ "}"
41
+ );
42
+
20
43
myFixture .copyFileToProject ("FormOptionsUtil.php" );
44
+ myFixture .copyFileToProject ("FormOptionsUtilKeys.php" );
45
+
21
46
}
22
47
23
48
protected String getTestDataPath () {
@@ -47,4 +72,33 @@ public void testGetExtendedTypeClassesAsClassConstant() {
47
72
assertEquals ("\\ Foo\\ Bar\\ BarType" , myType .getPhpClass ().getFQN ());
48
73
}
49
74
}
75
+
76
+ public void testClassOptionsVisitorWithExtensionAndParents () {
77
+
78
+ final Set <String > options = new HashSet <String >();
79
+
80
+ FormOptionsUtil .visitFormOptions (getProject (), "foo" , new FormOptionVisitor () {
81
+ @ Override
82
+ public void visit (@ NotNull PsiElement psiElement , @ NotNull String option , @ NotNull FormClass formClass , @ NotNull FormOptionEnum optionEnum ) {
83
+ options .add (option );
84
+ }
85
+ });
86
+
87
+ assertContainsElements (options , "MyType" , "BarTypeParent" , "BarTypeExtension" );
88
+ }
89
+
90
+ public void testClassOptionsVisitorWithExtensionAndParentsWithClassConstant () {
91
+
92
+ final Set <String > optionsClass = new HashSet <String >();
93
+
94
+ FormOptionsUtil .visitFormOptions (getProject (), "Options\\ Bar\\ Foobar" , new FormOptionVisitor () {
95
+ @ Override
96
+ public void visit (@ NotNull PsiElement psiElement , @ NotNull String option , @ NotNull FormClass formClass , @ NotNull FormOptionEnum optionEnum ) {
97
+ optionsClass .add (option );
98
+ }
99
+ });
100
+
101
+ assertContainsElements (optionsClass , "BarType" );
102
+ }
103
+
50
104
}
0 commit comments