-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2324 from Haehnchen/feature/test-cases
migrate new Symfony test cases action
- Loading branch information
Showing
7 changed files
with
228 additions
and
195 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
src/main/java/fr/adrienbrault/idea/symfony2plugin/action/NewKernelTestCaseAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.action; | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.fileEditor.OpenFileDescriptor; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.Messages; | ||
import com.intellij.psi.PsiDirectory; | ||
import com.intellij.psi.PsiElement; | ||
import com.jetbrains.php.refactoring.PhpNameUtil; | ||
import com.jetbrains.php.roots.PhpNamespaceCompositeProvider; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; | ||
import fr.adrienbrault.idea.symfony2plugin.util.psi.PhpBundleFileFactory; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class NewKernelTestCaseAction extends AbstractProjectDumbAwareAction { | ||
public NewKernelTestCaseAction() { | ||
super("KernelTestCase", "Create KernelTestCase Class", Symfony2Icons.SYMFONY); | ||
} | ||
|
||
public void update(AnActionEvent event) { | ||
this.setStatus(event, false); | ||
Project project = getEventProject(event); | ||
if (!Symfony2ProjectComponent.isEnabled(project)) { | ||
return; | ||
} | ||
|
||
if (NewFileActionUtil.getSelectedDirectoryFromAction(event) != null) { | ||
this.setStatus(event, true); | ||
} | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent event) { | ||
PsiDirectory directory = NewFileActionUtil.getSelectedDirectoryFromAction(event); | ||
if (directory == null) { | ||
return; | ||
} | ||
|
||
Project project = getEventProject(event); | ||
String className = Messages.showInputDialog(project, "New class name:", "New File", Symfony2Icons.SYMFONY); | ||
if (StringUtils.isBlank(className)) { | ||
return; | ||
} | ||
|
||
if (!className.toLowerCase().endsWith("test")) { | ||
className += "Test"; | ||
} | ||
|
||
if (!PhpNameUtil.isValidClassName(className)) { | ||
JOptionPane.showMessageDialog(null, "Invalid class name"); | ||
return; | ||
} | ||
|
||
List<String> strings = PhpNamespaceCompositeProvider.INSTANCE.suggestNamespaces(directory); | ||
if (strings.isEmpty()) { | ||
JOptionPane.showMessageDialog(null, "No namespace found"); | ||
return; | ||
} | ||
|
||
String finalClassName = className; | ||
ApplicationManager.getApplication().runWriteAction(() -> { | ||
HashMap<String, String> hashMap = new HashMap<>() {{ | ||
put("class", finalClassName); | ||
put("namespace", strings.get(0)); | ||
}}; | ||
|
||
PsiElement commandAttributes = PhpBundleFileFactory.createFile( | ||
project, | ||
directory.getVirtualFile(), | ||
"kernel_test_case", | ||
finalClassName, | ||
hashMap | ||
); | ||
|
||
new OpenFileDescriptor(project, commandAttributes.getContainingFile().getVirtualFile(), 0).navigate(true); | ||
}); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/fr/adrienbrault/idea/symfony2plugin/action/NewWebTestCaseAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.action; | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.fileEditor.OpenFileDescriptor; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.Messages; | ||
import com.intellij.psi.PsiDirectory; | ||
import com.intellij.psi.PsiElement; | ||
import com.jetbrains.php.refactoring.PhpNameUtil; | ||
import com.jetbrains.php.roots.PhpNamespaceCompositeProvider; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; | ||
import fr.adrienbrault.idea.symfony2plugin.util.psi.PhpBundleFileFactory; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class NewWebTestCaseAction extends AbstractProjectDumbAwareAction { | ||
public NewWebTestCaseAction() { | ||
super("WebTestCase", "Create WebTestCase Class", Symfony2Icons.SYMFONY); | ||
} | ||
|
||
public void update(AnActionEvent event) { | ||
this.setStatus(event, false); | ||
Project project = getEventProject(event); | ||
if (!Symfony2ProjectComponent.isEnabled(project)) { | ||
return; | ||
} | ||
|
||
if (NewFileActionUtil.getSelectedDirectoryFromAction(event) != null) { | ||
this.setStatus(event, true); | ||
} | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent event) { | ||
|
||
PsiDirectory directory = NewFileActionUtil.getSelectedDirectoryFromAction(event); | ||
if (directory == null) { | ||
return; | ||
} | ||
|
||
Project project = getEventProject(event); | ||
String className = Messages.showInputDialog(project, "New class name:", "New File", Symfony2Icons.SYMFONY); | ||
if (StringUtils.isBlank(className)) { | ||
return; | ||
} | ||
|
||
if (!className.toLowerCase().endsWith("test")) { | ||
className += "Test"; | ||
} | ||
|
||
if (!PhpNameUtil.isValidClassName(className)) { | ||
JOptionPane.showMessageDialog(null, "Invalid class name"); | ||
return; | ||
} | ||
|
||
List<String> strings = PhpNamespaceCompositeProvider.INSTANCE.suggestNamespaces(directory); | ||
if (strings.isEmpty()) { | ||
JOptionPane.showMessageDialog(null, "No namespace found"); | ||
return; | ||
} | ||
|
||
String finalClassName = className; | ||
ApplicationManager.getApplication().runWriteAction(() -> { | ||
HashMap<String, String> hashMap = new HashMap<>() {{ | ||
put("class", finalClassName); | ||
put("namespace", strings.get(0)); | ||
}}; | ||
|
||
PsiElement commandAttributes = PhpBundleFileFactory.createFile( | ||
project, | ||
directory.getVirtualFile(), | ||
"web_test_case", | ||
finalClassName, | ||
hashMap | ||
); | ||
|
||
new OpenFileDescriptor(project, commandAttributes.getContainingFile().getVirtualFile(), 0).navigate(true); | ||
}); | ||
} | ||
} |
69 changes: 0 additions & 69 deletions
69
...main/java/fr/adrienbrault/idea/symfony2plugin/action/bundle/BundleClassGeneratorUtil.java
This file was deleted.
Oops, something went wrong.
104 changes: 0 additions & 104 deletions
104
...in/java/fr/adrienbrault/idea/symfony2plugin/action/bundle/WebTestCaseGeneratorAction.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.