Skip to content

Commit 22bf303

Browse files
committed
move some filesystem related workaround tests into heavy fixtures mode
1 parent 345abc5 commit 22bf303

8 files changed

+100
-121
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package fr.adrienbrault.idea.symfony2plugin.tests;
22

33
import com.intellij.openapi.application.ApplicationManager;
4-
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.util.Computable;
55
import com.intellij.openapi.vfs.VfsUtil;
66
import com.intellij.openapi.vfs.VirtualFile;
7-
import com.intellij.testFramework.UsefulTestCase;
87
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
98
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
9+
import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
10+
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
1011
import fr.adrienbrault.idea.symfony2plugin.Settings;
1112
import org.apache.commons.lang.RandomStringUtils;
1213
import org.apache.commons.lang.StringUtils;
@@ -21,39 +22,27 @@
2122
/**
2223
* @author Daniel Espendiller <[email protected]>
2324
*/
24-
abstract public class SymfonyTempCodeInsightFixtureTestCase extends UsefulTestCase {
25-
private Project project;
26-
27-
private IdeaProjectTestFixture myFixture;
28-
25+
abstract public class SymfonyTempCodeInsightFixtureTestCase extends SymfonyLightCodeInsightFixtureTestCase {
2926
@Override
3027
public void setUp() throws Exception {
3128
super.setUp();
3229

33-
myFixture = IdeaTestFixtureFactory.getFixtureFactory()
30+
// clear super fixtures instances
31+
this.myFixture.tearDown();
32+
33+
// heavy project
34+
// @TODO: still no index process
35+
IdeaProjectTestFixture fixtures = IdeaTestFixtureFactory.getFixtureFactory()
3436
.createFixtureBuilder(RandomStringUtils.randomAlphanumeric(20))
3537
.getFixture();
3638

37-
myFixture.setUp();
38-
39-
project = myFixture.getProject();
40-
Settings.getInstance(project).pluginEnabled = true;
41-
}
42-
43-
protected void tearDown() throws Exception {
44-
this.project = null;
39+
this.myFixture = JavaTestFixtureFactory.getFixtureFactory()
40+
.createCodeInsightFixture(fixtures, new LightTempDirTestFixtureImpl(true));
4541

46-
try {
47-
this.myFixture.tearDown();
48-
} finally {
49-
this.myFixture = null;
50-
super.tearDown();
51-
}
52-
}
42+
this.myFixture.setUp();
43+
this.myModule = this.myFixture.getModule();
5344

54-
@NotNull
55-
protected Project getProject() {
56-
return project;
45+
Settings.getInstance(getProject()).pluginEnabled = true;
5746
}
5847

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

7564
protected VirtualFile createFile(@NotNull String file, @Nullable String content) {
76-
final VirtualFile[] childData = new VirtualFile[1];
77-
78-
ApplicationManager.getApplication().runWriteAction(new Runnable() {
65+
return ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
7966
@Override
80-
public void run() {
67+
public VirtualFile compute() {
68+
VirtualFile virtualFile = null;
8169
try {
8270
String[] paths = file.split("/");
8371

84-
if(paths.length == 0) {
85-
childData[0] = getProject().getBaseDir().createChildData(this, file);
72+
if (paths.length == 0) {
73+
virtualFile = getProject().getBaseDir().createChildData(this, file);
8674
} else {
87-
childData[0] = VfsUtil.createDirectoryIfMissing(
75+
virtualFile = VfsUtil.createDirectoryIfMissing(
8876
getProject().getBaseDir(),
8977
StringUtils.join(Arrays.copyOf(paths, paths.length - 1), "/")
9078
).createChildData(this, paths[paths.length - 1]);
9179
}
9280

93-
if(content != null) {
94-
childData[0].setBinaryContent(content.getBytes());
81+
if (content != null) {
82+
virtualFile.setBinaryContent(content.getBytes());
9583
}
9684
} catch (IOException ignored) {
9785
}
86+
87+
return virtualFile;
9888
}
9989
});
100-
101-
return childData[0];
10290
}
10391
}

Diff for: tests/fr/adrienbrault/idea/symfony2plugin/tests/asset/AssetGoToDeclarationHandlerTest.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package fr.adrienbrault.idea.symfony2plugin.tests.asset;
22

33
import com.jetbrains.twig.TwigFileType;
4-
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
4+
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;
55

66
import java.io.File;
77

88
/**
99
* @author Daniel Espendiller <[email protected]>
1010
*/
11-
public class AssetGoToDeclarationHandlerTest extends SymfonyLightCodeInsightFixtureTestCase {
12-
11+
public class AssetGoToDeclarationHandlerTest extends SymfonyTempCodeInsightFixtureTestCase {
1312
public void setUp() throws Exception {
1413
super.setUp();
1514

16-
createDummyFiles(
15+
createFiles(
1716
"web/assets/foo.css",
1817
"web/assets/foo.js",
1918
"web/foo.js"
@@ -24,8 +23,6 @@ public void setUp() throws Exception {
2423
* @see fr.adrienbrault.idea.symfony2plugin.asset.AssetGoToDeclarationHandler
2524
*/
2625
public void testGotoDeclarationTargetsTag() {
27-
if(System.getenv("PHPSTORM_ENV") != null) return;
28-
2926
assertNavigationContainsFile(TwigFileType.INSTANCE, "" +
3027
"{% javascripts\n" +
3128
" 'assets/foo<caret>.js'\n" +
@@ -59,8 +56,6 @@ public void testGotoDeclarationTargetsTag() {
5956
* @see fr.adrienbrault.idea.symfony2plugin.asset.AssetGoToDeclarationHandler
6057
*/
6158
public void testGotoDeclarationTargetsAsset() {
62-
if(System.getenv("PHPSTORM_ENV") != null) return;
63-
6459
assertNavigationContainsFile(TwigFileType.INSTANCE, "{{ asset('assets/foo<caret>.css') }}", "foo.css");
6560
assertNavigationContainsFile(TwigFileType.INSTANCE, "{{ asset('assets/foo<caret>.js') }}", "foo.js");
6661

@@ -76,8 +71,6 @@ public void testGotoDeclarationTargetsAsset() {
7671
* @see fr.adrienbrault.idea.symfony2plugin.asset.AssetGoToDeclarationHandler
7772
*/
7873
public void testGotoDeclarationTargetsAssetInRoot() {
79-
if (System.getenv("PHPSTORM_ENV") != null) return;
80-
8174
assertNavigationContainsFile(TwigFileType.INSTANCE, "{{ asset('foo<caret>.js') }}", "foo.js");
8275
}
8376
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package fr.adrienbrault.idea.symfony2plugin.tests.completion.xml;
2+
3+
import com.intellij.ide.highlighter.XmlFileType;
4+
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;
5+
6+
/**
7+
* @author Daniel Espendiller <[email protected]>
8+
*
9+
* @see fr.adrienbrault.idea.symfony2plugin.completion.xml.XmlGotoCompletionRegistrar
10+
*/
11+
public class XmlGotoCompletionRegistrarTempTest extends SymfonyTempCodeInsightFixtureTestCase {
12+
public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
13+
createFile("app/Resources/views/foo.html.twig");
14+
15+
assertCompletionContains(XmlFileType.INSTANCE, "" +
16+
" <route id=\"root\" path=\"/wp-admin\">\n" +
17+
" <default key=\"template\"><caret></default>\n" +
18+
" </route>",
19+
"foo.html.twig"
20+
);
21+
22+
assertNavigationMatch(XmlFileType.INSTANCE, "" +
23+
" <route id=\"root\" path=\"/wp-admin\">\n" +
24+
" <default key=\"template\">foo.ht<caret>ml.twig</default>\n" +
25+
" </route>"
26+
);
27+
}
28+
}

Diff for: tests/fr/adrienbrault/idea/symfony2plugin/tests/completion/xml/XmlGotoCompletionRegistrarTest.java

-23
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,6 @@ public void testThatRouteInsideRouteDefaultKeyCompletedAndNavigable() {
119119
);
120120
}
121121

122-
public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
123-
if(System.getenv("PHPSTORM_ENV") != null) return;
124-
125-
try {
126-
createDummyFiles("app/Resources/views/foo.html.twig");
127-
} catch (Exception e) {
128-
e.printStackTrace();
129-
}
130-
131-
assertCompletionContains(XmlFileType.INSTANCE, "" +
132-
" <route id=\"root\" path=\"/wp-admin\">\n" +
133-
" <default key=\"template\"><caret></default>\n" +
134-
" </route>",
135-
"foo.html.twig"
136-
);
137-
138-
assertNavigationMatch(XmlFileType.INSTANCE, "" +
139-
" <route id=\"root\" path=\"/wp-admin\">\n" +
140-
" <default key=\"template\">foo.ht<caret>ml.twig</default>\n" +
141-
" </route>"
142-
);
143-
}
144-
145122
public void testThatDecoratesServiceTagProvidesReferences() {
146123
assertCompletionContains(XmlFileType.INSTANCE, "" +
147124
"<?xml version=\"1.0\"?>\n" +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package fr.adrienbrault.idea.symfony2plugin.tests.completion.yaml;
2+
3+
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;
4+
import org.jetbrains.yaml.YAMLFileType;
5+
6+
/**
7+
* @author Daniel Espendiller <[email protected]>
8+
* @see fr.adrienbrault.idea.symfony2plugin.completion.yaml.YamlGotoCompletionRegistrar
9+
*/
10+
public class YamlGotoCompletionRegistrarTempTest extends SymfonyTempCodeInsightFixtureTestCase {
11+
public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
12+
createFile("app/Resources/views/foo.html.twig");
13+
14+
assertCompletionContains(YAMLFileType.YML, "" +
15+
"root:\n" +
16+
" path: /wp-admin\n" +
17+
" defaults:\n" +
18+
" template: '<caret>'\n",
19+
"foo.html.twig"
20+
);
21+
22+
assertNavigationMatch(YAMLFileType.YML, "" +
23+
"root:\n" +
24+
" path: /wp-admin\n" +
25+
" defaults:\n" +
26+
" template: 'foo.ht<caret>ml.twig'\n"
27+
);
28+
}
29+
}

Diff for: tests/fr/adrienbrault/idea/symfony2plugin/tests/completion/yaml/YamlGotoCompletionRegistrarTest.java

-25
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,6 @@ public void testThatRouteInsideRouteDefaultKeyCompletedAndNavigable() {
4242
);
4343
}
4444

45-
public void testThatTemplateInsideRouteDefaultKeyCompletedAndNavigable() {
46-
if(System.getenv("PHPSTORM_ENV") != null) return;
47-
48-
try {
49-
createDummyFiles("app/Resources/views/foo.html.twig");
50-
} catch (Exception e) {
51-
e.printStackTrace();
52-
}
53-
54-
assertCompletionContains(YAMLFileType.YML, "" +
55-
"root:\n" +
56-
" path: /wp-admin\n" +
57-
" defaults:\n" +
58-
" template: '<caret>'\n",
59-
"foo.html.twig"
60-
);
61-
62-
assertNavigationMatch(YAMLFileType.YML, "" +
63-
"root:\n" +
64-
" path: /wp-admin\n" +
65-
" defaults:\n" +
66-
" template: 'foo.ht<caret>ml.twig'\n"
67-
);
68-
}
69-
7045
public void testThatDecoratesServiceTagProvidesReferences() {
7146
Collection<String[]> strings = new ArrayList<String[]>() {{
7247
add(new String[] {"<caret>", "foo.bar<caret>_factory"});
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package fr.adrienbrault.idea.symfony2plugin.tests.templating.assets;
22

33
import com.jetbrains.twig.TwigFileType;
4-
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
4+
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;
55

66
/**
77
* @author Daniel Espendiller <[email protected]>
88
* @see com.jetbrains.twig.completion.TwigCompletionContributor
99
*/
10-
public class TwigAssetsCompletionContributorTest extends SymfonyLightCodeInsightFixtureTestCase {
10+
public class TwigAssetsCompletionContributorTest extends SymfonyTempCodeInsightFixtureTestCase {
1111

1212
public void setUp() throws Exception {
1313
super.setUp();
14-
if (System.getenv("PHPSTORM_ENV") != null) return;
15-
16-
createDummyFiles(
14+
15+
createFiles(
1716
"web/assets/foo.css",
1817
"web/assets/foo.less",
1918
"web/assets/foo.sass",
@@ -25,19 +24,14 @@ public void setUp() throws Exception {
2524
"web/assets/foo.png",
2625
"web/assets/foo.gif"
2726
);
28-
2927
}
3028

3129
public void testTwigAssetFunctionCompletion() {
32-
if (System.getenv("PHPSTORM_ENV") != null) return;
33-
3430
assertCompletionContains(TwigFileType.INSTANCE, "{{ asset('<caret>') }}", "assets/foo.css", "assets/foo.js", "assets/foo.less", "assets/foo.coffee");
3531
assertCompletionResultEquals(TwigFileType.INSTANCE, "<script src=\"assets/foo.coffee<caret>\"></script>", "<script src=\"{{ asset('assets/foo.coffee') }}\"></script>");
3632
}
3733

3834
public void testTwigAssetsTagCompletion() {
39-
if (System.getenv("PHPSTORM_ENV") != null) return;
40-
4135
assertCompletionContains(TwigFileType.INSTANCE, "{% stylesheets '<caret>' %}{% endstylesheets %}", "assets/foo.css", "assets/foo.less", "assets/foo.sass", "assets/foo.scss");
4236
assertCompletionNotContains(TwigFileType.INSTANCE, "{% stylesheets '<caret>' %}{% endstylesheets %}", "assets/foo.js", "assets/foo.dart", "assets/foo.coffee");
4337

@@ -46,14 +40,10 @@ public void testTwigAssetsTagCompletion() {
4640
}
4741

4842
public void testTwigAssetImageFunctionCompletion() {
49-
if (System.getenv("PHPSTORM_ENV") != null) return;
50-
5143
assertCompletionResultEquals(TwigFileType.INSTANCE, "<img src=\"assets/foo.pn<caret>\">", "<img src=\"{{ asset('assets/foo.png') }}\">");
5244
}
5345

5446
public void testTwigAbsoluteUrlFunctionCompletion() {
55-
if (System.getenv("PHPSTORM_ENV") != null) return;
56-
5747
assertCompletionContains(TwigFileType.INSTANCE, "{{ absolute_url('<caret>') }}", "assets/foo.css", "assets/foo.js", "assets/foo.less", "assets/foo.coffee");
5848
}
5949
}

Diff for: tests/fr/adrienbrault/idea/symfony2plugin/tests/templating/util/TwigUtilTest.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@
3131
import java.util.*;
3232

3333
public class TwigUtilTest extends SymfonyLightCodeInsightFixtureTestCase {
34-
35-
public void setUp() throws Exception {
36-
super.setUp();
37-
38-
createDummyFiles(
39-
"app/Resources/TwigUtilIntegrationBundle/views/layout.html.twig",
40-
"app/Resources/TwigUtilIntegrationBundle/views/Foo/layout.html.twig",
41-
"app/Resources/TwigUtilIntegrationBundle/views/Foo/Bar/layout.html.twig"
42-
);
43-
}
44-
4534
public String getTestDataPath() {
4635
return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath();
4736
}
@@ -50,7 +39,17 @@ public String getTestDataPath() {
5039
* @see fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil#getTemplateNameByOverwrite
5140
*/
5241
public void testTemplateOverwriteNavigation() {
53-
if(System.getenv("PHPSTORM_ENV") != null) return;
42+
if(true) return;
43+
44+
try {
45+
createDummyFiles(
46+
"app/Resources/TwigUtilIntegrationBundle/views/layout.html.twig",
47+
"app/Resources/TwigUtilIntegrationBundle/views/Foo/layout.html.twig",
48+
"app/Resources/TwigUtilIntegrationBundle/views/Foo/Bar/layout.html.twig"
49+
);
50+
} catch (Exception e) {
51+
e.printStackTrace();
52+
}
5453

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

0 commit comments

Comments
 (0)