sebastianbergmann/phpunit · error · CannotLoadBaselineException

Cannot read baseline %s, version %d is not supported

Error message

Cannot read baseline %s, version %d is not supported

What it means

The baseline document's root element carries a version attribute (the Writer records Baseline::VERSION, currently 1) and Reader::read() refuses any other value because the schema cannot be trusted. The message shows the file and the offending version; a missing version attribute parses as '' and (int) casts to 0, which is also rejected.

Source

Thrown at src/Runner/Baseline/Reader.php:67

            $document = (new XmlLoader)->loadFile($baselineFile);
        } catch (XmlException $e) {
            throw new CannotLoadBaselineException(
                sprintf(
                    'Cannot read baseline %s: %s',
                    $baselineFile,
                    trim($e->getMessage()),
                ),
            );
        }

        $documentElement = $document->documentElement;

        assert($documentElement !== null);

        $version = (int) $documentElement->getAttribute('version');

        if ($version !== Baseline::VERSION) {
            throw new CannotLoadBaselineException(
                sprintf(
                    'Cannot read baseline %s, version %d is not supported',
                    $baselineFile,
                    $version,
                ),
            );
        }

        $baseline             = new Baseline;
        $resolvedBaselineFile = realpath($baselineFile);

        assert($resolvedBaselineFile !== false);

        $baselineDirectory = dirname($resolvedBaselineFile);
        $xpath             = new DOMXPath($document);

        $fileElements = $xpath->query('file');

View on GitHub (pinned to f123cdb2a2)

Solutions

  1. Regenerate the baseline with the PHPUnit version you now run: vendor/bin/phpunit --generate-baseline=<path>.
  2. If hand-authoring, ensure the root element is <files version="1"> (the value of Baseline::VERSION in your build).
  3. Do not share a baseline across PHPUnit versions with differing schema versions; regenerate after each upgrade.

Example fix

<!-- before -->
<files>
  <file path="src/Foo.php"><line number="1" hash="..."/></file>
</files>

<!-- after -->
<files version="1">
  <file path="src/Foo.php"><line number="1" hash="..."/></file>
</files>
Defensive patterns

Strategy: validation

Validate before calling

// Check the schema version before loading
$doc = new DOMDocument();
$doc->load($baselinePath);
$version = (int) ($doc->documentElement->getAttribute('version') ?? '0');
if ($version !== 1) { // Baseline::VERSION of the PHPUnit build in use
    fwrite(STDERR, "Baseline version {$version} not supported; regenerate it\n");
    exit(1);
}

Prevention

When it happens

Trigger: Baseline generated by a different PHPUnit version whose Baseline::VERSION differs; hand-written baseline without version="1" on the root; a baseline produced by a newer schema version then consumed by an older PHPUnit.

Common situations: Upgrading or downgrading PHPUnit while reusing an old baseline file; teams sharing one baseline across PHPUnit versions; crafting a baseline by hand from a template that omits the attribute.

Related errors


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