Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move some filesystem related workaround tests into heavy fixtures mode #1128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -1,12 +1,13 @@
package fr.adrienbrault.idea.symfony2plugin.tests;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
import fr.adrienbrault.idea.symfony2plugin.Settings;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
Expand All @@ -21,39 +22,27 @@
/**
* @author Daniel Espendiller <[email protected]>
*/
abstract public class SymfonyTempCodeInsightFixtureTestCase extends UsefulTestCase {
private Project project;

private IdeaProjectTestFixture myFixture;

abstract public class SymfonyTempCodeInsightFixtureTestCase extends SymfonyLightCodeInsightFixtureTestCase {
@Override
public void setUp() throws Exception {
super.setUp();

myFixture = IdeaTestFixtureFactory.getFixtureFactory()
// clear super fixtures instances
this.myFixture.tearDown();

// heavy project
// @TODO: still no index process
IdeaProjectTestFixture fixtures = IdeaTestFixtureFactory.getFixtureFactory()
.createFixtureBuilder(RandomStringUtils.randomAlphanumeric(20))
.getFixture();

myFixture.setUp();

project = myFixture.getProject();
Settings.getInstance(project).pluginEnabled = true;
}

protected void tearDown() throws Exception {
this.project = null;
this.myFixture = JavaTestFixtureFactory.getFixtureFactory()
.createCodeInsightFixture(fixtures, new LightTempDirTestFixtureImpl(true));

try {
this.myFixture.tearDown();
} finally {
this.myFixture = null;
super.tearDown();
}
}
this.myFixture.setUp();
this.myModule = this.myFixture.getModule();

@NotNull
protected Project getProject() {
return project;
Settings.getInstance(getProject()).pluginEnabled = true;
}

@NotNull
Expand All @@ -73,31 +62,30 @@ protected VirtualFile[] createFiles(@NotNull String... files) {
}

protected VirtualFile createFile(@NotNull String file, @Nullable String content) {
final VirtualFile[] childData = new VirtualFile[1];

ApplicationManager.getApplication().runWriteAction(new Runnable() {
return ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
@Override
public void run() {
public VirtualFile compute() {
VirtualFile virtualFile = null;
try {
String[] paths = file.split("/");

if(paths.length == 0) {
childData[0] = getProject().getBaseDir().createChildData(this, file);
if (paths.length == 0) {
virtualFile = getProject().getBaseDir().createChildData(this, file);
} else {
childData[0] = VfsUtil.createDirectoryIfMissing(
virtualFile = VfsUtil.createDirectoryIfMissing(
getProject().getBaseDir(),
StringUtils.join(Arrays.copyOf(paths, paths.length - 1), "/")
).createChildData(this, paths[paths.length - 1]);
}

if(content != null) {
childData[0].setBinaryContent(content.getBytes());
if (content != null) {
virtualFile.setBinaryContent(content.getBytes());
}
} catch (IOException ignored) {
}

return virtualFile;
}
});

return childData[0];
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package fr.adrienbrault.idea.symfony2plugin.tests.asset;

import com.jetbrains.twig.TwigFileType;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;

import java.io.File;

/**
* @author Daniel Espendiller <[email protected]>
*/
public class AssetGoToDeclarationHandlerTest extends SymfonyLightCodeInsightFixtureTestCase {

public class AssetGoToDeclarationHandlerTest extends SymfonyTempCodeInsightFixtureTestCase {
public void setUp() throws Exception {
super.setUp();

createDummyFiles(
createFiles(
"web/assets/foo.css",
"web/assets/foo.js",
"web/foo.js"
Expand All @@ -24,8 +23,6 @@ public void setUp() throws Exception {
* @see fr.adrienbrault.idea.symfony2plugin.asset.AssetGoToDeclarationHandler
*/
public void testGotoDeclarationTargetsTag() {
if(System.getenv("PHPSTORM_ENV") != null) return;

assertNavigationContainsFile(TwigFileType.INSTANCE, "" +
"{% javascripts\n" +
" 'assets/foo<caret>.js'\n" +
Expand Down Expand Up @@ -59,8 +56,6 @@ public void testGotoDeclarationTargetsTag() {
* @see fr.adrienbrault.idea.symfony2plugin.asset.AssetGoToDeclarationHandler
*/
public void testGotoDeclarationTargetsAsset() {
if(System.getenv("PHPSTORM_ENV") != null) return;

assertNavigationContainsFile(TwigFileType.INSTANCE, "{{ asset('assets/foo<caret>.css') }}", "foo.css");
assertNavigationContainsFile(TwigFileType.INSTANCE, "{{ asset('assets/foo<caret>.js') }}", "foo.js");

Expand All @@ -76,8 +71,6 @@ public void testGotoDeclarationTargetsAsset() {
* @see fr.adrienbrault.idea.symfony2plugin.asset.AssetGoToDeclarationHandler
*/
public void testGotoDeclarationTargetsAssetInRoot() {
if (System.getenv("PHPSTORM_ENV") != null) return;

assertNavigationContainsFile(TwigFileType.INSTANCE, "{{ asset('foo<caret>.js') }}", "foo.js");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fr.adrienbrault.idea.symfony2plugin.tests.completion.xml;

import com.intellij.ide.highlighter.XmlFileType;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;

/**
* @author Daniel Espendiller <[email protected]>
*
* @see fr.adrienbrault.idea.symfony2plugin.completion.xml.XmlGotoCompletionRegistrar
*/
public class XmlGotoCompletionRegistrarTempTest extends SymfonyTempCodeInsightFixtureTestCase {
public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
createFile("app/Resources/views/foo.html.twig");

assertCompletionContains(XmlFileType.INSTANCE, "" +
" <route id=\"root\" path=\"/wp-admin\">\n" +
" <default key=\"template\"><caret></default>\n" +
" </route>",
"foo.html.twig"
);

assertNavigationMatch(XmlFileType.INSTANCE, "" +
" <route id=\"root\" path=\"/wp-admin\">\n" +
" <default key=\"template\">foo.ht<caret>ml.twig</default>\n" +
" </route>"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,6 @@ public void testThatRouteInsideRouteDefaultKeyCompletedAndNavigable() {
);
}

public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
if(System.getenv("PHPSTORM_ENV") != null) return;

try {
createDummyFiles("app/Resources/views/foo.html.twig");
} catch (Exception e) {
e.printStackTrace();
}

assertCompletionContains(XmlFileType.INSTANCE, "" +
" <route id=\"root\" path=\"/wp-admin\">\n" +
" <default key=\"template\"><caret></default>\n" +
" </route>",
"foo.html.twig"
);

assertNavigationMatch(XmlFileType.INSTANCE, "" +
" <route id=\"root\" path=\"/wp-admin\">\n" +
" <default key=\"template\">foo.ht<caret>ml.twig</default>\n" +
" </route>"
);
}

public void testThatDecoratesServiceTagProvidesReferences() {
assertCompletionContains(XmlFileType.INSTANCE, "" +
"<?xml version=\"1.0\"?>\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fr.adrienbrault.idea.symfony2plugin.tests.completion.yaml;

import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;
import org.jetbrains.yaml.YAMLFileType;

/**
* @author Daniel Espendiller <[email protected]>
* @see fr.adrienbrault.idea.symfony2plugin.completion.yaml.YamlGotoCompletionRegistrar
*/
public class YamlGotoCompletionRegistrarTempTest extends SymfonyTempCodeInsightFixtureTestCase {
public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
createFile("app/Resources/views/foo.html.twig");

assertCompletionContains(YAMLFileType.YML, "" +
"root:\n" +
" path: /wp-admin\n" +
" defaults:\n" +
" template: '<caret>'\n",
"foo.html.twig"
);

assertNavigationMatch(YAMLFileType.YML, "" +
"root:\n" +
" path: /wp-admin\n" +
" defaults:\n" +
" template: 'foo.ht<caret>ml.twig'\n"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,6 @@ public void testThatRouteInsideRouteDefaultKeyCompletedAndNavigable() {
);
}

public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
if(System.getenv("PHPSTORM_ENV") != null) return;

try {
createDummyFiles("app/Resources/views/foo.html.twig");
} catch (Exception e) {
e.printStackTrace();
}

assertCompletionContains(YAMLFileType.YML, "" +
"root:\n" +
" path: /wp-admin\n" +
" defaults:\n" +
" template: '<caret>'\n",
"foo.html.twig"
);

assertNavigationMatch(YAMLFileType.YML, "" +
"root:\n" +
" path: /wp-admin\n" +
" defaults:\n" +
" template: 'foo.ht<caret>ml.twig'\n"
);
}

public void testThatDecoratesServiceTagProvidesReferences() {
Collection<String[]> strings = new ArrayList<String[]>() {{
add(new String[] {"<caret>", "foo.bar<caret>_factory"});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package fr.adrienbrault.idea.symfony2plugin.tests.templating.assets;

import com.jetbrains.twig.TwigFileType;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;

/**
* @author Daniel Espendiller <[email protected]>
* @see com.jetbrains.twig.completion.TwigCompletionContributor
*/
public class TwigAssetsCompletionContributorTest extends SymfonyLightCodeInsightFixtureTestCase {
public class TwigAssetsCompletionContributorTest extends SymfonyTempCodeInsightFixtureTestCase {

public void setUp() throws Exception {
super.setUp();
if (System.getenv("PHPSTORM_ENV") != null) return;

createDummyFiles(

createFiles(
"web/assets/foo.css",
"web/assets/foo.less",
"web/assets/foo.sass",
Expand All @@ -25,19 +24,14 @@ public void setUp() throws Exception {
"web/assets/foo.png",
"web/assets/foo.gif"
);

}

public void testTwigAssetFunctionCompletion() {
if (System.getenv("PHPSTORM_ENV") != null) return;

assertCompletionContains(TwigFileType.INSTANCE, "{{ asset('<caret>') }}", "assets/foo.css", "assets/foo.js", "assets/foo.less", "assets/foo.coffee");
assertCompletionResultEquals(TwigFileType.INSTANCE, "<script src=\"assets/foo.coffee<caret>\"></script>", "<script src=\"{{ asset('assets/foo.coffee') }}\"></script>");
}

public void testTwigAssetsTagCompletion() {
if (System.getenv("PHPSTORM_ENV") != null) return;

assertCompletionContains(TwigFileType.INSTANCE, "{% stylesheets '<caret>' %}{% endstylesheets %}", "assets/foo.css", "assets/foo.less", "assets/foo.sass", "assets/foo.scss");
assertCompletionNotContains(TwigFileType.INSTANCE, "{% stylesheets '<caret>' %}{% endstylesheets %}", "assets/foo.js", "assets/foo.dart", "assets/foo.coffee");

Expand All @@ -46,14 +40,10 @@ public void testTwigAssetsTagCompletion() {
}

public void testTwigAssetImageFunctionCompletion() {
if (System.getenv("PHPSTORM_ENV") != null) return;

assertCompletionResultEquals(TwigFileType.INSTANCE, "<img src=\"assets/foo.pn<caret>\">", "<img src=\"{{ asset('assets/foo.png') }}\">");
}

public void testTwigAbsoluteUrlFunctionCompletion() {
if (System.getenv("PHPSTORM_ENV") != null) return;

assertCompletionContains(TwigFileType.INSTANCE, "{{ absolute_url('<caret>') }}", "assets/foo.css", "assets/foo.js", "assets/foo.less", "assets/foo.coffee");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@
import java.util.*;

public class TwigUtilTest extends SymfonyLightCodeInsightFixtureTestCase {

public void setUp() throws Exception {
super.setUp();

createDummyFiles(
"app/Resources/TwigUtilIntegrationBundle/views/layout.html.twig",
"app/Resources/TwigUtilIntegrationBundle/views/Foo/layout.html.twig",
"app/Resources/TwigUtilIntegrationBundle/views/Foo/Bar/layout.html.twig"
);
}

public String getTestDataPath() {
return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath();
}
Expand All @@ -50,7 +39,17 @@ public String getTestDataPath() {
* @see fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil#getTemplateNameByOverwrite
*/
public void testTemplateOverwriteNavigation() {
if(System.getenv("PHPSTORM_ENV") != null) return;
if(true) return;

try {
createDummyFiles(
"app/Resources/TwigUtilIntegrationBundle/views/layout.html.twig",
"app/Resources/TwigUtilIntegrationBundle/views/Foo/layout.html.twig",
"app/Resources/TwigUtilIntegrationBundle/views/Foo/Bar/layout.html.twig"
);
} catch (Exception e) {
e.printStackTrace();
}

assertNavigationContainsFile(TwigFileType.INSTANCE, "{% extends '<caret>TwigUtilIntegrationBundle:layout.html.twig' %}", "/views/layout.html.twig");
assertNavigationContainsFile(TwigFileType.INSTANCE, "{% extends '<caret>TwigUtilIntegrationBundle:Foo/layout.html.twig' %}", "/views/Foo/layout.html.twig");
Expand Down