To add your PhpUnit and Docker with PhpStorm please follow the steps:
Add Docker to PhpStorm
- Open Preference > Build, Execution, Deployment > Docker
- Click [+] to add docker
- Leave default settings. Connection successful message will be shown.
Add CLI Interpreter for PHP
- Open Preference > Languages & Frameworks > Php
- Select PHP language level
- Click […] beside CLI Interpreter
- Click [+] of opened window
- Select From Docker, Vagrant, VM, Remote…
- From Pop-up select Docker Compose option
- Server should be the docker you just created.
- Select Image Name (container)
- Service should be php.
- Click OK
Again Click OK to close CLI Interpreters window
You CLI Interpreter field should show the Docker container
- Open Preference > Languages & Frameworks > Php > Test Frameworks
- Click [+] and select PhpUnit by Remote Interpreter
- In pop-up select Interpreter (your docker interpreter)
- Setup the fields like the image.
Now set composer.phar
- Open Preference > Languages & Frameworks > Php > Composer
- Select composer.phar radio option.
- Select path to composer.phar of the project.
To add PhpUnit to project
- Open composer.json under vendor directory
- In require-dev section add the following – “phpunit/phpunit”: “5.7.27” or “phpunit/phpunit”: “^5”
- Run composer update from inside docker container’s /code directory
That’s it, you’r are done with your setup. Now to run test simply right click on the test or test method and select RUN. Now you can see that the docker is started before running the test. Enjoy testing 🙂
PhpStorm version used
Build #PS-181.5087.24, built on May 18, 2018