Skip to content

Instantly share code, notes, and snippets.

Created Mar 18, 2018
What would you like to do?
Experimental setup of Drupal 8 testing for ddev
# This script runs inside the ddev web container and sets up Drupal 8 testing.
# It assumes a regular Drupal 8 checkout, with the docroot in the project root.
# It can be added to the config.yaml as a step to automatically happen on start
# - Run this manually with "ddev exec ./"
# - Run this in the container (after "ddev ssh) by just running "./"
# - Run it automatically run on start by adding it to the project's config.yaml:
# post-start:
# - exec: ./
set -x
set -o errexit
set -o pipefail
set -o nounset
# fontconfig package is required for phantomjs; install it if not already here
# We need bzip to uncompress the tar file.
if ! dpkg -l fontconfig bzip2 >/dev/null 2>&1 ; then
apt-get update && apt-get install -y fontconfig bzip2
# Download the phantomjs package if we don't have it already
if [ ! -f $D8TESTROOT/tmp/phantomjs.tar.bz2 ] ; then
curl -L --output $D8TESTROOT/tmp/phantomjs.tar.bz2
# Unpack phantom
if [ ! -f $PHANTOMROOT/bin/phantomjs ] ; then
tar -jxf $D8TESTROOT/tmp/phantomjs.tar.bz2 --strip-components=1 -C $PHANTOMROOT
# Create a phpunit.xml with the values for this ddev project
awk -v ddev_url=$DDEV_URL '
/env name=.SIMPLETEST_DB/ { sub("value=\"\"", "value=\"mysql://db:db@db/db\"", $0) }
/env name=.SIMPLETEST_BASE_URL/ { sub("value=\"\"", "value=\"" ddev_url "\"", $0) }
{ print $0 }' core/phpunit.xml.dist >core/phpunit.xml
mkdir -p sites/default/simpletest && chmod 777 sites/default/simpletest
# Run phantomjs if it is not already running.
if ! pgrep phantomjs ; then
$PHANTOMROOT/bin/phantomjs vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 >/dev/null 2>&1 &
# At this point you should be able to use "ddev ssh" and run a test like this:
# vendor/bin/phpunit -c core core/modules/datetime/tests/src/Unit/Plugin/migrate/field/DateFieldTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment