Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<!-- Add your actions here -->
<action id="OpenSpecForClass" class="pl.projectspace.idea.plugins.php.atoum.actions.AtoumSwitchContext"
icon="/pl/projectspace/idea/plugins/php/atoum/icons/atoum_16_16.png"
text="Go to atoum test">
text="Swicth to test class / tested class">
<add-to-group group-id="GoToCodeGroup" anchor="last"/>
<add-to-group group-id="EditorPopupMenu.GoTo" anchor="last"/>
</action>
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@

Integrates atoum into PHPStorm


## Features

Menu entry to go to the test from the tested class.
### Go to the test class from the tested class

* From the tested class you can go to the test class from a menu entry in navigation

![Demo](doc/switch.png)

* Or by an entry bin the right click menu

![Demo](doc/switch-right_click.png)


### Go to the tested class from the test class

* From the test class you can go to the tested class from a menu entry in navigation

![Demo](doc/switch_back-right_click.png)

* Or by an entry bin the right click menu

![Demo](doc/switch_back-right_click.png)

## Links

Expand Down
Binary file added doc/switch-right_click.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/switch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/switch_back-right_click.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/switch_back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,92 @@ public class AtoumSwitchContext extends AnAction {
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(false);
e.getPresentation().setVisible(true);
e.getPresentation().setText("Go to atoum test");
e.getPresentation().setText("atoum - switch to");

PhpClass testedClass = getTestedClass(e);
PhpClass testedClass = getSwitchClass(e);
if (null == testedClass) {
return;
}

e.getPresentation().setText("Go to atoum test : " + testedClass.getFQN());
e.getPresentation().setText("atoum - switch to : " + testedClass.getFQN());
e.getPresentation().setEnabled(true);
}

public void actionPerformed(final AnActionEvent e) {
PhpClass testedClass = getTestedClass(e);
PhpClass testedClass = getSwitchClass(e);
if (null == testedClass) {
return;
}
OpenFileAction.openFile(testedClass.getContainingFile().getVirtualFile().getPath(), e.getProject());
}

@Nullable
protected PhpClass getTestedClass(final AnActionEvent e) {
protected PhpClass getSwitchClass(final AnActionEvent e) {
Object psiFile = e.getData(PlatformDataKeys.PSI_FILE);

if (null == psiFile) {
return null;
}

if (psiFile instanceof PhpFile) {
PhpFile phpFile = ((PhpFile) psiFile);
PhpClass testedClass = getTestedClass(e.getProject(), phpFile);
if (null == testedClass) {
return null;
}
if (!(psiFile instanceof PhpFile)) {
return null;
}
PhpFile phpFile = ((PhpFile) psiFile);
PhpClass testedClass = getSwitchClass(e.getProject(), phpFile);

return testedClass;
if (null == testedClass) {
return null;
}

return null;
return testedClass;
}

@Nullable
protected PhpClass getTestedClass(Project project, PhpFile phpFile) {
protected PhpClass getSwitchClass(Project project, PhpFile phpFile) {
PhpClass currentClass = getFirstClassFromFile(phpFile);
if (null == currentClass) {
return null;
}

String testedClassname = currentClass.getNamespaceName() + "tests\\units\\" + currentClass.getName();
Collection<PhpClass> phpClasses = PhpIndex.getInstance(project).getAnyByFQN(testedClassname);
if (phpClasses.size() == 1) {
PhpClass testedClass = (PhpClass)phpClasses.toArray()[0];
return testedClass;
if (isClassAtoumTest(currentClass)) {
return locateTestedClass(project, currentClass);
}

return null;
return locateTestClass(project, currentClass);
}

protected Boolean isClassAtoumTest(PhpClass checkedClass)
{
return checkedClass.getNamespaceName().endsWith(getTestsNamespaceSuffix());
}

@Nullable
protected PhpClass locateTestClass(Project project, PhpClass testedClass) {
String testClassname = testedClass.getNamespaceName() + getTestsNamespaceSuffix() + testedClass.getName();
return locatePhpClass(project, testClassname);
}

@Nullable
protected PhpClass locateTestedClass(Project project, PhpClass testClass) {
String testClassNamespaceName = testClass.getNamespaceName();
String testedClassname = testClassNamespaceName.substring(0, testClassNamespaceName.length() - getTestsNamespaceSuffix().length()) + testClass.getName();
return locatePhpClass(project, testedClassname);

}

@Nullable
protected PhpClass locatePhpClass(Project project, String name) {
Collection<PhpClass> phpClasses = PhpIndex.getInstance(project).getAnyByFQN(name);
if (phpClasses.size() != 1) {
return null;
}

return (PhpClass)phpClasses.toArray()[0];
}

private String getTestsNamespaceSuffix()
{
return "tests\\units\\";
}

//https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/cb422db9779025d65fdf0ba5d26a38d401eca939/src/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java#L784
Expand Down