Troubleshooting (PhpStorm + Docker + PHPUnit)
This guide helps fix common issues when running tests in PhpStorm using Docker Compose.
Symptoms
During test runs you may see:
Warning: file_put_contents(/app/.phpunit.result.cache): Permission denied
or:
ERROR: No container found for test_1
Causes
- Permission denied: Container user UID/GID does not match your host user; the container cannot write to the mounted project.
- No container found: The
testcontainer is not running (starts and exits immediately) or PhpStorm can’t attach to it.
Fix: Set correct permissions (UID/GID)
Create a local
.envand set your host IDs (check withid -uandid -g):cp .env.example .env
UID=1000 GID=1000
Rebuild and start the container:
docker compose down docker compose build --no-cache docker compose up -d test
(Once) recreate the PHPUnit cache file if needed:
rm -f .phpunit.result.cache touch .phpunit.result.cache chmod 666 .phpunit.result.cache
Fix: Keep the container running
Ensure your docker-compose.yml prevents immediate exit, for example:
command: tail -f /dev/null
Then start the service:
docker compose up -d test
PhpStorm configuration (quick overview)
Interpreter: Settings → PHP → CLI Interpreter → Add → From Docker Compose → select service
test.PHPUnit: Settings → PHP → Test Frameworks → Add → PHPUnit (by Remote Interpreter) → Autoloader path:
/app/vendor/autoload.phpOptional: set interpreter lifecycle to execute in an existing container instead of starting new ones.
Verify
Check your host IDs:
id -u id -gCheck the container is running:
docker psRun PHPUnit inside the container:
docker compose exec test vendor/bin/phpunit
Useful commands
Open a shell:
docker compose exec test bashView logs:
docker compose logs -f testStop containers:
docker compose down
Notes
- When PhpStorm starts Docker Compose directly (not via your Makefile), it won’t inherit
UID/GIDfrom your shell. The.envfile ensures consistent IDs. - If your host user is not
1000:1000, update.envaccordingly; otherwise write issues will persist.