Skip to content

Instantly share code, notes, and snippets.

@rfay
Created March 18, 2018 20:42
Show Gist options
  • Save rfay/830442d7ffcb98d541fc7e9f5b73d616 to your computer and use it in GitHub Desktop.
Save rfay/830442d7ffcb98d541fc7e9f5b73d616 to your computer and use it in GitHub Desktop.
Experimental setup of Drupal 8 testing for ddev
#!/bin/bash
# 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 ./d8test_setup.sh"
# - Run this in the container (after "ddev ssh) by just running "./d8test_setup.sh"
# - Run it automatically run on start by adding it to the project's config.yaml:
#hooks:
# post-start:
# - exec: ./d8test_setup.sh
set -x
set -o errexit
set -o pipefail
set -o nounset
PROJROOT=/var/www/html
PHANTOMROOT=$PROJROOT/.d8testsupport/phantomjs
D8TESTROOT=$PROJROOT/.d8testsupport
# 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
fi
# Download the phantomjs package if we don't have it already
mkdir -p $PHANTOMROOT $D8TESTROOT/tmp
if [ ! -f $D8TESTROOT/tmp/phantomjs.tar.bz2 ] ; then
curl -L --output $D8TESTROOT/tmp/phantomjs.tar.bz2 https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
fi
# Unpack phantom
if [ ! -f $PHANTOMROOT/bin/phantomjs ] ; then
tar -jxf $D8TESTROOT/tmp/phantomjs.tar.bz2 --strip-components=1 -C $PHANTOMROOT
fi
# 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 &
fi
# 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