{"record":{"id":"6bbbac44fdb0d2cf","repo":"sebastianbergmann/phpunit","slug":"directory-s-does-not-exist-and-could-not-be-cre","errorCode":null,"errorMessage":"Directory \"%s\" does not exist and could not be created","messagePattern":"Directory \"(.+?)\" does not exist and could not be created","errorType":"exception","errorClass":"DirectoryDoesNotExistException","httpStatus":null,"severity":"error","filePath":"src/Runner/TestIndex/TestIndex.php","lineNumber":195,"sourceCode":"                continue;\n            }\n\n            $this->entries[$file] = $entry;\n        }\n    }\n\n    /**\n     * Entries that were not recorded during this run are written back\n     * unchanged: a run that skipped a file did not learn anything about it and\n     * must not cause what is known about it to be forgotten. Entries for files\n     * that no longer exist are dropped.\n     *\n     * @throws Exception\n     */\n    public function persist(): void\n    {\n        if (!Filesystem::createDirectory(dirname($this->indexFilename))) {\n            throw new DirectoryDoesNotExistException(dirname($this->indexFilename));\n        }\n\n        /*\n         * The group names are collected in a list of their own, and not as the\n         * keys of the map that assigns a position to each of them: a group name\n         * such as \"6546\" would become an integer key, and would then be written\n         * as an integer and no longer be readable as a group name.\n         */\n        $groupNames     = [];\n        $groupPositions = [];\n        $entries        = [];\n\n        foreach ($this->entries as $file => $entry) {\n            if (!is_file($file)) {\n                continue;\n            }\n\n            $groups = [];","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/TestIndex/TestIndex.php#L177-L213","documentation":"TestIndex::persist() writes its index to $this->indexFilename and first asks Filesystem::createDirectory() to create the file's parent directory; when that returns false, DirectoryDoesNotExistException('Directory \"%s\" does not exist and could not be created') is thrown. So the directory of the configured index/cache location neither exists nor could be created by the PHP process.","triggerScenarios":"Calling persist() when the index file's parent directory does not exist and cannot be created: the path is outside open_basedir, the filesystem is read-only, or the process lacks write permission on the parent.","commonSituations":"Running in containers/CI with a read-only or non-writable volume mounted at the cache location; a configured cache directory path with a typo; open_basedir restrictions; running as a user without write access to the project root.","solutions":["Create the directory manually and give the PHP process write permission: mkdir -p path/to/dir && chown $(whoami) path/to/dir.","Point the index/cache location to a writable directory in your configuration.","Check open_basedir and read-only mounts (containers) covering the configured path."],"exampleFix":"# before\nphpunit   # persist() fails: Directory \"/build/.phpunit\" does not exist and could not be created\n\n# after\nmkdir -p /build/.phpunit && chmod u+w /build/.phpunit\nphpunit","handlingStrategy":"validation","validationCode":"// before persisting the test index, ensure the target directory is writable\n$dir = dirname($indexFilename);\nif (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {\n    throw new RuntimeException(\"Cannot create index directory {$dir}; check permissions/open_basedir\");\n}\nif (!is_writable($dir)) {\n    throw new RuntimeException(\"Index directory {$dir} is not writable\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure the index/cache path to a directory guaranteed writable in CI (e.g. a workspace dir), not a read-only layer.","Provision the directory in the container/CI job definition before running PHPUnit.","Run the test process as a user with write access to the configured path."],"tags":["phpunit","test-index","filesystem","permissions","ci"],"backgroundTag":"directory-creation-failed","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}