Skip to content

Commit 01c0fa4

Browse files
committed
Migrate to PHPUnit 8.5+
1 parent 31d0930 commit 01c0fa4

26 files changed

+397
-402
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Downloads last month](http://phpstorm.espend.de/badge/9674/last-month)](https://plugins.jetbrains.com/plugin/9674)
77
[![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/DanielEspendiller)
88

9-
PhpStorm plugin to provide smart autocomplete, code navigation and refactoring features for mocked class methods. Supported all versions of PhpStorm since 2017.1
9+
PhpStorm plugin to provide smart autocomplete, code navigation and refactoring features for mocked class methods. Supported all versions of PhpStorm since 2020.1
1010

1111
Key | Value
1212
----------- | -----------

build-test.xml

Lines changed: 0 additions & 192 deletions
This file was deleted.

build.gradle

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
22

33
plugins {
4-
id "org.jetbrains.intellij" version "0.4.11"
4+
id 'idea'
5+
id 'java'
6+
id "org.jetbrains.intellij" version "0.4.21"
57
id 'com.palantir.git-version' version "0.11.0"
68
}
79

810
def htmlFixer = { htmlFile -> file(htmlFile).text.replace('<html>', '').replace('</html>', '') }
911

10-
apply plugin: 'idea'
11-
apply plugin: 'org.jetbrains.intellij'
12-
apply plugin: 'java'
12+
repositories {
13+
mavenCentral()
14+
}
1315

16+
apply plugin: 'org.jetbrains.intellij'
1417
intellij {
1518
version ideaVersion
16-
pluginName 'PHPUnit Enhancement'
19+
pluginName 'PHPUnit Helper'
1720
updateSinceUntilBuild false
1821
plugins = [
1922
"com.jetbrains.php:${phpPluginVersion}",
@@ -31,11 +34,11 @@ publishPlugin {
3134
}
3235

3336
patchPluginXml {
34-
sinceBuild '192.6603'
37+
sinceBuild phpPluginVersion
3538
changeNotes = htmlFixer('src/main/resources/META-INF/change-notes.html')
3639
}
3740

38-
group 'de.espend.idea.php.phpunit'
41+
group 'com.dimabdc.idea.php.phpunit'
3942

4043
def details = versionDetails()
4144
if (details.isCleanTag) {
@@ -44,8 +47,4 @@ if (details.isCleanTag) {
4447
version = "${details.lastTag}.${details.gitHash}-SNAPSHOT"
4548
}
4649

47-
wrapper {
48-
gradleVersion '5.5.1'
49-
}
50-
5150
test.testLogging.exceptionFormat = TestExceptionFormat.FULL
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/com/phpuaca/annotator/StringAnnotator.java

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.intellij.lang.annotation.AnnotationHolder;
44
import com.intellij.lang.annotation.Annotator;
5-
import com.intellij.openapi.util.TextRange;
5+
import com.intellij.lang.annotation.HighlightSeverity;
66
import com.intellij.openapi.util.text.StringUtil;
77
import com.intellij.psi.PsiElement;
88
import com.jetbrains.php.lang.psi.elements.Method;
@@ -11,32 +11,63 @@
1111
import com.phpuaca.filter.FilterFactory;
1212
import com.phpuaca.helper.AvailabilityHelper;
1313
import org.jetbrains.annotations.NotNull;
14+
import org.jetbrains.annotations.Nullable;
15+
16+
import java.util.Objects;
1417

1518
public class StringAnnotator implements Annotator {
1619

1720
@Override
1821
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
1922
AvailabilityHelper availabilityHelper = new AvailabilityHelper();
20-
if (availabilityHelper.checkFile(psiElement.getContainingFile()) && availabilityHelper.checkScope(psiElement)) {
21-
Filter filter = FilterFactory.getInstance().getFilter(psiElement);
22-
if (filter != null) {
23-
PhpClass phpClass = filter.getPhpClass();
24-
if (phpClass != null) {
25-
String name = StringUtil.unquoteString(psiElement.getText());
26-
Method method = phpClass.findMethodByName(name);
27-
TextRange textRange = psiElement.getTextRange();
28-
TextRange annotationTextRange = new TextRange(textRange.getStartOffset() + 1, textRange.getEndOffset() - 1);
29-
if (method == null) {
30-
if (phpClass.findFieldByName(name, false) == null) {
31-
annotationHolder.createWarningAnnotation(annotationTextRange, "Method '" + name + "' not found in class " + phpClass.getName());
32-
}
33-
} else {
34-
if (!filter.isMethodAllowed(method)) {
35-
annotationHolder.createWarningAnnotation(annotationTextRange, "Method '" + name + "' is not allowed to use here");
36-
}
37-
}
38-
}
23+
if (!availabilityHelper.checkFile(psiElement.getContainingFile())) {
24+
return;
25+
}
26+
27+
if (!availabilityHelper.checkScope(psiElement)) {
28+
return;
29+
}
30+
31+
Filter filter = FilterFactory.getInstance().getFilter(psiElement);
32+
if (filter == null) {
33+
return;
34+
}
35+
36+
PhpClass phpClass = filter.getPhpClass();
37+
if (phpClass == null) {
38+
return;
39+
}
40+
41+
String name = StringUtil.unquoteString(psiElement.getText());
42+
Method method = findMethod(phpClass, name);
43+
if (method == null) {
44+
if (Objects.equals(filter.getPhpMethod(), "addMethods")) {
45+
return;
46+
}
47+
48+
if (filter.isMethodAllowed(name) && Objects.equals(filter.getPhpMethod(), "method")) {
49+
return;
50+
}
51+
52+
annotationHolder.newAnnotation(HighlightSeverity.WARNING, "Method '" + name + "' not found in class " + phpClass.getName()).create();
53+
} else {
54+
boolean isMethodAllowed = filter.isMethodAllowed(method);
55+
boolean isAddMethods = Objects.equals(filter.getPhpMethod(), "addMethods");
56+
if ((!isMethodAllowed && !isAddMethods) || (isMethodAllowed && isAddMethods)) {
57+
annotationHolder.newAnnotation(HighlightSeverity.WARNING, "Method '" + name + "' is not allowed to use here").create();
3958
}
4059
}
4160
}
61+
62+
@Nullable
63+
private Method findMethod(PhpClass phpClass, String name) {
64+
do {
65+
Method method = phpClass.findOwnMethodByName(name);
66+
if (method != null) {
67+
return method;
68+
}
69+
} while ((phpClass = phpClass.getSuperClass()) != null);
70+
71+
return null;
72+
}
4273
}

src/main/java/com/phpuaca/completion/StringCompletionProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class StringCompletionProvider extends CompletionProvider<CompletionParameters> {
2121

2222
@Override
23-
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
23+
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
2424
PsiElement originalPosition = completionParameters.getOriginalPosition();
2525
if (originalPosition != null) {
2626
Filter filter = FilterFactory.getInstance().getFilter(originalPosition.getParent());
@@ -32,7 +32,7 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters
3232

3333
@NotNull
3434
protected List<LookupElement> getLookupElements(@NotNull Filter filter) {
35-
List<LookupElement> list = new ArrayList<LookupElement>();
35+
List<LookupElement> list = new ArrayList<>();
3636
PhpClass phpClass = filter.getPhpClass();
3737

3838
if (phpClass != null) {

0 commit comments

Comments
 (0)