Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Fixed

- Starting a mutation run no longer reads the coverage report on the UI thread.
- OpenIDE: a Coverage run says why it could not check for Xdebug or PCOV, and refuses to start when PHP cannot be started at all.

## [2026.18] - 2026-11-27

Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ org.gradle.configuration-cache = true

# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching = true

# Maven Central answers bursts of CI requests with 429; Gradle retries it only 3 times over 3 s by default
systemProp.org.gradle.internal.network.retry.max.attempts = 6
systemProp.org.gradle.internal.network.retry.initial.backOff = 5000
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.fileEditor.FileDocumentManager
import org.jetbrains.concurrency.Promise
import ru.openide.openphp.settings.launch.PhpModuleProbeFailureKind
import ru.openide.openphp.settings.launch.PhpModuleProbeResult
import java.io.File
import java.nio.file.Path

Expand Down Expand Up @@ -139,26 +141,36 @@ open class TestoCoverageProgramRunner : AsyncProgramRunner<RunnerSettings>() {
if (driver == TestoCoverageDriver.XDEBUG) mapOf("XDEBUG_MODE" to "coverage") else emptyMap()

/**
* Whether the driver's extension is loaded where the process runs: refuses when the module list says it is
* not, answers a warning when there is no module list — the probe failed, which says nothing either way.
* Whether the driver's extension is loaded where the process runs: refuses when the probe lists the modules
* without it, or when PHP did not start for the probe — the run would not start either. Any other failed
* probe says nothing either way and answers a warning naming why.
*/
private fun checkExtension(driver: TestoCoverageDriver, launch: TestoLaunch): String? {
val (extension, name) = when (driver) {
TestoCoverageDriver.PCOV -> "pcov" to "PCOV"
else -> "xdebug" to "Xdebug"
}
val modules = launch.environment.modules(File(launch.workingDirectory))
if (modules.isEmpty()) {
return "Testo: could not tell whether $name is loaded in ${launch.environment.displayName}; " +
"without it the run writes no coverage."
val environment = launch.environment.displayName
val failure = when (val probe = launch.environment.probeModules(File(launch.workingDirectory))) {
is PhpModuleProbeResult.Known -> {
if (extension in probe.modules) return null
throw ExecutionException(
"Cannot collect coverage: $name is not loaded in the PHP of $environment. " +
"Enable the $extension extension there, or choose the other engine in the configuration.",
)
}
is PhpModuleProbeResult.Unknown -> probe.failure
}
if (extension !in modules) {
throw ExecutionException(
"Cannot collect coverage: $name is not loaded in the PHP of ${launch.environment.displayName}. " +
"Enable the $extension extension there, or choose the other engine in the configuration.",
)
if (failure.kind == PhpModuleProbeFailureKind.START_FAILURE) {
throw ExecutionException(sentences("Cannot collect coverage: the PHP of $environment did not start.", failure.message))
}
return null
return sentences(
"Testo: could not check whether $name is loaded in $environment.",
failure.message,
"Without it the run writes no coverage.",
)
}

private fun sentences(vararg parts: String): String = parts.filter { it.isNotBlank() }.joinToString(" ")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import com.intellij.openapi.util.io.FileUtil
import ru.openide.openphp.settings.launch.PhpExposedPath
import ru.openide.openphp.settings.launch.PhpLaunchEnvironment
import ru.openide.openphp.settings.launch.PhpLaunchLocality
import ru.openide.openphp.settings.launch.PhpModuleProbeResult
import java.io.File

/**
* A launch environment with rules a test states outright: [mappings] from a host directory to the one the process sees,
* [exposed] for what a report path turns into, [modules] for what the module probe finds. Its command shows plainly
* what the plugin passed: a local one runs `php`, any other runs `env <locality>` with the mounts, the working
* directory and then `php`.
* [exposed] for what a report path turns into, [modules] for what the module probe finds, [probe] for a probe that
* fails. Its command shows plainly what the plugin passed: a local one runs `php`, any other runs `env <locality>`
* with the mounts, the working directory and then `php`.
*/
class FakeLaunchEnvironment(
override val locality: PhpLaunchLocality = PhpLaunchLocality.SameHost,
private val mappings: Map<String, String> = emptyMap(),
private val exposed: (String) -> PhpExposedPath = { PhpExposedPath.Visible(it) },
private val modules: Set<String> = emptySet(),
private val probe: PhpModuleProbeResult = PhpModuleProbeResult.Known(modules),
override val projectRoot: String = "",
override val displayName: String = "fake",
) : PhpLaunchEnvironment {
Expand Down Expand Up @@ -54,4 +56,6 @@ class FakeLaunchEnvironment(
override fun exposeFile(hostFile: String, mountAt: String?): PhpExposedPath = exposed(hostFile)

override fun modules(workDir: File?): Set<String> = modules

override fun probeModules(workDir: File?): PhpModuleProbeResult = probe
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import com.intellij.testFramework.fixtures.BasePlatformTestCase
import ru.openide.openphp.settings.launch.PhpExposedPath
import ru.openide.openphp.settings.launch.PhpLaunchEnvironment
import ru.openide.openphp.settings.launch.PhpLaunchLocality
import ru.openide.openphp.settings.launch.PhpModuleProbeFailure
import ru.openide.openphp.settings.launch.PhpModuleProbeFailureKind
import ru.openide.openphp.settings.launch.PhpModuleProbeResult
import java.io.File
import java.nio.file.Path

Expand Down Expand Up @@ -94,12 +97,39 @@ class TestoCoverageRunnerTest : BasePlatformTestCase() {
assertTrue(refusal.message, refusal.message!!.contains("Xdebug is not loaded"))
}

fun testAnUnknownModuleListRunsWithAWarning() {
val covered = covered(TestoCoverageDriver.PCOV, FakeLaunchEnvironment(modules = emptySet()))
fun testAProbeThatTimedOutRunsWithItsReason() {
val probe = failedProbe(PhpModuleProbeFailureKind.TIMEOUT, "The PHP module check timed out after 5000 ms.", timeoutMillis = 5000)

assertTrue(covered.unverifiedExtension, covered.unverifiedExtension!!.contains("could not tell whether PCOV is loaded"))
assertEquals(
"Testo: could not check whether PCOV is loaded in fake. The PHP module check timed out after 5000 ms. " +
"Without it the run writes no coverage.",
covered(TestoCoverageDriver.PCOV, probe).unverifiedExtension,
)
}

fun testEveryInconclusiveProbeRunsWithItsReason() {
val failures = mapOf(
PhpModuleProbeFailureKind.NON_ZERO_EXIT to "The PHP module check exited with code 255.",
PhpModuleProbeFailureKind.INVALID_RESPONSE to "The PHP module check returned an empty or invalid module list.",
PhpModuleProbeFailureKind.NO_INFORMATION to "The interpreter did not return module information.",
)
for ((kind, message) in failures) {
val warning = covered(TestoCoverageDriver.XDEBUG, failedProbe(kind, message)).unverifiedExtension!!
assertTrue(warning, warning.contains(" $message Without it"))
}
}

fun testAPhpThatDidNotStartForTheProbeRefusesTheRun() {
val message = "The PHP module check could not start: Cannot run program \"php\": CreateProcess error=2."
val refusal = thrown<ExecutionException> {
covered(TestoCoverageDriver.XDEBUG, failedProbe(PhpModuleProbeFailureKind.START_FAILURE, message))
}
assertEquals("Cannot collect coverage: the PHP of fake did not start. $message", refusal.message)
}

private fun failedProbe(kind: PhpModuleProbeFailureKind, message: String, exitCode: Int? = null, timeoutMillis: Int? = null) =
FakeLaunchEnvironment(probe = PhpModuleProbeResult.Unknown(PhpModuleProbeFailure(kind, message, exitCode, timeoutMillis)))

fun testPhpdbgIsRefusedBeforeStart() {
val refusal = thrown<ExecutionException> { covered(TestoCoverageDriver.PHPDBG) }
assertTrue(refusal.message, refusal.message!!.contains("PHPDBG"))
Expand Down
Loading