diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d11d4f28..e809ab69 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -150,3 +150,96 @@ jobs: files: runtime/clover.xml disable_search: true token: ${{ secrets.CODECOV_TOKEN }} + + code-coverage-turbocov: + runs-on: ubuntu-latest + name: Code Coverage (turbocov) + concurrency: + group: code-coverage-turbocov-${{ github.ref }} + cancel-in-progress: true + + steps: + + - name: Checkout + uses: actions/checkout@v7 + + - name: Resolve root package version + run: echo "COMPOSER_ROOT_VERSION=$(jq -r '.["."]' resources/version.json)" >> "$GITHUB_ENV" + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.5 + coverage: none + tools: pie + ini-values: opcache.enable_cli=0 + + - name: Resolve turbocov build key + id: turbocov + run: | + echo "version=$(curl -fsSL https://repo.packagist.org/p2/shipmonk/turbocov.json | jq -r '.packages["shipmonk/turbocov"][0].version')" >> "$GITHUB_OUTPUT" + echo "php=$(php -r 'echo PHP_VERSION;')" >> "$GITHUB_OUTPUT" + + - name: Cache turbocov build + id: turbocov-cache + uses: actions/cache@v4 + with: + path: ~/.turbocov + key: turbocov-${{ runner.os }}-php${{ steps.turbocov.outputs.php }}-${{ steps.turbocov.outputs.version }} + + - name: Build turbocov + if: steps.turbocov-cache.outputs.cache-hit != 'true' + run: | + sudo pie install "shipmonk/turbocov:${{ steps.turbocov.outputs.version }}" + mkdir -p ~/.turbocov + cp "$(php-config --extension-dir)/turbocov.so" ~/.turbocov/ + + # One ini for both a fresh build and a cache hit; whatever PIE enabled is replaced by it. + - name: Enable turbocov + run: | + scan="$(php -r 'echo PHP_CONFIG_FILE_SCAN_DIR;')" + sudo rm -f "$scan"/*turbocov*.ini + echo "extension=$HOME/.turbocov/turbocov.so" | sudo tee "$scan/99-turbocov.ini" + php --ri turbocov + + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 + with: + dependency-versions: highest + + - name: Install bin tools + run: composer bin all install --ignore-platform-req=php + + # A loaded turbocov that cannot collect the sources must abort a mandatory coverage run with + # its reason instead of writing an empty report. + - name: Reject a turbocov that cannot collect + env: + TESTO_CI: 1 + run: | + expect_failure() { + local message=$1; shift + if php "$@" vendor/bin/testo --coverage --suite=Codecov/Unit > /tmp/run.log 2>&1; then + cat /tmp/run.log; echo "Expected the run to fail with: $message"; exit 1 + fi + # Console output wraps long messages, so whitespace is collapsed before the search. + tr -s "[:space:]" " " < /tmp/run.log | grep -qF "$message" || { cat /tmp/run.log; exit 1; } + } + expect_failure 'turbocov.collect_paths is not set' + expect_failure 'contains none of the configured source paths' -d turbocov.collect_paths="$GITHUB_WORKSPACE/tests" + + # turbocov instruments only `turbocov.collect_paths`, read at compile time; the source filter + # of testo.php narrows it further. + - name: Run Tests with Coverage + env: + TESTO_CI: 1 + run: >- + php + -d turbocov.collect_paths="$GITHUB_WORKSPACE/core:$GITHUB_WORKSPACE/plugin:$GITHUB_WORKSPACE/bridge" + vendor/bin/testo --coverage --coverage-clover=runtime/clover.xml --type=!bench + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + files: runtime/clover.xml + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/bridge/rector/src/TestoToPhpunit/ThrowSkipTestToPhpUnitRector.php b/bridge/rector/src/TestoToPhpunit/ThrowSkipTestToPhpUnitRector.php index 09e3fb9d..4c4f86b2 100644 --- a/bridge/rector/src/TestoToPhpunit/ThrowSkipTestToPhpUnitRector.php +++ b/bridge/rector/src/TestoToPhpunit/ThrowSkipTestToPhpUnitRector.php @@ -7,10 +7,13 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; +use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Throw_; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; +use PhpParser\Node\Name; use PHPStan\Analyser\Scope; +use PHPStan\Reflection\MethodReflection; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -32,7 +35,8 @@ * untouched. * * Only rewrites a throw that lives inside a class: `$this->markTestSkipped()` needs a method scope, - * so a `throw new SkipTest(...)` in a free function or at namespace level is left as-is. + * so a `throw new SkipTest(...)` in a free function or at namespace level is left as-is. Inside a + * static method, which has no `$this`, it becomes `self::markTestSkipped()`. */ #[TestRectorFixtures('ThrowSkipTestToPhpUnitRector')] final class ThrowSkipTestToPhpUnitRector extends AbstractRector @@ -76,27 +80,23 @@ public function refactor(Node $node): ?Node return null; } - # Only convert inside a class: `$this->markTestSkipped()` has no valid target in a free - # function or at namespace level, so such a throw is left unchanged. - if (!$this->isInClassScope($node)) { + # Only convert inside a class: `markTestSkipped()` has no valid target in a free function or + # at namespace level, so such a throw is left unchanged. + $scope = $node->getAttribute(AttributeKey::SCOPE); + if (!$scope instanceof Scope || !$scope->isInClass()) { return null; } + # `markTestSkipped()` is static in PHPUnit; a static helper has no `$this` to call it on. + $function = $scope->getFunction(); + if ($function instanceof MethodReflection && $function->isStatic()) { + return new StaticCall(new Name('self'), new Identifier('markTestSkipped'), $thrown->args); + } + return new MethodCall( new Variable('this'), new Identifier('markTestSkipped'), $thrown->args, ); } - - /** - * Whether $node sits inside a class. Outside one — a free function or namespace-level code — the - * emitted `$this->markTestSkipped()` call would have no valid target, so the throw is left as-is. - */ - private function isInClassScope(Node $node): bool - { - $scope = $node->getAttribute(AttributeKey::SCOPE); - - return $scope instanceof Scope && $scope->isInClass(); - } } diff --git a/bridge/rector/src/TestoToPhpunit/ThrowSkipTestToPhpUnitRector/static_method_uses_self.php.inc b/bridge/rector/src/TestoToPhpunit/ThrowSkipTestToPhpUnitRector/static_method_uses_self.php.inc new file mode 100644 index 00000000..07835f5d --- /dev/null +++ b/bridge/rector/src/TestoToPhpunit/ThrowSkipTestToPhpUnitRector/static_method_uses_self.php.inc @@ -0,0 +1,29 @@ +driverResolved) { $this->driverResolved = true; - $this->driver = self::detectAvailableDriver($this->container->get(ApplicationConfig::class)->src); + $this->driver = $this->detectAvailableDriver($this->container->get(ApplicationConfig::class)->src); } } @@ -162,7 +170,8 @@ public function contribute(CoverageLevel $level, array $testTypes, array $report */ public function verifyDriverRequirement(): void { - $this->mode === CoverageMode::Always && $this->driver === null and throw new CoverageDriverNotAvailable(); + $this->mode === CoverageMode::Always && $this->driver === null + and throw new CoverageDriverNotAvailable($this->driverUnavailableReason); } /** @@ -216,23 +225,6 @@ private static function rank(CoverageLevel $level): int }; } - /** - * Returns a usable driver if a coverage extension is present, otherwise null. Never throws — the - * {@see CoverageMode::Always} "no driver" failure is decided in {@see onSessionStarting()} once - * the merged mode is known. `Never` plugins return before contributing, so mode is not consulted - * here. - * - * For XDebug this also installs the engine-level coverage filter (see {@see XdebugDriver::create()}). - */ - private static function detectAvailableDriver(FinderConfig $src): ?CoverageDriver - { - return match (true) { - \extension_loaded('pcov') => PcovDriver::create($src), - self::isXdebugCoverageEnabled() => XdebugDriver::create($src), - default => null, - }; - } - /** * True when Xdebug is loaded and `coverage` is among its active modes; otherwise * `xdebug_start_code_coverage()` is a no-op and reports come back empty. @@ -290,4 +282,32 @@ private static function resolveSourceRoot(FinderConfig $src): ?string return $commonLen === 0 ? null : \implode('/', \array_slice($first, 0, $commonLen)); } + + /** + * Returns a usable driver if a coverage extension is present, otherwise null. Never throws — the + * {@see CoverageMode::Always} "no driver" failure is decided in {@see onSessionStarting()} once + * the merged mode is known. `Never` plugins return before contributing, so mode is not consulted + * here. + * + * For XDebug this also installs the engine-level coverage filter (see {@see XdebugDriver::create()}). + * + * A turbocov that cannot collect the sources (next to Xdebug, without `turbocov.collect_paths`, or with + * one that shares no path with `src`) yields to the other drivers; its reason is kept for the error + * when none is left. + */ + private function detectAvailableDriver(FinderConfig $src): ?CoverageDriver + { + if (\extension_loaded('turbocov')) { + $this->driverUnavailableReason = TurbocovDriver::unavailableReason($src); + if ($this->driverUnavailableReason === null) { + return TurbocovDriver::create($src); + } + } + + return match (true) { + \extension_loaded('pcov') => PcovDriver::create($src), + self::isXdebugCoverageEnabled() => XdebugDriver::create($src), + default => null, + }; + } } diff --git a/plugin/codecov/src/Internal/Driver/PathFilter.php b/plugin/codecov/src/Internal/Driver/PathFilter.php new file mode 100644 index 00000000..28e87b14 --- /dev/null +++ b/plugin/codecov/src/Internal/Driver/PathFilter.php @@ -0,0 +1,39 @@ + $includes` and `$excludes` built with {@see NormalizePath}. + * + * @internal + */ +trait PathFilter +{ + private function matchesFilter(string $file): bool + { + $included = false; + foreach ($this->includes as $path) { + if (\str_starts_with($file, $path)) { + $included = true; + break; + } + } + + if (!$included) { + return false; + } + + foreach ($this->excludes as $path) { + if (\str_starts_with($file, $path)) { + return false; + } + } + + return true; + } +} diff --git a/plugin/codecov/src/Internal/Driver/PcovDriver.php b/plugin/codecov/src/Internal/Driver/PcovDriver.php index 80c5a4bf..4503f5e8 100644 --- a/plugin/codecov/src/Internal/Driver/PcovDriver.php +++ b/plugin/codecov/src/Internal/Driver/PcovDriver.php @@ -17,6 +17,7 @@ final readonly class PcovDriver implements CoverageDriver { use NormalizePath; + use PathFilter; /** * @param list $includes @@ -87,27 +88,4 @@ public function clear(): void { \pcov\clear(); } - - private function matchesFilter(string $file): bool - { - $included = false; - foreach ($this->includes as $path) { - if (\str_starts_with($file, $path)) { - $included = true; - break; - } - } - - if (!$included) { - return false; - } - - foreach ($this->excludes as $path) { - if (\str_starts_with($file, $path)) { - return false; - } - } - - return true; - } } diff --git a/plugin/codecov/src/Internal/Driver/TurbocovDriver.php b/plugin/codecov/src/Internal/Driver/TurbocovDriver.php new file mode 100644 index 00000000..28efe37e --- /dev/null +++ b/plugin/codecov/src/Internal/Driver/TurbocovDriver.php @@ -0,0 +1,152 @@ + $includes + * @param list $excludes + */ + private function __construct( + private array $includes = [], + private array $excludes = [], + ) {} + + public static function create(FinderConfig $src): self + { + return new self( + \array_map(self::normalizePath(...), $src->includes), + \array_map(self::normalizePath(...), $src->excludes), + ); + } + + /** + * Returns why turbocov cannot collect the given sources in this process, or null when it can. + * + * Besides turbocov's own reasons (an unset `turbocov.collect_paths`, a conflicting extension), this + * rejects a `collect_paths` that shares no path with the sources, which would report nothing. + * A partial overlap is accepted: a list of changed files is a narrower `collect_paths` on purpose. + * + * @return non-empty-string|null + */ + public static function unavailableReason(FinderConfig $src): ?string + { + try { + \turbocov\ensure_can_collect(); + } catch (\turbocov\CannotCollectException $e) { + return $e->getMessage(); + } + + $collect = self::collectPaths(); + if ($src->includes === [] || $collect === null) { + return null; + } + + foreach ($src->includes as $include) { + $source = self::normalizePath($include); + foreach ($collect as $path) { + if (\str_starts_with($source, $path) || \str_starts_with($path, $source)) { + return null; + } + } + } + + return \sprintf( + 'turbocov cannot collect coverage: turbocov.collect_paths (%s) contains none of the configured source paths.', + \ini_get('turbocov.collect_paths'), + ); + } + + #[\Override] + public function withFilter(FinderConfig $filter): static + { + return self::create($filter); + } + + /** + * turbocov only supports line coverage. Higher levels silently fall back to Line. + */ + #[\Override] + public function withLevel(CoverageLevel $level): static + { + return $this; + } + + #[\Override] + public function start(): void + { + \turbocov\start(); + } + + #[\Override] + public function collect(): CoverageResult + { + # Keyed by every instrumented file compiled or executed since the last stop, with the lines that ran. + $executed = \turbocov\stop(); + + $files = \array_keys($executed); + $this->includes === [] or $files = \array_values(\array_filter($files, $this->matchesFilter(...))); + if ($files === []) { + return CoverageResult::fromRawData([]); + } + + $data = []; + foreach (\turbocov\get_executable_lines($files) as $file => $lines) { + $data[$file] = \array_replace($lines, $executed[$file] ?? []); + } + + return CoverageResult::fromRawData(UncountedLines::remove(PseudoFile::remove($data))); + } + + #[\Override] + public function clear(): void + { + \turbocov\stop(); + } + + /** + * Resolves `turbocov.collect_paths`: a `:`-separated list, or `@` and a file with one path per line. + * + * @return list|null Null when the list file cannot be read. + */ + private static function collectPaths(): ?array + { + $value = (string) \ini_get('turbocov.collect_paths'); + if (\str_starts_with($value, '@')) { + $entries = @\file(\substr($value, 1), \FILE_IGNORE_NEW_LINES | \FILE_SKIP_EMPTY_LINES); + if ($entries === false) { + return null; + } + } else { + $entries = \explode(':', $value); + } + + $paths = []; + foreach ($entries as $entry) { + $real = \realpath(\trim($entry)); + $real === false or $paths[] = \is_dir($real) ? \rtrim($real, \DIRECTORY_SEPARATOR) . \DIRECTORY_SEPARATOR : $real; + } + + return $paths; + } +} diff --git a/plugin/codecov/tests/Fixture/Turbocov/Sign.php b/plugin/codecov/tests/Fixture/Turbocov/Sign.php new file mode 100644 index 00000000..8c25b63a --- /dev/null +++ b/plugin/codecov/tests/Fixture/Turbocov/Sign.php @@ -0,0 +1,17 @@ +driver(); + + $driver->start(); + Sign::of(1); + $result = $driver->collect(); + + Assert::same(self::status($result, 'if ($value < 0) {'), LineStatus::Executed); + Assert::same(self::status($result, "return 'negative';"), LineStatus::NotExecuted); + Assert::same(self::status($result, "return 'positive';"), LineStatus::Executed); + } + + public function collectDropsExcludedFiles(): void + { + $driver = $this->driver([self::fixtureFile()]); + + $driver->start(); + Sign::of(1); + $result = $driver->collect(); + + Assert::array($result->files)->doesNotHaveKeys(self::fixtureFile()); + } + + public function clearDiscardsCollectedLines(): void + { + $driver = $this->driver(); + Sign::of(-1); + + $driver->start(); + Sign::of(-1); + $driver->clear(); + $driver->start(); + $result = $driver->collect(); + + Assert::array($result->files)->doesNotHaveKeys(self::fixtureFile()); + } + + public function sourcesOutsideCollectPathsAreRejected(): void + { + $this->driver(); + + $reason = TurbocovDriver::unavailableReason(new FinderConfig([self::repositoryRoot() . '/tests'])); + + Assert::string((string) $reason)->contains('contains none of the configured source paths'); + } + + public function sourcesEnclosingCollectPathsAreAccepted(): void + { + $this->driver(); + + Assert::null(TurbocovDriver::unavailableReason(new FinderConfig([self::repositoryRoot()]))); + } + + /** + * @param list $excludes + */ + private function driver(array $excludes = []): TurbocovDriver + { + \extension_loaded('turbocov') or throw new SkipTest('turbocov is not loaded'); + $src = new FinderConfig([self::fixtureDir()], $excludes); + $reason = TurbocovDriver::unavailableReason($src); + $reason === null or throw new SkipTest($reason); + + return TurbocovDriver::create($src); + } + + private static function repositoryRoot(): string + { + return \dirname(__DIR__, 5); + } + + private static function status(CoverageResult $result, string $code): ?LineStatus + { + $line = \array_search($code, \array_map(\trim(...), \file(self::fixtureFile())), true) + 1; + + return $result->files[self::fixtureFile()]->lines[$line]->status ?? null; + } + + private static function fixtureDir(): string + { + return \dirname(__DIR__, 2) . '/Fixture/Turbocov'; + } + + private static function fixtureFile(): string + { + return (string) \realpath(self::fixtureDir() . '/Sign.php'); + } +} diff --git a/plugin/codecov/tests/Unit/Internal/CoverageActivationTest.php b/plugin/codecov/tests/Unit/Internal/CoverageActivationTest.php index cf1a36c9..39a4623d 100644 --- a/plugin/codecov/tests/Unit/Internal/CoverageActivationTest.php +++ b/plugin/codecov/tests/Unit/Internal/CoverageActivationTest.php @@ -148,6 +148,18 @@ public function verifyDriverRequirementThrowsWhenAlwaysWithoutDriver(): never $activation->verifyDriverRequirement(); } + public function verifyDriverRequirementReportsWhyLoadedDriverCannotCollect(): never + { + $activation = self::createActivation(); + self::write($activation, 'mode', CoverageMode::Always); + self::write($activation, 'driverUnavailableReason', 'turbocov cannot collect coverage: turbocov.collect_paths is not set'); + + Expect::exception(CoverageDriverNotAvailable::class) + ->withMessage('turbocov cannot collect coverage: turbocov.collect_paths is not set'); + + $activation->verifyDriverRequirement(); + } + public function verifyDriverRequirementPassesWhenAlwaysWithDriver(): void { $activation = self::createActivation(); diff --git a/skills/testo-coverage/SKILL.md b/skills/testo-coverage/SKILL.md index 57690489..cefa01ff 100644 --- a/skills/testo-coverage/SKILL.md +++ b/skills/testo-coverage/SKILL.md @@ -9,7 +9,7 @@ Coverage is opt-in via the **`CodecovPlugin`** in `testo.php`. The plugin needs: 1. A coverage **level** — `Line`, `Branch`, or `Path` (each adds cost and information). 2. One or more **report writers** — Clover, Cobertura, PHPUnit XML. -3. Xdebug ≥ 3.1 (in coverage mode) **or** PCOV available on the runner. Without one of them, the plugin will skip. The coverage mode can be set via `xdebug.mode=coverage`, the `-d xdebug.mode=coverage` CLI flag, **or** the `XDEBUG_MODE=coverage` env var — Testo resolves the active mode with `xdebug_info('mode')`, so the env override (used by `composer infect` and IDE coverage runners) counts. +3. A coverage driver on the runner: turbocov, PCOV, or Xdebug ≥ 3.1 in coverage mode (checked in that order). Without one of them, the plugin will skip. The coverage mode can be set via `xdebug.mode=coverage`, the `-d xdebug.mode=coverage` CLI flag, **or** the `XDEBUG_MODE=coverage` env var — Testo resolves the active mode with `xdebug_info('mode')`, so the env override (used by `composer infect` and IDE coverage runners) counts. Exact class names and constructor parameters are authoritative in the installed `vendor/testo/codecov` — verify against it before editing. @@ -50,7 +50,7 @@ vendor/bin/testo --no-coverage # explicit off, overrides config ``` `--coverage` makes coverage **mandatory** (`CoverageMode::Always`): the run aborts with -`CoverageDriverNotAvailable` (non-zero exit) when no Xdebug/PCOV driver is present — even with no +`CoverageDriverNotAvailable` (non-zero exit) when no turbocov/PCOV/Xdebug driver is present — even with no report flags. That makes a bare `vendor/bin/testo --coverage` a handy CI gate to assert the driver is actually available. `--no-coverage` always wins over everything. @@ -66,7 +66,7 @@ vendor/bin/testo --coverage-xml=build/coverage-xml # directory, for Infecti ``` - **Soft activation.** Passing any of these implies coverage collection *if a driver is available*; - with no Xdebug/PCOV the run skips silently (no file). `--no-coverage` still wins and disables it. + with no driver the run skips silently (no file). `--no-coverage` still wins and disables it. - **Parallel with your config.** If `testo.php` already declares a `CodecovPlugin`, the flag-driven reports run **alongside** your configured ones — both sets of files are written. The two are **merged** into a single coverage collection (no double overhead): the deepest requested level @@ -103,6 +103,25 @@ report. The bug persists in current Xdebug builds (reproduced on 3.5.3). Testo t test with `BranchCoverageUnsafeInFiber`, but the guard is tied to the Xdebug version and doesn't fire on every build — don't rely on it. PCOV is unaffected (it only does `Line` anyway). +## turbocov + +[turbocov](https://github.com/shipmonk-rnd/turbocov) records a line only the first time it runs in a +test, so it adds a fraction of PCOV's overhead. It supports `Line` only, needs PHP 8.4 or newer on +Linux or macOS, and cannot be loaded next to Xdebug or PCOV. + +It instruments only the files under `turbocov.collect_paths`, which it reads when PHP compiles a file: +set it in `php.ini` or with `-d`, never with `ini_set()`. Point it at a root that contains the +configured `src` (`php -d turbocov.collect_paths=/app/src vendor/bin/testo --coverage`); the `src` +filter of `testo.php` narrows the report further, and files outside `collect_paths` never appear in it. + +A narrower `collect_paths` is fine, such as a list of changed files for PR-only coverage +(`-d turbocov.collect_paths=@changed.txt`). One that shares no path with `src` would report nothing, +so Testo treats it like a turbocov that cannot collect. + +A turbocov that is loaded but cannot collect (no `collect_paths`, one outside `src`, a conflicting +extension) yields to PCOV or Xdebug when one is present. Under `--coverage` with no other driver, +`CoverageDriverNotAvailable` carries the reason, such as `turbocov.collect_paths is not set`. + ## `#[Covers]` and `#[CoversNothing]` Declare which production classes a test exercises. The test is credited only with lines inside its targets; anything else it ran stays in the report as uncovered unless another test covers it, so a narrow `#[Covers]` never hides code from the total. @@ -209,7 +228,7 @@ final readonly class MyReport implements CoverageReport ## Pitfalls -- No coverage written? Check the active Xdebug mode includes `coverage` — set it via `xdebug.mode`, `-d xdebug.mode=coverage`, or `XDEBUG_MODE=coverage` (or load PCOV). Testo skips the driver if neither is available. +- No coverage written? Check the active Xdebug mode includes `coverage` — set it via `xdebug.mode`, `-d xdebug.mode=coverage`, or `XDEBUG_MODE=coverage` (or load PCOV or turbocov). Testo skips the driver if none is available. - A report landed in the project root under a name like `C:\Users\...`? A Windows path reached a Linux PHP (WSL, Docker): it has no `/`, so it reads as a relative file name. Pass the path as the interpreter sees it (`/mnt/c/...`). - `clover.xml` empty? Suite-level finder probably excludes the `src` directory you expected — verify the `FinderConfig` covers it. - Don't enable coverage in benchmark suites — it falsifies timings. diff --git a/skills/testo-increase-coverage/SKILL.md b/skills/testo-increase-coverage/SKILL.md index 797e96d5..9f7fe1ea 100644 --- a/skills/testo-increase-coverage/SKILL.md +++ b/skills/testo-increase-coverage/SKILL.md @@ -38,7 +38,7 @@ Before running any command — for read-only immediately, for the improve path o php -r "echo PHP_BINARY;" # e.g. C:\php\php.exe or /usr/bin/php ``` -`PHP_BINARY` is the exact interpreter currently running — using it guarantees subagents collect coverage with the same PHP (same Xdebug/PCOV). Carry this `` value into every command below, and pass it to each subagent as `{{PHP}}` (Phase 4). +`PHP_BINARY` is the exact interpreter currently running — using it guarantees subagents collect coverage with the same PHP (same coverage driver). Carry this `` value into every command below, and pass it to each subagent as `{{PHP}}` (Phase 4). ## Phase 2 — Collect coverage @@ -48,7 +48,7 @@ php -r "echo PHP_BINARY;" # e.g. C:\php\php.exe or /usr/bin/php ### 2. Run once (whole project) -Collect for the whole project in one run — no `--path`/`--filter`, so the report covers everything. Needs an active coverage driver (Xdebug ≥ 3.1 in coverage mode, or PCOV) — see `testo-coverage` for wiring. Emit all three artifacts in the **one** run (they merge into a single collection — no extra overhead): +Collect for the whole project in one run — no `--path`/`--filter`, so the report covers everything. Needs an active coverage driver (turbocov, PCOV, or Xdebug ≥ 3.1 in coverage mode) — see `testo-coverage` for wiring. Emit all three artifacts in the **one** run (they merge into a single collection — no extra overhead): ```bash -d xdebug.mode=coverage -d xdebug.max_nesting_level=100000 \ diff --git a/skills/testo-mutation-testing/references/setup.md b/skills/testo-mutation-testing/references/setup.md index 26d524ae..6131ddd8 100644 --- a/skills/testo-mutation-testing/references/setup.md +++ b/skills/testo-mutation-testing/references/setup.md @@ -49,11 +49,11 @@ runs work too. The bridge is auto-discovered. ## 3. Coverage driver -Infection needs per-test coverage, produced in Phase 3 with Xdebug (`xdebug.mode=coverage`) or -PCOV. Check the PHP that will run the tests: +Infection needs per-test coverage, produced in Phase 3 with Xdebug (`xdebug.mode=coverage`), PCOV or +turbocov. Check the PHP that will run the tests: ```bash -php -m | grep -iE 'xdebug|pcov' +php -m | grep -iE 'xdebug|pcov|turbocov' ``` No driver → install one (`pecl install xdebug` / `pecl install pcov`, or the distro package) before diff --git a/skills/testo-mutation-testing/scripts/precheck.php b/skills/testo-mutation-testing/scripts/precheck.php index 34680898..a41beb61 100644 --- a/skills/testo-mutation-testing/scripts/precheck.php +++ b/skills/testo-mutation-testing/scripts/precheck.php @@ -106,7 +106,12 @@ // --- Coverage driver ----------------------------------------------------------------------------- // Checked in *this* PHP process; the test run may use another binary/ini — advisory only. -$driver = \extension_loaded('xdebug') ? 'xdebug' : (\extension_loaded('pcov') ? 'pcov' : null); +$driver = match (true) { + \extension_loaded('xdebug') => 'xdebug', + \extension_loaded('pcov') => 'pcov', + \extension_loaded('turbocov') => 'turbocov', + default => null, +}; // --- Report -------------------------------------------------------------------------------------- @@ -125,7 +130,7 @@ echo "| infection.json with source dirs | {$yn($configOk)} | " . ($configFile ?? 'no config file') . " |\n"; echo "| testFramework pinned to testo | " . ($frameworkPinned ? 'yes' : 'no (advisory)') . " | " . ($configFile !== null ? 'testFramework=' . \var_export($testFramework, true) : '—') . " |\n"; -echo "| coverage driver (this PHP) | " . ($driver ?? 'NO') . " | xdebug/pcov |\n"; +echo "| coverage driver (this PHP) | " . ($driver ?? 'NO') . " | xdebug/pcov/turbocov |\n"; echo "\n"; if ($configOk) { @@ -140,7 +145,7 @@ ($infectionInstalled && $bridgeInstalled && !$bridgeRegistered) and $fixes[] = 'Bridge installed but not registered — allow the plugin (above) and run `composer install` again.'; $configOk or $fixes[] = 'Create `infection.json` with `source.directories` — template in `references/setup.md`.'; -$driver !== null or $fixes[] = 'No Xdebug/PCOV in this PHP. Install one, or point commands at a PHP that has it (`php -m | grep -i xdebug`).'; +$driver !== null or $fixes[] = 'No Xdebug/PCOV/turbocov in this PHP. Install one, or point commands at a PHP that has it (`php -m | grep -i xdebug`).'; $ready = $testoInstalled && $infectionInstalled && $bridgeInstalled && $bridgeRegistered && $configOk;