Skip to content

Instantly share code, notes, and snippets.

@segovia94
Last active April 30, 2024 21:59
Show Gist options
  • Save segovia94/271dee02a907e57e0c3559e83dbb7783 to your computer and use it in GitHub Desktop.
Save segovia94/271dee02a907e57e0c3559e83dbb7783 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: drupal10
config:
webroot: web
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://drupal10:drupal10@database/drupal10'
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-download:
service: appserver
description: Download Drupal with Composer.
cmd:
- composer create-project drupal/recommended-project:10.1.5 tmp && cp -r tmp/. . && rm -rf tmp
- composer require drush/drush
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'"
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. Copy this .lando.yml file to the project root and change as needed.

  2. Use Composer to install Drupal core:

$ lando drupal-download
  1. Start the Lando server.
lando start
  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
  1. You can now visit the url created by Lando.
http://drupal.lndo.site/

If you prefered not to do step 4, then use the following database credentials:

database = drupal10
username = drupal10
password = drupal10
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.

@markfullmer
Copy link

Note: the chromedriver command may need to be updated to include allowed-origins:

      command: chromedriver --log-path=/tmp/chromedriver.log --verbose --whitelisted-ips= --allowed-origins=*

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