{"record":{"id":"61b58ebeb0c9ea8c","repo":"sebastianbergmann/phpunit","slug":"file-s-does-not-exist","errorCode":null,"errorMessage":"File \"%s\" does not exist","messagePattern":"File \"(.+?)\" does not exist","errorType":"exception","errorClass":"FileDoesNotExistException","httpStatus":null,"severity":"error","filePath":"src/Runner/Baseline/Issue.php","lineNumber":132,"sourceCode":"               $this->hash() === $other->hash() &&\n               $this->description() === $other->description();\n    }\n\n    /**\n     * @param non-empty-string $file\n     * @param positive-int     $line\n     *\n     * @throws FileDoesNotExistException\n     * @throws FileDoesNotHaveLineException\n     *\n     * @return non-empty-string\n     */\n    private static function calculateHash(string $file, int $line): string\n    {\n        $lines = @file($file, FILE_IGNORE_NEW_LINES);\n\n        if ($lines === false && !is_file($file)) {\n            throw new FileDoesNotExistException($file);\n        }\n\n        $key = $line - 1;\n\n        if (!isset($lines[$key])) {\n            throw new FileDoesNotHaveLineException($file, $line);\n        }\n\n        $hash = sha1($lines[$key]);\n\n        assert($hash !== '');\n\n        return $hash;\n    }\n}\n","sourceCodeStart":114,"sourceCodeEnd":148,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/Baseline/Issue.php#L114-L148","documentation":"When PHPUnit records an issue for a baseline (--generate-baseline) or checks a triggered issue against a loaded baseline, it hashes the offending source line by reading the file with file(). calculateHash() could not read the file and is_file() confirmed it does not exist, so FileDoesNotExistException names the path. Hash calculation runs exactly when no hash was supplied — Issue::from() with $hash = null, as done by the baseline Generator (Generator.php:68) and the ErrorHandler's baseline lookup (ErrorHandler.php:632).","triggerScenarios":"Running --generate-baseline when a deprecation/notice/warning was triggered in a file that is not on disk at hash time — eval()'d or dynamically generated code, stream-wrapped code, or a source file deleted/renamed during the run; also calling Issue::from($file, $line, null, $description) programmatically with a non-existent path.","commonSituations":"Runtime-generated code (compiled templates, eval'd snippets) whose reported file never existed; files moved between generating and using a baseline; container images where recorded paths are absent.","solutions":["Verify the path in the exception exists in the current environment (checkout, container image).","Exclude runtime-generated code from baseline generation via the <source> settings (restrict deprecations/notices/warnings to real source files).","When creating issues programmatically, pass a precomputed hash to Issue::from() instead of null so no file read is needed."],"exampleFix":"// before\n$issue = Issue::from($file, $line, null, $description);\n\n// after: supply the hash when the file cannot be read\n$issue = Issue::from($file, $line, $knownHash, $description);","handlingStrategy":"validation","validationCode":"// Before generating a baseline (or calling Issue::from with null hash)\nif (!is_file($file)) {\n    // exclude this issue from baseline generation or fix the path\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict <source> in phpunit.xml so only real project files contribute baseline issues.","Run --generate-baseline in the same environment (paths, container) where the baseline will be consumed.","When integrating Issue programmatically, pass an explicit hash to avoid reading the file."],"tags":["phpunit","php","baseline","deprecation"],"backgroundTag":"baseline-source-file-missing","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}