From 09133d8d8831504cddfbe17e7cea6a0aff0247b4 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Tue, 29 Jul 2025 21:11:55 +0300 Subject: [PATCH 1/2] made a generic class for the tests --- .../infrastructure/InspectionTestBase.kt | 18 +-------------- .../infrastructure/IntentionTestBase.kt | 21 +---------------- .../infrastructure/KphpStormTestBase.kt | 23 +++++++++++++++++++ .../testing/infrastructure/TypeTestBase.kt | 4 +--- 4 files changed, 26 insertions(+), 40 deletions(-) create mode 100644 src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt diff --git a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/InspectionTestBase.kt b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/InspectionTestBase.kt index f69e2223..8e8bb355 100644 --- a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/InspectionTestBase.kt +++ b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/InspectionTestBase.kt @@ -1,21 +1,11 @@ package com.vk.kphpstorm.testing.infrastructure -import com.intellij.testFramework.fixtures.BasePlatformTestCase -import com.jetbrains.php.config.PhpLanguageLevel -import com.jetbrains.php.config.PhpProjectConfigurationFacade import com.jetbrains.php.lang.inspections.PhpInspection import com.vk.kphpstorm.configuration.KphpStormConfiguration import com.vk.kphpstorm.configuration.setupKphpStormPluginForProject import java.io.File - -abstract class InspectionTestBase( - private val inspectionToEnable: PhpInspection? = null, -) : BasePlatformTestCase() { - - open val languageLevel: PhpLanguageLevel = PhpLanguageLevel.PHP740 - - override fun getTestDataPath() = "src/test/fixtures" +abstract class InspectionTestBase(private val inspectionToEnable: PhpInspection? = null) : KphpStormTestBase() { override fun setUp() { super.setUp() @@ -25,17 +15,11 @@ abstract class InspectionTestBase( } } - private fun setupLanguageLevel() { - val projectConfigurationFacade = PhpProjectConfigurationFacade.getInstance(project) - projectConfigurationFacade.languageLevel = languageLevel - } - /** * Run inspection on file.fixture.php and check that all and match * If file.qf.php exists, apply quickfixes and compare result to file.qf.php */ protected fun runFixture(fixtureFile: String) { - setupLanguageLevel() setupKphpStormPluginForProject(project) // Highlighting test diff --git a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/IntentionTestBase.kt b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/IntentionTestBase.kt index cc39a302..504d9bc2 100644 --- a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/IntentionTestBase.kt +++ b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/IntentionTestBase.kt @@ -1,32 +1,15 @@ package com.vk.kphpstorm.testing.infrastructure import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.testFramework.fixtures.BasePlatformTestCase -import com.jetbrains.php.config.PhpLanguageLevel -import com.jetbrains.php.config.PhpProjectConfigurationFacade import com.vk.kphpstorm.configuration.KphpStormConfiguration - -abstract class IntentionTestBase( - private val intentionToExecute: IntentionAction -) : BasePlatformTestCase() { - - open val languageLevel: PhpLanguageLevel = PhpLanguageLevel.PHP740 - - override fun getTestDataPath() = "src/test/fixtures" - - private fun setupLanguageLevel() { - val projectConfigurationFacade = PhpProjectConfigurationFacade.getInstance(project) - projectConfigurationFacade.languageLevel = languageLevel - } +abstract class IntentionTestBase(private val intentionToExecute: IntentionAction) : KphpStormTestBase() { /** * Run intention on file.fixture.php at place marked * file.qf.php must exist, the result of applying intention is compared to its contents */ protected fun runIntention(fixtureFile: String) { - setupLanguageLevel() - KphpStormConfiguration.saveThatSetupForProjectDone(project) myFixture.configureByFile(fixtureFile) myFixture.launchAction(myFixture.findSingleIntention(intentionToExecute.familyName)) @@ -39,8 +22,6 @@ abstract class IntentionTestBase( * Assert there are no intention [intentionToExecute] in file [fixtureFile] */ protected fun assertNoIntention(fixtureFile: String) { - setupLanguageLevel() - KphpStormConfiguration.saveThatSetupForProjectDone(project) myFixture.configureByFile(fixtureFile) val availableIntentions = myFixture diff --git a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt new file mode 100644 index 00000000..b7de149c --- /dev/null +++ b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt @@ -0,0 +1,23 @@ +package com.vk.kphpstorm.testing.infrastructure + +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import com.jetbrains.php.config.PhpLanguageLevel +import com.jetbrains.php.config.PhpProjectConfigurationFacade + + +abstract class KphpStormTestBase() : BasePlatformTestCase() { + + protected open val languageLevel: PhpLanguageLevel = PhpLanguageLevel.PHP740 + + override fun getTestDataPath() = "src/test/fixtures" + + override fun setUp() { + super.setUp() + setupLanguageLevel() + } + + private fun setupLanguageLevel() { + val projectConfigurationFacade = PhpProjectConfigurationFacade.getInstance(project) + projectConfigurationFacade.languageLevel = languageLevel + } +} diff --git a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/TypeTestBase.kt b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/TypeTestBase.kt index 4aee7ce2..dd2c83b2 100644 --- a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/TypeTestBase.kt +++ b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/TypeTestBase.kt @@ -2,7 +2,6 @@ package com.vk.kphpstorm.testing.infrastructure import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement -import com.intellij.testFramework.fixtures.BasePlatformTestCase import com.jetbrains.php.lang.psi.elements.FunctionReference import com.jetbrains.php.lang.psi.elements.PhpPsiElement import com.jetbrains.php.lang.psi.elements.PhpTypedElement @@ -12,8 +11,7 @@ import com.vk.kphpstorm.configuration.KphpStormConfiguration import com.vk.kphpstorm.exphptype.ExPhpTypePipe import com.vk.kphpstorm.helpers.toExPhpType -abstract class TypeTestBase : BasePlatformTestCase() { - override fun getTestDataPath() = "src/test/fixtures" +abstract class TypeTestBase : KphpStormTestBase() { protected open fun runFixture(vararg fixtureFiles: String) { KphpStormConfiguration.saveThatSetupForProjectDone(project) From 73b83661ffbd34b30f08bf470f22ba5b92054eb9 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Tue, 29 Jul 2025 21:13:13 +0300 Subject: [PATCH 2/2] oops --- .../com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt index b7de149c..07b3c434 100644 --- a/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt +++ b/src/test/kotlin/com/vk/kphpstorm/testing/infrastructure/KphpStormTestBase.kt @@ -4,7 +4,6 @@ import com.intellij.testFramework.fixtures.BasePlatformTestCase import com.jetbrains.php.config.PhpLanguageLevel import com.jetbrains.php.config.PhpProjectConfigurationFacade - abstract class KphpStormTestBase() : BasePlatformTestCase() { protected open val languageLevel: PhpLanguageLevel = PhpLanguageLevel.PHP740