{"record":{"id":"2e42f5b0c4fb6834","repo":"sebastianbergmann/phpunit","slug":"schema-for-phpunit-s-is-not-available","errorCode":null,"errorMessage":"Schema for PHPUnit %s is not available","messagePattern":"Schema for PHPUnit (.+?) is not available","errorType":"exception","errorClass":"PHPUnit\\TextUI\\XmlConfiguration\\CannotFindSchemaException","httpStatus":null,"severity":"error","filePath":"src/TextUI/Configuration/Xml/SchemaFinder.php","lineNumber":64,"sourceCode":"\n        rsort($result);\n\n        return $result;\n    }\n\n    /**\n     * @throws CannotFindSchemaException\n     */\n    public function find(string $version): string\n    {\n        if ($version === Version::series()) {\n            $filename = $this->path() . 'phpunit.xsd';\n        } else {\n            $filename = $this->path() . 'schema/' . $version . '.xsd';\n        }\n\n        if (!is_file($filename)) {\n            throw new CannotFindSchemaException(\n                sprintf(\n                    'Schema for PHPUnit %s is not available',\n                    $version,\n                ),\n            );\n        }\n\n        return $filename;\n    }\n\n    private function path(): string\n    {\n        if (defined('__PHPUNIT_PHAR_ROOT__') && is_string(__PHPUNIT_PHAR_ROOT__)) {\n            return __PHPUNIT_PHAR_ROOT__ . '/';\n        }\n\n        return __DIR__ . '/../../../../';\n    }","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/TextUI/Configuration/Xml/SchemaFinder.php#L46-L82","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Request the schema for the installed version: `Version::series()` rather than a hardcoded number","Reinstall cleanly: `composer reinstall phpunit/phpunit` or re-fetch the PHAR","Verify the schema directory exists: `ls vendor/phpunit/phpunit/schema`"],"exampleFix":"// before (hardcoded version may not be bundled)\n$schema = (new SchemaFinder)->find('9.2');\n\n// after (use the installed series)\nuse PHPUnit\\Runner\\Version;\n\n$schema = (new SchemaFinder)->find(Version::series());","handlingStrategy":"validation","validationCode":"use PHPUnit\\Runner\\Version;\n\n$version = Version::series(); // the series actually installed\n$schemaDir = dirname((new \\ReflectionClass(Version::class))->getFileName()) . '/schema';\n\nif (!is_file(\"{$schemaDir}/{$version}.xsd\") && !is_file(dirname($schemaDir) . '/phpunit.xsd')) {\n    fwrite(STDERR, 'PHPUnit installation is missing its schema files; reinstall phpunit/phpunit' . PHP_EOL);\n    exit(2);\n}","typeGuard":null,"tryCatchPattern":"try {\n    $schema = (new \\PHPUnit\\TextUI\\XmlConfiguration\\SchemaFinder)->find($version);\n} catch (\\PHPUnit\\TextUI\\XmlConfiguration\\CannotFindSchemaException $e) {\n    // requested series has no bundled XSD: retry with Version::series(),\n    // or reinstall the phpunit/phpunit package intact\n}","preventionTips":["Never hardcode a schema version string; derive it from PHPUnit\\Runner\\Version::series()","Do not prune vendor/phpunit/phpunit/schema when building docker images or custom PHARs","After composer partial-update weirdness, `composer reinstall phpunit/phpunit` restores data files"],"tags":["phpunit","xml","schema","installation","validation"],"backgroundTag":"missing-schema-file","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}