Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ public class PhpJobMethodReferenceProvider extends PsiReferenceProvider {

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
if (!(element instanceof XmlElement)) {
return PsiReference.EMPTY_ARRAY;
}

List<PsiReference> psiReferences = new ArrayList<>();

String methodName = StringUtil.unquoteString(element.getText());
public PsiReference[] getReferencesByElement(
@NotNull final PsiElement element,
@NotNull final ProcessingContext context
) {
final List<PsiReference> psiReferences = new ArrayList<>();
final String methodName = StringUtil.unquoteString(element.getText());
final PhpClass phpClass = DiIndex.getPhpClassOfJobMethod((XmlElement) element);

PhpClass phpClass = DiIndex.getPhpClassOfJobMethod((XmlElement) element);
if (phpClass != null) {
Collection<Method> methods = phpClass.getMethods();
methods.removeIf(method -> !method.getName().contains(methodName));
psiReferences.add(new PolyVariantReferenceBase(element, methods));
final Collection<Method> methods = phpClass.getMethods();
methods.removeIf(method -> !method.getName().matches(methodName));
if (!methods.isEmpty()) {
psiReferences.add(new PolyVariantReferenceBase(element, methods));
}
}

return psiReferences.toArray(new PsiReference[psiReferences.size()]);
return psiReferences.toArray(new PsiReference[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
<job name="test_catalog_index_refresh_price" instance="Magento\Catalog\Cron\RefreshSpecialPrices" method="execute<caret>">
<schedule>0 * * * *</schedule>
<job name="catalog_index_refresh_price"
instance="Magento\Catalog\Cron\RefreshSpecialPrices"
method="execute<caret>">
<schedule>* * * * *</schedule>
</job>
</group>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
<job name="catalog_index_refresh_price"
instance="Magento\Catalog\Cron\RefreshSpecialPrices"
method="notExecute<caret>">
<schedule>* * * * *</schedule>
</job>
</group>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected void assertHasReferenceToClassMethod(
final PsiElement element = getElementFromCaret();
final PsiReference[] references = element.getReferences();
final String actualClassName = ((PhpClass) references[references.length - 1].resolve()
.getParent()).getFQN();
.getParent()).getPresentableFQN();
final String actualMethodName = ((Method) references[references.length - 1].resolve())
.getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,36 @@
import com.magento.idea.magento2plugin.magento.files.CrontabXmlTemplate;

public class CrontabReferenceRegistrarTest extends ReferenceXmlFixtureTestCase {
private static final String EXPECTED_REFERENCE = "Magento\\Catalog\\Cron\\RefreshSpecialPrices";
private static final String EXPECTED_CLASS = "Magento\\Catalog\\Cron\\RefreshSpecialPrices";
private static final String EXPECTED_METHOD = "execute";

/**
* Test instance attribute of the crontab.xml file
* must have reference.
* Test instance attribute of the crontab.xml file must have reference.
*/
public void testCrontabInstanceMustHaveReference() {
final String filePath = this.getFixturePath(CrontabXmlTemplate.FILE_NAME);
myFixture.configureByFile(filePath);
myFixture.configureByFile(this.getFixturePath(CrontabXmlTemplate.FILE_NAME));

assertHasReferencePhpClass(EXPECTED_REFERENCE);
assertHasReferencePhpClass(EXPECTED_CLASS);
}

/**
* Tests for reference to valid PHP method in crontab.xml.
*/
public void testCrontabMethodMustHaveReference() {
myFixture.configureByFile(this.getFixturePath(CrontabXmlTemplate.FILE_NAME));

assertHasReferenceToClassMethod(
EXPECTED_CLASS,
EXPECTED_METHOD
);
}

/**
* Tests for no reference to invalid PHP method in crontab.xml.
*/
public void testCrontabMethodMustNotHaveReference() {
myFixture.configureByFile(this.getFixturePath(CrontabXmlTemplate.FILE_NAME));

assertEmptyReference();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void testWebApiMethodMustHaveReference() {
myFixture.configureByFile(this.getFixturePath("webapi.xml"));

assertHasReferenceToClassMethod(
"\\Magento\\Catalog\\Api\\ProductRepositoryInterface",
"Magento\\Catalog\\Api\\ProductRepositoryInterface",
"save"
);
}
Expand Down