Skip to content

Commit ca1f389

Browse files
committed
feat: contirbute any possible run configurations with testo line marker contributor
1 parent 6ce6402 commit ca1f389

File tree

6 files changed

+29
-4
lines changed

6 files changed

+29
-4
lines changed

src/main/kotlin/com/github/xepozz/testo/TestoComposerConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.github.xepozz.testo.tests.run.TestoRunConfigurationType
55
import com.jetbrains.php.testFramework.PhpTestFrameworkComposerConfig
66

77
class TestoComposerConfig : PhpTestFrameworkComposerConfig(TestoFrameworkType.INSTANCE, PACKAGE, RELATIVE_PATH) {
8-
override fun getDefaultConfigName() = "phpunit.xml"
8+
override fun getDefaultConfigName() = "testo.php"
99

1010
override fun getConfigurationType() = TestoRunConfigurationType.INSTANCE
1111

src/main/kotlin/com/github/xepozz/testo/tests/TestoTestRunLineMarkerProvider.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.xepozz.testo.tests
33
import com.github.xepozz.testo.index.TestoDataProviderUtils
44
import com.github.xepozz.testo.isTestoClass
55
import com.github.xepozz.testo.isTestoExecutable
6+
import com.intellij.execution.lineMarker.ExecutorAction
67
import com.intellij.execution.lineMarker.RunLineMarkerContributor
78
import com.intellij.openapi.project.Project
89
import com.intellij.psi.PsiElement
@@ -17,8 +18,11 @@ import com.jetbrains.php.lang.psi.elements.PhpClass
1718
import com.jetbrains.php.lang.psi.elements.PhpNamedElement
1819
import com.jetbrains.php.run.remote.PhpRemoteInterpreterManager
1920
import java.util.concurrent.ExecutionException
21+
import javax.swing.Icon
2022

2123
class TestoTestRunLineMarkerProvider : RunLineMarkerContributor() {
24+
override fun producesAllPossibleConfigurations(file: PsiFile) = true
25+
2226
override fun getInfo(leaf: PsiElement): Info? {
2327
if (leaf.elementType != PhpTokenTypes.IDENTIFIER) return null
2428
val element = leaf.parent as? PhpNamedElement ?: return null
@@ -61,6 +65,11 @@ class TestoTestRunLineMarkerProvider : RunLineMarkerContributor() {
6165
}
6266
}
6367

68+
fun withExecutorActions(icon: Icon) = TestoTestRunLineMarkerProviderInfo(
69+
icon,
70+
ExecutorAction.getActions(),
71+
RUN_TEST_TOOLTIP_PROVIDER,
72+
)
6473
// fun getLocationHint(containingClass: PhpClass, method: Method, datasetName: String?) =
6574
// getLocationHint(containingClass) + "::" + method.name + " with data set " + datasetName
6675

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.github.xepozz.testo.tests
2+
3+
import com.intellij.execution.lineMarker.RunLineMarkerContributor
4+
import com.intellij.openapi.actionSystem.AnAction
5+
import com.intellij.psi.PsiElement
6+
import java.util.function.Function
7+
import javax.swing.Icon
8+
9+
class TestoTestRunLineMarkerProviderInfo(
10+
icon: Icon, actions: Array<AnAction>, tooltipProvider: Function<in PsiElement, String?>?
11+
) : RunLineMarkerContributor.Info(icon, actions, tooltipProvider) {
12+
override fun shouldReplace(other: RunLineMarkerContributor.Info) = true
13+
}

src/main/kotlin/com/github/xepozz/testo/tests/run/TestoRunConfigurationProducer.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.jetbrains.php.lang.psi.elements.PhpClass
3232
import com.jetbrains.php.lang.psi.elements.PhpNamedElement
3333
import com.jetbrains.php.phpunit.PhpMethodLocation
3434
import com.jetbrains.php.phpunit.PhpUnitRuntimeConfigurationProducer
35+
import com.jetbrains.php.phpunit.PhpUnitUtil
3536
import com.jetbrains.php.testFramework.run.PhpTestConfigurationProducer
3637
import com.jetbrains.php.testFramework.run.PhpTestRunnerSettings
3738
import java.util.*
@@ -105,7 +106,7 @@ class TestoRunConfigurationProducer : PhpTestConfigurationProducer<TestoRunConfi
105106

106107
override fun getConfigurationFactory() = TestoRunConfigurationFactory(TestoRunConfigurationType.INSTANCE)
107108

108-
override fun shouldReplace(self: ConfigurationFromContext, other: ConfigurationFromContext) = true
109+
override fun shouldReplace(self: ConfigurationFromContext, other: ConfigurationFromContext) = false
109110

110111
override fun onFirstRun(
111112
configuration: ConfigurationFromContext,
@@ -173,6 +174,8 @@ class TestoRunConfigurationProducer : PhpTestConfigurationProducer<TestoRunConfi
173174
else -> element
174175
} ?: return null
175176

177+
if (PhpUnitUtil.isPhpUnitTestFile(element.containingFile)) return null
178+
176179
return findTestElement(target)
177180
?: findTestElement(target.parentOfType<Function>(true))
178181
?: findTestElement(target.parentOfType<PhpClass>(true))

src/main/kotlin/com/github/xepozz/testo/tests/run/TestoRunConfigurationType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestoRunConfigurationType :
1818
TestoRunConfiguration(project, this)
1919

2020
companion object Companion {
21-
const val ID = "TestoRunConfiguration"
21+
val ID = TestoRunConfiguration::class.java.simpleName
2222

2323
val INSTANCE
2424
get() = findConfigurationType(TestoRunConfigurationType::class.java)

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
name="PHP"
1515
fileNames="testo;testo.php;testo.bat"/>
1616
<runLineMarkerContributor
17-
language="PHP"
17+
language="PHP" order="first"
1818
implementationClass="com.github.xepozz.testo.tests.TestoTestRunLineMarkerProvider"/>
1919
<configurationType
2020
implementation="com.github.xepozz.testo.tests.run.TestoRunConfigurationType"/>

0 commit comments

Comments
 (0)