Skip to content

Commit 291615d

Browse files
committed
Mocks: add support of newMockInstance method
1 parent 5b15112 commit 291615d

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/org/atoum/intellij/plugin/atoum/MockTypeProvider.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import com.intellij.openapi.project.Project;
44
import com.intellij.psi.PsiElement;
5-
import com.jetbrains.php.lang.psi.elements.ClassReference;
6-
import com.jetbrains.php.lang.psi.elements.NewExpression;
7-
import com.jetbrains.php.lang.psi.elements.PhpNamedElement;
5+
import com.jetbrains.php.lang.psi.elements.*;
86
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
97
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider3;
108
import org.jetbrains.annotations.Nullable;
@@ -29,6 +27,26 @@ public PhpType getType(PsiElement psiElement) {
2927
if (ref != null && ref.getFQN() != null && ref.getFQN().startsWith("\\mock\\")) {
3028
return new PhpType().add(ref.getFQN().substring("\\mock".length()));
3129
}
30+
} else if (psiElement instanceof MethodReference) {
31+
MethodReference expr = (MethodReference) psiElement;
32+
if (expr.getName() == null || !expr.getName().equals("newMockInstance")) {
33+
return null;
34+
}
35+
36+
if (expr.getParameters().length == 0) {
37+
return null;
38+
}
39+
40+
PsiElement param = expr.getParameters()[0];
41+
42+
if (param instanceof ClassConstantReference) {
43+
PhpExpression ref = ((ClassConstantReference) param).getClassReference();
44+
if (ref instanceof ClassReference) {
45+
return new PhpType().add(ref);
46+
}
47+
} else if (param instanceof StringLiteralExpression) {
48+
return new PhpType().add(((StringLiteralExpression) param).getContents());
49+
}
3250
}
3351

3452
return null;

0 commit comments

Comments
 (0)