{"record":{"id":"4cb373c921e1833b","repo":"sebastianbergmann/phpunit","slug":"cannot-read-from-file","errorCode":null,"errorMessage":"Cannot read from {file}","messagePattern":"Cannot read from (.+?)","errorType":"exception","errorClass":"PHPUnit\\TextUI\\RuntimeException","httpStatus":null,"severity":"error","filePath":"src/TextUI/TestSuiteFilterProcessor.php","lineNumber":94,"sourceCode":"                    $configuration->testsUsing(),\n                ),\n            );\n        }\n\n        if ($configuration->hasTestsRequiringPhpExtension()) {\n            $factory->addIncludeGroupFilter(\n                array_map(\n                    Groups::virtualGroupForRequiredPhpExtension(...),\n                    $configuration->testsRequiringPhpExtension(),\n                ),\n            );\n        }\n\n        if ($configuration->hasTestIdFilterFile()) {\n            $lines = @file($configuration->testIdFilterFile(), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);\n\n            if ($lines === false) {\n                throw new RuntimeException('Cannot read from ' . $configuration->testIdFilterFile());\n            }\n\n            $testIds = [];\n\n            foreach ($lines as $line) {\n                if ($line !== '') {\n                    $testIds[] = $line;\n                }\n            }\n\n            if ($testIds !== []) {\n                $factory->addTestIdFilter($testIds);\n            }\n        }\n\n        if ($configuration->hasTestIdFilter()) {\n            $factory->addTestIdFilter([$configuration->testIdFilter()]);\n        }","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/TextUI/TestSuiteFilterProcessor.php#L76-L112","documentation":"When you pass --test-id-filter-file, PHPUnit reads one test ID per line from that file to re-run a selected subset of tests (e.g. previously failed ones). TestSuiteFilterProcessor::process() reads the file with @file(); if the read fails it throws RuntimeException('Cannot read from <file>'). It means the file identified by the merged CLI configuration could not be read at all.","triggerScenarios":"Running `vendor/bin/phpunit --test-id-filter-file ids.txt` where ids.txt does not exist at run time (deleted after Application's earlier is_file check), is not readable due to permissions, or is outside the paths allowed by open_basedir.","commonSituations":"CI jobs that cache a test-ID file between steps and the cache misses or is cleaned; files generated in one container but not mounted into the test container; permission mismatches when the generator and the runner use different users.","solutions":["Verify the file exists and is readable in the exact container/step that runs PHPUnit: `test -r ids.txt`","Regenerate the ID file from its source (for example the recorded failed test IDs) before the run instead of relying on a stale cache","Fix permissions or mounts so the runner user can read the file","Pass a path that is absolute or relative to the directory PHPUnit is invoked from"],"exampleFix":"# before\n$ vendor/bin/phpunit --test-id-filter-file ids.txt\n# RuntimeException: Cannot read from ids.txt\n\n# after\n$ test -r ids.txt || regenerate-ids.sh\n$ vendor/bin/phpunit --test-id-filter-file \"$PWD/ids.txt\"","handlingStrategy":"validation","validationCode":"$file = 'ids.txt';\nif (!is_string($file) || !is_file($file) || !is_readable($file)) {\n    throw new RuntimeException(\"Test ID filter file {$file} is missing or unreadable\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    // run phpunit with --test-id-filter-file\n} catch (\\RuntimeException $e) {\n    if (str_starts_with($e->getMessage(), 'Cannot read from ')) {\n        // regenerate or fix the ID file, then re-run\n    }\n}","preventionTips":["Gate the CI step: `test -r ids.txt || exit 1` before the phpunit invocation","Generate the ID file in the same job that consumes it instead of passing it between jobs via cache","Store the file under an absolute path or relative to the project root, not the ephemeral CI working directory"],"tags":["phpunit","cli","file-io","test-selection"],"backgroundTag":"config-file-unreadable","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}