sebastianbergmann/phpunit · error · BootstrapScriptDoesNotExistException
Cannot open bootstrap script "%s"
Error message
Cannot open bootstrap script "%s"
What it means
BootstrapLoader::load() (via handle(), driven by the bootstrap attribute in phpunit.xml or --bootstrap on the CLI) first checks is_readable($filename); when that fails it throws BootstrapScriptDoesNotExistException('Cannot open bootstrap script "%s"'). The bootstrap file must exist and be readable before PHPUnit will include it.
Source
Thrown at src/TextUI/Configuration/BootstrapLoader.php:57
if ($configuration->includeTestSuites() !== [] && !in_array($testSuiteName, $configuration->includeTestSuites(), true)) {
continue;
}
if ($configuration->excludeTestSuites() !== [] && in_array($testSuiteName, $configuration->excludeTestSuites(), true)) {
continue;
}
$this->load($bootstrapForTestSuite);
}
}
/**
* @param non-empty-string $filename
*/
private function load(string $filename): void
{
if (!is_readable($filename)) {
throw new BootstrapScriptDoesNotExistException($filename);
}
try {
include_once $filename;
} catch (Throwable $t) {
$message = sprintf(
'Error in bootstrap script: %s:%s%s%s%s',
$t::class,
PHP_EOL,
$t->getMessage(),
PHP_EOL,
$t->getTraceAsString(),
);
while (($t = $t->getPrevious()) !== null) {
$message .= sprintf(
'%s%sPrevious error: %s:%s%s%s%s',
PHP_EOL,View on GitHub (pinned to f123cdb2a2)
Solutions
- Create the missing file — usually by running composer install for vendor/autoload.php.
- Fix the bootstrap path in phpunit.xml/--bootstrap; relative paths resolve against the CWD, so prefer a path relative to the configuration file.
- Make the file readable by the PHP process if permissions are the issue.
Example fix
# before composer dump-coverage 2>/dev/null; phpunit --bootstrap vendor/autoload.php tests # => Cannot open bootstrap script "vendor/autoload.php" # after composer install phpunit --bootstrap vendor/autoload.php tests
Defensive patterns
Strategy: validation
Validate before calling
$bootstrap = 'vendor/autoload.php';
if (!is_readable($bootstrap)) {
throw new RuntimeException(
"Bootstrap '{$bootstrap}' missing or unreadable; run 'composer install' first"
);
}
// only then hand off to phpunit / BootstrapLoader Prevention
- Make 'composer install' (or the script that creates the bootstrap) a mandatory CI step before phpunit.
- Reference the bootstrap relative to the phpunit.xml location, not the CWD.
- Add a smoke check (is_readable) in CI wrapper scripts to fail with a clear message.
When it happens
Trigger: Configuring bootstrap="vendor/autoload.php" (or --bootstrap) when the file is missing — e.g. composer install has not run — or exists but is not readable by the PHP process.
Common situations: Fresh clones without 'composer install'; bootstrap path relative to the CWD while phpunit runs from another directory; path typos in phpunit.xml; permission problems in containers/CI.
Related errors
- Error in bootstrap script: %s:%s%s%s%s
- Test file "%s" not found
- Class %s is abstract
- Cannot read baseline %s, file does not exist
- Configured code coverage driver class "%s" does not exist
AI-assisted analysis of sebastianbergmann/phpunit@f123cdb2a2 (2026-08-23).
Data as JSON: /api/errors/f424621afbfb5b47.
Report an issue: GitHub.