PHPUnit and PhpStorm#
Note
This document assumes the following:
- You are using Docker.
- You are using a standard Amazee/Lagoon project with a docker-compose.yml
file.
- You are on a Mac - it should work for other operating systems but folder structure and some configuration settings may be different.
Configuring the project#
- Duplicate* the
/core/phpunit.xml.dist
file to/core/phpunit.xml
-
Edit*
/core/phpunit.xml
and fill in the following variables:- SIMPLETEST_DB:
mysql://drupal:drupal@mariadb:3306/drupal#db
- SIMPLETEST_BASE_URL:
<PROJECT_URL>
- SIMPLETEST_DB:
Configuring PhpStorm#
Set Up Docker#
- In PhpStorm, go to File > Settings > Build, Execution, Deployment > Docker
- Click:
+
- Select:
Docker for Mac
Set Up CLI interpreter#
Add a new CLI interpreter:
- In PhpStorm, go to File > Settings > Languages & Frameworks > PHP
- Click
...
and then+
- Next select: Add a new CLI interpreter from Docker, vagrant...
- Use the following configurations:
- Server:
<DOCKER>
- Configuration file(s):
./docker-compose.yml
- Service:
cli
- Lifecycle:
Connect to existing container ('docker compose exec')
- Server:
- Path mappings:
- Local path:
<ROOT_PATH>
- Remote path*:
/app
- Local path:
Set Up Remote Interpreter#
Add Remote Interpreter:
- In PhpStorm, go to File > Settings > Languages & Frameworks > PHP > Test Frameworks
- Click
+
and selectPHPUnit by Remote Interpreter
- Use the following configurations:
- CLI Interpreter:
<CLI_INTERPRETER>
- Path mappings*:
<PROJECT_ROOT> -> /app
- PHPUnit:
Use Composer autoloader
- Path to script*:
/app/vendor/autoload.php
- Default configuration file*:
/app/web/core/phpunit.xml
- CLI Interpreter:
Setup/Configure Runner Template #
- Configure runner:
- In PhpStorm, go to Run > Edit Configurations... > Templates > PHPUnit
- Use the following configurations:
1. Test scope:
Defined in the configuration file
2. Interpreter:
<CLI_INTERPRETER>
Note
If you are not on a Mac, this may vary.
Final checks#
Some final checks to run before you run a test#
- You have the project up and running:
$ docker compose up -d
- The project is working without any errors, visit the site just to make sure it all works as expected - this is not 100% necessary, but nice to know it is working normally.
- We should be ready to run some tests!
Ready to Run#
Now you have the above configuration set up it should be as straightforward as going to the test you want to run and pressing the green arrow!
Once you press this PhpStorm will use Docker to enter the CLI container, then start running PHPUnit based upon the config.