{"record":{"id":"12e7acb9de85f1f5","repo":"sebastianbergmann/phpunit","slug":"cannot-load-xml-configuration-file-s","errorCode":null,"errorMessage":"Cannot load XML configuration file %s","messagePattern":"Cannot load XML configuration file (.+?)","errorType":"validation","errorClass":"PHPUnit\\TextUI\\XmlConfiguration\\Exception","httpStatus":null,"severity":"error","filePath":"src/TextUI/Configuration/Xml/Loader.php","lineNumber":161,"sourceCode":"                $this->source($configurationFileRealpath, $xpath),\n                $this->codeCoverage($configurationFileRealpath, $xpath),\n                $this->groups($xpath),\n                $this->logging($configurationFileRealpath, $xpath),\n                $this->php($configurationFileRealpath, $xpath),\n                $this->phpunit($configurationFileRealpath, $document, $xpath),\n                $this->testSuite($configurationFileRealpath, $xpath),\n            );\n        } catch (Throwable $t) {\n            $message = sprintf(\n                'Cannot load XML configuration file %s',\n                $configurationFileRealpath,\n            );\n\n            if ($validationResult->hasValidationErrors()) {\n                $message .= ' because it has validation errors:' . PHP_EOL . $validationResult->asString();\n            }\n\n            throw new Exception($message, previous: $t);\n        }\n    }\n\n    private function logging(string $filename, DOMXPath $xpath): Logging\n    {\n        $junit   = null;\n        $element = $this->element($xpath, 'logging/junit');\n\n        if ($element !== null) {\n            $junit = new Junit(\n                new File(\n                    $this->toAbsolutePath(\n                        $filename,\n                        (string) $this->parseStringAttribute($element, 'outputFile'),\n                    ),\n                ),\n            );\n        }","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/TextUI/Configuration/Xml/Loader.php#L143-L179","documentation":"Thrown by the XML configuration Loader when a phpunit.xml cannot be loaded or does not validate against the bundled XML schema. When validation fails, PHPUnit appends every schema violation with line and column ('because it has validation errors:' followed by the validator output), and the original throwable is chained as the previous exception. This is the main error surface for a broken or outdated phpunit.xml/XML configuration file.","triggerScenarios":"`vendor/bin/phpunit -c phpunit.xml` where the XML misspells elements (e.g. <testsuit>), puts attributes in wrong places, or uses elements removed/renamed in the installed PHPUnit major version; malformed XML (unclosed tags, bad entities); a configuration written for PHPUnit 9 (e.g. <filter><whitelist>) loaded by PHPUnit 11/12.","commonSituations":"Upgrading PHPUnit across major versions without migrating phpunit.xml; hand-editing the XML and introducing typos; extensions adding custom elements without proper schema handling; CI resolving a different PHPUnit version than local.","solutions":["Read the appended validation errors: they name each element/attribute and its line and column in the XML","Run `vendor/bin/phpunit --migrate-configuration` to auto-migrate an older file to the current schema","Validate quickly with `vendor/bin/phpunit --validate-configuration`","If hand-written, compare against vendor/phpunit/phpunit/phpunit.xsd or a freshly `--generate-configuration`-generated file"],"exampleFix":"<!-- before: PHPUnit 9 syntax read by PHPUnit 11+ -->\n<filter>\n  <whitelist>\n    <directory suffix=\".php\">src</directory>\n  </whitelist>\n</filter>\n\n<!-- after: migrate, or write current syntax -->\n<!-- run: vendor/bin/phpunit --migrate-configuration -->\n<source>\n  <include>\n    <directory suffix=\".php\">src</directory>\n  </include>\n</source>","handlingStrategy":"validation","validationCode":"// Fast pre-flight in CI before running tests:\n$exit = 0;\nsystem('vendor/bin/phpunit --validate-configuration', $exit);\n\nif ($exit !== 0) {\n    fwrite(STDERR, \"phpunit.xml is invalid; refusing to run\" . PHP_EOL);\n    exit($exit);\n}\n\n// or schema-check directly:\n// xmllint --noout --schema vendor/phpunit/phpunit/phpunit.xsd phpunit.xml","typeGuard":null,"tryCatchPattern":"try {\n    $configuration = (new \\PHPUnit\\TextUI\\XmlConfiguration\\Loader)->loadFile('phpunit.xml');\n} catch (\\PHPUnit\\TextUI\\XmlConfiguration\\Exception $e) {\n    // message includes each validation error with line/column; chain contains the original Throwable.\n    // Run --migrate-configuration for version drift, or fix the named elements.\n}","preventionTips":["Add `phpunit --validate-configuration` as a CI step after any PHPUnit version bump","Run `--migrate-configuration` immediately after upgrading major versions","Never hand-add custom elements to phpunit.xml without checking them against phpunit.xsd"],"tags":["phpunit","xml","configuration","schema-validation","migration"],"backgroundTag":"xml-schema-validation-failed","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}