|
1 | 1 | package fr.adrienbrault.idea.symfony2plugin.tests.util.yaml; |
2 | 2 |
|
| 3 | +import com.intellij.openapi.vfs.VirtualFile; |
3 | 4 | import com.intellij.psi.PsiElement; |
4 | 5 | import com.intellij.psi.PsiFile; |
| 6 | +import com.intellij.psi.PsiManager; |
| 7 | +import com.intellij.psi.util.PsiTreeUtil; |
5 | 8 | import com.intellij.util.Function; |
6 | 9 | import com.intellij.util.containers.ContainerUtil; |
7 | 10 | import com.jetbrains.php.lang.psi.elements.Parameter; |
| 11 | +import com.jetbrains.php.lang.psi.elements.PhpNamedElement; |
8 | 12 | import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; |
9 | 13 | import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper; |
10 | 14 | import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlPsiElementFactory; |
|
20 | 24 | import java.util.Collection; |
21 | 25 | import java.util.List; |
22 | 26 | import java.util.Set; |
23 | | -import java.util.function.Predicate; |
| 27 | +import java.util.stream.Collectors; |
24 | 28 |
|
25 | 29 | /** |
26 | 30 | * @author Daniel Espendiller <daniel@espendiller.net> |
@@ -605,6 +609,74 @@ public void testGetServiceKeyFromResourceFromStringOrArray() { |
605 | 609 | assertEquals("App\\", YamlHelper.getServiceKeyFromResourceFromStringOrArray(fromText)); |
606 | 610 | } |
607 | 611 |
|
| 612 | + @NotNull |
| 613 | + private Collection<String> getClassNamesFromResourceGlob(@NotNull Collection<YAMLKeyValue> yamlKeyValues, @NotNull String namespace) { |
| 614 | + YAMLKeyValue yamlKeyValue = yamlKeyValues.stream() |
| 615 | + .filter(yamlKeyValue1 -> namespace.equals(yamlKeyValue1.getKeyText())) |
| 616 | + .findFirst() |
| 617 | + .orElseThrow(); |
| 618 | + |
| 619 | + return YamlHelper.getNamespaceResourcesClasses(yamlKeyValue).stream() |
| 620 | + .map(PhpNamedElement::getFQN) |
| 621 | + .collect(Collectors.toSet()); |
| 622 | + } |
| 623 | + |
| 624 | + public void testGetNamespaceResourcesClasses() { |
| 625 | + myFixture.copyFileToProject("YamlHelper.php", "src/YamlHelper.php"); |
| 626 | + VirtualFile service = myFixture.copyFileToProject("services.yml", "src/services.yml"); |
| 627 | + PsiFile file = PsiManager.getInstance(getProject()).findFile(service); |
| 628 | + |
| 629 | + Collection<YAMLKeyValue> yamlKeyValues = PsiTreeUtil.collectElementsOfType(file, YAMLKeyValue.class); |
| 630 | + |
| 631 | + assertContainsElements( |
| 632 | + getClassNamesFromResourceGlob(yamlKeyValues, "Foo\\"), |
| 633 | + "\\Foo\\Bar" |
| 634 | + ); |
| 635 | + |
| 636 | + assertContainsElements( |
| 637 | + getClassNamesFromResourceGlob(yamlKeyValues, "Foo1\\"), |
| 638 | + "\\Foo1\\Bar" |
| 639 | + ); |
| 640 | + |
| 641 | + assertContainsElements( |
| 642 | + getClassNamesFromResourceGlob(yamlKeyValues, "Foo2\\"), |
| 643 | + "\\Foo2\\Bar" |
| 644 | + ); |
| 645 | + |
| 646 | + assertContainsElements( |
| 647 | + getClassNamesFromResourceGlob(yamlKeyValues, "Foo3\\"), |
| 648 | + "\\Foo3\\Bar" |
| 649 | + ); |
| 650 | + |
| 651 | + assertContainsElements( |
| 652 | + getClassNamesFromResourceGlob(yamlKeyValues, "Foo4\\"), |
| 653 | + "\\Foo4\\Bar" |
| 654 | + ); |
| 655 | + } |
| 656 | + |
| 657 | + public void testGetNamespaceResourcesClassesWithExclude() { |
| 658 | + myFixture.copyFileToProject("YamlHelper.php", "src/YamlHelper.php"); |
| 659 | + VirtualFile service = myFixture.copyFileToProject("services.yml", "src/services.yml"); |
| 660 | + PsiFile file = PsiManager.getInstance(getProject()).findFile(service); |
| 661 | + |
| 662 | + Collection<YAMLKeyValue> yamlKeyValues = PsiTreeUtil.collectElementsOfType(file, YAMLKeyValue.class); |
| 663 | + |
| 664 | + assertDoesntContain( |
| 665 | + getClassNamesFromResourceGlob(yamlKeyValues, "Foo5\\"), |
| 666 | + "\\Foo5\\Bar" |
| 667 | + ); |
| 668 | + |
| 669 | + assertDoesntContain( |
| 670 | + getClassNamesFromResourceGlob(yamlKeyValues, "Foo6\\"), |
| 671 | + "\\Foo6\\Bar" |
| 672 | + ); |
| 673 | + |
| 674 | + assertDoesntContain( |
| 675 | + getClassNamesFromResourceGlob(yamlKeyValues, "Foo7\\"), |
| 676 | + "\\Foo7\\Bar" |
| 677 | + ); |
| 678 | + } |
| 679 | + |
608 | 680 | private int getIndentForTextContent(@NotNull String content) { |
609 | 681 | return YamlHelper.getIndentSpaceForFile((YAMLFile) YamlPsiElementFactory.createDummyFile( |
610 | 682 | getProject(), |
|
0 commit comments