Skip to content

Commit 6697450

Browse files
committed
Fixed static test failures
1 parent a746b28 commit 6697450

File tree

6 files changed

+53
-50
lines changed

6 files changed

+53
-50
lines changed

src/com/magento/idea/magento2plugin/completion/php/PhpCompletionContributor.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@
88
import com.intellij.codeInsight.completion.CompletionContributor;
99
import com.intellij.codeInsight.completion.CompletionType;
1010
import com.magento.idea.magento2plugin.completion.provider.ModuleNameCompletionProvider;
11+
import com.magento.idea.magento2plugin.util.php.PhpPatternsHelper;
1112

12-
import static com.magento.idea.magento2plugin.util.php.PhpPatternsHelper.CONFIGPHP_COMPLETION;
13-
13+
@SuppressWarnings({
14+
"PMD.CallSuperInConstructor",
15+
})
1416
public class PhpCompletionContributor extends CompletionContributor {
17+
18+
/**
19+
* Constructor.
20+
*/
1521
public PhpCompletionContributor() {
1622
/*
1723
'modules' => [
1824
'Vendor_Module' => 1
1925
]
2026
*/
2127
extend(
22-
CompletionType.BASIC,
23-
CONFIGPHP_COMPLETION,
24-
new ModuleNameCompletionProvider()
28+
CompletionType.BASIC,
29+
PhpPatternsHelper.CONFIGPHP_COMPLETION,
30+
new ModuleNameCompletionProvider()
2531
);
2632
}
2733
}

src/com/magento/idea/magento2plugin/reference/php/PhpReferenceContributor.java

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

88
import com.intellij.psi.PsiReferenceContributor;
99
import com.intellij.psi.PsiReferenceRegistrar;
10+
import com.magento.idea.magento2plugin.reference.provider.EventDispatchReferenceProvider;
1011
import com.magento.idea.magento2plugin.reference.provider.ModuleNameReferenceProvider;
1112
import com.magento.idea.magento2plugin.util.php.PhpPatternsHelper;
12-
import com.magento.idea.magento2plugin.reference.provider.EventDispatchReferenceProvider;
1313
import org.jetbrains.annotations.NotNull;
1414

1515
public class PhpReferenceContributor extends PsiReferenceContributor {
@@ -27,8 +27,8 @@ public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar regi
2727
]
2828
*/
2929
registrar.registerReferenceProvider(
30-
PhpPatternsHelper.CONFIGPHP_MODULENAME,
31-
new ModuleNameReferenceProvider()
30+
PhpPatternsHelper.CONFIGPHP_MODULENAME,
31+
new ModuleNameReferenceProvider()
3232
);
3333
}
3434
}

src/com/magento/idea/magento2plugin/util/php/PhpPatternsHelper.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.intellij.patterns.ElementPattern;
99
import com.intellij.patterns.PlatformPatterns;
10+
import com.intellij.patterns.StandardPatterns;
1011
import com.intellij.psi.PsiElement;
1112
import com.jetbrains.php.lang.PhpLanguage;
1213
import com.jetbrains.php.lang.lexer.PhpTokenTypes;
@@ -16,38 +17,36 @@
1617
import com.jetbrains.php.lang.psi.elements.PhpPsiElement;
1718
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
1819

19-
import static com.intellij.patterns.StandardPatterns.string;
20-
2120
public class PhpPatternsHelper {
2221
public static final ElementPattern<? extends PsiElement> STRING_METHOD_ARGUMENT =
23-
PhpPatterns
24-
.phpLiteralExpression()
25-
.withParent(
26-
PlatformPatterns
27-
.psiElement(ParameterList.class)
28-
.withParent(
29-
PhpPatterns
30-
.phpFunctionReference()
31-
)
32-
).withLanguage(PhpLanguage.INSTANCE);
22+
PhpPatterns
23+
.phpLiteralExpression()
24+
.withParent(
25+
PlatformPatterns
26+
.psiElement(ParameterList.class)
27+
.withParent(
28+
PhpPatterns
29+
.phpFunctionReference()
30+
)
31+
).withLanguage(PhpLanguage.INSTANCE);
3332

3433
public static final ElementPattern<? extends PsiElement> CONFIGPHP_MODULENAME =
35-
PlatformPatterns.psiElement(StringLiteralExpression.class)
36-
.withSuperParent(5,PlatformPatterns.psiElement(ArrayHashElement.class)
37-
.withChild(PlatformPatterns.psiElement(PhpPsiElement.class)
38-
.withChild(PlatformPatterns.psiElement(StringLiteralExpression.class)
39-
.withText(string().contains("modules").withLength(9))
34+
PlatformPatterns.psiElement(StringLiteralExpression.class)
35+
.withSuperParent(5,PlatformPatterns.psiElement(ArrayHashElement.class)
36+
.withChild(PlatformPatterns.psiElement(PhpPsiElement.class)
37+
.withChild(PlatformPatterns.psiElement(StringLiteralExpression.class)
38+
.withText(StandardPatterns.string().contains("modules").withLength(9))
39+
)
4040
)
41-
)
42-
);
41+
);
4342

4443
public static final ElementPattern<? extends PsiElement> CONFIGPHP_COMPLETION =
45-
PlatformPatterns.psiElement(PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE)
46-
.withSuperParent(6, PlatformPatterns.psiElement(ArrayHashElement.class)
47-
.withChild(PlatformPatterns.psiElement(PhpPsiElement.class)
48-
.withChild(PlatformPatterns.psiElement(StringLiteralExpression.class)
49-
.withText(string().contains("modules").withLength(9))
44+
PlatformPatterns.psiElement(PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE)
45+
.withSuperParent(6, PlatformPatterns.psiElement(ArrayHashElement.class)
46+
.withChild(PlatformPatterns.psiElement(PhpPsiElement.class)
47+
.withChild(PlatformPatterns.psiElement(StringLiteralExpression.class)
48+
.withText(StandardPatterns.string().contains("modules").withLength(9))
49+
)
5050
)
51-
)
52-
);
51+
);
5352
}

tests/com/magento/idea/magento2plugin/completion/BaseCompletionTestCase.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.Arrays;
1111
import java.util.List;
1212

13-
abstract public class BaseCompletionTestCase extends BaseProjectTestCase {
13+
public abstract class BaseCompletionTestCase extends BaseProjectTestCase {
1414
private static final String MESSAGE_NO_LOOKUP = "No lookup element was provided";
1515
private final String testDataFolderPath
1616
= "testData" + File.separator + "completion" + File.separator;
@@ -26,6 +26,9 @@ private void configureFixture(final String filePath) {
2626
myFixture.completeBasic();
2727
}
2828

29+
/**
30+
* Assert that completion suggestions contains the given lookup strings.
31+
*/
2932
public void assertCompletionContains(final String filePath, final String... lookupStrings) {
3033
configureFixture(filePath);
3134

@@ -55,13 +58,11 @@ protected void assertFileNotContainsCompletions(
5558
) {
5659
configureFixture(filePath);
5760

58-
final String messageEmptyLookup
59-
= "Failed that completion does not contain `%s` for file " + filePath;
6061
final String messageCompletionNotContains
6162
= "Failed that completion does not contain `%s` in `%s` for file " + filePath;
6263

6364
checkDoesNotContainCompletion(
64-
lookupStrings, messageEmptyLookup, messageCompletionNotContains
65+
lookupStrings, messageCompletionNotContains
6566
);
6667
}
6768

@@ -104,7 +105,6 @@ protected void checkContainsCompletion(
104105

105106
protected void checkDoesNotContainCompletion(
106107
final String[] lookupStrings,
107-
final String emptyLookupError,
108108
final String completionDoesNotContainError
109109
) {
110110
if (lookupStrings.length == 0) {
@@ -113,15 +113,13 @@ protected void checkDoesNotContainCompletion(
113113

114114
final List<String> lookupElements = myFixture.getLookupElementStrings();
115115

116-
if (lookupElements == null || lookupElements.isEmpty()) {
117-
fail(String.format(emptyLookupError, Arrays.toString(lookupStrings)));
118-
}
119-
120-
for (final String lookupString : lookupStrings) {
121-
if (lookupElements.contains(lookupString)) {
122-
fail(String.format(
123-
completionDoesNotContainError, lookupString, lookupElements.toString())
124-
);
116+
if (lookupElements != null) {
117+
for (final String lookupString : lookupStrings) {
118+
if (lookupElements.contains(lookupString)) {
119+
fail(String.format(
120+
completionDoesNotContainError, lookupString, lookupElements.toString())
121+
);
122+
}
125123
}
126124
}
127125
}

tests/com/magento/idea/magento2plugin/completion/php/CompletionPhpFixtureTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.magento.idea.magento2plugin.completion.BaseCompletionTestCase;
99
import com.magento.idea.magento2plugin.magento.packages.File;
1010

11-
abstract public class CompletionPhpFixtureTestCase extends BaseCompletionTestCase {
11+
public abstract class CompletionPhpFixtureTestCase extends BaseCompletionTestCase {
1212
private static final String FIXTURES_FOLDER_PATH = "php" + File.separator;
1313

1414
@Override

tests/com/magento/idea/magento2plugin/completion/xml/CompletionXmlFixtureTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.magento.idea.magento2plugin.completion.BaseCompletionTestCase;
99
import com.magento.idea.magento2plugin.magento.packages.File;
1010

11-
abstract public class CompletionXmlFixtureTestCase extends BaseCompletionTestCase {
11+
public abstract class CompletionXmlFixtureTestCase extends BaseCompletionTestCase {
1212
private static final String FIXTURES_FOLDER_PATH = "xml" + File.separator;
1313

1414
@Override

0 commit comments

Comments
 (0)