Skip to content

Commit 084c4ff

Browse files
Refactoring
1 parent 3526bee commit 084c4ff

File tree

10 files changed

+79
-4
lines changed

10 files changed

+79
-4
lines changed

src/com/magento/idea/magento2plugin/inspections/graphqls/SchemaResolverInspection.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
import com.intellij.lang.jsgraphql.psi.GraphQLValue;
1212
import com.intellij.lang.jsgraphql.psi.GraphQLVisitor;
1313
import com.jetbrains.php.lang.psi.elements.PhpClass;
14+
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
1415
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
1516
import com.magento.idea.magento2plugin.util.magento.graphql.GraphQlUtil;
1617
import org.jetbrains.annotations.NotNull;
1718

1819
public class SchemaResolverInspection extends LocalInspectionTool {
1920

20-
public static final String GraphQlResolverProblemDescription = "Class must implements \\Magento\\Framework\\GraphQl\\Query\\ResolverInterface";
21+
private final InspectionBundle inspectionBundle = new InspectionBundle();
2122

2223
@NotNull
2324
@Override
@@ -38,7 +39,9 @@ public void visitValue(@NotNull GraphQLValue element) {
3839
}
3940
if (!GraphQlUtil.isResolver(resolverClass)) {
4041
holder.registerProblem(element,
41-
GraphQlResolverProblemDescription,
42+
inspectionBundle.message(
43+
"inspection.graphql.resolver.mustImplement"
44+
),
4245
ProblemHighlightType.ERROR);
4346
}
4447
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
type Query {
5+
test(input: test!): test @resolver(class: "\\Magento\\InspectionTest\\Model\\GraphQl\\WithValidBatchResolverInterface\\Item") @doc(description: "Test")
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
type Query {
5+
test(input: test!): test @resolver(class: "\\Magento\\InspectionTest\\Model\\GraphQl\\WithValidBatchServiceContractResolverInterface\\Item") @doc(description: "Test")
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InspectionTest\Model\GraphQl\WithValidBatchResolverInterface;
9+
10+
use Magento\Framework\GraphQl\Query\Resolver\BatchResolverInterface;
11+
12+
class Item implements BatchResolverInterface
13+
{
14+
}
15+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InspectionTest\Model\GraphQl\WithValidBatchServiceContractResolverInterface;
9+
10+
use Magento\Framework\GraphQl\Query\Resolver\BatchServiceContractResolverInterface;
11+
12+
class Item implements BatchServiceContractResolverInterface
13+
{
14+
}
15+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
28
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
39
<module name="Magento_InspectionTest"/>
410
</config>

testData/project/magento2/app/code/Magento/InspectionTest/registration.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
27
\Magento\Framework\Component\ComponentRegistrar::register(
38
\Magento\Framework\Component\ComponentRegistrar::MODULE,
49
'Magento_InspectionTest',

tests/com/magento/idea/magento2plugin/BaseProjectTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
88
import com.intellij.openapi.util.text.StringUtil;
99
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
10+
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
1011
import com.magento.idea.magento2plugin.indexes.IndexManager;
1112
import com.magento.idea.magento2plugin.project.Settings;
1213
import com.magento.idea.magento2plugin.magento.packages.File;
@@ -18,6 +19,7 @@
1819
abstract public class BaseProjectTestCase extends BasePlatformTestCase {
1920
private static final String testDataProjectPath = "testData" + File.separator + "project";
2021
private static final String testDataProjectDirectory = "magento2";
22+
protected final InspectionBundle inspectionBundle = new InspectionBundle();
2123

2224
@Override
2325
protected void setUp() throws Exception {

tests/com/magento/idea/magento2plugin/inspections/graphqls/SchemaResolverInspectionTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.inspections.graphqls;
26

37
public class SchemaResolverInspectionTest extends InspectionGraphqlsFixtureTestCase {
48

5-
private final String errorMessage = "Class must implements \\Magento\\Framework\\GraphQl\\Query\\ResolverInterface";
9+
private final String errorMessage = inspectionBundle.message(
10+
"inspection.graphql.resolver.mustImplement"
11+
);
612

713
@Override
814
public void setUp() throws Exception {
@@ -23,4 +29,16 @@ public void testWithInvalidSchemaResolverInterface() throws Exception {
2329
myFixture.configureByFile(getFixturePath("schema.graphqls"));
2430
assertHasHighlighting(errorMessage);
2531
}
32+
33+
public void testWithValidBatchResolverInterface() throws Exception {
34+
myFixture.configureByFile(getFixturePath("schema.graphqls"));
35+
36+
assertHasNoHighlighting(errorMessage);
37+
}
38+
39+
public void testWithValidBatchServiceContractResolverInterface() throws Exception {
40+
myFixture.configureByFile(getFixturePath("schema.graphqls"));
41+
42+
assertHasNoHighlighting(errorMessage);
43+
}
2644
}

tests/com/magento/idea/magento2plugin/inspections/php/GraphQlResolverInspectionTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
public class GraphQlResolverInspectionTest extends InspectionPhpFixtureTestCase {
1010

11-
private final InspectionBundle inspectionBundle = new InspectionBundle();
1211
private final String errorMessage = inspectionBundle.message(
1312
"inspection.graphql.resolver.mustImplement"
1413
);

0 commit comments

Comments
 (0)