Skip to content
Latchkey

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.

PHPUnit
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

  1. Set the step working directory to where phpunit.xml lives.
  2. Or pass --configuration with a path valid from the job cwd.
  3. Re-run so PHPUnit can load the config.
.github/workflows/ci.yml
- run: vendor/bin/phpunit --configuration phpunit.xml.dist
  working-directory: backend

Commit the config file

Ensure phpunit.xml or phpunit.xml.dist is tracked and present in the checkout, not gitignored.

Terminal
git add phpunit.xml.dist

How to prevent it

  • Keep the PHPUnit config tracked in version control.
  • Set working-directory so auto-discovery finds the config.
  • Pass --configuration explicitly for non-standard layouts.

Frequently asked questions

What causes ""Could not read \"phpunit.xml\"""?
PHPUnit auto-discovers phpunit.xml/phpunit.xml.dist in the current directory; if CI runs elsewhere, it finds nothing.
How do I fix "Could not read \"phpunit.xml\""?
Run from the directory holding the config, or pass it

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card