{"record":{"id":"6bdc08363bac2403","repo":"sebastianbergmann/phpunit","slug":"file-s-exists-phpt-test-s-will-not-be-executed","errorCode":null,"errorMessage":"File %s exists, PHPT test %s will not be executed","messagePattern":"File (.+?) exists, PHPT test (.+?) will not be executed","errorType":"exception","errorClass":"CodeCoverageFileExistsException","httpStatus":null,"severity":"error","filePath":"src/Runner/Phpt/TestCase.php","lineNumber":1017,"sourceCode":"     * @param array<non-empty-string, string> $sections\n     * @param non-empty-string                $key\n     */\n    private function sectionOffset(array $sections, string $key): int\n    {\n        assert(isset($sections[$key]));\n\n        return (int) $sections[$key];\n    }\n\n    /**\n     * @throws CodeCoverageFileExistsException\n     */\n    private function ensureCoverageFileDoesNotExist(): void\n    {\n        $files = $this->coverageFiles();\n\n        if (file_exists($files['coverage'])) {\n            throw new CodeCoverageFileExistsException(\n                sprintf(\n                    'File %s exists, PHPT test %s will not be executed',\n                    $files['coverage'],\n                    $this->filename,\n                ),\n            );\n        }\n    }\n}\n","sourceCodeStart":999,"sourceCodeEnd":1027,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/Phpt/TestCase.php#L999-L1027","documentation":"The PHPT TestCase constructor calls ensureCoverageFileDoesNotExist(): for a test.phpt it derives <testdir>/<basename>.coverage (basename with 'phpt' replaced by 'coverage') and throws CodeCoverageFileExistsException('File %s exists, PHPT test %s will not be executed') when that file already exists. The .coverage file is written during execution and removed afterwards, so a leftover one means a previous run crashed mid-test; re-running would corrupt or be corrupted by the stale file.","triggerScenarios":"A previous PHPT test run crashed (fatal error, kill -9, OOM) between writing <test>.coverage and cleanup, leaving <test>.coverage on disk; constructing the PHPT TestCase again in the same or a later session.","commonSituations":"Interrupting a coverage-enabled PHPT run (Ctrl+C); a segfault or timeout inside a PHPT test; parallel runners restarting after a crash without cleanup.","solutions":["Delete the stale <test>.coverage file named in the message.","Sweep the test directory for leftover *.coverage artifacts: find tests/ -name '*.coverage' -delete.","Investigate why the earlier run crashed mid-test (fatal error, OOM, timeout) so the artifact does not reappear."],"exampleFix":"# before\nphpunit tests/example.phpt\n# => File tests/example.coverage exists, PHPT test tests/example.phpt will not be executed\n\n# after\nrm tests/example.coverage\nphpunit tests/example.phpt","handlingStrategy":"validation","validationCode":"// before running a PHPT suite, clear stale coverage artifacts\nforeach (glob('tests/*.coverage') as $stale) {\n    unlink($stale); // left over from a crashed previous run\n}\n\n// or targeted, per test file\n$phpt     = 'tests/example.phpt';\n$coverage = substr($phpt, 0, -4) . 'coverage';\nif (file_exists($coverage)) {\n    unlink($coverage);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clean *.coverage artifacts in CI before each PHPT run: find . -name '*.coverage' -delete.","Investigate and fix whatever crashed the earlier run (OOM, timeout, fatal error) so artifacts stop accumulating.","Do not commit *.coverage files; add them to .gitignore."],"tags":["phpunit","phpt","code-coverage","stale-artifact","crash-recovery"],"backgroundTag":"stale-artifact-file","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}