-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathServicePropertyInsertUtilTest.java
126 lines (94 loc) · 6.51 KB
/
ServicePropertyInsertUtilTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package fr.adrienbrault.idea.symfony2plugin.tests.completion;
import com.jetbrains.php.lang.psi.PhpPsiElementFactory;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import fr.adrienbrault.idea.symfony2plugin.completion.ServicePropertyInsertUtil;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
import java.util.List;
/**
* @author Daniel Espendiller <daniel@espendiller.net>
* @see ServicePropertyInsertUtil
*/
public class ServicePropertyInsertUtilTest extends SymfonyLightCodeInsightFixtureTestCase {
public void setUp() throws Exception {
super.setUp();
myFixture.copyFileToProject("ServicePropertyInsertUtil.php");
}
public String getTestDataPath() {
return "src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/completion/fixtures";
}
public void testAppendPropertyInjection() {
PhpClass fromText = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
"\n" +
"class Foobar\n" +
"{\n" +
" public function __construct(private readonly \\DateTime $d)\n" +
" {\n" +
" }\n" +
"}"
);
ServicePropertyInsertUtil.appendPropertyInjection(fromText, "router", "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
String text = fromText.getText();
assertTrue(text.contains("public function __construct(private readonly \\DateTime $d,private readonly UrlGeneratorInterface $router)"));
PhpClass fromText2 = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
"\n" +
"class Foobar\n" +
"{\n" +
"}"
);
ServicePropertyInsertUtil.appendPropertyInjection(fromText2, "router", "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
String text2 = fromText2.getText();
assertTrue(text2.contains("public function __construct(UrlGeneratorInterface $router)"));
PhpClass fromText3 = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
"\n" +
"readonly class Foobar\n" +
"{\n" +
" public function __construct(private readonly \\DateTime $d)\n" +
" {\n" +
" }\n" +
"}"
);
ServicePropertyInsertUtil.appendPropertyInjection(fromText3, "router", "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
String text3 = fromText3.getText();
assertTrue(text3.contains("public function __construct(private readonly \\DateTime $d,private UrlGeneratorInterface $router)"));
}
public void testInjectionService() {
List<String> classes1 = ServicePropertyInsertUtil.getInjectionService(getProject(), "router");
assertContainsElements(classes1, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
List<String> classes2 = ServicePropertyInsertUtil.getInjectionService(getProject(), "urlgenerator");
assertContainsElements(classes2, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
List<String> classes3 = ServicePropertyInsertUtil.getInjectionService(getProject(), "urlGenerator");
assertContainsElements(classes3, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
List<String> classes4 = ServicePropertyInsertUtil.getInjectionService(getProject(), "_urlGenerator");
assertContainsElements(classes4, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
List<String> classes5 = ServicePropertyInsertUtil.getInjectionService(getProject(), "__url_generator");
assertContainsElements(classes5, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
List<String> classes6 = ServicePropertyInsertUtil.getInjectionService(getProject(), "_router");
assertContainsElements(classes6, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
List<String> classes7 = ServicePropertyInsertUtil.getInjectionService(getProject(), "foobar");
assertContainsElements(classes7, "\\App\\Service\\FoobarInterface");
List<String> classes8 = ServicePropertyInsertUtil.getInjectionService(getProject(), "_routerInterface");
assertContainsElements(classes8, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
List<String> classes9 = ServicePropertyInsertUtil.getInjectionService(getProject(), "foobarCar");
assertContainsElements(classes9, "\\App\\Service\\InterfaceFoobarCar");
List<String> classes10 = ServicePropertyInsertUtil.getInjectionService(getProject(), "foobarCarInterface");
assertContainsElements(classes10, "\\App\\Service\\InterfaceFoobarCar");
List<String> classes11 = ServicePropertyInsertUtil.getInjectionService(getProject(), "fooBarLogger");
assertContainsElements(classes11, "\\Psr\\Log\\LoggerInterface");
List<String> classes12 = ServicePropertyInsertUtil.getInjectionService(getProject(), "foobarLongClassNameServiceFactory");
assertContainsElements(classes12, "\\App\\Service\\FoobarLongClassNameServiceFactory");
List<String> classes13 = ServicePropertyInsertUtil.getInjectionService(getProject(), "longClassNameServiceFactory");
assertContainsElements(classes13, "\\App\\Service\\FoobarLongClassNameServiceFactory");
List<String> classes14 = ServicePropertyInsertUtil.getInjectionService(getProject(), "nameServiceFactory");
assertContainsElements(classes14, "\\App\\Service\\FoobarLongClassNameServiceFactory");
List<String> classes15 = ServicePropertyInsertUtil.getInjectionService(getProject(), "serviceFactory");
assertFalse(classes15.contains("\\App\\Service\\FoobarLongClassNameServiceFactory"));
List<String> classes16 = ServicePropertyInsertUtil.getInjectionService(getProject(), "_name_Service__Factory");
assertContainsElements(classes16, "\\App\\Service\\FoobarLongClassNameServiceFactory");
}
public void testInjectionServiceWithName() {
List<String> classes1 = ServicePropertyInsertUtil.getInjectionService(getProject(), "urlGenerator", "foobarUnknown");
assertContainsElements(classes1, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
List<String> classes2 = ServicePropertyInsertUtil.getInjectionService(getProject(), "urlGenerator", "generate");
assertContainsElements(classes2, "\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface");
}
}