diff --git a/.lando.yml b/.lando.yml index 6e41f65..8dda550 100644 --- a/.lando.yml +++ b/.lando.yml @@ -8,6 +8,8 @@ recipe: drupal8 # Add some default configuration for the recipe here. Which will be passed to all the services within the recipe. # https://docs.devwithlando.io/recipes/drupal8.html config: + # Set the php version. + php: 7.3 # Set the webroot dir. webroot: web # Enable xdebug using "lando xdebug-on" tooling defined below. diff --git a/README.images/docker-container.png b/README.images/docker-container.png new file mode 100644 index 0000000..76c2c08 Binary files /dev/null and b/README.images/docker-container.png differ diff --git a/README.images/test-framework.png b/README.images/test-framework.png index ba5f58d..45b5e92 100644 Binary files a/README.images/test-framework.png and b/README.images/test-framework.png differ diff --git a/README.md b/README.md index cb6f57b..a07a60b 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ The purpose of this lando "recipe" is to provide an easy setup for Drupal 8 core ## Setup ### To start: -1. Make sure your software stack is installed and up to date: you need [lando](https://github.com/lando/lando/releases), Docker, Chrome and java. +1. Make sure your software stack is installed and up to date: you need an up to date version of [lando](https://github.com/lando/lando/releases), Docker, Chrome and java. 2. Download the the repo to a new empty dir. -3. Run lando start from inside this dir. +3. Start docker and run lando start from inside this dir. ### Run! @@ -30,16 +30,24 @@ NNNB: Sometimes testing becomes very slow. It can help to restart docker, or eve The test output files can be found in various locations under the /files directory. -### Running tests and debugging in PHPStorm: check your PHPStorm debug settings: -- Register Docker so you can register its PHP interpreter: Preferences > Build, Execution, Deployment > Docker ![docker](README.images/docker.png) +### Debugging in PHPStorm: check your PHPStorm debug settings: +- To debug tests run from the command line you only need to provide a php server configuration in PhpStorm. Configure path mappings so PHPStorm knows where you are when debugging. Make sure the server is named 'appserver' and you map the top level path to '/app': Preferences > Languages & Frameworks > PHP > Servers ![server-path-mappings](README.images/server-path-mappings.png) + +Try and enable xdebug ('lando xdebug-on'), enable your debug listener in PHPStorm, setting a breakpoint in a test and running a test. You should now be able to debug your tests. + +NB: Running Docker (for Mac) with a debugger on slows down php quite a bit. Use the tooling provided to quickly switch debugging on/off without restarting your containers: 'lando xdebug-on' and 'lando xdebug-off'. + +### Running tests in PHPStorm: check your PHPStorm debug settings: +- To run tests from the PhpStorm GUI you need to configure a test framework. The test framework needs a CLI interpreter that refers to Docker, so the first thing to do is configure PhpStorm to register Docker: Preferences > Build, Execution, Deployment > Docker ![docker](README.images/docker.png) - Register the CLI PHP interpreter from Docker so you can use its debugger: Preferences > Languages & Frameworks > PHP, then click the '...' button after CLI Interpreter, then add a new From Docker interpreter from the correct Docker image ![cli-interpreters](README.images/cli-interpreters.png) -- Configure the PHP debug settings, especially the max simultaneous connections: Preferences > Languages & Frameworks > PHP > Debug ![debug](README.images/debug.png) -- Configure a server with path mappings so PHPStorm knows where you are when debugging. Make sure the server is named 'appserver' and you map the top level path to '/app': Preferences > Languages & Frameworks > PHP > Servers ![server-path-mappings](README.images/server-path-mappings.png) -- Configure the test framework so PHPStorm can run tests using the PHPStorm GUI (right click a test and select "run"). Add a PHPUnit by Remote Interpreter and choose the Docker interpreter. Make sure you set the config file and bootstrap file using paths that are local to the PHPStorm docker helper container as shown: Preferences > Languages & Frameworks > PHP > Test Frameworks ![test-framework](README.images/test-framework.png) +- Change the default Docker container settings so the network and path mapping correspond to lando's defaults: Preferences > Languages & Frameworks > PHP, then click the folder icon after button after the line "Docker container" ![docker-container](README.images/docker-container.png) +- Configure the test framework so PHPStorm can run tests using the PHPStorm GUI: Preferences > Languages & Frameworks > PHP > Test Frameworks, add a PHPUnit by Remote Interpreter and choose the Docker interpreter. Make sure you set the autoload script, config file and bootstrap file using paths that are local to the PHPStorm docker helper container as shown: ![test-framework](README.images/test-framework.png) In PHPStorm try to right-click a test function and select 'run'. Running tests via the PHPStorm GUI currently only works with Unit and Kernel tests. -Try and enable your debug listener in PHPStorm, setting a breakpoint in a test and running a test (CLI or GUI). You should now be able to debug your tests. +- If you are having trouble getting this to work check the PHP debug settings, especially the max simultaneous connections: Preferences > Languages & Frameworks > PHP > Debug ![debug](README.images/debug.png) + + ### The files in this package do the following: - **.lando.yml**: the lando file that spins up the apache/php/database containers and set some defaults. Here the init.sh script is called after the containers are up. @@ -51,7 +59,6 @@ Try and enable your debug listener in PHPStorm, setting a breakpoint in a test a ## Future imporvements - run functional and fjs tests via PHPStorm GUI -- find out why we cannot use phpunit 7 - export and import PHPStorm settings - enable Test module by default - use Chromedriver without Selenium