currentBranch() ?? 'main'; $sha = $changedFiles->currentSha(); $id = fn (string $description): string => 'P\Tests\Fixtures\Suites\TiaReplayHooks::'.Str::evaluable($description); $graph = new Graph($projectRoot); $graph->setFingerprint(Fingerprint::compute($projectRoot)); $graph->setRecordedAtSha($branch, $sha); // Hashes the working tree as it stands, so the replay sees nothing as changed. $graph->setLastRunTree($branch, $changedFiles->snapshotTree($changedFiles->since($sha) ?? [])); $graph->markKnownTestFiles([$fixture]); $graph->setResult($branch, $id('replayed pass'), 0, '', 0.01, 1, $fixture); $graph->setResult($branch, $id('replayed skip'), 1, 'cached skip', 0.01, 0, $fixture); $graph->setResult($branch, $id('replayed incomplete'), 2, 'cached incomplete', 0.01, 0, $fixture); $json = $graph->encode(); expect($json)->not->toBeNull(); $originalHome = getenv('HOME'); putenv('HOME='.$home); try { $storage = new FileState(Storage::tempDir($projectRoot)); } finally { putenv($originalHome === false ? 'HOME' : 'HOME='.$originalHome); } expect($storage->write(Tia::KEY_GRAPH, (string) $json))->toBeTrue(); $process = new Process( ['php', 'bin/pest', '--configuration', 'tests/Fixtures/Suites/TiaReplayHooks.xml', '--tia'], $projectRoot, [ 'COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PARATEST' => 0, 'PAO_DISABLE' => '1', 'HOME' => $home, ], ); $process->run(); $output = removeAnsiEscapeSequences($process->getOutput().$process->getErrorOutput()); // Both hooks throw, so the run stays green only if neither one ran. expect($output)->toContain('3 replayed') ->and($output)->not->toContain('must not run for replayed tests') ->and($output)->toContain('1 incomplete, 1 skipped, 1 passed') ->and($process->getExitCode())->toBe(0); } finally { $paths = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($home, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST, ); foreach ($paths as $path) { $path->isDir() ? @rmdir($path->getPathname()) : @unlink($path->getPathname()); } @rmdir($home); } })->skipOnWindows();