Skip to content

Commit f7415b0

Browse files
Danil42RussiavldF
authored andcommitted
made a generic class for the tests (VKCOM#70)
1 parent ebcf5ef commit f7415b0

4 files changed

Lines changed: 25 additions & 40 deletions

File tree

src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/InspectionTestBase.kt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
package com.vk.kphpstorm.testing.infrastructure
22

3-
import com.intellij.testFramework.fixtures.BasePlatformTestCase
4-
import com.jetbrains.php.config.PhpLanguageLevel
5-
import com.jetbrains.php.config.PhpProjectConfigurationFacade
63
import com.jetbrains.php.lang.inspections.PhpInspection
74
import com.vk.kphpstorm.configuration.KphpStormConfiguration
85
import com.vk.kphpstorm.configuration.setupKphpStormPluginForProject
96
import java.io.File
107

11-
12-
abstract class InspectionTestBase(
13-
private val inspectionToEnable: PhpInspection? = null,
14-
) : BasePlatformTestCase() {
15-
16-
open val languageLevel: PhpLanguageLevel = PhpLanguageLevel.PHP740
17-
18-
override fun getTestDataPath() = "src/test/fixtures"
8+
abstract class InspectionTestBase(private val inspectionToEnable: PhpInspection? = null) : KphpStormTestBase() {
199

2010
override fun setUp() {
2111
super.setUp()
@@ -25,17 +15,11 @@ abstract class InspectionTestBase(
2515
}
2616
}
2717

28-
private fun setupLanguageLevel() {
29-
val projectConfigurationFacade = PhpProjectConfigurationFacade.getInstance(project)
30-
projectConfigurationFacade.languageLevel = languageLevel
31-
}
32-
3318
/**
3419
* Run inspection on file.fixture.php and check that all <warning> and <error> match
3520
* If file.qf.php exists, apply quickfixes and compare result to file.qf.php
3621
*/
3722
protected fun runFixture(fixtureFile: String) {
38-
setupLanguageLevel()
3923
setupKphpStormPluginForProject(project)
4024

4125
// Highlighting test

src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/IntentionTestBase.kt

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
11
package com.vk.kphpstorm.testing.infrastructure
22

33
import com.intellij.codeInsight.intention.IntentionAction
4-
import com.intellij.testFramework.fixtures.BasePlatformTestCase
5-
import com.jetbrains.php.config.PhpLanguageLevel
6-
import com.jetbrains.php.config.PhpProjectConfigurationFacade
74
import com.vk.kphpstorm.configuration.KphpStormConfiguration
85

9-
10-
abstract class IntentionTestBase(
11-
private val intentionToExecute: IntentionAction
12-
) : BasePlatformTestCase() {
13-
14-
open val languageLevel: PhpLanguageLevel = PhpLanguageLevel.PHP740
15-
16-
override fun getTestDataPath() = "src/test/fixtures"
17-
18-
private fun setupLanguageLevel() {
19-
val projectConfigurationFacade = PhpProjectConfigurationFacade.getInstance(project)
20-
projectConfigurationFacade.languageLevel = languageLevel
21-
}
6+
abstract class IntentionTestBase(private val intentionToExecute: IntentionAction) : KphpStormTestBase() {
227

238
/**
249
* Run intention on file.fixture.php at place marked <caret>
2510
* file.qf.php must exist, the result of applying intention is compared to its contents
2611
*/
2712
protected fun runIntention(fixtureFile: String) {
28-
setupLanguageLevel()
29-
3013
KphpStormConfiguration.saveThatSetupForProjectDone(project)
3114
myFixture.configureByFile(fixtureFile)
3215
myFixture.launchAction(myFixture.findSingleIntention(intentionToExecute.familyName))
@@ -39,8 +22,6 @@ abstract class IntentionTestBase(
3922
* Assert there are no intention [intentionToExecute] in file [fixtureFile]
4023
*/
4124
protected fun assertNoIntention(fixtureFile: String) {
42-
setupLanguageLevel()
43-
4425
KphpStormConfiguration.saveThatSetupForProjectDone(project)
4526
myFixture.configureByFile(fixtureFile)
4627
val availableIntentions = myFixture
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.vk.kphpstorm.testing.infrastructure
2+
3+
import com.intellij.testFramework.fixtures.BasePlatformTestCase
4+
import com.jetbrains.php.config.PhpLanguageLevel
5+
import com.jetbrains.php.config.PhpProjectConfigurationFacade
6+
7+
abstract class KphpStormTestBase() : BasePlatformTestCase() {
8+
9+
protected open val languageLevel: PhpLanguageLevel = PhpLanguageLevel.PHP740
10+
11+
override fun getTestDataPath() = "src/test/fixtures"
12+
13+
override fun setUp() {
14+
super.setUp()
15+
setupLanguageLevel()
16+
}
17+
18+
private fun setupLanguageLevel() {
19+
val projectConfigurationFacade = PhpProjectConfigurationFacade.getInstance(project)
20+
projectConfigurationFacade.languageLevel = languageLevel
21+
}
22+
}

src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/TypeTestBase.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.vk.kphpstorm.testing.infrastructure
22

33
import com.intellij.psi.PsiDocumentManager
44
import com.intellij.psi.PsiElement
5-
import com.intellij.testFramework.fixtures.BasePlatformTestCase
65
import com.jetbrains.php.lang.psi.elements.FunctionReference
76
import com.jetbrains.php.lang.psi.elements.PhpPsiElement
87
import com.jetbrains.php.lang.psi.elements.PhpTypedElement
@@ -12,8 +11,7 @@ import com.vk.kphpstorm.configuration.KphpStormConfiguration
1211
import com.vk.kphpstorm.exphptype.ExPhpTypePipe
1312
import com.vk.kphpstorm.helpers.toExPhpType
1413

15-
abstract class TypeTestBase : BasePlatformTestCase() {
16-
override fun getTestDataPath() = "src/test/fixtures"
14+
abstract class TypeTestBase : KphpStormTestBase() {
1715

1816
protected open fun runFixture(vararg fixtureFiles: String) {
1917
KphpStormConfiguration.saveThatSetupForProjectDone(project)

0 commit comments

Comments
 (0)