Skip to content

Commit 4ddef2b

Browse files
committed
Added unit tests for ParameterLanguageInjector
1 parent e3d476e commit 4ddef2b

File tree

2 files changed

+413
-0
lines changed

2 files changed

+413
-0
lines changed

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/ParameterLanguageInjectorTest.java

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,288 @@ public void testDqlLanguageInjections() {
7070
assertInjectedLangAtCaret(PhpFileType.INSTANCE, "<?php $dql = \"<caret>\");", LANGUAGE_ID_DQL);
7171
}
7272

73+
public void testExpressionLanguageLanguageInjections() {
74+
assertInjectedLangAtCaret(
75+
PhpFileType.INSTANCE,
76+
"<?php $expr = new \\Symfony\\Component\\ExpressionLanguage\\Expression('<caret>');",
77+
LANGUAGE_ID_EXPRESSION_LANGUAGE
78+
);
79+
80+
assertInjectedLangAtCaret(
81+
PhpFileType.INSTANCE,
82+
"<?php \n" +
83+
"$expr = new \\Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage(); \n" +
84+
"$expr->evaluate('<caret>');\n",
85+
LANGUAGE_ID_EXPRESSION_LANGUAGE
86+
);
87+
88+
assertInjectedLangAtCaret(
89+
PhpFileType.INSTANCE,
90+
"<?php \n" +
91+
"$expr = new \\Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage(); \n" +
92+
"$expr->compile('<caret>');\n",
93+
LANGUAGE_ID_EXPRESSION_LANGUAGE
94+
);
95+
96+
assertInjectedLangAtCaret(
97+
PhpFileType.INSTANCE,
98+
"<?php \n" +
99+
"$routes = new \\Symfony\\Component\\Routing\\Loader\\Configurator\\RoutingConfigurator();\n" +
100+
"$routes->condition('<caret>');\n",
101+
LANGUAGE_ID_EXPRESSION_LANGUAGE
102+
);
103+
104+
assertInjectedLangAtCaret(
105+
PhpFileType.INSTANCE,
106+
"<?php \n" +
107+
"$routes = new \\Symfony\\Component\\Routing\\Loader\\Configurator\\RoutingConfigurator();\n" +
108+
"$routes->condition(condition: '<caret>');\n",
109+
LANGUAGE_ID_EXPRESSION_LANGUAGE
110+
);
111+
112+
assertInjectedLangAtCaret(
113+
PhpFileType.INSTANCE,
114+
"<?php\n" +
115+
"\n" +
116+
"use Symfony\\Component\\Routing\\Annotation\\Route;\n" +
117+
"\n" +
118+
"class ExampleController\n" +
119+
"{\n" +
120+
" #[Route(\"/contact\", condition: \"<caret>\")]\n" +
121+
" public function contact() {}\n" +
122+
"}\n",
123+
LANGUAGE_ID_EXPRESSION_LANGUAGE
124+
);
125+
126+
assertInjectedLangAtCaret(
127+
PhpFileType.INSTANCE,
128+
"<?php\n" +
129+
"\n" +
130+
"use Symfony\\Component\\Routing\\Annotation\\Route;\n" +
131+
"\n" +
132+
"class ExampleController\n" +
133+
"{\n" +
134+
" #[Route([], \"/contact\", \"contact\", [], [], [], null, [], [], '<caret>')]\n" +
135+
" public function contact() {}\n" +
136+
"}",
137+
LANGUAGE_ID_EXPRESSION_LANGUAGE
138+
);
139+
140+
assertInjectedLangAtCaret(
141+
PhpFileType.INSTANCE,
142+
"<?php\n" +
143+
"\n" +
144+
"use Symfony\\Component\\Routing\\Annotation\\Route;\n" +
145+
"\n" +
146+
"class ExampleController\n" +
147+
"{\n" +
148+
" /**\n" +
149+
" * @Route(\"/contact\", name=\"contact\", condition=\"<caret>\")\n" +
150+
" */\n" +
151+
" public function contact() {}\n" +
152+
"}",
153+
LANGUAGE_ID_EXPRESSION_LANGUAGE
154+
);
155+
156+
assertInjectedLangAtCaret(
157+
PhpFileType.INSTANCE,
158+
"<?php\n" +
159+
"\n" +
160+
"use Symfony\\Component\\Validator\\Constraints\\Expression;\n" +
161+
"\n" +
162+
"#[Expression(\"<caret>\")]\n" +
163+
"class BlogPost {}\n",
164+
LANGUAGE_ID_EXPRESSION_LANGUAGE
165+
);
166+
167+
assertInjectedLangAtCaret(
168+
PhpFileType.INSTANCE,
169+
"<?php\n" +
170+
"\n" +
171+
"use Symfony\\Component\\Validator\\Constraints\\Expression;\n" +
172+
"\n" +
173+
"#[Expression(expression: \"<caret>\")]\n" +
174+
"class BlogPost {}\n",
175+
LANGUAGE_ID_EXPRESSION_LANGUAGE
176+
);
177+
178+
assertInjectedLangAtCaret(
179+
PhpFileType.INSTANCE,
180+
"<?php\n" +
181+
"\n" +
182+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Security;\n" +
183+
"\n" +
184+
"class ExampleController\n" +
185+
"{\n" +
186+
" #[Security(\"<caret>\")]\n" +
187+
" public function contact() {}\n" +
188+
"}",
189+
LANGUAGE_ID_EXPRESSION_LANGUAGE
190+
);
191+
192+
assertInjectedLangAtCaret(
193+
PhpFileType.INSTANCE,
194+
"<?php\n" +
195+
"\n" +
196+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Security;\n" +
197+
"\n" +
198+
"class ExampleController\n" +
199+
"{\n" +
200+
" #[Security(data: \"<caret>\")]\n" +
201+
" public function contact() {}\n" +
202+
"}",
203+
LANGUAGE_ID_EXPRESSION_LANGUAGE
204+
);
205+
206+
// assertInjectedLangAtCaret(
207+
// PhpFileType.INSTANCE,
208+
// "<?php\n" +
209+
// "\n" +
210+
// "use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Security;\n" +
211+
// "\n" +
212+
// "class ExampleController\n" +
213+
// "{\n" +
214+
// " /**\n" +
215+
// " * @Security(\"<caret>\")\n" +
216+
// " */\n" +
217+
// " public function contact() {}\n" +
218+
// "}",
219+
// LANGUAGE_ID_EXPRESSION_LANGUAGE
220+
// );
221+
222+
assertInjectedLangAtCaret(
223+
PhpFileType.INSTANCE,
224+
"<?php\n" +
225+
"\n" +
226+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Security;\n" +
227+
"\n" +
228+
"class ExampleController\n" +
229+
"{\n" +
230+
" /**\n" +
231+
" * @Security(expression=\"<caret>\")\n" +
232+
" */\n" +
233+
" public function contact() {}\n" +
234+
"}",
235+
LANGUAGE_ID_EXPRESSION_LANGUAGE
236+
);
237+
238+
assertInjectedLangAtCaret(
239+
PhpFileType.INSTANCE,
240+
"<?php\n" +
241+
"\n" +
242+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Cache;\n" +
243+
"\n" +
244+
"class ExampleController\n" +
245+
"{\n" +
246+
" #[Cache(lastModified: '<caret>')]\n" +
247+
" public function contact() {}\n" +
248+
"}",
249+
LANGUAGE_ID_EXPRESSION_LANGUAGE
250+
);
251+
252+
assertInjectedLangAtCaret(
253+
PhpFileType.INSTANCE,
254+
"<?php\n" +
255+
"\n" +
256+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Cache;\n" +
257+
"\n" +
258+
"class ExampleController\n" +
259+
"{\n" +
260+
" #[Cache(ETag: '<caret>')]\n" +
261+
" public function contact() {}\n" +
262+
"}",
263+
LANGUAGE_ID_EXPRESSION_LANGUAGE
264+
);
265+
266+
assertInjectedLangAtCaret(
267+
PhpFileType.INSTANCE,
268+
"<?php\n" +
269+
"\n" +
270+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Cache;\n" +
271+
"\n" +
272+
"class ExampleController\n" +
273+
"{\n" +
274+
" /**\n" +
275+
" * @Cache(lastModified=\"<caret>\")\n" +
276+
" */\n" +
277+
" public function contact() {}\n" +
278+
"}",
279+
LANGUAGE_ID_EXPRESSION_LANGUAGE
280+
);
281+
282+
assertInjectedLangAtCaret(
283+
PhpFileType.INSTANCE,
284+
"<?php\n" +
285+
"\n" +
286+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Cache;\n" +
287+
"\n" +
288+
"class ExampleController\n" +
289+
"{\n" +
290+
" /**\n" +
291+
" * @Cache(Etag=\"<caret>\")\n" +
292+
" */\n" +
293+
" public function contact() {}\n" +
294+
"}",
295+
LANGUAGE_ID_EXPRESSION_LANGUAGE
296+
);
297+
298+
assertInjectedLangAtCaret(
299+
PhpFileType.INSTANCE,
300+
"<?php\n" +
301+
"\n" +
302+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Entity;\n" +
303+
"\n" +
304+
"class ExampleController\n" +
305+
"{\n" +
306+
" #[Entity('post', expr: '<caret>')]\n" +
307+
" public function contact($post) {}\n" +
308+
"}",
309+
LANGUAGE_ID_EXPRESSION_LANGUAGE
310+
);
311+
312+
assertInjectedLangAtCaret(
313+
PhpFileType.INSTANCE,
314+
"<?php\n" +
315+
"\n" +
316+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Entity;\n" +
317+
"\n" +
318+
"class ExampleController\n" +
319+
"{\n" +
320+
" #[Entity('post', '<caret>')]\n" +
321+
" public function contact($post) {}\n" +
322+
"}",
323+
LANGUAGE_ID_EXPRESSION_LANGUAGE
324+
);
325+
326+
assertInjectedLangAtCaret(
327+
PhpFileType.INSTANCE,
328+
"<?php\n" +
329+
"\n" +
330+
"use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Entity;\n" +
331+
"\n" +
332+
"class ExampleController\n" +
333+
"{\n" +
334+
" /**\n" +
335+
" * @Entity('post', expr=\"<caret>\")\n" +
336+
" */\n" +
337+
" public function contact($post) {}\n" +
338+
"}",
339+
LANGUAGE_ID_EXPRESSION_LANGUAGE
340+
);
341+
342+
assertInjectedLangAtCaret(
343+
PhpFileType.INSTANCE,
344+
"<?php $expr = \\Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\expr(\"<caret>\");\n",
345+
LANGUAGE_ID_EXPRESSION_LANGUAGE
346+
);
347+
348+
assertInjectedLangAtCaret(
349+
PhpFileType.INSTANCE,
350+
"<?php $expr = \\Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\expr(expression: \"<caret>\");",
351+
LANGUAGE_ID_EXPRESSION_LANGUAGE
352+
);
353+
}
354+
73355
private void assertInjectedLangAtCaret(LanguageFileType fileType, String configureByText, String lang) {
74356
myFixture.configureByText(fileType, configureByText);
75357
injectionTestFixture.assertInjectedLangAtCaret(lang);

0 commit comments

Comments
 (0)