Skip to content

Instantly share code, notes, and snippets.

@visabhishek
Forked from segovia94/.lando.yml
Created January 21, 2022 13:47
Show Gist options
  • Save visabhishek/9807d9ca05a5232de62b14b611978a69 to your computer and use it in GitHub Desktop.
Save visabhishek/9807d9ca05a5232de62b14b611978a69 to your computer and use it in GitHub Desktop.
Lando config for running PHPUnit Browser and Javascript tests in Drupal with chromedriver
name: drupal
recipe: drupal9
config:
webroot: .
services:
appserver:
build:
- mkdir -p $LANDO_WEBROOT/sites/simpletest/browser_output
overrides:
environment:
# Support debugging Drush with Xdebug.
#PHP_IDE_CONFIG: "serverName=appserver"
# Allow XDebug with WSL2 on Windows.
#LANDO_HOST_IP: "host.docker.internal"
#XDEBUG_CONFIG: "remote_enable=1 remote_host=host.docker.internal"
# PhpUnit vars.
SIMPLETEST_BASE_URL: 'http://drupal.lndo.site'
SIMPLETEST_DB: 'mysql://drupal9:drupal9@database/drupal9'
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", { "chromeOptions": { "args": [ "disable-gpu", "headless", "no-sandbox" ] } }, "http://chromedriver:9515"]'
BROWSERTEST_OUTPUT_DIRECTORY: /app/sites/simpletest/browser_output
chromedriver:
type: compose
services:
image: drupalci/webdriver-chromedriver:production
# This is the ENTRYPOINT + CMD from the Dockerfile. Empty whitelisted-ips
# param opens the chromedriver port for other hosts.
command: chromedriver --log-path=/tmp/chromedriver.log --verbose --whitelisted-ips=
tooling:
drupal-local-settings:
service: appserver
description: Setup Drupal with local config.
cmd:
# 'cd' is throwing errors so for now we will copy each file to the full directory path.
- FILE=$LANDO_WEBROOT/sites/default/services.local.yml && [ ! -f $FILE ] && wget -O $FILE https://raw.githubusercontent.com/segovia94/drupal-local-settings/master/services.local.yml || echo '$FILE already exist'
- FILE=$LANDO_WEBROOT/sites/default/settings.local.php && [ ! -f $FILE ] && wget -O $FILE https://raw.githubusercontent.com/segovia94/drupal-local-settings/master/settings.local.php || echo '$FILE already exist'
- FILE=$LANDO_WEBROOT/sites/default/settings.php && [ ! -f $FILE ] && wget -O $FILE https://raw.githubusercontent.com/segovia94/drupal-local-settings/master/settings.php || echo "\\\nif \(file_exists\(\$app_root . \'/\' . \$site_path . \'/settings.local.php\'\)\) { \\\n include \$app_root . \'/\' . \$site_path . \'/settings.local.php\'\;\\\n}" >> $FILE
- "echo 'Your local Drupal config is setup'"
user: root
drupal-install:
service: appserver
description: Install Drupal
cmd:
- APP=$LANDO_APP_NAME && drush si standard --account-pass=admin --account-name=admin --site-name=$APP
- drush uli --uri=http://drupal.lndo.site
xdebug-on:
service: appserver
description: Enable xdebug for apache.
cmd: "docker-php-ext-enable xdebug && /etc/init.d/apache2 reload"
user: root
xdebug-off:
service: appserver
description: Disable xdebug for apache.
cmd: "rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && /etc/init.d/apache2 reload"
user: root
phpunit:
service: appserver
description: Run PHPUnit tests including browser and javascript tests
cmd: "/app/vendor/bin/phpunit -c /app/core/phpunit.xml.dist"
# Ensure that drush uses the domain name and drupal root directory.
drush:
service: appserver
cmd: drush --root=/app --uri=http://drupal.lndo.site

Drupal Core and Contrib Local Setup with Lando

Lando needs to be installed as a prerequisite.

  1. Clone Drupal core:
git clone https://git.drupalcode.org/project/drupal.git .
  1. Copy this .lando.yml file to the project root and change as needed. Start lando.
lando start
  1. Install Drupal module and php package dependencies with Composer
lando composer install
  1. (Optional) Setup all the local settings files and database connection. (Be aware that this will disable caching and turn on twig debugging).
lando drupal-local-settings

If you prefer not to do this step then use the following database credentials:

database = drupal9
username = drupal9
password = drupal9
host = database
port = 3306

How to run Tests

Run tests

lando phpunit modules/contrib/

or run a group of tests tagged with an @group. Ex. @group ckeditor

lando phpunit --group ckeditor

Credits

The testing setup came from https://gist.github.com/mikeshiyan/a91b6aadcf76734dfad08dd5811119de and it has extra config for doing Nightwatch tests if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment