Skip to content

Commit b1fcaa9

Browse files
committed
Merge pull request #27 from agallou/fix_subdirectories
fix the run of the test when the composer.json is on a project subdirectory
2 parents d9aff95 + d81da91 commit b1fcaa9

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/pl/projectspace/idea/plugins/php/atoum/actions/AtoumRunTests.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
import com.intellij.openapi.actionSystem.PlatformDataKeys;
1515
import com.intellij.openapi.project.Project;
1616
import com.intellij.openapi.util.Key;
17+
import com.intellij.openapi.vfs.VirtualFile;
1718
import com.intellij.openapi.wm.ToolWindow;
1819
import com.intellij.openapi.wm.ToolWindowAnchor;
1920
import com.intellij.openapi.wm.ToolWindowManager;
21+
import com.intellij.psi.PsiDirectory;
2022
import com.intellij.ui.content.Content;
2123
import com.intellij.ui.content.ContentManager;
2224
import com.jetbrains.php.lang.psi.PhpFile;
@@ -25,10 +27,8 @@
2527
import org.codehaus.jettison.json.JSONObject;
2628
import org.jetbrains.annotations.Nullable;
2729

28-
import java.io.BufferedReader;
2930
import java.io.File;
3031
import java.io.IOException;
31-
import java.io.InputStreamReader;
3232
import java.nio.file.Files;
3333
import java.nio.file.Paths;
3434
import java.util.Arrays;
@@ -75,9 +75,10 @@ protected String runTest(PhpClass currentTestClass, Project project) {
7575
commandLineArgs[0] = currentTestClass.getContainingFile().getVirtualFile().getPath();
7676

7777
try {
78+
VirtualFile testBaseDir = findTestBaseDir(currentTestClass, project);
7879
OSProcessHandler processHandler = ScriptRunnerUtil.execute(
79-
findAtoumBinPath(project),
80-
project.getBasePath(),
80+
findAtoumBinPath(testBaseDir),
81+
testBaseDir.getPath(),
8182
null,
8283
commandLineArgs
8384
);
@@ -102,12 +103,38 @@ public void onTextAvailable(ProcessEvent event, Key outputType) {
102103
}
103104
}
104105

105-
protected String findAtoumBinPath(Project project)
106+
protected VirtualFile findTestBaseDir(PhpClass currentTestClass, Project project)
106107
{
107-
String defaultBinPath = project.getBasePath() + "/vendor/bin/atoum";
108+
Boolean continueSearch = true;
109+
Integer maxDirs = 35;
110+
Integer dirCount = 0;
111+
PsiDirectory currentDir = currentTestClass.getContainingFile().getContainingDirectory();
112+
while (continueSearch) {
113+
dirCount++;
114+
if (currentDir.getVirtualFile().equals(project.getBaseDir())) {
115+
continueSearch = false;
116+
} else if (dirCount >= maxDirs) {
117+
continueSearch = false;
118+
} else {
119+
if (new File(currentDir.getVirtualFile().getPath() + "/composer.json").exists()) {
120+
return currentDir.getVirtualFile();
121+
}
122+
}
123+
currentDir = currentDir.getParentDirectory();
124+
if (null == currentDir) {
125+
return project.getBaseDir();
126+
}
127+
}
128+
129+
return project.getBaseDir();
130+
}
131+
132+
protected String findAtoumBinPath(VirtualFile dir)
133+
{
134+
String defaultBinPath = dir.getPath() + "/vendor/bin/atoum";
108135

109-
String binDir = getComposerBinDir(project.getBasePath() + "/composer.json");
110-
String binPath = project.getBasePath() + "/" + binDir + "/atoum";
136+
String binDir = getComposerBinDir(dir.getPath() + "/composer.json");
137+
String binPath = dir.getPath() + "/" + binDir + "/atoum";
111138
if (null != binDir && new File(binPath).exists()) {
112139
return binPath;
113140
}

0 commit comments

Comments
 (0)