{"record":{"id":"91622f8b5d2c9e7a","repo":"sebastianbergmann/phpunit","slug":"cannot-write-baseline-to-s","errorCode":null,"errorMessage":"Cannot write baseline to \"%s\".","messagePattern":"Cannot write baseline to \"(.+?)\"\\.","errorType":"exception","errorClass":"CannotWriteBaselineException","httpStatus":null,"severity":"error","filePath":"src/Runner/Baseline/Writer.php","lineNumber":36,"sourceCode":"\n/**\n * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit\n *\n * @internal This class is not covered by the backward compatibility promise for PHPUnit\n */\nfinal readonly class Writer\n{\n    /**\n     * @param non-empty-string $baselineFile\n     *\n     * @throws CannotWriteBaselineException\n     */\n    public function write(string $baselineFile, Baseline $baseline): void\n    {\n        $normalizedBaselineFile = realpath(dirname($baselineFile));\n\n        if ($normalizedBaselineFile === false || !is_dir($normalizedBaselineFile)) {\n            throw new CannotWriteBaselineException(sprintf('Cannot write baseline to \"%s\".', $baselineFile));\n        }\n\n        $pathCalculator = new RelativePathCalculator($normalizedBaselineFile);\n\n        $writer = new XMLWriter;\n\n        $writer->openMemory();\n        $writer->setIndent(true);\n        $writer->startDocument();\n\n        $writer->startElement('files');\n        $writer->writeAttribute('version', (string) Baseline::VERSION);\n\n        foreach ($baseline->groupedByFileAndLine() as $file => $lines) {\n            $writer->startElement('file');\n            $writer->writeAttribute('path', $pathCalculator->calculate($file));\n\n            foreach ($lines as $line => $issues) {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/Baseline/Writer.php#L18-L54","documentation":"A baseline write was requested (--generate-baseline, or Writer::write() called from a run) but the directory that would contain the file does not exist: realpath(dirname($baselineFile)) failed or the result is not a directory. Only the parent directory is verified — the file itself is then written with file_put_contents.","triggerScenarios":"vendor/bin/phpunit --generate-baseline=build/baseline.xml when build/ does not exist; a path through a missing intermediate directory; dirname resolving to an existing file; a symlink whose target does not exist so realpath() fails.","commonSituations":"Fresh clones without build artifacts; CI jobs assuming a directory created by an earlier step; refactoring output paths; typo in the target path.","solutions":["Create the parent directory first: mkdir -p build (or commit a .gitkeep inside it).","Fix the path passed to --generate-baseline so every directory component exists.","If calling Writer::write() programmatically, ensure dirname($baselineFile) passes realpath() and is_dir() first."],"exampleFix":"# before\nvendor/bin/phpunit --generate-baseline=build/baseline.xml  # build/ missing\n\n# after\nmkdir -p build\nvendor/bin/phpunit --generate-baseline=build/baseline.xml","handlingStrategy":"validation","validationCode":"// Before --generate-baseline / Writer::write()\n$dir = dirname($baselineFile);\nif (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {\n    throw new RuntimeException(\"Cannot create baseline directory {$dir}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create output directories in CI before the step that writes baselines.","Commit a .gitkeep in artifact directories so fresh clones have them.","Validate target paths (no missing intermediate directories, no symlinked ghosts) in a preflight check."],"tags":["phpunit","php","baseline","filesystem"],"backgroundTag":"baseline-write-path-invalid","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}