sebastianbergmann/phpunit · error · FileDoesNotExistException

File "%s" does not exist

Error message

File "%s" does not exist

What it means

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).

Source

Thrown at src/Runner/Baseline/Issue.php:132

               $this->hash() === $other->hash() &&
               $this->description() === $other->description();
    }

    /**
     * @param non-empty-string $file
     * @param positive-int     $line
     *
     * @throws FileDoesNotExistException
     * @throws FileDoesNotHaveLineException
     *
     * @return non-empty-string
     */
    private static function calculateHash(string $file, int $line): string
    {
        $lines = @file($file, FILE_IGNORE_NEW_LINES);

        if ($lines === false && !is_file($file)) {
            throw new FileDoesNotExistException($file);
        }

        $key = $line - 1;

        if (!isset($lines[$key])) {
            throw new FileDoesNotHaveLineException($file, $line);
        }

        $hash = sha1($lines[$key]);

        assert($hash !== '');

        return $hash;
    }
}

View on GitHub (pinned to f123cdb2a2)

Solutions

  1. Verify the path in the exception exists in the current environment (checkout, container image).
  2. Exclude runtime-generated code from baseline generation via the <source> settings (restrict deprecations/notices/warnings to real source files).
  3. When creating issues programmatically, pass a precomputed hash to Issue::from() instead of null so no file read is needed.

Example fix

// before
$issue = Issue::from($file, $line, null, $description);

// after: supply the hash when the file cannot be read
$issue = Issue::from($file, $line, $knownHash, $description);
Defensive patterns

Strategy: validation

Validate before calling

// Before generating a baseline (or calling Issue::from with null hash)
if (!is_file($file)) {
    // exclude this issue from baseline generation or fix the path
    return;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sebastianbergmann/phpunit@f123cdb2a2 (2026-08-23). Data as JSON: /api/errors/61b58ebeb0c9ea8c. Report an issue: GitHub.