Skip to content

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#

  1. Duplicate* the /core/phpunit.xml.dist file to /core/phpunit.xml
  2. Edit* /core/phpunit.xml and fill in the following variables:

  3. SIMPLETEST_DB: mysql://drupal:drupal@mariadb:3306/drupal#db

  4. SIMPLETEST_BASE_URL: <PROJECT_URL>

Configuring PhpStorm#

Set Up Docker#

  1. In PhpStorm, go to File > Settings > Build, Execution, Deployment > Docker
  2. Click: +
  3. Select: Docker for Mac

Set Up Docker

Set Up CLI interpreter#

Add a new CLI interpreter:

  1. In PhpStorm, go to File > Settings > Languages & Frameworks > PHP
  2. Click ... and then +
  3. Next select: Add a new CLI interpreter from Docker, vagrant...
  4. Use the following configurations:
  5. Server: <DOCKER>
  6. Configuration file(s): ./docker-compose.yml
  7. Service: cli
  8. Lifecycle: Connect to existing container ('docker compose exec')
  9. Path mappings:
  10. Local path: <ROOT_PATH>
  11. Remote path*: /app

Add a new CLI interpreter:

Set Up Remote Interpreter#

Add Remote Interpreter:

  1. In PhpStorm, go to File > Settings > Languages & Frameworks > PHP > Test Frameworks
  2. Click + and select PHPUnit by Remote Interpreter
  3. Use the following configurations:
  4. CLI Interpreter: <CLI_INTERPRETER>
  5. Path mappings*: <PROJECT_ROOT> -> /app
  6. PHPUnit: Use Composer autoloader
  7. Path to script*: /app/vendor/autoload.php
  8. Default configuration file*: /app/web/core/phpunit.xml

Add Remote Interpreter

Setup/Configure Runner Template #

  1. Configure runner:
  2. In PhpStorm, go to Run > Edit Configurations... > Templates > PHPUnit
  3. Use the following configurations:

    1. Test scope: Defined in the configuration file

    2. Interpreter: <CLI_INTERPRETER>

Configure runner

Note

If you are not on a Mac, this may vary.

Final checks#

Some final checks to run before you run a test#

  1. You have the project up and running: $ docker compose up -d
  2. 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.
  3. 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.

Here it is in action, look at it go!!