Skip to content

Commit 6053535

Browse files
committed
fix template extraction for methods with ending "Action" to fix non-existing template complaining in @template() annotation #999
1 parent 58d96d9 commit 6053535

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

src/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static String[] getControllerMethodShortcut(@NotNull Method method) {
111111
symfonyBundle.getName(),
112112
templateFolderName,
113113
templateName,
114-
StringUtils.stripEnd(methodName, "Action")
114+
!methodName.endsWith("Action") ? methodName : methodName.substring(0, methodName.length() - "Action".length())
115115
);
116116
}
117117

tests/fr/adrienbrault/idea/symfony2plugin/tests/templating/util/TwigUtilTest.java

+25-16
Original file line numberDiff line numberDiff line change
@@ -373,22 +373,31 @@ public void testGetTwigMacroNameAndParameter() {
373373
public void testGetControllerMethodShortcut() {
374374
myFixture.copyFileToProject("controller_method.php");
375375

376-
myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
377-
"namespace FooBundle\\Controller;\n" +
378-
"class FoobarController\n" +
379-
"{\n" +
380-
" public function fo<caret>obarAction() {}\n" +
381-
"" +
382-
"}\n"
383-
);
384-
385-
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
386-
387-
List<String> strings = Arrays.asList(TwigUtil.getControllerMethodShortcut((Method) psiElement.getParent()));
388-
389-
assertContainsElements(strings, "FooBundle:Foobar:foobar.html.twig");
390-
assertContainsElements(strings, "FooBundle:Foobar:foobar.json.twig");
391-
assertContainsElements(strings, "FooBundle:Foobar:foobar.xml.twig");
376+
Collection<String[]> dataProvider = new ArrayList<String[]>() {{
377+
add(new String[] {"fo<caret>obarAction", "foobar"});
378+
add(new String[] {"fo<caret>obar", "foobar"});
379+
add(new String[] {"editAction", "edit"});
380+
add(new String[] {"ed<caret>it", "edit"});
381+
}};
382+
383+
for (String[] string : dataProvider) {
384+
myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
385+
"namespace FooBundle\\Controller;\n" +
386+
"class FoobarController\n" +
387+
"{\n" +
388+
" public function " + string[0] + "() {}\n" +
389+
"" +
390+
"}\n"
391+
);
392+
393+
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
394+
395+
List<String> strings = Arrays.asList(TwigUtil.getControllerMethodShortcut((Method) psiElement.getParent()));
396+
397+
assertContainsElements(strings, "FooBundle:Foobar:" + string[1] + ".html.twig");
398+
assertContainsElements(strings, "FooBundle:Foobar:" + string[1] + ".json.twig");
399+
assertContainsElements(strings, "FooBundle:Foobar:" + string[1] + ".xml.twig");
400+
}
392401
}
393402

394403
public void testGetControllerMethodShortcutForInvoke() {

0 commit comments

Comments
 (0)