I'm trying to setup PHPUnit in PhpStorm, so I can run tests from inside my IDE.
I have Docker setup in PhpStorm, and I can see my containers in the 'Services'-tab and exec stuff in them, from inside PhpStorm.
And if I click Update button (the circular arrows) next to 'Path to script', then it throws the error:
Cannot parse PHPUnit version output: Could not open file: /var/www/docroot/vendor/phpunit/phpunit/phpunit
It can be seen here:
The overarching question
What is failing here? I'm guessing that PhpStorm is trying to access PHPUnit inside the Docker-container, but can't find that phpunit-file (from the error).
... Oh, yeah - and how do I fix it? :-)
Quick solution attempts and thoughts
If I run this in my terminal:
docker-compose exec php bin/phpunit --log-junit testresults.xml, then all the tests run. Great!If I, inside PhpStorm, right click the
php-container and chooseexecand paste in:php bin/phpunit --log-junit testresults.xml, then the tests all run in PhpStorm. Great!I could also try and find the
phpunit.phar-file directly and point to that. But if I access the container (withdocker-compose exec -i php /bin/bash) and then search for the file (withfind . -name 'phpunit.phar') then nothing is found.Default configuration file is blank. I also tried setting that to:
/Users/myusername/Code/myproject/phpunit.xml.dist. Same result.What if PHPUnit is installed in the php-image - and therefore not via Composer or something? Hmm... The only
phpunit-line in the composer-file seem to be this:"symfony/phpunit-bridge": "^5.2",...
Solution attempt 1: Check for the file
If I check for the file it's looking for in the vendor directory, then I can't seem to find the file it's looking for:
| vendor
| ...
| phpunit
| php-timer
| .github
| src
| tests
| ...
| ...
| ...
It looks like something is missing. But the tests can run inside the docker-container?! Hmm.!
And it's the same inside the container:
Links and resources
- Docker container with PHPUnit: Could not open input file: /var/www/vendor/phpunit/phpunit/phpunit
- PHPUnit "use Composer autoloader" could not parse PHPUnit version output.
- I tried following this (old) guide here, for the setup. He blasts through it, without my error: Running PHPUnit Tests in PhpStorm with Docker.
- How to run PHPUnit test inside a running container


