PHPUnit "Could not read phpunit.xml" configuration in CI
PHPUnit looked for its configuration and could not read it. Either the file is not in the working directory PHPUnit ran from, or the path passed via --configuration does not exist on the runner.
What this error means
PHPUnit exits with "Could not read \"phpunit.xml\"." or "Cannot open file \"phpunit.xml.dist\".", before running tests. It often fails in CI because the job runs from the repo root and the config lives in a subdirectory.
Could not read "phpunit.xml".
(or)
Cannot open file "phpunit.xml.dist".Common causes
Wrong working directory
PHPUnit auto-discovers phpunit.xml/phpunit.xml.dist in the current directory; if CI runs elsewhere, it finds nothing.
A --configuration path that does not exist
The command passes an explicit config path that is wrong or not present in the checkout.
How to fix it
Run from the directory holding the config, or pass it
- Set the step working directory to where
phpunit.xmllives. - Or pass
--configurationwith a path valid from the job cwd. - Re-run so PHPUnit can load the config.
- run: vendor/bin/phpunit --configuration phpunit.xml.dist
working-directory: backendCommit the config file
Ensure phpunit.xml or phpunit.xml.dist is tracked and present in the checkout, not gitignored.
git add phpunit.xml.distHow to prevent it
- Keep the PHPUnit config tracked in version control.
- Set
working-directoryso auto-discovery finds the config. - Pass
--configurationexplicitly for non-standard layouts.