Skip to content

Commit 3526bee

Browse files
Test added
1 parent bbe49a0 commit 3526bee

File tree

12 files changed

+160
-36
lines changed

12 files changed

+160
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void visitValue(@NotNull GraphQLValue element) {
3636
if (resolverClass == null) {
3737
return;
3838
}
39-
if (GraphQlUtil.isNotResolver(resolverClass)) {
39+
if (!GraphQlUtil.isResolver(resolverClass)) {
4040
holder.registerProblem(element,
4141
GraphQlResolverProblemDescription,
4242
ProblemHighlightType.ERROR);
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\\WithInvalidSchemaResolverInterface\\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\\WithValidSchemaResolverInterface\\Item") @doc(description: "Test")
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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\WithInvalidSchemaResolverInterface;
9+
10+
class Item
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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\WithValidSchemaResolverInterface;
9+
10+
use Magento\Framework\GraphQl\Query\ResolverInterface;
11+
12+
class Item implements ResolverInterface
13+
{
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "magento/inspectiontest",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"version": "1.0.0",
6+
"require": {
7+
"magento/framework": "*"
8+
},
9+
"autoload": {
10+
"files": [
11+
"registration.php"
12+
],
13+
"psr-4": {
14+
"Magento\\InspectionTest\\": ""
15+
}
16+
}
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
<module name="Magento_InspectionTest"/>
4+
</config>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
\Magento\Framework\Component\ComponentRegistrar::register(
3+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
4+
'Magento_InspectionTest',
5+
__DIR__
6+
);

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
*/
55
package com.magento.idea.magento2plugin;
66

7+
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
78
import com.intellij.openapi.util.text.StringUtil;
89
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
910
import com.magento.idea.magento2plugin.indexes.IndexManager;
1011
import com.magento.idea.magento2plugin.project.Settings;
11-
import com.magento.idea.magento2plugin.project.util.GetProjectBasePath;
1212
import com.magento.idea.magento2plugin.magento.packages.File;
13+
import java.util.List;
1314

1415
/**
1516
* Configure test environment with Magento 2 project
@@ -65,4 +66,39 @@ protected String prepareFixturePath(String fileName, String fixturesFolderPath)
6566
private String name() {
6667
return StringUtil.trimEnd(getTestName(true), "Test");
6768
}
69+
70+
protected void assertHasHighlighting(String message) {
71+
String highlightingNotFound = "Failed that documents contains highlighting with the description `%s`";
72+
73+
List<HighlightInfo> highlightingList = myFixture.doHighlighting();
74+
if (highlightingList.isEmpty()) {
75+
fail(String.format(highlightingNotFound, message));
76+
}
77+
78+
for (HighlightInfo highlighting :
79+
highlightingList) {
80+
if (highlighting.getDescription() == null) continue;
81+
if (highlighting.getDescription().equals(message)) {
82+
return;
83+
}
84+
}
85+
fail(String.format(highlightingNotFound, message));
86+
}
87+
88+
protected void assertHasNoHighlighting(String message) {
89+
String highlightingNotFound = "Failed that documents not contains highlighting with the description `%s`";
90+
91+
List<HighlightInfo> highlightingList = myFixture.doHighlighting();
92+
if (highlightingList.isEmpty()) {
93+
return;
94+
}
95+
96+
for (HighlightInfo highlighting :
97+
highlightingList) {
98+
if (highlighting.getDescription() == null) continue;
99+
if (highlighting.getDescription().equals(message)) {
100+
fail(String.format(highlightingNotFound, message));
101+
}
102+
}
103+
}
68104
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.inspections.graphqls;
7+
8+
import com.magento.idea.magento2plugin.BaseProjectTestCase;
9+
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
10+
import java.io.File;
11+
12+
abstract public class InspectionGraphqlsFixtureTestCase extends BaseProjectTestCase {
13+
14+
private static final String testDataFolderPath = "testData" + File.separator + "inspections" + File.separator;
15+
private static final String fixturesFolderPath = "graphqls" + File.separator;
16+
17+
@Override
18+
protected void setUp() throws Exception {
19+
super.setUp();
20+
myFixture.setTestDataPath(testDataFolderPath);
21+
}
22+
23+
@Override
24+
protected boolean isWriteActionRequired() {
25+
return false;
26+
}
27+
28+
protected String getFixturePath(String fileName) {
29+
return prepareFixturePath(fileName, fixturesFolderPath);
30+
}
31+
}

0 commit comments

Comments
 (0)