sebastianbergmann/phpunit · error · PHPUnit\TextUI\XmlConfiguration\CannotFindSchemaException

Schema for PHPUnit is not available

Error message

Schema for PHPUnit %s is not available

What it means

SchemaFinder::find($version) locates the XSD for a given PHPUnit series inside the installation (schema/<version>.xsd, or phpunit.xsd for the current series) and throws CannotFindSchemaException when that file is not present. It typically surfaces from schema validation/migration tooling that asked for a version whose schema is not bundled with the installed PHPUnit release, or from an incomplete installation where the schema directory is missing.

Solutions

  1. Request the schema for the installed version: `Version::series()` rather than a hardcoded number
  2. Reinstall cleanly: `composer reinstall phpunit/phpunit` or re-fetch the PHAR
  3. Verify the schema directory exists: `ls vendor/phpunit/phpunit/schema`

Example fix

// before (hardcoded version may not be bundled)
$schema = (new SchemaFinder)->find('9.2');

// after (use the installed series)
use PHPUnit\Runner\Version;

$schema = (new SchemaFinder)->find(Version::series());
Defensive patterns

Strategy: validation

Validate before calling

use PHPUnit\Runner\Version;

$version = Version::series(); // the series actually installed
$schemaDir = dirname((new \ReflectionClass(Version::class))->getFileName()) . '/schema';

if (!is_file("{$schemaDir}/{$version}.xsd") && !is_file(dirname($schemaDir) . '/phpunit.xsd')) {
    fwrite(STDERR, 'PHPUnit installation is missing its schema files; reinstall phpunit/phpunit' . PHP_EOL);
    exit(2);
}

Try / catch

try {
    $schema = (new \PHPUnit\TextUI\XmlConfiguration\SchemaFinder)->find($version);
} catch (\PHPUnit\TextUI\XmlConfiguration\CannotFindSchemaException $e) {
    // requested series has no bundled XSD: retry with Version::series(),
    // or reinstall the phpunit/phpunit package intact
}

Prevention

When it happens

Trigger: Passing a version series string that has no schema/NN.xsd in the installed phpunit (e.g. validating against a newer or older series than what vendor/phpunit/phpunit/schema ships); extracting the PHAR or copying files in a way that drops the schema directory; custom distributions that prune data files.

Common situations: Tooling that hardcodes a version string instead of using PHPUnit\Runner\Version::series(); composer/phive installations corrupted by partial updates or aggressive .gitignore/classmap optimizers; docker images copying only PHPUnit's PHP files.

Related errors


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

Appendix: source

Thrown at src/TextUI/Configuration/Xml/SchemaFinder.php:64

        rsort($result);

        return $result;
    }

    /**
     * @throws CannotFindSchemaException
     */
    public function find(string $version): string
    {
        if ($version === Version::series()) {
            $filename = $this->path() . 'phpunit.xsd';
        } else {
            $filename = $this->path() . 'schema/' . $version . '.xsd';
        }

        if (!is_file($filename)) {
            throw new CannotFindSchemaException(
                sprintf(
                    'Schema for PHPUnit %s is not available',
                    $version,
                ),
            );
        }

        return $filename;
    }

    private function path(): string
    {
        if (defined('__PHPUNIT_PHAR_ROOT__') && is_string(__PHPUNIT_PHAR_ROOT__)) {
            return __PHPUNIT_PHAR_ROOT__ . '/';
        }

        return __DIR__ . '/../../../../';
    }

View on GitHub (pinned to f123cdb2a2)