{"record":{"id":"e9d54527696f28f7","repo":"sebastianbergmann/phpunit","slug":"no-supported-schema-was-detected","errorCode":null,"errorMessage":"No supported schema was detected","messagePattern":"No supported schema was detected","errorType":"exception","errorClass":"PHPUnit\\Util\\Xml\\XmlException","httpStatus":null,"severity":"error","filePath":"src/TextUI/Configuration/Xml/SchemaDetector/SchemaDetectionResult.php","lineNumber":36,"sourceCode":" *\n * @immutable\n */\nabstract readonly class SchemaDetectionResult\n{\n    /**\n     * @phpstan-assert-if-true SuccessfulSchemaDetectionResult $this\n     */\n    public function detected(): bool\n    {\n        return false;\n    }\n\n    /**\n     * @throws XmlException\n     */\n    public function version(): string\n    {\n        throw new XmlException('No supported schema was detected');\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":39,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/TextUI/Configuration/Xml/SchemaDetector/SchemaDetectionResult.php#L18-L39","documentation":"SchemaDetector::detect() returns either a successful or a failed SchemaDetectionResult. version() on the failed result unconditionally throws PHPUnit\\Util\\Xml\\XmlException('No supported schema was detected') because a version simply does not exist for a failed detection. Calling it without first checking detected() is a programming error in the caller.","triggerScenarios":"`(new SchemaDetector)->detect('phpunit.xml')->version()` chained without checking ->detected(); any custom tooling (IDE plugin, migration script, linter) built on SchemaDetector that reads version() unconditionally when the file matched no schema.","commonSituations":"Third-party tooling wrapping PHPUnit's schema detection; scripts that assumed detect() throws on failure instead of returning a result object.","solutions":["Always branch on the guard first: `$result = $detector->detect($file); if ($result->detected()) { $v = $result->version(); }`","Handle the non-detected case explicitly (report 'unsupported configuration' to the user)","Only as a last resort, catch PHPUnit\\Util\\Xml\\XmlException around the version() call"],"exampleFix":"// before\n$version = (new SchemaDetector)->detect($filename)->version(); // throws on failure\n\n// after\n$result = (new SchemaDetector)->detect($filename);\n\nif (!$result->detected()) {\n    throw new RuntimeException(\"{$filename} does not match any known PHPUnit schema\");\n}\n\n$version = $result->version();","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"$result = (new \\PHPUnit\\TextUI\\XmlConfiguration\\SchemaDetector)->detect($filename);\n\nif (!$result->detected()) {\n    // FailedSchemaDetectionResult: do NOT call version() on it\n    throw new RuntimeException(\"{$filename} matches no supported schema\");\n}\n\n// detected() === true implies a version is available\n$version = $result->version();","tryCatchPattern":"try {\n    $version = $result->version();\n} catch (\\PHPUnit\\Util\\Xml\\XmlException $e) {\n    // only reachable when detected() was false; fix the missing guard instead of catching\n    $version = null;\n}","preventionTips":["Treat detect() as a result object: branch on detected() before any getter","Never chain ->detect($f)->version() — the failed result cannot answer version()","In custom tooling, surface 'no supported schema detected' as a first-class user-facing outcome"],"tags":["phpunit","xml","schema-detection","api-misuse","result-object"],"backgroundTag":"schema-detection-failed","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}