|
| 1 | +package com.github.xepozz.testo.coverage |
| 2 | + |
| 3 | +import com.github.xepozz.testo.tests.run.TestoRunConfiguration |
| 4 | +import com.intellij.execution.configurations.RunProfile |
| 5 | +import com.intellij.execution.configurations.RunProfileState |
| 6 | +import com.intellij.execution.runners.ExecutionEnvironment |
| 7 | +import com.jetbrains.php.config.commandLine.PhpCommandSettings |
| 8 | +import com.jetbrains.php.config.interpreters.PhpInterpreter |
| 9 | +import com.jetbrains.php.debug.xdebug.options.XdebugConfigurationOptionsManager |
| 10 | +import com.jetbrains.php.phpunit.coverage.PhpCoverageRunner |
| 11 | +import com.jetbrains.php.phpunit.coverage.PhpUnitCoverageEngine.CoverageEngine |
| 12 | +import com.jetbrains.php.run.PhpConfigurationOption |
| 13 | +import com.jetbrains.php.run.PhpRunConfigurationHolder |
| 14 | + |
| 15 | +open class TestoCoverageProgramRunner : PhpCoverageRunner() { |
| 16 | + companion object { |
| 17 | + const val EXECUTOR_ID: String = "Coverage" |
| 18 | + const val RUNNER_ID: String = "TestoCoverageRunner" |
| 19 | + } |
| 20 | + |
| 21 | + override fun canRun(executorId: String, profile: RunProfile) = |
| 22 | + executorId == EXECUTOR_ID && profile is TestoRunConfiguration |
| 23 | + |
| 24 | + override fun createCoverageArguments(targetCoverage: String?) = mutableListOf("--coverage") |
| 25 | + |
| 26 | + override fun getRunnerId(): String = RUNNER_ID |
| 27 | + |
| 28 | + override fun createState( |
| 29 | + env: ExecutionEnvironment, |
| 30 | + interpreter: PhpInterpreter, |
| 31 | + runConfigurationHolder: PhpRunConfigurationHolder<*>, |
| 32 | + coverageArguments: MutableList<String>, |
| 33 | + localCoverage: String, |
| 34 | + targetCoverage: String |
| 35 | + ): RunProfileState? { |
| 36 | + val runConfiguration = runConfigurationHolder.runConfiguration as TestoRunConfiguration |
| 37 | + |
| 38 | + val command = createTestoCoverageCommand( |
| 39 | + runConfiguration, |
| 40 | + interpreter, |
| 41 | + coverageArguments, |
| 42 | + localCoverage, |
| 43 | + targetCoverage, |
| 44 | + ) |
| 45 | + |
| 46 | + runConfiguration.checkConfiguration() |
| 47 | + return runConfiguration.getState(env, command, null) |
| 48 | + } |
| 49 | + |
| 50 | + fun createTestoCoverageCommand( |
| 51 | + runConfiguration: TestoRunConfiguration, |
| 52 | + interpreter: PhpInterpreter, |
| 53 | + coverageArguments: List<String>, |
| 54 | + localCoverage: String, |
| 55 | + targetCoverage: String |
| 56 | + ): PhpCommandSettings { |
| 57 | + val command = runConfiguration.createCommand( |
| 58 | + interpreter, |
| 59 | + mutableMapOf<String, String>(), |
| 60 | + coverageArguments.toMutableList(), |
| 61 | + true, |
| 62 | + ) |
| 63 | + |
| 64 | + val options = when (runConfiguration.testoSettings.getTestoRunnerSettings().coverageEngine) { |
| 65 | + CoverageEngine.XDEBUG -> XdebugConfigurationOptionsManager |
| 66 | + .getConfigurationOptionsProvider(runConfiguration.project, interpreter) |
| 67 | + .enableCoverage() |
| 68 | + .createXdebugConfigurations() |
| 69 | + |
| 70 | + CoverageEngine.PCOV -> listOf(PhpConfigurationOption("pcov.enabled", 1)) |
| 71 | + else -> throw IllegalArgumentException("Unsupported coverage engine.") |
| 72 | + } |
| 73 | + command.addConfigurationOptions(options) |
| 74 | + setAdditionalMapping(localCoverage, targetCoverage, command) |
| 75 | + |
| 76 | + return command |
| 77 | + } |
| 78 | +} |
0 commit comments