Skip to content

Commit 49e63de

Browse files
author
Vitaliy
authored
Merge pull request #223 from magento/213-web-api-linemarker-test
Added tests for WEB-API line markers, fixed performance issue
2 parents 267f558 + f517ecc commit 49e63de

File tree

6 files changed

+123
-3
lines changed

6 files changed

+123
-3
lines changed

src/com/magento/idea/magento2plugin/linemarker/php/WebApiLineMarkerProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.codeInsight.daemon.LineMarkerProvider;
99
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
1010
import com.intellij.psi.PsiElement;
11+
import com.intellij.psi.util.PsiTreeUtil;
1112
import com.intellij.psi.xml.XmlTag;
1213
import com.jetbrains.php.lang.psi.elements.Method;
1314
import com.jetbrains.php.lang.psi.elements.PhpClass;
@@ -62,7 +63,7 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
6263
.create(MagentoIcons.WEB_API)
6364
.setTargets(results)
6465
.setTooltipText(tooltipText.toString());
65-
collection.add(builder.createLineMarkerInfo(psiElement));
66+
collection.add(builder.createLineMarkerInfo(PsiTreeUtil.getDeepestFirst(psiElement)));
6667
}
6768
}
6869

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model;
8+
9+
class ClassNotConfiguredInWebApiXml
10+
{
11+
public function create()
12+
{
13+
}
14+
15+
public function update()
16+
{
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Service;
8+
9+
class TestService
10+
{
11+
public function create()
12+
{
13+
}
14+
15+
public function update()
16+
{
17+
}
18+
}
19+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
9+
<route url="/V1/blog/post" method="PUT">
10+
<service class="Magento\Catalog\Service\TestService" method="create"/>
11+
<resources>
12+
<resource ref="Magento_Catalog::test"/>
13+
</resources>
14+
</route>
15+
<route url="/V1/blog/update" method="POST">
16+
<service class="Magento\Catalog\Service\TestService" method="update"/>
17+
<resources>
18+
<resource ref="Magento_Catalog::test"/>
19+
</resources>
20+
</route>
21+
</routes>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*/
55
package com.magento.idea.magento2plugin.inspections.php;
66

7-
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
8-
97
public class GraphQlResolverInspectionTest extends InspectionPhpFixtureTestCase {
108

119
private final String errorMessage = inspectionBundle.message(
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.linemarker.php;
6+
7+
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
8+
import com.magento.idea.magento2plugin.MagentoIcons;
9+
10+
public class WebApiLinemarkerRegistrarTest extends LinemarkerPhpFixtureTestCase {
11+
12+
private static final String expectedClassLineMarkerTooltip =
13+
"Navigate to Web API configuration:<pre> PUT /V1/blog/post\n" +
14+
" POST /V1/blog/update\n" +
15+
"</pre>";
16+
17+
private static final String expectedMethodCreateLineMarkerTooltip =
18+
"Navigate to Web API configuration:<pre> POST /V1/blog/update\n" +
19+
"</pre>";
20+
21+
private static final String expectedMethodUpdateLineMarkerTooltip =
22+
"Navigate to Web API configuration:<pre> PUT /V1/blog/post\n" +
23+
"</pre>";
24+
25+
/**
26+
* Class configured as WEB API service in web_api.xml should have WEB API line markers
27+
*/
28+
public void testWebApiServiceShouldHaveLinemarker() {
29+
String filePath = this.getFixturePath("TestService.php");
30+
31+
//work around for issue caused by com.magento.idea.magento2plugin.linemarker.xml.LineMarkerXmlTagDecorator
32+
//in com.intellij.psi.impl.smartPointers.SmartPsiElementPointerImpl.createElementInfo
33+
boolean isInStressTestCurrent = ApplicationInfoImpl.isInStressTest();
34+
ApplicationInfoImpl.setInStressTest(true);
35+
36+
myFixture.configureByFile(filePath);
37+
38+
//assert class line marker
39+
assertHasLinemarkerWithTooltipAndIcon(expectedClassLineMarkerTooltip, MagentoIcons.WEB_API.toString());
40+
41+
//assert methods line markers
42+
assertHasLinemarkerWithTooltipAndIcon(expectedMethodCreateLineMarkerTooltip, MagentoIcons.WEB_API.toString());
43+
assertHasLinemarkerWithTooltipAndIcon(expectedMethodUpdateLineMarkerTooltip, MagentoIcons.WEB_API.toString());
44+
45+
//restore default value
46+
ApplicationInfoImpl.setInStressTest(isInStressTestCurrent);
47+
}
48+
49+
/**
50+
* Regular class should not have WEB API line markers
51+
*/
52+
public void testRegularPhpClassShouldNotHaveLinemarker() {
53+
String filePath = this.getFixturePath("ClassNotConfiguredInWebApiXml.php");
54+
myFixture.configureByFile(filePath);
55+
56+
//assert class line marker
57+
assertHasNoLinemarkerWithTooltipAndIcon(expectedClassLineMarkerTooltip, MagentoIcons.WEB_API.toString());
58+
59+
//assert methods line markers
60+
assertHasNoLinemarkerWithTooltipAndIcon(expectedMethodCreateLineMarkerTooltip, MagentoIcons.WEB_API.toString());
61+
assertHasNoLinemarkerWithTooltipAndIcon(expectedMethodUpdateLineMarkerTooltip, MagentoIcons.WEB_API.toString());
62+
}
63+
}

0 commit comments

Comments
 (0)