|
| 1 | +package fr.adrienbrault.idea.symfony2plugin.tests.external.toolbox.provider; |
| 2 | + |
| 3 | +import com.intellij.psi.PsiElement; |
| 4 | +import com.intellij.util.containers.ContainerUtil; |
| 5 | +import com.jetbrains.php.lang.PhpFileType; |
| 6 | +import com.jetbrains.php.lang.psi.PhpPsiElementFactory; |
| 7 | +import com.jetbrains.php.lang.psi.elements.PhpClass; |
| 8 | +import com.jetbrains.php.lang.psi.elements.PhpNamedElement; |
| 9 | +import de.espend.idea.php.toolbox.navigation.dict.PhpToolboxDeclarationHandlerParameter; |
| 10 | +import de.espend.idea.php.toolbox.type.PhpToolboxTypeProviderArguments; |
| 11 | +import fr.adrienbrault.idea.symfony2plugin.external.toolbox.provider.ServiceToolboxProvider; |
| 12 | +import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; |
| 13 | + |
| 14 | +import java.io.File; |
| 15 | +import java.util.ArrayList; |
| 16 | +import java.util.Collection; |
| 17 | + |
| 18 | +public class ServiceToolboxProviderTest extends SymfonyLightCodeInsightFixtureTestCase { |
| 19 | + public void setUp() throws Exception { |
| 20 | + super.setUp(); |
| 21 | + myFixture.copyFileToProject("services.xml"); |
| 22 | + myFixture.copyFileToProject("classes.php"); |
| 23 | + } |
| 24 | + |
| 25 | + public String getTestDataPath() { |
| 26 | + return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath(); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @see ServiceToolboxProvider#resolveParameter |
| 31 | + */ |
| 32 | + public void testTypeResolve() { |
| 33 | + ServiceToolboxProvider provider = new ServiceToolboxProvider(); |
| 34 | + Collection<PhpNamedElement> classes = provider.resolveParameter( |
| 35 | + new PhpToolboxTypeProviderArguments(getProject(), "foo_bar_foo_Bar", new ArrayList<>()) |
| 36 | + ); |
| 37 | + |
| 38 | + assertNotNull(classes); |
| 39 | + assertNotNull(ContainerUtil.find(classes, phpNamedElement -> |
| 40 | + phpNamedElement instanceof PhpClass && "FooBar".equals(phpNamedElement.getName())) |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @see ServiceToolboxProvider#resolveParameter |
| 46 | + */ |
| 47 | + public void testTypeNullResolve() { |
| 48 | + assertNull(new ServiceToolboxProvider().resolveParameter( |
| 49 | + new PhpToolboxTypeProviderArguments(getProject(), "unknown_xxx", new ArrayList<>()) |
| 50 | + )); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @see ServiceToolboxProvider#getPsiTargets |
| 55 | + */ |
| 56 | + public void testTargetIsReturnedForService() { |
| 57 | + Collection<PsiElement> classes = new ServiceToolboxProvider().getPsiTargets( |
| 58 | + new PhpToolboxDeclarationHandlerParameter(PhpPsiElementFactory.createComma(getProject()), "foo_bar_foo_Bar", PhpFileType.INSTANCE) |
| 59 | + ); |
| 60 | + |
| 61 | + assertNotNull(classes); |
| 62 | + assertNotNull(ContainerUtil.find(classes, phpNamedElement -> |
| 63 | + phpNamedElement instanceof PhpClass && "FooBar".equals(((PhpClass) phpNamedElement).getName())) |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
0 commit comments