Search code examples
dockerunit-testingdocker-composephpunitphpstorm

How to run PHPUnit test inside a running container


I use PhpStorm in development. To run a test I do below 3 commands:

docker-compose exec app bash
cd app/
vendor/bin/phpunit unitTest/Sample.php 

I want to be able to run the test just by clicking the "Run" button inside PhpStorm.

I tried to accomplish it using docs from IntelliJ but they overwhelmed me. I thought I just need to change the interpreter path but couldn't understand how to attach to a running docker.


Solution

  • First you need to add your Docker-compose based interpreter. See this guide. php interpreter Second, add a PHPUnit configuration based on this interpreter, see "Integrate PHPUnit with a PhpStorm project". phpunit config After that you should be able to simply Run the tests using IDE UI.